vendor/composer/package-versions-deprecated/src/PackageVersions/Versions.php line 55

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace PackageVersions;
  4. use Composer\InstalledVersions;
  5. use OutOfBoundsException;
  6. use UnexpectedValueException;
  7. class_exists(InstalledVersions::class);
  8. /**
  9.  * This is a stub class: it is in place only for scenarios where PackageVersions
  10.  * is installed with a `--no-scripts` flag, in which scenarios the Versions class
  11.  * is not being replaced.
  12.  *
  13.  * If you are reading this docBlock inside your `vendor/` dir, then this means
  14.  * that PackageVersions didn't correctly install, and is in "fallback" mode.
  15.  */
  16. final class Versions
  17. {
  18.     /**
  19.      * @deprecated please use {@see self::rootPackageName()} instead.
  20.      *             This constant will be removed in version 2.0.0.
  21.      */
  22.     const ROOT_PACKAGE_NAME 'unknown/root-package@UNKNOWN';
  23.     /** @internal */
  24.     const VERSIONS          = [];
  25.     private function __construct()
  26.     {
  27.     }
  28.     /**
  29.      * @psalm-pure
  30.      *
  31.      * @psalm-suppress ImpureMethodCall we know that {@see InstalledVersions} interaction does not
  32.      *                                  cause any side effects here.
  33.      */
  34.     public static function rootPackageName() : string
  35.     {
  36.         if (!class_exists(InstalledVersions::class, false) || !InstalledVersions::getRawData()) {
  37.             return self::ROOT_PACKAGE_NAME;
  38.         }
  39.         return InstalledVersions::getRootPackage()['name'];
  40.     }
  41.     /**
  42.      * @throws OutOfBoundsException if a version cannot be located.
  43.      * @throws UnexpectedValueException if the composer.lock file could not be located.
  44.      */
  45.     public static function getVersion(string $packageName): string
  46.     {
  47.         if (!class_exists(InstalledVersions::class, false) || !InstalledVersions::getRawData()) {
  48.             return FallbackVersions::getVersion($packageName);
  49.         }
  50.         /** @psalm-suppress DeprecatedConstant */
  51.         if ($packageName === self::ROOT_PACKAGE_NAME) {
  52.             $rootPackage InstalledVersions::getRootPackage();
  53.             return $rootPackage['pretty_version'] . '@' $rootPackage['reference'];
  54.         }
  55.         return InstalledVersions::getPrettyVersion($packageName)
  56.             . '@' InstalledVersions::getReference($packageName);
  57.     }
  58. }