-
Notifications
You must be signed in to change notification settings - Fork 89
ReflectionBasedAbstractFactory should not be expected to instantiate private constructors #268
ReflectionBasedAbstractFactory should not be expected to instantiate private constructors #268
Conversation
@@ -1,7 +1,7 @@ | |||
<?php | |||
/** | |||
* @link http://github.com/zendframework/zend-servicemanager for the canonical source repository | |||
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) | |||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com) |
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.
Year range: 2016-2018
@@ -135,10 +135,27 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o | |||
|
|||
/** | |||
* {@inheritDoc} | |||
* @throws \ReflectionException |
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.
Hm... I know it could be thrown, but I don't think we should have it here.
|
||
/** | ||
* @param string $requestedName | ||
* @return bool |
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.
Definitely we don't need two above doc-block comments, as these are duplicated with method signature.
The third one, yes, it's possible but as it is not throw explicitly I would remove it as well.
@@ -1,7 +1,7 @@ | |||
<?php | |||
/** | |||
* @link http://github.com/zendframework/zend-servicemanager for the canonical source repository | |||
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) | |||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com) |
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.
Year range, please.
@@ -17,6 +17,8 @@ | |||
|
|||
class ReflectionBasedAbstractFactoryTest extends TestCase | |||
{ | |||
private $container; |
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.
Please add docblock:
/** @var ContainerInterface|ObjectProphecy $container */
@@ -38,6 +40,20 @@ public function testCanCreateReturnsFalseForNonClassRequestedNames($requestedNam | |||
self::assertFalse($factory->canCreate($this->container->reveal(), $requestedName)); | |||
} | |||
|
|||
/** | |||
* @throws \ReflectionException |
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 point of having it here.
5d1b0aa
to
9e33889
Compare
@webimpress thanks for review! updated |
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.
👍
return true; | ||
} | ||
|
||
return $constructor->isPublic(); |
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.
Could these be boiled down to:
return $constructor === null || $constructor->isPublic();
?
@@ -38,6 +42,17 @@ public function testCanCreateReturnsFalseForNonClassRequestedNames($requestedNam | |||
self::assertFalse($factory->canCreate($this->container->reveal(), $requestedName)); | |||
} | |||
|
|||
public function testCanCreateReturnsFalseWhenConstructorIsPrivate() : void |
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 also looks like the new method would return true if no constructor is defined, correct? If so, that deserves its own test case.
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.
Correct; test case added
Can this be merged now @weierophinney |
Um... Bugfixes target **master**, features/improvements target develop; can
you clarify what you meant please, @Ocramius?
…On Fri, Dec 14, 2018, 6:39 AM Marco Pivetta ***@***.*** wrote:
@GeeH <https://github.com/GeeH> @asgrim <https://github.com/asgrim> we
need this to re-target develop, since it is a bug fix
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#268 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABlVxGhQyAss6hGv6NwxJpkcIGpaCnJks5u45vygaJpZM4T2hee>
.
|
|
…private constructors
3026296
to
3378c43
Compare
I noticed that when using the
ReflectionBasedAbstractFactory
, it chokes when classes withprivate
constructors are used. These types of classes should be ignored from the start, so I've updatedcanCreate
to returnfalse
where any class has aprivate
constructor.