phpmnd icon indicating copy to clipboard operation
phpmnd copied to clipboard

Check for named constants

Open exussum12 opened this issue 6 years ago • 7 comments

Eg remove $six = 6

or $week = 7

These sorts of numbers are still magic, fixes #83

exussum12 avatar Jan 28 '19 06:01 exussum12

Not sure why appveyor is complaining. Will take a look later. Passes travis

exussum12 avatar Jan 28 '19 12:01 exussum12

This should be multilingual now.

exussum12 avatar Apr 09 '19 07:04 exussum12

Is the complexity really worth the benefit? I mean, you can still call your constant WHATEVER and the tool won't complain. You can still do const FIRST_COLOUR=1 and it'll pass fine. I don't think this tool can ever replace thorough code review, it can help, by ensuring there are constants for everything, but IMO deciding if the name of the constant is meaningful enough cannot be really automated.

ramonacat avatar Apr 09 '19 11:04 ramonacat

I don't think this tool can ever replace thorough code review, it can help, by ensuring there are constants for everything

Completely agree. Since using this Ive seen more and more bad constant naming. That can not be prevented but the main cases I have seen, this will prevent that.

To be clear this check is not enabled by default, so its only if you want the additional level of checking.

FIRST_COLOUR=1 may be fine, because FIRST_COLOUR=2 may also be valid.

SIX=6 is never valid.

exussum12 avatar Apr 09 '19 11:04 exussum12

@sidz thoughts on getting this in soon ? It will solve lots of magic constants. I don't think it should be Included in all but as a separate flag to not suddenly include lots of magic numbers

exussum12 avatar Dec 12 '21 20:12 exussum12

As an idea it's ok for me so far. But we need to rebase this PR against latest master and fix all conflicts first.

sidz avatar Dec 12 '21 21:12 sidz

Yeah was just checking that before I did that work. I'll sort the conflicts this week

exussum12 avatar Dec 12 '21 21:12 exussum12