Skip to content

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

Closed
wants to merge 7 commits into from
Closed

MethodGenerator::fromArray() add config keys #107

wants to merge 7 commits into from

Conversation

WinterSilence
Copy link
Contributor

Q A
Documentation yes
Bugfix no
BC Break no
New Feature no
RFC no
QA no

Description

Add keys 'returntype'/setReturnType() and 'returnsreference'/setReturnsReference() to array passed in MethodGenerator::fromArray().

Add  keys `'returntype'/setReturnType()` and  `'returnsreference'/setReturnsReference()`.
Copy link
Member

@Ocramius Ocramius left a 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?

@WinterSilence
Copy link
Contributor Author

@Ocramius ok, tomorrow.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@WinterSilence
Copy link
Contributor Author

WinterSilence commented Sep 24, 2021

@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);
Copy link
Member

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

Copy link
Contributor

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 = [
Copy link
Member

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;
Copy link
Member

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);
Copy link
Member

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

@Ocramius Ocramius added this to the 4.5.0 milestone Sep 26, 2021
@Brammm
Copy link
Contributor

Brammm commented Dec 6, 2021

Is there something I can help with to get this PR through, @WinterSilence?

@Brammm
Copy link
Contributor

Brammm commented Dec 6, 2021

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.

@WinterSilence
Copy link
Contributor Author

WinterSilence commented Dec 6, 2021

@Brammm PR sended 2 months ago... now, I don't care anymore

@Ocramius Ocramius added the Duplicate This issue or pull request already exists label Dec 7, 2021
@Ocramius Ocramius removed this from the 4.5.0 milestone Dec 7, 2021
@Ocramius Ocramius removed the Duplicate This issue or pull request already exists label Dec 7, 2021
@Ocramius Ocramius added this to the 4.5.0 milestone Dec 7, 2021
@Ocramius Ocramius added Duplicate This issue or pull request already exists and removed Awaiting Author Updates labels Dec 7, 2021
@Ocramius Ocramius self-assigned this Dec 7, 2021
@Ocramius
Copy link
Member

Ocramius commented Dec 7, 2021

Merged via #121

@WinterSilence WinterSilence deleted the patch-1 branch December 7, 2021 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate This issue or pull request already exists Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants