-
Notifications
You must be signed in to change notification settings - Fork 73
Conversation
According to @MarkRedeman, only methods should be mutated right now and function support is pending. `$inMethod` was set to `true` for functions as well, because it didn't check whether it's inside a class.
Output changed in symfony/console@324d1c1.
A bad method call is an exception starting with PHP 7, not a fatal error anymore.
This fixes tests on PHP 5.5, 5.6 and 7. |
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.
Thanks for the contribution @kelunik and sorry for the late answer. Would you mind to add a test fore it? (that a function is not mutated)
@@ -23,7 +23,7 @@ Feature: Use Humbug | |||
$foo = new Foo; | |||
$r = $foo->add(2, 1); | |||
// emulate error | |||
if ($r !== 3) $foo->bar(); | |||
if ($r !== 3) require __DIR__ . "/this.does.not.exist.xyz"; |
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.
let's go with single quotes
src/Mutable.php
Outdated
@@ -146,7 +146,7 @@ public function generate() | |||
} | |||
|
|||
//TODO: handle whitespace! | |||
if (is_array($token) && $token[0] == T_FUNCTION) { | |||
if (is_array($token) && $token[0] == T_FUNCTION && $className !== '???') { |
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.
is_array($token) && $token[0] === T_FUNCTION && '???' !== $className
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.
Why Yoda comparison? It's not consistently used and decreases readability IMO.
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.
To avoid things like $token[0] = T_FUNCTION
. We could argue about having assignments in a function call or if condition, but it's sometimes used. Yoda condition in those cases prevent those mistakes
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.
It's a potential mistake I probably never made. It's not worth the readability tradeoff IMO.
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 thought the same before making it once :) Also I don't think the tradeoff is that bad.
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.
We wouldn't need yoda if languages implemented assignment as :=
.
According to @MarkRedeman, only methods should be mutated right now and
function support is pending.
$inMethod
was set totrue
for functionsas well, because it didn't check whether it's inside a class.