You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?php
if ( 'cli' !== PHP_SAPI ) { // THIS LINE
throw new \Exception('only from CLI');
}
echo 'hi';
We check if the current system state is something that we can work with. In general we reject everything except the one working thing which is an assertion IMHO.
This wouldn't be reported:
<?php
if ( 'cli' === PHP_SAPI ) {
echo 'hi';
} else {
throw new \Exception('CLI!');
}
Which makes the code unreadable if you think of 4-5 paths which are then nested damn deep.
Also PHPMD may nag about the "else" and the linux kernel standards says
Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program.
So please tell me how we can avoid the first expression to be marked as an "assumption".
The text was updated successfully, but these errors were encountered:
There's currently no way to exclude this. This tool is also not in active development. But feel free to create a PR with a proposal and we can look into implementing it.
I would also argue that it shouldn't be a goal to have php-assumptions report 0 warnings. There are always edge-cases.
@ScreamingDev I'm not too sure whether I considered that. I may have gone down this path to learn more about how to write a static analyser. If you can somehow turn it into a rule that would be awesome of course.
This would be reported:
We check if the current system state is something that we can work with. In general we reject everything except the one working thing which is an assertion IMHO.
This wouldn't be reported:
Which makes the code unreadable if you think of 4-5 paths which are then nested damn deep.
Also PHPMD may nag about the "else" and the linux kernel standards says
So please tell me how we can avoid the first expression to be marked as an "assumption".
The text was updated successfully, but these errors were encountered: