beberlei / assert

Thin assertion library for use in libraries and business-model
Other
2.41k stars 188 forks source link

add assertion that a constant is defined. #193

Closed abacaphiliac closed 7 years ago

abacaphiliac commented 7 years ago

as a simple example:

20:50 $ php -r "echo NOT_A_CONSTANT;"
PHP Notice:  Use of undefined constant NOT_A_CONSTANT - assumed 'NOT_A_CONSTANT' in Command line code on line 1
PHP Stack trace:
PHP   1. {main}() Command line code:0

Notice: Use of undefined constant NOT_A_CONSTANT - assumed 'NOT_A_CONSTANT' in Command line code on line 1

Call Stack:
    0.0001     218768   1. {main}() Command line code:0

NOT_A_CONSTANT

this assertion will allow us to ensure that a constant is defined before attempting to use it which can cause php to make an assumption, generate a notice, and do something unexpected.

what do you think?

rquadling commented 7 years ago

Can you adjust the code such that return true; is the last line. See how the other assertions are written.

abacaphiliac commented 7 years ago

sure, no problem.

abacaphiliac commented 7 years ago

@rquadling fixed and squashed.

rquadling commented 7 years ago

I suppose a Assertion::notDefined() would match the pairing. Not sure how useful that would be though.

abacaphiliac commented 7 years ago

@rquadling i defer to your judgement. i'm happy to add it now if you think it will provide value : )

abacaphiliac commented 7 years ago

hi @rquadling, sorry to bother. do you have any more feedback for me?