1 | <?php |
||
32 | class Plugin implements PluginInterface, EventSubscriberInterface |
||
33 | { |
||
34 | const MESSAGE_RUNNING_INSTALLER = 'Running PHPCodeSniffer Composer Installer'; |
||
|
|||
35 | const MESSAGE_NOTHING_TO_INSTALL = 'Nothing to install or update'; |
||
36 | const MESSAGE_NOT_INSTALLED = 'PHPCodeSniffer is not installed'; |
||
37 | |||
38 | const PACKAGE_NAME = 'squizlabs/php_codesniffer'; |
||
39 | const PACKAGE_TYPE = 'phpcodesniffer-standard'; |
||
40 | |||
41 | const PHPCS_CONFIG_KEY = 'installed_paths'; |
||
42 | |||
43 | /** |
||
44 | * @var Composer |
||
45 | */ |
||
46 | private $composer; |
||
47 | |||
48 | /** |
||
49 | * @var IOInterface |
||
50 | */ |
||
51 | private $io; |
||
52 | |||
53 | /** |
||
54 | * @var array |
||
55 | */ |
||
56 | private $installedPaths; |
||
57 | |||
58 | /** |
||
59 | * @var ProcessBuilder |
||
60 | */ |
||
61 | private $processBuilder; |
||
62 | |||
63 | /** |
||
64 | * Triggers the plugin's main functionality. |
||
65 | * |
||
66 | * Makes it possible to run the plugin as a custom command. |
||
67 | * |
||
68 | * @param Event $event |
||
69 | * |
||
70 | * @throws \InvalidArgumentException |
||
71 | * @throws LogicException |
||
72 | * @throws ProcessFailedException |
||
73 | * @throws RuntimeException |
||
74 | */ |
||
75 | public static function run(Event $event) |
||
87 | |||
88 | /** |
||
89 | * {@inheritDoc} |
||
90 | * |
||
91 | * @throws \RuntimeException |
||
92 | * @throws LogicException |
||
93 | * @throws RuntimeException |
||
94 | * @throws ProcessFailedException |
||
95 | */ |
||
96 | public function activate(Composer $composer, IOInterface $io) |
||
103 | |||
104 | /** |
||
105 | * Prepares the plugin so it's main functionality can be run. |
||
106 | * |
||
107 | * @throws \RuntimeException |
||
108 | * @throws LogicException |
||
109 | * @throws ProcessFailedException |
||
110 | * @throws RuntimeException |
||
111 | */ |
||
112 | private function init() |
||
121 | |||
122 | /** |
||
123 | * {@inheritDoc} |
||
124 | */ |
||
125 | public static function getSubscribedEvents() |
||
136 | |||
137 | /** |
||
138 | * Entry point for post install and post update events. |
||
139 | * |
||
140 | * @throws \InvalidArgumentException |
||
141 | * @throws RuntimeException |
||
142 | * @throws LogicException |
||
143 | * @throws ProcessFailedException |
||
144 | */ |
||
145 | public function onDependenciesChangedEvent() |
||
167 | |||
168 | /** |
||
169 | * Load all paths from PHP_CodeSniffer into an array. |
||
170 | * |
||
171 | * @throws RuntimeException |
||
172 | * @throws LogicException |
||
173 | * @throws ProcessFailedException |
||
174 | */ |
||
175 | private function loadInstalledPaths() |
||
192 | |||
193 | /** |
||
194 | * Save all coding standard paths back into PHP_CodeSniffer |
||
195 | * |
||
196 | * @throws RuntimeException |
||
197 | * @throws LogicException |
||
198 | * @throws ProcessFailedException |
||
199 | */ |
||
200 | private function saveInstalledPaths() |
||
232 | |||
233 | /** |
||
234 | * Iterate trough all known paths and check if they are still valid. |
||
235 | * |
||
236 | * If path does not exists, is not an directory or isn't readable, the path |
||
237 | * is removed from the list. |
||
238 | * |
||
239 | * @return bool True if changes where made, false otherwise |
||
240 | */ |
||
241 | private function cleanInstalledPaths() |
||
252 | |||
253 | /** |
||
254 | * Check all installed packages against the installed paths from |
||
255 | * PHP_CodeSniffer and add the missing ones. |
||
256 | * |
||
257 | * @return bool True if changes where made, false otherwise |
||
258 | * |
||
259 | * @throws \InvalidArgumentException |
||
260 | */ |
||
261 | private function updateInstalledPaths() |
||
286 | |||
287 | /** |
||
288 | * Iterates through Composers' local repository looking for valid Coding |
||
289 | * Standard packages. |
||
290 | * |
||
291 | * @return array Composer packages containing coding standard(s) |
||
292 | */ |
||
293 | private function getPHPCodingStandardPackages() |
||
311 | |||
312 | /** |
||
313 | * Simple check if PHP_CodeSniffer is installed. |
||
314 | * |
||
315 | * @return bool Whether PHP_CodeSniffer is installed |
||
316 | */ |
||
317 | private function isPHPCodeSnifferInstalled() |
||
330 | } |
||
331 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.