1 | <?php |
||
33 | class Plugin implements PluginInterface, EventSubscriberInterface |
||
34 | { |
||
35 | |||
36 | const PACKAGE_TYPE = 'phpcodesniffer-standard'; |
||
37 | |||
38 | const PHPCS_CONFIG_KEY = 'installed_paths'; |
||
39 | |||
40 | /** |
||
41 | * @var Composer |
||
42 | */ |
||
43 | private $composer; |
||
44 | |||
45 | /** |
||
46 | * @var IOInterface |
||
47 | */ |
||
48 | private $io; |
||
|
|||
49 | |||
50 | /** |
||
51 | * @var array |
||
52 | */ |
||
53 | private $installedPaths; |
||
54 | |||
55 | /** |
||
56 | * @var ProcessBuilder |
||
57 | */ |
||
58 | private $processBuilder; |
||
59 | |||
60 | public function setComposer($composer) |
||
64 | |||
65 | public static function run(Event $event) |
||
74 | |||
75 | /** |
||
76 | * {@inheritDoc} |
||
77 | * |
||
78 | * @throws \RuntimeException |
||
79 | * @throws LogicException |
||
80 | * @throws RuntimeException |
||
81 | * @throws ProcessFailedException |
||
82 | */ |
||
83 | public function activate(Composer $composer, IOInterface $io) |
||
90 | |||
91 | public function init() |
||
100 | |||
101 | /** |
||
102 | * {@inheritDoc} |
||
103 | */ |
||
104 | public static function getSubscribedEvents() |
||
115 | |||
116 | /** |
||
117 | * Entry point for post install and post update events. |
||
118 | * |
||
119 | * @throws RuntimeException |
||
120 | * @throws LogicException |
||
121 | * @throws ProcessFailedException |
||
122 | */ |
||
123 | public function onDependenciesChangedEvent() |
||
134 | |||
135 | /** |
||
136 | * Load all paths from PHP_CodeSniffer into an array. |
||
137 | * |
||
138 | * @throws RuntimeException |
||
139 | * @throws LogicException |
||
140 | * @throws ProcessFailedException |
||
141 | */ |
||
142 | private function loadInstalledPaths() |
||
159 | |||
160 | /** |
||
161 | * Save all coding standard paths back into PHP_CodeSniffer |
||
162 | * |
||
163 | * @throws RuntimeException |
||
164 | * @throws LogicException |
||
165 | * @throws ProcessFailedException |
||
166 | */ |
||
167 | private function saveInstalledPaths() |
||
199 | |||
200 | /** |
||
201 | * Iterate trough all known paths and check if they are still valid. |
||
202 | * |
||
203 | * If path does not exists, is not an directory or isn't readable, the path |
||
204 | * is removed from the list. |
||
205 | * |
||
206 | * @return bool True if changes where made, false otherwise |
||
207 | */ |
||
208 | private function cleanInstalledPaths() |
||
219 | |||
220 | /** |
||
221 | * Check all installed packages against the installed paths from |
||
222 | * PHP_CodeSniffer and add the missing ones. |
||
223 | * |
||
224 | * @return bool True if changes where made, false otherwise |
||
225 | */ |
||
226 | private function updateInstalledPaths() |
||
251 | |||
252 | /** |
||
253 | * Iterates through Composers' local repository looking for valid Coding |
||
254 | * Standard packages. |
||
255 | * |
||
256 | * @return array Composer packages containing coding standard(s) |
||
257 | */ |
||
258 | private function getPHPCodingStandardPackages() |
||
276 | |||
277 | /** |
||
278 | * Simple check if PHP_CodeSniffer is installed. |
||
279 | * |
||
280 | * @return bool PHP_CodeSniffer is installed |
||
281 | */ |
||
282 | private function isPHPCodeSnifferInstalled() |
||
293 | } |
||
294 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.