| Conditions | 4 |
| Paths | 4 |
| Total Lines | 69 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 69 | public function testReverseDefinition(): void |
||
| 70 | { |
||
| 71 | $className = '\\Spiral\\Tests\\Scaffolder\\App\\Config\\ReversedConfig'; |
||
| 72 | $this->console()->run('create:config', [ |
||
| 73 | 'name' => 'reversed', |
||
| 74 | '--comment' => 'Reversed Config', |
||
| 75 | '--reverse' => true |
||
| 76 | ]); |
||
| 77 | |||
| 78 | clearstatcache(); |
||
| 79 | $this->assertTrue(class_exists($className)); |
||
| 80 | |||
| 81 | $reflection = new ReflectionClass($className); |
||
| 82 | |||
| 83 | $this->assertTrue($reflection->hasConstant('CONFIG')); |
||
| 84 | $this->assertTrue($reflection->hasProperty('config')); |
||
| 85 | |||
| 86 | $this->assertIsString($reflection->getReflectionConstant('CONFIG')->getValue()); |
||
| 87 | $this->assertIsArray($reflection->getDefaultProperties()['config']); |
||
| 88 | $this->assertNotEmpty($reflection->getDefaultProperties()['config']); |
||
| 89 | |||
| 90 | $methods = [ |
||
| 91 | 'getStrParam' => ['hint' => 'string', 'annotation' => 'string'], |
||
| 92 | 'getIntParam' => ['hint' => 'int', 'annotation' => 'int'], |
||
| 93 | 'getFloatParam' => ['hint' => 'float', 'annotation' => 'float'], |
||
| 94 | 'getBoolParam' => ['hint' => 'bool', 'annotation' => 'bool'], |
||
| 95 | 'getNullParam' => ['hint' => null, 'annotation' => 'null'], |
||
| 96 | |||
| 97 | 'getArrParam' => ['hint' => 'array', 'annotation' => 'array|string[]'], |
||
| 98 | |||
| 99 | 'getMapParam' => ['hint' => 'array', 'annotation' => 'array|string[]'], |
||
| 100 | 'getMapParamBy' => ['hint' => 'string', 'annotation' => 'string'], |
||
| 101 | |||
| 102 | 'getMixedArrParam' => ['hint' => 'array', 'annotation' => 'array'], |
||
| 103 | 'getParams' => ['hint' => 'array', 'annotation' => 'array|string[]'], |
||
| 104 | |||
| 105 | 'getParameters' => ['hint' => 'array', 'annotation' => 'array|array[]'], |
||
| 106 | 'getParameter' => ['hint' => 'array', 'annotation' => 'array'], |
||
| 107 | |||
| 108 | 'getConflicts' => ['hint' => 'array', 'annotation' => 'array|array[]'], |
||
| 109 | 'getConflict' => ['hint' => 'string', 'annotation' => 'string'], |
||
| 110 | 'getConflictBy' => ['hint' => 'array', 'annotation' => 'array|int[]'], |
||
| 111 | |||
| 112 | 'getValues' => ['hint' => 'array', 'annotation' => 'array|array[]'], |
||
| 113 | 'getValue' => ['hint' => 'string', 'annotation' => 'string'], |
||
| 114 | 'getValueBy' => ['hint' => 'string', 'annotation' => 'string'], |
||
| 115 | ]; |
||
| 116 | |||
| 117 | $reflectionMethods = []; |
||
| 118 | foreach ($reflection->getMethods() as $method) { |
||
| 119 | if ($method->getDeclaringClass()->name !== $reflection->name) { |
||
| 120 | continue; |
||
| 121 | } |
||
| 122 | |||
| 123 | $reflectionMethods[$method->name] = $method; |
||
| 124 | $this->assertArrayHasKey($method->name, $methods); |
||
| 125 | |||
| 126 | if (!$method->hasReturnType()) { |
||
| 127 | $this->assertNull($methods[$method->name]['hint']); |
||
| 128 | } else { |
||
| 129 | $this->assertEquals($methods[$method->name]['hint'], $method->getReturnType()->getName()); |
||
| 130 | } |
||
| 131 | |||
| 132 | $this->assertStringContainsString($methods[$method->name]['annotation'], $method->getDocComment()); |
||
| 133 | } |
||
| 134 | |||
| 135 | $this->assertCount(count($methods), $reflectionMethods); |
||
| 136 | |||
| 137 | $this->deleteDeclaration($className); |
||
| 138 | } |
||
| 251 |