2626 */
2727class InstalledVersions
2828{
29- /**
30- * @var string|null if set (by reflection by Composer), this should be set to the path where this class is being copied to
31- * @internal
32- */
33- private static $ selfDir = null ;
34-
3529 /**
3630 * @var mixed[]|null
3731 * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
3832 */
3933 private static $ installed ;
4034
41- /**
42- * @var bool
43- */
44- private static $ installedIsLocalDir ;
45-
4635 /**
4736 * @var bool|null
4837 */
@@ -320,24 +309,6 @@ public static function reload($data)
320309 {
321310 self ::$ installed = $ data ;
322311 self ::$ installedByVendor = array ();
323-
324- // when using reload, we disable the duplicate protection to ensure that self::$installed data is
325- // always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
326- // so we have to assume it does not, and that may result in duplicate data being returned when listing
327- // all installed packages for example
328- self ::$ installedIsLocalDir = false ;
329- }
330-
331- /**
332- * @return string
333- */
334- private static function getSelfDir ()
335- {
336- if (self ::$ selfDir === null ) {
337- self ::$ selfDir = strtr (__DIR__ , '\\' , '/ ' );
338- }
339-
340- return self ::$ selfDir ;
341312 }
342313
343314 /**
@@ -354,24 +325,19 @@ private static function getInstalled()
354325 $ copiedLocalDir = false ;
355326
356327 if (self ::$ canGetVendors ) {
357- $ selfDir = self ::getSelfDir ();
358328 foreach (ClassLoader::getRegisteredLoaders () as $ vendorDir => $ loader ) {
359- $ vendorDir = strtr ($ vendorDir , '\\' , '/ ' );
360329 if (isset (self ::$ installedByVendor [$ vendorDir ])) {
361330 $ installed [] = self ::$ installedByVendor [$ vendorDir ];
362331 } elseif (is_file ($ vendorDir .'/composer/installed.php ' )) {
363332 /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
364333 $ required = require $ vendorDir .'/composer/installed.php ' ;
365334 self ::$ installedByVendor [$ vendorDir ] = $ required ;
366335 $ installed [] = $ required ;
367- if (self :: $ installed === null && $ vendorDir .'/composer ' === $ selfDir ) {
336+ if (strtr ( $ vendorDir .'/composer ' , '\\' , ' / ' ) === strtr ( __DIR__ , '\\' , ' / ' ) ) {
368337 self ::$ installed = $ required ;
369- self :: $ installedIsLocalDir = true ;
338+ $ copiedLocalDir = true ;
370339 }
371340 }
372- if (self ::$ installedIsLocalDir && $ vendorDir .'/composer ' === $ selfDir ) {
373- $ copiedLocalDir = true ;
374- }
375341 }
376342 }
377343
0 commit comments