Skip to content
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

Merged
merged 1 commit into from Jun 7, 2017

Conversation

@neemzy
Copy link
Contributor

commented May 12, 2017

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.

@Gregoire-M

This comment has been minimized.

Copy link

commented May 12, 2017

👍

@neemzy

This comment has been minimized.

Copy link
Contributor Author

commented May 12, 2017

I don't think the failing test on Travis is related to this changeset in any way.

@nicolas-grekas nicolas-grekas added this to the 2.8 milestone May 15, 2017

@nicolas-grekas

This comment has been minimized.

Copy link
Member

commented May 15, 2017

I don't think it's a good idea to allow this kind of global configuration. All instances will be impacted by this overriding.
Instead, what about turning these into regular properties?
This should be done on master as a new feature btw.

@neemzy

This comment has been minimized.

Copy link
Contributor Author

commented May 15, 2017

Fair enough! I'll be working on this.

@neemzy neemzy changed the base branch from 2.8 to master May 15, 2017

@neemzy

This comment has been minimized.

Copy link
Contributor Author

commented May 15, 2017

@nicolas-grekas Does this look good to you? I left the static properties untouched (apart from their name) because they are referenced in PhpDocExtractor.

@neemzy neemzy changed the title [PropertyInfo] Fixed static property references in ReflectionExtractor [PropertyInfo] Made ReflectionExtractor's prefix lists instance variables May 15, 2017

@nicolas-grekas
Copy link
Member

left a comment

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)) {

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas May 15, 2017

Member

I guess this also should be turned into $this->arrayMutatorPrefixes

This comment has been minimized.

Copy link
@neemzy

neemzy May 15, 2017

Author Contributor

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?

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas May 15, 2017

Member

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 :)

This comment has been minimized.

Copy link
@neemzy

neemzy May 15, 2017

Author Contributor

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

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas May 15, 2017

Member

using $this also here
please revert the code style change

@nicolas-grekas nicolas-grekas modified the milestones: 3.4, 2.8 May 15, 2017

*
* @return self
*/
public function setMutatorPrefixes(array $mutatorPrefixes)

This comment has been minimized.

Copy link
@dunglas

dunglas May 15, 2017

Member

Why not passing those values in the constructor to make this class immutable?

@neemzy

This comment has been minimized.

Copy link
Contributor Author

commented May 16, 2017

@nicolas-grekas @dunglas Is that better?

@nicolas-grekas
Copy link
Member

left a comment

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;

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas May 16, 2017

Member

I think we should allow empty arrays, which means we should compare with null here

This comment has been minimized.

Copy link
@neemzy

neemzy May 16, 2017

Author Contributor

Good point

* @param string[] $accessorPrefixes
* @param string[] $arrayMutatorPrefixes
*/
public function __construct(array $mutatorPrefixes = array(), array $accessorPrefixes = array(), array $arrayMutatorPrefixes = array())

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas May 16, 2017

Member

same: null as default, then compare with null below

/**
* @return string[]
*/
public function getMutatorPrefixes()

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas May 16, 2017

Member

not sure we need any accessor, do we?

This comment has been minimized.

Copy link
@neemzy

neemzy May 16, 2017

Author Contributor

No, actually we don't

@neemzy

This comment has been minimized.

Copy link
Contributor Author

commented May 16, 2017

@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;

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas May 16, 2017

Member

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)) {

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas May 16, 2017

Member

'' !== ...

@neemzy

This comment has been minimized.

Copy link
Contributor Author

commented May 16, 2017

Once again, the CI results are beyond me.

@neemzy

This comment has been minimized.

Copy link
Contributor Author

commented May 22, 2017

@nicolas-grekas @dunglas Just fixed conflicts that occurred since the last merges on master. May I request a moment of your time to review this changeset for what I reckon will be the last time? :)

@nicolas-grekas nicolas-grekas changed the base branch from master to 3.4 May 22, 2017

@nicolas-grekas

This comment has been minimized.

Copy link
Member

commented May 22, 2017

this should be rebased on 3.4 in fact (I already changed the base branch)

@neemzy

This comment has been minimized.

Copy link
Contributor Author

commented May 22, 2017

@nicolas-grekas Alright, done!

/**
* @param DocBlockFactoryInterface $docBlockFactory
* @param string[] $mutatorPrefixes

This comment has been minimized.

Copy link
@xabbuh

xabbuh May 27, 2017

Member

string[]|null in fact

@@ -53,11 +53,35 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
*/
private $phpDocTypeHelper;
public function __construct(DocBlockFactoryInterface $docBlockFactory = null)
/**
* @var string[]

This comment has been minimized.

Copy link
@xabbuh

xabbuh May 27, 2017

Member

docblocks are actually not needed when private properties are initialised in the constructor

This comment has been minimized.

Copy link
@neemzy

neemzy May 29, 2017

Author Contributor

They were present for existing properties, so I added them for consistency's sake.

@xabbuh

This comment has been minimized.

Copy link
Member

commented May 27, 2017

PhpDocExtractor tests should probably be updated too.

[PropertyInfo] Made ReflectionExtractor's prefix lists instance varia…
…bles

This allows for easier, instance-specific overriding of said values.
@neemzy

This comment has been minimized.

Copy link
Contributor Author

commented May 29, 2017

@xabbuh Thanks for the feedback, I took it into account.
@nicolas-grekas @dunglas Anything left to do in your opinion?

@nicolas-grekas
Copy link
Member

left a comment

👍

@xabbuh
xabbuh approved these changes May 29, 2017
@neemzy

This comment has been minimized.

Copy link
Contributor Author

commented May 31, 2017

@dunglas Is that OK for you? :)

@dunglas
dunglas approved these changes Jun 7, 2017
@fabpot

This comment has been minimized.

Copy link
Member

commented Jun 7, 2017

Thank you @neemzy.

@fabpot fabpot merged commit 58e733b into symfony:3.4 Jun 7, 2017

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details
fabpot added a commit that referenced this pull request Jun 7, 2017
feature #22696 [PropertyInfo] Made ReflectionExtractor's prefix lists…
… 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

@neemzy neemzy deleted the neemzy:allow-reflection-extractor-extension branch Jun 9, 2017

This was referenced Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.