11<?php
2+
23declare (strict_types=1 );
34
45namespace PhpList \Core \Composer ;
56
67use Composer \Package \PackageInterface ;
78use Composer \Script \Event ;
9+ use DomainException ;
810use PhpList \Core \Core \ApplicationStructure ;
11+ use RuntimeException ;
912use Symfony \Component \Filesystem \Filesystem ;
1013
1114/**
@@ -48,7 +51,7 @@ class ScriptHandler
4851 /**
4952 * @return string absolute application root directory without the trailing slash
5053 *
51- * @throws \ RuntimeException if there is no composer.json in the application root
54+ * @throws RuntimeException if there is no composer.json in the application root
5255 */
5356 private static function getApplicationRoot (): string
5457 {
@@ -61,7 +64,7 @@ private static function getApplicationRoot(): string
6164 */
6265 private static function getCoreDirectory (): string
6366 {
64- return static ::getApplicationRoot () . '/vendor/ ' . static ::CORE_PACKAGE_NAME ;
67+ return self ::getApplicationRoot () . '/vendor/ ' . static ::CORE_PACKAGE_NAME ;
6568 }
6669
6770 /**
@@ -73,12 +76,12 @@ private static function getCoreDirectory(): string
7376 *
7477 * @return void
7578 *
76- * @throws \ DomainException if this method is called for the core package
79+ * @throws DomainException if this method is called for the core package
7780 */
78- public static function createBinaries (Event $ event )
81+ public static function createBinaries (Event $ event ): void
7982 {
80- static ::preventScriptFromCorePackage ($ event );
81- static ::mirrorDirectoryFromCore ('bin ' );
83+ self ::preventScriptFromCorePackage ($ event );
84+ self ::mirrorDirectoryFromCore ('bin ' );
8285 }
8386
8487 /**
@@ -90,27 +93,27 @@ public static function createBinaries(Event $event)
9093 *
9194 * @return void
9295 *
93- * @throws \ DomainException if this method is called for the core package
96+ * @throws DomainException if this method is called for the core package
9497 */
95- public static function createPublicWebDirectory (Event $ event )
98+ public static function createPublicWebDirectory (Event $ event ): void
9699 {
97- static ::preventScriptFromCorePackage ($ event );
98- static ::mirrorDirectoryFromCore ('public ' );
100+ self ::preventScriptFromCorePackage ($ event );
101+ self ::mirrorDirectoryFromCore ('public ' );
99102 }
100103
101104 /**
102105 * @param Event $event
103106 *
104107 * @return void
105108 *
106- * @throws \ DomainException if this method is called for the core package
109+ * @throws DomainException if this method is called for the core package
107110 */
108- private static function preventScriptFromCorePackage (Event $ event )
111+ private static function preventScriptFromCorePackage (Event $ event ): void
109112 {
110113 $ composer = $ event ->getComposer ();
111114 $ packageName = $ composer ->getPackage ()->getName ();
112- if ($ packageName === static ::CORE_PACKAGE_NAME ) {
113- throw new \ DomainException (
115+ if ($ packageName === self ::CORE_PACKAGE_NAME ) {
116+ throw new DomainException (
114117 'This Composer script must not be called for the core package itself. ' ,
115118 1501240572
116119 );
@@ -128,14 +131,14 @@ private static function preventScriptFromCorePackage(Event $event)
128131 *
129132 * @return void
130133 */
131- private static function mirrorDirectoryFromCore (string $ directoryWithoutSlashes )
134+ private static function mirrorDirectoryFromCore (string $ directoryWithoutSlashes ): void
132135 {
133136 $ directoryWithSlashes = '/ ' . $ directoryWithoutSlashes . '/ ' ;
134137
135138 $ fileSystem = new Filesystem ();
136139 $ fileSystem ->mirror (
137- static ::getCoreDirectory () . $ directoryWithSlashes ,
138- static ::getApplicationRoot () . $ directoryWithSlashes ,
140+ self ::getCoreDirectory () . $ directoryWithSlashes ,
141+ self ::getApplicationRoot () . $ directoryWithSlashes ,
139142 null ,
140143 ['override ' => true , 'delete ' => false ]
141144 );
@@ -148,13 +151,13 @@ private static function mirrorDirectoryFromCore(string $directoryWithoutSlashes)
148151 *
149152 * @return void
150153 */
151- public static function listModules (Event $ event )
154+ public static function listModules (Event $ event ): void
152155 {
153156 $ packageRepository = new PackageRepository ();
154157 $ packageRepository ->injectComposer ($ event ->getComposer ());
155158
156159 $ modules = $ packageRepository ->findModules ();
157- $ maximumPackageNameLength = static ::calculateMaximumPackageNameLength ($ modules );
160+ $ maximumPackageNameLength = self ::calculateMaximumPackageNameLength ($ modules );
158161
159162 foreach ($ modules as $ module ) {
160163 $ paddedName = str_pad ($ module ->getName (), $ maximumPackageNameLength + 1 );
@@ -185,11 +188,11 @@ private static function calculateMaximumPackageNameLength(array $modules): int
185188 *
186189 * @return void
187190 */
188- public static function createBundleConfiguration (Event $ event )
191+ public static function createBundleConfiguration (Event $ event ): void
189192 {
190- static ::createAndWriteFile (
191- static ::getApplicationRoot () . static ::BUNDLE_CONFIGURATION_FILE ,
192- static ::createAndInitializeModuleFinder ($ event )->createBundleConfigurationYaml ()
193+ self ::createAndWriteFile (
194+ self ::getApplicationRoot () . self ::BUNDLE_CONFIGURATION_FILE ,
195+ self ::createAndInitializeModuleFinder ($ event )->createBundleConfigurationYaml ()
193196 );
194197 }
195198
@@ -205,13 +208,13 @@ public static function createBundleConfiguration(Event $event)
205208 *
206209 * @return void
207210 *
208- * @throws \ RuntimeException
211+ * @throws RuntimeException
209212 */
210- private static function createAndWriteFile (string $ path , string $ contents )
213+ private static function createAndWriteFile (string $ path , string $ contents ): void
211214 {
212215 $ fileHandle = fopen ($ path , 'wb ' );
213216 if ($ fileHandle === false ) {
214- throw new \ RuntimeException ('The file " ' . $ path . '" could not be opened for writing. ' , 1519851153 );
217+ throw new RuntimeException ('The file " ' . $ path . '" could not be opened for writing. ' , 1519851153 );
215218 }
216219
217220 fwrite ($ fileHandle , $ contents );
@@ -226,11 +229,11 @@ private static function createAndWriteFile(string $path, string $contents)
226229 *
227230 * @return void
228231 */
229- public static function createRoutesConfiguration (Event $ event )
232+ public static function createRoutesConfiguration (Event $ event ): void
230233 {
231- static ::createAndWriteFile (
232- static ::getApplicationRoot () . static ::ROUTES_CONFIGURATION_FILE ,
233- static ::createAndInitializeModuleFinder ($ event )->createRouteConfigurationYaml ()
234+ self ::createAndWriteFile (
235+ self ::getApplicationRoot () . self ::ROUTES_CONFIGURATION_FILE ,
236+ self ::createAndInitializeModuleFinder ($ event )->createRouteConfigurationYaml ()
234237 );
235238 }
236239
@@ -255,20 +258,20 @@ private static function createAndInitializeModuleFinder(Event $event): ModuleFin
255258 *
256259 * @return void
257260 */
258- public static function clearAllCaches ()
261+ public static function clearAllCaches (): void
259262 {
260263 $ fileSystem = new Filesystem ();
261- $ fileSystem ->remove (static ::getApplicationRoot () . '/var/cache ' );
264+ $ fileSystem ->remove (self ::getApplicationRoot () . '/var/cache ' );
262265 }
263266
264267 /**
265268 * Creates config/parameters.yml (the parameters configuration file).
266269 *
267270 * @return void
268271 */
269- public static function createParametersConfiguration ()
272+ public static function createParametersConfiguration (): void
270273 {
271- $ configurationFilePath = static ::getApplicationRoot () . static ::PARAMETERS_CONFIGURATION_FILE ;
274+ $ configurationFilePath = self ::getApplicationRoot () . self ::PARAMETERS_CONFIGURATION_FILE ;
272275 if (file_exists ($ configurationFilePath )) {
273276 return ;
274277 }
@@ -279,7 +282,7 @@ public static function createParametersConfiguration()
279282 $ secret = bin2hex (random_bytes (20 ));
280283 $ configuration = sprintf ($ template , $ secret );
281284
282- static ::createAndWriteFile ($ configurationFilePath , $ configuration );
285+ self ::createAndWriteFile ($ configurationFilePath , $ configuration );
283286 }
284287
285288 /**
@@ -289,11 +292,11 @@ public static function createParametersConfiguration()
289292 *
290293 * @return void
291294 */
292- public static function createGeneralConfiguration (Event $ event )
295+ public static function createGeneralConfiguration (Event $ event ): void
293296 {
294- static ::createAndWriteFile (
295- static ::getApplicationRoot () . static ::GENERAL_CONFIGURATION_FILE ,
296- static ::createAndInitializeModuleFinder ($ event )->createGeneralConfigurationYaml ()
297+ self ::createAndWriteFile (
298+ self ::getApplicationRoot () . self ::GENERAL_CONFIGURATION_FILE ,
299+ self ::createAndInitializeModuleFinder ($ event )->createGeneralConfigurationYaml ()
297300 );
298301 }
299302}
0 commit comments