Total Complexity | 47 |
Total Lines | 238 |
Duplicated Lines | 0 % |
Changes | 5 | ||
Bugs | 2 | Features | 0 |
Complex classes like MystemBinaryInstaller often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use MystemBinaryInstaller, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | class MystemBinaryInstaller |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * @var Composer $composer |
||
|
|||
16 | */ |
||
17 | public static $composer; |
||
18 | |||
19 | /** |
||
20 | * @var IOInterface $io |
||
21 | */ |
||
22 | public static $io; |
||
23 | |||
24 | /** |
||
25 | * @var InstallationManager $installer |
||
26 | */ |
||
27 | public static $installer; |
||
28 | |||
29 | /** |
||
30 | * @var WritableRepositoryInterface $localRepo |
||
31 | */ |
||
32 | public static $localRepo; |
||
33 | |||
34 | /** |
||
35 | * @var array $config |
||
36 | */ |
||
37 | public static $config; |
||
38 | |||
39 | /** |
||
40 | * @var Package[] platform-specific packages to install |
||
41 | */ |
||
42 | public static $toInstall = array(); |
||
43 | |||
44 | public static function init(Event $event) |
||
91 | } |
||
92 | |||
93 | public static function install(Event $event) |
||
94 | { |
||
95 | |||
96 | if (!self::init($event)) { |
||
97 | return; |
||
98 | } |
||
99 | |||
100 | $notInstalled = 0; |
||
101 | if (!empty(self::$toInstall)) { |
||
102 | self::$io->write('<info>Installing platform-specific dependencies</info>'); |
||
103 | foreach (self::$toInstall as $package) { |
||
104 | if (!self::$installer->isPackageInstalled(self::$localRepo, $package)) { |
||
105 | self::$installer->install(self::$localRepo, new InstallOperation($package)); |
||
106 | self::updateBinary($package); |
||
107 | } else { |
||
108 | $notInstalled++; |
||
109 | } |
||
110 | } |
||
111 | } |
||
112 | if (empty(self::$toInstall) || $notInstalled > 0) { |
||
113 | self::$io->write('Nothing to install or update in platform-specific dependencies'); |
||
114 | } |
||
115 | } |
||
116 | |||
117 | public static function update(Event $event) |
||
118 | { |
||
119 | //@TODO: update changed packages |
||
120 | self::install($event); |
||
121 | } |
||
122 | |||
123 | public static function updateBinary(Package $package) |
||
124 | { |
||
125 | $binaries = $package->getBinaries(); |
||
126 | if (isset($binaries[0]) && self::getOS() !== 'windows') { |
||
127 | $binDir = rtrim(self::$composer->getConfig()->get('bin-dir'), '/') . '/'; |
||
128 | if (!@chmod($binDir . 'mystem', 0555)) { |
||
129 | throw new Exception("Can't chmod binary file '{$binDir}mystem'"); |
||
130 | } |
||
131 | } |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * @param string $packageName |
||
136 | * @param array $variants |
||
137 | * @return null|Package |
||
138 | */ |
||
139 | protected static function createPlatformSpecificPackage($packageName, $variants) |
||
140 | { |
||
141 | foreach ($variants as $variant) { |
||
142 | if (!empty($variant['architecture']) && $variant['architecture'] !== self::getArchitecture()) { |
||
143 | continue; |
||
144 | } |
||
145 | |||
146 | if (!empty($variant['os']) && $variant['os'] !== self::getOS()) { |
||
147 | continue; |
||
148 | } |
||
149 | |||
150 | reset($variant); |
||
151 | $name = key($variant); |
||
152 | $version = $variant[$name]; |
||
153 | |||
154 | return self::createPackage($name, $version, $packageName); |
||
155 | } |
||
156 | |||
157 | return null; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * @param string $name |
||
162 | * @param string $version |
||
163 | * @param string $newName |
||
164 | * @return null|Package |
||
165 | */ |
||
166 | protected static function createPackage($name, $version, $newName) |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * @param string $newName |
||
191 | * @param array $package |
||
192 | * @return Package |
||
193 | */ |
||
194 | protected static function bindPackageValues($newName, array $package) |
||
195 | { |
||
196 | $new = new Package($newName, $package['version'], $package['version']); |
||
197 | $new->setType('dist'); |
||
198 | if (isset($package['bin'])) { |
||
199 | $new->setBinaries($package['bin']); |
||
200 | } |
||
201 | if (isset($package['dist']['type'])) { |
||
202 | $new->setDistType($package['dist']['type']); |
||
203 | } |
||
204 | if (isset($package['dist']['url'])) { |
||
205 | $new->setDistUrl($package['dist']['url']); |
||
206 | } |
||
207 | if (isset($package['excludes'])) { |
||
208 | $new->setArchiveExcludes($package['excludes']); |
||
209 | } |
||
210 | return $new; |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * Returns the Operating System. |
||
215 | * |
||
216 | * @return string OS, e.g. macosx, freebsd, windows, linux. |
||
217 | */ |
||
218 | public static function getOS() |
||
232 | } |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * Returns the Architecture. |
||
237 | * |
||
238 | * @return string BitSize, e.g. i386, x64. |
||
239 | */ |
||
240 | public static function getArchitecture() |
||
249 | } |
||
250 | } |
||
252 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths