Repository navigation
Handle nullable types #30
Changes from all commits
b55edca
f1a1103
1e35af6
9cdbb55
3802751
b360d76
ba1faad
59fdcc0
3fdd90c
c4ac768
878baf4
739cddd
309adda
cbf870f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -205,8 +205,17 @@ private function addParametersAndGetArgs(array $freeVariables, $methodBuilder, S | |
| $variableType = $freeVariable->symbolContext()->type(); | ||
|
|
||
| if ($variableType->isDefined()) { | ||
| $parameterBuilder->type($variableType->short()); | ||
| // TODO Create a utils class or something to get the shortest type by taking | ||
| // into account the import table, to handle aliases and partial namespaces | ||
| $shortTypeAsString = ($variableType->isNullable() ? '?' : '') . $variableType->short(); | ||
|
|
||
| $parameterBuilder->type($shortTypeAsString); | ||
| if ($variableType->isClass()) { | ||
| // TODO Remove this ? | ||
| // We should not have to import it, we are extracting the | ||
| // method into the same file. We should not try to fix an | ||
| // oversight from the user, espacially since he might want | ||
| // to keep his partial qualified name | ||
| $builder->use((string) $variableType); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to import it -- f.e.
Can we change the comment to reflect that? We need to fix the whole qualfiied name issue, but it's a separate thing :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the delay to respond, I needed to take care of some other stuff and I don't have a lot of time left. I'm not sure to see the case you're talking about. So I understand that we can try, just in case there is only one possibility. If you still want to use the import I will change the comment for the one you proposed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is not true (I previously fell for this) -- if you call a method on an imported class, that method can return a type not in the current scope and you will therefore need to import it if it's a parameter of the extracted mehtod. |
||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ class extractMethod | |
| if ($foobar) { | ||
| return 'yes'; | ||
| } | ||
|
|
||
| return 'no'; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ class extractMethod | |
| if ($foobar) { | ||
| return $barfoo; | ||
| } | ||
|
|
||
| return 'no'; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ class extractMethod | |
| if ($foobar) { | ||
| return 'yes'; | ||
| } | ||
|
|
||
| return $foobar; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // File: source | ||
| <?php | ||
|
|
||
| namespace Test\Foo; | ||
|
|
||
| class Bar | ||
| { | ||
| public function baz(?string $s) | ||
| { | ||
| <>$foobar = $s.'hello';<> | ||
| } | ||
| } | ||
| // File: expected | ||
| <?php | ||
|
|
||
| namespace Test\Foo; | ||
|
|
||
| class Bar | ||
| { | ||
| public function baz(?string $s) | ||
| { | ||
| $this->newMethod($s); | ||
| } | ||
|
|
||
| private function newMethod(?string $s) | ||
| { | ||
| $foobar = $s.'hello'; | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // File: source | ||
| <?php | ||
|
|
||
| namespace Test\Foo; | ||
|
|
||
| class Bar | ||
| { | ||
| pr<>ivate ?string $baz; | ||
| } | ||
| // File: expected | ||
| <?php | ||
|
|
||
| namespace Test\Foo; | ||
|
|
||
| class Bar | ||
| { | ||
| private ?string $baz; | ||
|
|
||
| public function baz(): ?string | ||
| { | ||
| return $this->baz; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // File: source | ||
| <?php | ||
|
|
||
| namespace Test\Foo; | ||
|
|
||
| class Bar | ||
| { | ||
| public function baz(?int $i): string | ||
| { | ||
| $this->f<>oo($i); | ||
| } | ||
| } | ||
| // File: expected | ||
| <?php | ||
|
|
||
| namespace Test\Foo; | ||
|
|
||
| class Bar | ||
| { | ||
| public function baz(?int $i): string | ||
| { | ||
| $this->foo($i); | ||
| } | ||
|
|
||
| private function foo(?int $i) | ||
| { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // File: source | ||
| <?php | ||
|
|
||
| namespace Test\Foo; | ||
|
|
||
| class Bar | ||
| { | ||
| public function baz(?int $i): ?string | ||
| { | ||
| } | ||
| } | ||
|
|
||
| class Baz extends Bar | ||
| { | ||
| } | ||
| // File: expected | ||
| <?php | ||
|
|
||
| namespace Test\Foo; | ||
|
|
||
| class Bar | ||
| { | ||
| public function baz(?int $i): ?string | ||
| { | ||
| } | ||
| } | ||
|
|
||
| class Baz extends Bar | ||
| { | ||
| public function baz(?int $i): ?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.
can we remove the TODO. This is to do with the qualified names topic :)
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.
Will do