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 | public static function run(Event $event) |
||
75 | |||
76 | /** |
||
77 | * {@inheritDoc} |
||
78 | * |
||
79 | * @throws \RuntimeException |
||
80 | * @throws LogicException |
||
81 | * @throws RuntimeException |
||
82 | * @throws ProcessFailedException |
||
83 | */ |
||
84 | public function activate(Composer $composer, IOInterface $io) |
||
91 | |||
92 | private function init() |
||
101 | |||
102 | /** |
||
103 | * {@inheritDoc} |
||
104 | */ |
||
105 | public static function getSubscribedEvents() |
||
116 | |||
117 | /** |
||
118 | * Entry point for post install and post update events. |
||
119 | * |
||
120 | * @throws RuntimeException |
||
121 | * @throws LogicException |
||
122 | * @throws ProcessFailedException |
||
123 | */ |
||
124 | public function onDependenciesChangedEvent() |
||
146 | |||
147 | /** |
||
148 | * Load all paths from PHP_CodeSniffer into an array. |
||
149 | * |
||
150 | * @throws RuntimeException |
||
151 | * @throws LogicException |
||
152 | * @throws ProcessFailedException |
||
153 | */ |
||
154 | private function loadInstalledPaths() |
||
171 | |||
172 | /** |
||
173 | * Save all coding standard paths back into PHP_CodeSniffer |
||
174 | * |
||
175 | * @throws RuntimeException |
||
176 | * @throws LogicException |
||
177 | * @throws ProcessFailedException |
||
178 | */ |
||
179 | private function saveInstalledPaths() |
||
211 | |||
212 | /** |
||
213 | * Iterate trough all known paths and check if they are still valid. |
||
214 | * |
||
215 | * If path does not exists, is not an directory or isn't readable, the path |
||
216 | * is removed from the list. |
||
217 | * |
||
218 | * @return bool True if changes where made, false otherwise |
||
219 | */ |
||
220 | private function cleanInstalledPaths() |
||
231 | |||
232 | /** |
||
233 | * Check all installed packages against the installed paths from |
||
234 | * PHP_CodeSniffer and add the missing ones. |
||
235 | * |
||
236 | * @return bool True if changes where made, false otherwise |
||
237 | */ |
||
238 | private function updateInstalledPaths() |
||
263 | |||
264 | /** |
||
265 | * Iterates through Composers' local repository looking for valid Coding |
||
266 | * Standard packages. |
||
267 | * |
||
268 | * @return array Composer packages containing coding standard(s) |
||
269 | */ |
||
270 | private function getPHPCodingStandardPackages() |
||
288 | |||
289 | /** |
||
290 | * Simple check if PHP_CodeSniffer is installed. |
||
291 | * |
||
292 | * @return bool Whether PHP_CodeSniffer is installed |
||
293 | */ |
||
294 | private function isPHPCodeSnifferInstalled() |
||
307 | } |
||
308 |
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.