@@ -59,7 +59,7 @@ public function __construct(?Event $event)
5959 public function processComposerInstall (): void
6060 {
6161 $ package = $ this ->getComposerPackage ();
62- if (!$ package || !$ this instanceof CopyFromComposerInterface) {
62+ if (!$ package instanceof BasePackage || !$ this instanceof CopyFromComposerInterface) {
6363 return ;
6464 }
6565
@@ -74,13 +74,14 @@ public function processComposerInstall(): void
7474 $ filesystem = $ this ->getFileSystem ();
7575
7676 if (!$ filesystem ->exists ($ copySourcePath ) && $ this instanceof CopyFromUnpkgInterface) {
77- if ($ event && $ event ->getIO ()->isVerbose ()) {
77+ if ($ event instanceof Event && $ event ->getIO ()->isVerbose ()) {
7878 $ event ->getIO ()->write (sprintf (
7979 'Fallback to Unpkg %s for %s ' ,
8080 $ this ->getUnpkgName (),
8181 $ this ->getComposerName (),
8282 ));
8383 }
84+
8485 $ this ->processUnpkgInstall ();
8586 return ;
8687 }
@@ -96,11 +97,11 @@ public function processComposerInstall(): void
9697
9798 try {
9899 $ filesystem ->copy ($ copySource , $ copytarget );
99- if ($ event && $ event ->getIO ()->isVeryVerbose ()) {
100+ if ($ event instanceof Event && $ event ->getIO ()->isVeryVerbose ()) {
100101 $ event ->getIO ()->write (sprintf ('Copy %s to %s ' , $ copySource , $ copytarget ));
101102 }
102103 } catch (IOException $ exception ) {
103- if ($ event ) {
104+ if ($ event instanceof Event ) {
104105 $ event ->getIO ()->write ($ exception ->getMessage ());
105106 }
106107 }
@@ -119,7 +120,7 @@ public function processUnpkgInstall(): void
119120 $ event = $ this ->getEvent ();
120121 $ sourcePath = $ this ->getUnpkSourcePath ();
121122
122- if ($ event && $ event ->getIO ()->isVerbose ()) {
123+ if ($ event instanceof Event && $ event ->getIO ()->isVerbose ()) {
123124 $ event ->getIO ()->write (sprintf (
124125 'Trying to download %s %s from %s ' ,
125126 $ this ->getUnpkgName (),
@@ -133,29 +134,32 @@ public function processUnpkgInstall(): void
133134 try {
134135 $ content = file_get_contents ($ sourceFilePath );
135136 } catch (ErrorException $ errorException ) {
136- if ($ event ) {
137+ if ($ event instanceof Event ) {
137138 $ event ->getIO ()->write ($ errorException ->getMessage ());
138139 }
140+
139141 return ;
140142 }
141143
142144 if (!$ content ) {
143- if ($ event ) {
145+ if ($ event instanceof Event ) {
144146 $ event ->getIO ()->write (sprintf ('Could not read from %s ' , $ sourceFilePath ));
145147 }
148+
146149 return ;
147150 }
148151
149152 try {
150153 $ targetFilePath = $ this ->getCopyTargetPath () . '/ ' . $ fileName ;
151154 $ this ->getFileSystem ()->dumpFile ($ targetFilePath , $ content );
152- if ($ event && $ event ->getIO ()->isVerbose ()) {
155+ if ($ event instanceof Event && $ event ->getIO ()->isVerbose ()) {
153156 $ event ->getIO ()->write (sprintf ('Added %s ' , $ targetFilePath ));
154157 }
155158 } catch (IOException $ exception ) {
156- if ($ event ) {
159+ if ($ event instanceof Event ) {
157160 $ event ->getIO ()->write ($ exception ->getMessage ());
158161 }
162+
159163 return ;
160164 }
161165 }
@@ -169,27 +173,29 @@ public function getComposerPackage(): ?BasePackage
169173
170174 $ vendorName = $ this ->getComposerName ();
171175 $ module = $ this ->getInstalledComposerPackage ($ vendorName );
172- if ($ module ) {
176+ if ($ module instanceof BasePackage ) {
173177 return $ module ;
174178 }
175179
176180 $ event = $ this ->getEvent ();
177- if (!$ event ) {
181+ if (!$ event instanceof Event ) {
178182 return null ;
179183 }
180184
181185 $ locker = $ event ->getComposer ()->getLocker ();
182- $ repo = $ locker ->getLockedRepository ();
186+ $ lockArrayRepository = $ locker ->getLockedRepository ();
183187
184- foreach ($ repo ->getPackages () as $ package ) {
185- if ($ package ->getName () === $ vendorName ) {
186- $ this ->setInstalledComposerPackage ($ vendorName , $ package );
188+ foreach ($ lockArrayRepository ->getPackages () as $ basePackage ) {
189+ if ($ basePackage ->getName () === $ vendorName ) {
190+ $ this ->setInstalledComposerPackage ($ vendorName , $ basePackage );
187191 if ($ event ->getIO ()->isVerbose ()) {
188- $ event ->getIO ()->write (sprintf ('%s found with version %s ' , $ vendorName , $ package ->getVersion ()));
192+ $ event ->getIO ()->write (sprintf ('%s found with version %s ' , $ vendorName , $ basePackage ->getVersion ()));
189193 }
194+
190195 return $ this ->getInstalledComposerPackage ($ vendorName );
191196 }
192197 }
198+
193199 return null ;
194200 }
195201
@@ -202,8 +208,9 @@ protected function getUnpkSourcePath(): string
202208 $ search = ['{{package}} ' , '{{version}} ' ];
203209 $ replace = [$ this ->getUnpkgName (), $ this ->getUnpkgVersion ()];
204210 $ path = str_replace ($ search , $ replace , CopyFromUnpkgInterface::UNPKG_URL );
205- return $ path . ($ this ->getUnpkgSource () ? $ this ->getUnpkgSource () . '/ ' : '' );
211+ return $ path . ($ this ->getUnpkgSource () !== '' && $ this -> getUnpkgSource () !== ' 0 ' ? $ this ->getUnpkgSource () . '/ ' : '' );
206212 }
213+
207214 return '' ;
208215 }
209216
@@ -216,6 +223,7 @@ protected function getCwd(): string
216223 if ($ cwd === false ) {
217224 throw new Exception ('This should not happen. ' );
218225 }
226+
219227 return $ cwd ;
220228 }
221229
@@ -225,7 +233,7 @@ protected function getCwd(): string
225233 protected function getVendorDirectoryFromComposer (): string
226234 {
227235 $ event = $ this ->getEvent ();
228- if (!$ event ) {
236+ if (!$ event instanceof Event ) {
229237 return '' ;
230238 }
231239
@@ -240,22 +248,20 @@ protected function getVendorDirectoryFromComposer(): string
240248 protected function getMageRootDirectoryFromComposer (): string
241249 {
242250 $ event = $ this ->getEvent ();
243- if (!$ event ) {
251+ if (!$ event instanceof Event ) {
244252 return '' ;
245253 }
246254
247255 $ composerExtra = $ event ->getComposer ()->getPackage ()->getExtra ();
248- $ magentoRootDir = '' ;
249-
250256 if (array_key_exists (self ::EXTRA_MAGENTO_ROOT_DIR , $ composerExtra ) &&
251- $ composerExtra [self ::EXTRA_MAGENTO_ROOT_DIR ] !== '. '
252- ) {
253- $ magentoRootDir = $ composerExtra [self ::EXTRA_MAGENTO_ROOT_DIR ] . '/ ' ;
257+ $ composerExtra [self ::EXTRA_MAGENTO_ROOT_DIR ] !== '. ' ) {
258+ return $ composerExtra [self ::EXTRA_MAGENTO_ROOT_DIR ] . '/ ' ;
254259 }
255- return $ magentoRootDir ;
260+
261+ return '' ;
256262 }
257263
258- private function getCopyTargetPath (): string
264+ protected function getCopyTargetPath (): string
259265 {
260266 return sprintf (
261267 '%s/%s%s ' ,
@@ -270,9 +276,9 @@ protected function getInstalledComposerPackage(string $vendorName): ?BasePackage
270276 return $ this ->composerPackages [$ vendorName ] ?? null ;
271277 }
272278
273- private function setInstalledComposerPackage (string $ vendorName , BasePackage $ package ): void
279+ protected function setInstalledComposerPackage (string $ vendorName , BasePackage $ basePackage ): void
274280 {
275- $ this ->composerPackages [$ vendorName ] = $ package ;
281+ $ this ->composerPackages [$ vendorName ] = $ basePackage ;
276282 }
277283
278284 public function getFileSystem (): Filesystem
0 commit comments