Skip to content
This repository was archived by the owner on Mar 6, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Adapter/WorseReflection/Refactor/WorseGenerateMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function generateMethod(SourceCode $sourceCode, int $offset, $methodName
$this->validate($methodCall);
$visibility = $this->determineVisibility($contextType, $methodCall->class());

$prototype = $this->addMethodCallToBuilder($methodCall, $visibility, $methodName);
$prototype = $this->addMethodCallToBuilder($methodCall, $visibility, $methodCall->isStatic(), $methodName);
$sourceCode = $this->resolveSourceCode($sourceCode, $methodCall, $visibility);

return SourceCode::fromStringAndPath(
Expand Down Expand Up @@ -92,6 +92,7 @@ private function contextType(SourceCode $sourceCode, int $offset): Type
private function addMethodCallToBuilder(
ReflectionMethodCall $methodCall,
Visibility $visibility,
bool $static,
$methodName
) {
$methodName = $methodName ?: $methodCall->name();
Expand All @@ -107,6 +108,9 @@ private function addMethodCallToBuilder(

$methodBuilder = $classBuilder->method($methodName);
$methodBuilder->visibility((string) $visibility);
if ($static) {
$methodBuilder->static();
}

/** @var ReflectionArgument $argument */
foreach ($methodCall->arguments() as $argument) {
Expand Down
Empty file removed tests/Adapter/Test.php
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public function provideExtractMethod()
'imports classes' => [
'generateMethod9.test',
],
'static private method' => [
'generateMethod10.test',
],
'static public method' => [
'generateMethod11.test',
],
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// File: source

<?php

namespace Foobar;

class generateStaticMethod
{
public function name()
{
self::fo<>obar();
}
}
// File: expected
<?php

namespace Foobar;

class generateStaticMethod
{
public function name()
{
self::foobar();
}

private static function foobar()
{
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// File: source

<?php

class anotherClass
{
}

class generateMethod
{
public function name()
{
anotherClass::so<>meMethod('foobar');
}
}
// File: expected
<?php

class anotherClass
{
public static function someMethod(string $string)
{
}
}

class generateMethod
{
public function name()
{
anotherClass::someMethod('foobar');
}
}