-
-
Notifications
You must be signed in to change notification settings - Fork 83
MethodGenerator::fromArray() add config keys #107
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
Conversation
Add keys `'returntype'/setReturnType()` and `'returnsreference'/setReturnsReference()`.
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.
Hey @WinterSilence, could you please add a test for the 'returnsreference'
scenario?
@Ocramius ok, tomorrow. |
@Ocramius fixed but something wrong in code style, can you help? |
@@ -170,6 +172,8 @@ public static function fromArray(array $array) | |||
case 'returntype': | |||
$method->setReturnType($value); | |||
break; | |||
case 'returnsreference': | |||
$method->setReturnsReference($value); |
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 need a (bool)
cast here.
Alternatively, we can declare @param array<...>
with more specific types, but that will likely open another rabbit hole
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.
How about the existing methods, like setBody, setVisibility (string) or setAbstract, setFinal, setInterface, setStatic (bools)? Should those get relevant type casts as well?
@@ -283,7 +283,7 @@ public function testDefaultValueGenerationDoesNotIncludeTrailingSemicolon() | |||
|
|||
public function testCreateFromArray() | |||
{ | |||
$methodGenerator = MethodGenerator::fromArray([ | |||
$config = [ |
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.
Run a vendor/bin/phpcbf
and it should fix any issues around this :)
@@ -305,6 +306,11 @@ public function testCreateFromArray() | |||
self::assertSame(MethodGenerator::VISIBILITY_PROTECTED, $methodGenerator->getVisibility()); | |||
self::assertInstanceOf(TypeGenerator::class, $methodGenerator->getReturnType()); | |||
self::assertSame('\\SampleType', $methodGenerator->getReturnType()->generate()); | |||
self::assertFalse($methodGenerator->isReturnsReference()); | |||
|
|||
$config['returnsreference'] = true; |
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.
IMO, we should have a separate (new) test method to verify this one
self::assertFalse($methodGenerator->isReturnsReference()); | ||
|
||
$config['returnsreference'] = true; | ||
$methodGenerator = MethodGenerator::fromArray($config); |
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.
Also here, vendor/bin/phpcbf
will fix most issues
Is there something I can help with to get this PR through, @WinterSilence? |
I've addressed @Ocramius' comments in this branch (I think): https://github.com/Brammm-forks/laminas-code/tree/patch-1 I can open a new PR or they can be merged into this one, I guess. Whatever is fine with me. |
@Brammm PR sended 2 months ago... now, I don't care anymore |
Merged via #121 |
Description
Add keys
'returntype'/setReturnType()
and'returnsreference'/setReturnsReference()
to array passed inMethodGenerator::fromArray()
.