-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix number bases other than 10 #90
base: master
Are you sure you want to change the base?
Conversation
Currently the magic number is detected but the wrong value is shown This converts the number back to what the user is expecting eg 015 used to show Magic Number 12
src/Visitor/DetectorVisitor.php
Outdated
$scalar instanceof LNumber && | ||
$scalar->getAttribute('kind') != LNumber::KIND_DEC | ||
)) { | ||
$scalar->value = (int) base_convert( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this case we are loosing base prefix (0 or 0b). Now dec 10 and binary 10 is displayed in the same way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would like more tests regarding this.
tests/files/test_1.php
Outdated
@@ -12,7 +12,7 @@ class TEST_1 | |||
|
|||
public function test($input = 4) { | |||
if ($input > 2) { | |||
return 15; | |||
return 015; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test should fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You think it should return 015 not 15 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well if we a respecting base than yes. Also if we want to ignore number 0b10 but not dec 10 would it work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are 2 separate numbers 0b10 would be ignored if you had 2 in the ignore list currently. so 0x2, 02, 2 and 0b1 would all be ignored by 2.. To get this to return like that we would need to add octal, hex and binary to the cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You won't be able to tell the difference between 0755 and 0o755 with this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change definitely needs more tests.
@sidz just updated this one too, shows 0755 as 0o755 now rather than 493 |
Hey @kubawerlos. |
Currently the magic number is detected but the wrong value is shown
This converts the number back to what the user is expecting
eg 015 used to show Magic Number 12