Conditions | 11 |
Paths | 5 |
Total Lines | 42 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
24 | public function download(string $name, string $version, string $reference, string $type): string |
||
25 | { |
||
26 | $path = $this->distPath.DIRECTORY_SEPARATOR.$name.DIRECTORY_SEPARATOR.$version; |
||
27 | $filePath = $path.DIRECTORY_SEPARATOR.$reference; |
||
28 | |||
29 | $config = $this->factory->createConfig(); |
||
30 | $io = new LogIO(); |
||
31 | $io->loadConfiguration($config); |
||
32 | |||
33 | if (file_exists($filePath)) { |
||
34 | return $filePath; |
||
35 | } |
||
36 | |||
37 | /** @var Provider $provider */ |
||
38 | $provider = $this->dm->getRepository('App:Provider')->find($name); |
||
39 | |||
40 | if (!$provider) { |
||
|
|||
41 | throw new \LogicException('Invalid provider'); |
||
42 | } |
||
43 | |||
44 | /** @var Package $package */ |
||
45 | foreach ($provider->getPackages() as $package) { |
||
46 | $data = $package->getData(); |
||
47 | if ( |
||
48 | isset($data['version_normalized']) && $data['version_normalized'] === $version && |
||
49 | isset($data['dist']['reference']) && $data['dist']['reference'] === $reference && |
||
50 | isset($data['dist']['type']) && $data['dist']['type'] === $type && |
||
51 | isset($data['dist']['url']) |
||
52 | ) { |
||
53 | $loader = new ArrayLoader(); |
||
54 | $composerPackage = $loader->load($data); |
||
55 | |||
56 | $downloader = new FileDownloader($io, $config); |
||
57 | $fileName = $downloader->download($composerPackage, $path, false); |
||
58 | |||
59 | rename($fileName, $filePath); |
||
60 | |||
61 | return $filePath; |
||
62 | } |
||
63 | } |
||
64 | |||
65 | throw new \LogicException('Invalid dist'); |
||
66 | } |
||
68 |