-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyInfo] Made ReflectionExtractor's prefix lists instance variables #22696
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
[PropertyInfo] Made ReflectionExtractor's prefix lists instance variables #22696
Conversation
👍 |
I don't think the failing test on Travis is related to this changeset in any way. |
I don't think it's a good idea to allow this kind of global configuration. All instances will be impacted by this overriding. |
Fair enough! I'll be working on this. |
@nicolas-grekas Does this look good to you? I left the static properties untouched (apart from their name) because they are referenced in |
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.
ping @dunglas for "domain" review
@@ -137,7 +137,7 @@ public function getTypes($class, $property, array $context = array()) | |||
return; | |||
} | |||
|
|||
if (!in_array($prefix, ReflectionExtractor::$arrayMutatorPrefixes)) { | |||
if (!in_array($prefix, ReflectionExtractor::$defaultArrayMutatorPrefixes)) { |
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 guess this also should be turned into $this->arrayMutatorPrefixes
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.
No can do, this is the other class, cf. my last reply
Edit: or do you mean these should be instance properties in PhpDocExtractor
as well?
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 mean your edit yes: if ReflectionExtractor needs this, why shouldn't PhpDocExtractor also?
But note that I'd suggest to wait for some feedback from @dunglas before spending more time on code here, just to not waste yours :)
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.
Duly noted. Do you think default values for these instance properties should come from ReflectionExtractor::$default*Prefix
?
@@ -217,7 +217,10 @@ private function getDocBlockFromProperty($class, $property) | |||
*/ | |||
private function getDocBlockFromMethod($class, $ucFirstProperty, $type) | |||
{ | |||
$prefixes = $type === self::ACCESSOR ? ReflectionExtractor::$accessorPrefixes : ReflectionExtractor::$mutatorPrefixes; | |||
$prefixes = $type === self::ACCESSOR |
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.
using $this also here
please revert the code style change
* | ||
* @return self | ||
*/ | ||
public function setMutatorPrefixes(array $mutatorPrefixes) |
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 not passing those values in the constructor to make this class immutable?
@nicolas-grekas @dunglas Is that better? |
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.
a few test cases and might be good :)
{ | ||
$this->docBlockFactory = $docBlockFactory ?: DocBlockFactory::createInstance(); | ||
$this->contextFactory = new ContextFactory(); | ||
$this->phpDocTypeHelper = new PhpDocTypeHelper(); | ||
$this->mutatorPrefixes = $mutatorPrefixes ?: ReflectionExtractor::$defaultMutatorPrefixes; |
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 think we should allow empty arrays, which means we should compare with null here
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.
Good point
* @param string[] $accessorPrefixes | ||
* @param string[] $arrayMutatorPrefixes | ||
*/ | ||
public function __construct(array $mutatorPrefixes = array(), array $accessorPrefixes = array(), array $arrayMutatorPrefixes = array()) |
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.
same: null as default, then compare with null below
/** | ||
* @return string[] | ||
*/ | ||
public function getMutatorPrefixes() |
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.
not sure we need any accessor, do we?
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.
No, actually we don't
@nicolas-grekas There you go ;) |
{ | ||
$this->docBlockFactory = $docBlockFactory ?: DocBlockFactory::createInstance(); | ||
$this->contextFactory = new ContextFactory(); | ||
$this->phpDocTypeHelper = new PhpDocTypeHelper(); | ||
$this->mutatorPrefixes = $mutatorPrefixes !== null ? $mutatorPrefixes : ReflectionExtractor::$defaultMutatorPrefixes; |
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.
yoda everywhere: null !== ...
|
||
if (preg_match('/^('.$pattern.')(.+)$/i', $methodName, $matches)) { | ||
if (!in_array($matches[1], self::$arrayMutatorPrefixes)) { | ||
if (!empty($pattern) && preg_match('/^('.$pattern.')(.+)$/i', $methodName, $matches)) { |
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.
'' !== ...
Once again, the CI results are beyond me. |
@nicolas-grekas @dunglas Just fixed conflicts that occurred since the last merges on |
this should be rebased on 3.4 in fact (I already changed the base branch) |
@nicolas-grekas Alright, done! |
|
||
/** | ||
* @param DocBlockFactoryInterface $docBlockFactory | ||
* @param string[] $mutatorPrefixes |
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.
string[]|null
in fact
@@ -53,11 +53,35 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property | |||
*/ | |||
private $phpDocTypeHelper; | |||
|
|||
public function __construct(DocBlockFactoryInterface $docBlockFactory = null) | |||
/** | |||
* @var string[] |
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.
docblocks are actually not needed when private properties are initialised in the constructor
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 were present for existing properties, so I added them for consistency's sake.
|
…bles This allows for easier, instance-specific overriding of said values.
@xabbuh Thanks for the feedback, I took it into account. |
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.
👍
@dunglas Is that OK for you? :) |
Thank you @neemzy. |
… instance variables (neemzy) This PR was merged into the 3.4 branch. Discussion ---------- [PropertyInfo] Made ReflectionExtractor's prefix lists instance variables | Q | A | ------------- | --- | Branch? | `3.4` | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT This PR makes `ReflectionExtractor`'s mutator/accessor prefixes instance variables in order to be able to override them to change its behavior. Commits ------- 58e733b [PropertyInfo] Made ReflectionExtractor's prefix lists instance variables
3.4
This PR makes
ReflectionExtractor
's mutator/accessor prefixes instance variables in order to be able to override them to change its behavior.