Skip to content

Commit b3f6d49

Browse files
committed
Fix tests and improve code quality
1 parent 1a261db commit b3f6d49

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

src/Moka/Generator/Template/ProxyClassTemplate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,20 @@ protected static function doGenerate(\ReflectionClass $class): string
5555
foreach ($methods as $method) {
5656
if (
5757
!$method->isFinal() &&
58-
!in_array($method->getName(), self::UNSAFE_METHODS, true)
58+
!in_array($method->name, self::UNSAFE_METHODS, true)
5959
) {
6060
$methodsCode[] = ProxyMethodTemplate::generate($method);
6161
}
6262

63-
if ('__call' === $method->getName()) {
63+
if ('__call' === $method->name) {
6464
$callParameters = $method->getParameters();
6565
foreach ($callParameters as $callParameter) {
6666
$callParametersTypes[$callParameter->getPosition()] = (string)$callParameter->getType();
6767
}
6868
}
6969
}
7070

71-
$mockClassName = $class->getName();
71+
$mockClassName = $class->name;
7272
$proxyClassName = sprintf(
7373
self::TEMPLATE_FQCN,
7474
preg_replace('/\\\/', '__', $mockClassName),

src/Moka/Generator/Template/ProxyMethodTemplate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected static function doGenerate(\ReflectionMethod $method): string
3535

3636
$parameters = $method->getParameters();
3737
$parametersCode = [];
38-
if ($parameters) {
38+
if (is_array($parameters)) {
3939
foreach ($parameters as $parameter) {
4040
$parametersCode[] = ProxyParameterTemplate::generate($parameter);
4141
}
@@ -50,7 +50,7 @@ protected static function doGenerate(\ReflectionMethod $method): string
5050
? 'return'
5151
: '';
5252

53-
$methodName = $method->getName();
53+
$methodName = $method->name;
5454

5555
return sprintf(
5656
self::TEMPLATE,

src/Moka/Generator/Template/ProxyParameterTemplate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected static function doGenerate(\ReflectionParameter $parameter): string
5151
$defaultValue = '';
5252
}
5353

54-
$name = '$' . $parameter->getName();
54+
$name = '$' . $parameter->name;
5555

5656
return sprintf(
5757
self::TEMPLATE,

src/Moka/Generator/Template/ProxyReturnTypeTemplate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected static function doGenerate(\ReflectionMethod $method): string
3232
: '';
3333

3434
$returnType = 'self' === (string)$originalReturnType
35-
? $method->getDeclaringClass()->getName()
35+
? $method->getDeclaringClass()->name
3636
: (string)$originalReturnType;
3737

3838
return sprintf(

tests/AbstractTestClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function getSelf(): TestInterface
2020
return $this;
2121
}
2222

23-
public function getCallable(): ?callable
23+
public function getCallable(): callable
2424
{
2525
return function () {
2626
};

tests/Generator/Template/ProxyReturnTypeTemplateTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function testGenerate()
1616
new \ReflectionMethod(FooTestClass::class, 'getCallable')
1717
);
1818

19-
$this->assertRegExp('/: *\? *callable/', $code);
19+
$this->assertRegExp('/: *callable/', $code);
2020
}
2121

2222
public function testGenerateWithSelf()
@@ -29,6 +29,6 @@ public function testGenerateWithSelf()
2929
new \ReflectionMethod(NewTestClass::class, 'getSelfNew')
3030
);
3131

32-
$this->assertRegExp('/: *Tests\\\NewTestClass/', $code);
32+
$this->assertRegExp('/: *\? *Tests\\\NewTestClass/', $code);
3333
}
3434
}

tests/NewTestClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class NewTestClass extends AbstractTestClass
77
{
8-
public function getSelfNew(): self
8+
public function getSelfNew(): ?self
99
{
1010
return $this;
1111
}

0 commit comments

Comments
 (0)