Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Code Lines | 34 |
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 |
||
37 | public function __invoke(string $installationPath) : SourceLocator |
||
38 | { |
||
39 | $realInstallationPath = realpath($installationPath); |
||
40 | |||
41 | Assert::that($realInstallationPath)->string(); |
||
42 | |||
43 | $composerJsonPath = $realInstallationPath . '/composer.json'; |
||
44 | |||
45 | Assert::that($composerJsonPath) |
||
46 | ->file() |
||
47 | ->readable(); |
||
48 | |||
49 | $composerDefinitionString = file_get_contents($composerJsonPath); |
||
50 | |||
51 | Assert::that($composerDefinitionString)->string(); |
||
52 | |||
53 | $composerDefinition = json_decode($composerDefinitionString, true); |
||
54 | |||
55 | Assert::that($composerDefinition)->isArray(); |
||
56 | |||
57 | $autoloadDefinition = $composerDefinition['autoload'] ?? []; |
||
58 | |||
59 | Assert::that($autoloadDefinition)->isArray(); |
||
60 | |||
61 | $prependInstallationPath = $this->prependInstallationPath($realInstallationPath); |
||
62 | |||
63 | return new AggregateSourceLocator(array_merge( |
||
64 | [ |
||
65 | new DirectoriesSourceLocator( |
||
66 | array_map( |
||
67 | $prependInstallationPath, |
||
68 | array_merge( |
||
69 | $this->psr0Directories($autoloadDefinition), |
||
70 | $this->psr4Directories($autoloadDefinition), |
||
71 | $this->classMapDirectories($autoloadDefinition, $installationPath) |
||
72 | ) |
||
73 | ), |
||
74 | $this->astLocator |
||
75 | ), |
||
76 | ], |
||
77 | array_map( |
||
78 | function (string $path) : SourceLocator { |
||
79 | return new SingleFileSourceLocator($path, $this->astLocator); |
||
80 | }, |
||
81 | array_map( |
||
82 | $prependInstallationPath, |
||
83 | $this->classMapFiles($autoloadDefinition, $installationPath) |
||
84 | ) |
||
85 | ), |
||
86 | array_map( |
||
87 | function (string $path) : SourceLocator { |
||
88 | return new SingleFileSourceLocator($path, $this->astLocator); |
||
89 | }, |
||
90 | array_map( |
||
91 | $prependInstallationPath, |
||
92 | $this->files($autoloadDefinition) |
||
93 | ) |
||
194 |