| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 37 |
| 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 |
||
| 94 | public function testWillLocateDependencies() : void |
||
| 95 | { |
||
| 96 | $composerInstallationStructure = realpath(__DIR__ . '/../../asset/composer-installation-structure'); |
||
| 97 | |||
| 98 | $this |
||
| 99 | ->makeInstaller |
||
| 100 | ->expects(self::any()) |
||
| 101 | ->method('__invoke') |
||
| 102 | ->with($composerInstallationStructure) |
||
| 103 | ->willReturn($this->composerInstaller); |
||
| 104 | |||
| 105 | $this |
||
| 106 | ->composerInstaller |
||
| 107 | ->expects(self::once()) |
||
| 108 | ->method('run') |
||
| 109 | ->willReturnCallback(function () use ($composerInstallationStructure) : void { |
||
| 110 | self::assertSame($composerInstallationStructure, getcwd()); |
||
| 111 | }); |
||
| 112 | |||
| 113 | $locator = $this |
||
| 114 | ->locateDependencies |
||
| 115 | ->__invoke($composerInstallationStructure); |
||
| 116 | |||
| 117 | self::assertInstanceOf(AggregateSourceLocator::class, $locator); |
||
| 118 | |||
| 119 | $reflectionLocators = new \ReflectionProperty(AggregateSourceLocator::class, 'sourceLocators'); |
||
| 120 | |||
| 121 | $reflectionLocators->setAccessible(true); |
||
| 122 | |||
| 123 | $locators = $reflectionLocators->getValue($locator); |
||
| 124 | |||
| 125 | self::assertCount(3, $locators); |
||
| 126 | self::assertEquals( |
||
| 127 | new StaticClassMapSourceLocator( |
||
| 128 | [ |
||
| 129 | 'A\\ClassName' => realpath(__DIR__ . '/../../asset/composer-installation-structure/AClassName.php'), |
||
| 130 | 'B\\ClassName' => realpath(__DIR__ . '/../../asset/composer-installation-structure/BClassName.php'), |
||
| 131 | ], |
||
| 132 | $this->astLocator |
||
| 133 | ), |
||
| 134 | $locators[0] |
||
| 135 | ); |
||
| 136 | self::assertEquals( |
||
| 137 | new AggregateSourceLocator([ |
||
| 138 | new SingleFileSourceLocator( |
||
| 139 | realpath(__DIR__ . '/../../asset/composer-installation-structure/included-file-1.php'), |
||
| 140 | $this->astLocator |
||
| 141 | ), |
||
| 142 | new SingleFileSourceLocator( |
||
| 143 | realpath(__DIR__ . '/../../asset/composer-installation-structure/included-file-2.php'), |
||
| 144 | $this->astLocator |
||
| 145 | ), |
||
| 146 | ]), |
||
| 147 | $locators[1] |
||
| 148 | ); |
||
| 149 | self::assertInstanceOf(PhpInternalSourceLocator::class, $locators[2]); |
||
| 150 | } |
||
| 198 |