Add ConstantScanner to Zend\Code\Scanner #4465

Closed
wants to merge 6 commits into
from

Projects

None yet

2 participants

@MatyCZ
Contributor
MatyCZ commented May 13, 2013

Fix bug introduced in #4457 and add some new features.

  • Can parse constants of type float, number or string
  • Can parse constants with docblock on previous line
  • Can parse constants with self:: reference
  • Added has* methods for constant and property
  • Updated docblocks

There is one BC break. Method getConstants() don't return constant names now, but return instance of ConstantScanner.

@weierophinney weierophinney commented on an outdated diff May 23, 2013
library/Zend/Code/Scanner/ClassScanner.php
@@ -262,7 +290,89 @@ public function getConstants()
}
/**
- * Returns a list of property names
+ * Return a list of constants
+ *
+ * @return ConstantScanner[]
+ */
+ public function getConstants()
@weierophinney
weierophinney May 23, 2013 Member

This is definitely a BC break, and we can't do that.

I'd argue instead for the following:

  • have an optional flag argument to getConstants(), $namesOnly, that defaults to true.
  • When $namesOnly is true, it will proxy to getConstantNames(). Additionally, raise an E_USER_DEPRECATED error, so that developers know they should alter their code to use getConstantNames() if they want the original behavior.
  • when the flag is false, do the new behavior.

This will allow developers to opt-in to the new behavior, and give us a migration path.

@MatyCZ
Contributor
MatyCZ commented May 27, 2013

@weierophinney Addition of E_USER_DEPRECATED breaks tests. It's OK or I must change it to E_USER_NOTICE with same message?

@weierophinney
Member

@MatyCZ alter the tests to check for the error as well as the behavior.

@weierophinney weierophinney added a commit that referenced this pull request Jun 11, 2013
@weierophinney weierophinney [#4465] Fixed test to identify error raised
- Add error handler, and verify E_USER_DEPRECATED was raised
- Ensure name of constant is correct case
71bf129
@weierophinney weierophinney added a commit that referenced this pull request Jun 11, 2013
@weierophinney weierophinney Merge branch 'hotfix/4465' into develop
Forward port #4465
6d01ad2
@weierophinney weierophinney added a commit that closed this pull request Jun 11, 2013
@weierophinney weierophinney Merge branch 'hotfix/4465'
Close #4465
bb5ec1d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment