Conditions | 4 |
Paths | 1 |
Total Lines | 88 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
54 | public function resolveForPackage(LinkedPackage $package): array |
||
55 | { |
||
56 | $originalComposer = new JsonFile('./composer.json'); |
||
57 | $lockFile = new JsonFile('./vendor/linked-composer.lock'); |
||
58 | $replaceComposer = new JsonFile('./vendor/linked-composer.json'); |
||
59 | $replaceComposer->write($originalComposer->read()); |
||
60 | |||
61 | $jsonConfigSource = new JsonConfigSource($replaceComposer); |
||
62 | $config = clone $this->composer->getConfig(); |
||
63 | $config->setConfigSource($jsonConfigSource); |
||
64 | $jsonConfigSource->addRepository('', ['type' => 'path', 'url' => $package->getPath()]); |
||
65 | $jsonConfigSource->addRepository('path-' . $package->getName(), ['type' => 'path', 'url' => $package->getPath()]); |
||
66 | $jsonConfigSource->addLink('require', $package->getName(), 'dev-master'); |
||
67 | |||
68 | $locker = new Locker( |
||
69 | $this->io, |
||
70 | $lockFile, |
||
71 | $this->composer->getInstallationManager(), |
||
72 | JsonFile::encode($originalComposer->read()) |
||
73 | ); |
||
74 | |||
75 | $installer = new Installer( |
||
76 | $this->io, |
||
77 | $config, |
||
78 | $this->composer->getPackage(), |
||
79 | $this->composer->getDownloadManager(), |
||
80 | $this->composer->getRepositoryManager(), |
||
81 | $locker, |
||
82 | $this->composer->getInstallationManager(), |
||
83 | new EventDispatcher($this->composer, $this->io), |
||
84 | $this->composer->getAutoloadGenerator() |
||
85 | ); |
||
86 | |||
87 | $installer->setUpdate(true); |
||
88 | $installer->setWriteLock(true); |
||
89 | $installer->run(); |
||
90 | |||
91 | return []; |
||
92 | // TODO use configuration of original composer.json |
||
93 | $repositorySet = new RepositorySet( |
||
|
|||
94 | 'dev', |
||
95 | [], |
||
96 | [], |
||
97 | ); |
||
98 | |||
99 | // TODO we can't use this |
||
100 | $exexutor = new ProcessExecutor($this->io); |
||
101 | $exexutor->enableAsync(); |
||
102 | |||
103 | // Fill repositories first the root package repository |
||
104 | $repositorySet->addRepository(new RootPackageRepository($this->composer->getPackage())); |
||
105 | |||
106 | // The locked repository, we don't do a full upgrade, so we want to keep as much as possible packages up to date |
||
107 | $repositorySet->addRepository($this->composer->getLocker()->getLockedRepository(true)); |
||
108 | |||
109 | // No we add our custom path repositories, we need to do this before we add the original repositories |
||
110 | // otherwise we do not get precedence over the other repositories |
||
111 | $repo = new PathRepository(['url' => $package->getPath()], $this->io, $this->composer->getConfig(), null, null, $exexutor); |
||
112 | $repositorySet->addRepository($repo); |
||
113 | |||
114 | // Add custom repositories defined in the composer file |
||
115 | $repositories = $this->composer->getRepositoryManager()->getRepositories(); |
||
116 | foreach ($repositories as $repository) { |
||
117 | $repositorySet->addRepository($repository); |
||
118 | } |
||
119 | |||
120 | // Make request for package, and fix all the currently existing packages |
||
121 | $request = new Request(); |
||
122 | $request->requireName($package->getName(), new Constraint('=', 'dev-master')); |
||
123 | foreach ($this->composer->getRepositoryManager()->getLocalRepository()->getPackages() as $localPackage) { |
||
124 | $request->fixPackage($localPackage); |
||
125 | } |
||
126 | $policy = new DefaultPolicy(true); |
||
127 | |||
128 | // Create pool and solve? |
||
129 | $pool = $repositorySet->createPool($request, $this->io); |
||
130 | $solver = new Solver($policy, $pool, $this->io); |
||
131 | |||
132 | $operations = []; |
||
133 | |||
134 | try { |
||
135 | $transaction = $solver->solve($request, PlatformRequirementFilterFactory::ignoreAll()); |
||
136 | $operations = $transaction->getOperations(); |
||
137 | } catch (SolverProblemsException $exception) { |
||
138 | $this->io->write($exception->getPrettyString($repositorySet, $request, $pool, true)); |
||
139 | } |
||
140 | |||
141 | return $operations; |
||
142 | } |
||
144 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.