From 0db443ba5f3a0a19081f7944ba988a32db2e7490 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 23 Feb 2022 14:09:49 +0100 Subject: [PATCH] Add visibility to all consts, fixes #10550 --- .php-cs-fixer.php | 2 +- phpstan/baseline.neon | 8 +++++++ .../Command/BaseDependencyCommand.php | 8 +++---- src/Composer/Command/SelfUpdateCommand.php | 4 ++-- src/Composer/Command/StatusCommand.php | 6 ++--- src/Composer/Composer.php | 14 +++++++---- src/Composer/Config.php | 8 +++---- src/Composer/DependencyResolver/Decisions.php | 4 ++-- .../Operation/InstallOperation.php | 2 +- .../Operation/MarkAliasInstalledOperation.php | 2 +- .../MarkAliasUninstalledOperation.php | 2 +- .../Operation/SolverOperation.php | 5 +++- .../Operation/UninstallOperation.php | 2 +- .../Operation/UpdateOperation.php | 2 +- src/Composer/DependencyResolver/Request.php | 6 ++--- src/Composer/DependencyResolver/Rule.php | 22 ++++++++--------- src/Composer/DependencyResolver/RuleSet.php | 6 ++--- src/Composer/DependencyResolver/Solver.php | 4 ++-- .../SolverProblemsException.php | 2 +- src/Composer/Downloader/PathDownloader.php | 4 ++-- src/Composer/IO/IOInterface.php | 10 ++++---- src/Composer/Installer.php | 10 ++++---- src/Composer/Installer/InstallerEvents.php | 2 +- src/Composer/Installer/PackageEvents.php | 12 +++++----- .../Installer/SuggestedPackagesReporter.php | 6 ++--- src/Composer/Json/JsonFile.php | 8 +++---- src/Composer/Package/BasePackage.php | 10 ++++---- src/Composer/Package/Link.php | 5 +--- .../Package/Loader/LoaderInterface.php | 1 - .../Package/Loader/ValidatingArrayLoader.php | 6 ++--- src/Composer/Package/PackageInterface.php | 6 ++--- src/Composer/Package/RootPackage.php | 2 +- .../Package/Version/VersionParser.php | 2 +- src/Composer/Plugin/PluginEvents.php | 12 +++++----- src/Composer/Plugin/PluginInterface.php | 2 +- .../Repository/PlatformRepository.php | 6 ++++- .../Repository/RepositoryInterface.php | 6 ++--- src/Composer/Repository/RepositorySet.php | 4 ++-- src/Composer/Repository/Vcs/GitLabDriver.php | 2 +- src/Composer/Script/ScriptEvents.php | 24 +++++++++---------- src/Composer/Util/Bitbucket.php | 2 +- src/Composer/Util/ConfigValidator.php | 2 +- src/Composer/Util/HttpDownloader.php | 10 ++++---- src/Composer/Util/ProcessExecutor.php | 10 ++++---- src/Composer/Util/Svn.php | 2 +- src/bootstrap.php | 4 +++- .../Test/Autoload/AutoloadGeneratorTest.php | 5 +--- .../Composer/Test/Command/InitCommandTest.php | 6 +++-- .../Repository/PlatformRepositoryTest.php | 2 +- .../Repository/Vcs/PerforceDriverTest.php | 6 ++--- tests/Composer/Test/Util/PerforceTest.php | 12 +++++----- 51 files changed, 163 insertions(+), 147 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 8e567fe0c..62d1ac7f7 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -65,7 +65,7 @@ return $config->setRules([ // TODO later once 2.2 is more stable // 'array_syntax' => true, // 'list_syntax' => true, - 'visibility_required' => ['elements' => ['property', 'method', /* TODO 'const' but need to review them all */]], + 'visibility_required' => ['elements' => ['property', 'method', 'const']], 'non_printable_character' => true, 'combine_nested_dirname' => true, 'random_api_migration' => true, diff --git a/phpstan/baseline.neon b/phpstan/baseline.neon index 8508c981f..f2e9f63da 100644 --- a/phpstan/baseline.neon +++ b/phpstan/baseline.neon @@ -4415,6 +4415,14 @@ parameters: count: 1 path: ../src/Composer/Repository/PlatformRepository.php + - + message: """ + #^Fetching deprecated class constant PLATFORM_PACKAGE_REGEX of class Composer\\\\Repository\\\\PlatformRepository\\: + use PlatformRepository\\:\\:isPlatformPackage\\(string \\$name\\) instead$# + """ + count: 1 + path: ../src/Composer/Repository/PlatformRepository.php + - message: "#^Only booleans are allowed in &&, mixed given on the right side\\.$#" count: 1 diff --git a/src/Composer/Command/BaseDependencyCommand.php b/src/Composer/Command/BaseDependencyCommand.php index c2597e7c7..f1ebe4277 100644 --- a/src/Composer/Command/BaseDependencyCommand.php +++ b/src/Composer/Command/BaseDependencyCommand.php @@ -36,10 +36,10 @@ use Symfony\Component\Console\Output\OutputInterface; */ class BaseDependencyCommand extends BaseCommand { - const ARGUMENT_PACKAGE = 'package'; - const ARGUMENT_CONSTRAINT = 'version'; - const OPTION_RECURSIVE = 'recursive'; - const OPTION_TREE = 'tree'; + protected const ARGUMENT_PACKAGE = 'package'; + protected const ARGUMENT_CONSTRAINT = 'version'; + protected const OPTION_RECURSIVE = 'recursive'; + protected const OPTION_TREE = 'tree'; /** @var ?string[] */ protected $colors; diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index 38c0e4cdd..38390c0c0 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -36,8 +36,8 @@ use Symfony\Component\Finder\Finder; */ class SelfUpdateCommand extends BaseCommand { - const HOMEPAGE = 'getcomposer.org'; - const OLD_INSTALL_EXT = '-old.phar'; + private const HOMEPAGE = 'getcomposer.org'; + private const OLD_INSTALL_EXT = '-old.phar'; /** * @return void diff --git a/src/Composer/Command/StatusCommand.php b/src/Composer/Command/StatusCommand.php index 8aec0e70d..58b6663a7 100644 --- a/src/Composer/Command/StatusCommand.php +++ b/src/Composer/Command/StatusCommand.php @@ -32,9 +32,9 @@ use Composer\Util\ProcessExecutor; */ class StatusCommand extends BaseCommand { - const EXIT_CODE_ERRORS = 1; - const EXIT_CODE_UNPUSHED_CHANGES = 2; - const EXIT_CODE_VERSION_CHANGES = 4; + private const EXIT_CODE_ERRORS = 1; + private const EXIT_CODE_UNPUSHED_CHANGES = 2; + private const EXIT_CODE_VERSION_CHANGES = 4; /** * @return void diff --git a/src/Composer/Composer.php b/src/Composer/Composer.php index 8913397b6..a4b769ee2 100644 --- a/src/Composer/Composer.php +++ b/src/Composer/Composer.php @@ -29,6 +29,8 @@ class Composer extends PartialComposer /* * Examples of the following constants in the various configurations they can be in * + * You are probably better off using Composer::getVersion() though as that will always return something usable + * * releases (phar): * const VERSION = '1.8.2'; * const BRANCH_ALIAS_VERSION = ''; @@ -46,11 +48,13 @@ class Composer extends PartialComposer * const BRANCH_ALIAS_VERSION = '@package_branch_alias_version@'; * const RELEASE_DATE = '@release_date@'; * const SOURCE_VERSION = '1.8-dev+source'; + * + * @see getVersion() */ - const VERSION = '@package_version@'; - const BRANCH_ALIAS_VERSION = '@package_branch_alias_version@'; - const RELEASE_DATE = '@release_date@'; - const SOURCE_VERSION = '2.3.999-dev+source'; + public const VERSION = '@package_version@'; + public const BRANCH_ALIAS_VERSION = '@package_branch_alias_version@'; + public const RELEASE_DATE = '@release_date@'; + public const SOURCE_VERSION = '2.3.999-dev+source'; /** * Version number of the internal composer-runtime-api package @@ -61,7 +65,7 @@ class Composer extends PartialComposer * * @var string */ - const RUNTIME_API_VERSION = '2.2.2'; + public const RUNTIME_API_VERSION = '2.2.2'; /** * @return string diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 935cd38da..18db2918e 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -24,11 +24,11 @@ use Composer\Util\ProcessExecutor; */ class Config { - const SOURCE_DEFAULT = 'default'; - const SOURCE_COMMAND = 'command'; - const SOURCE_UNKNOWN = 'unknown'; + public const SOURCE_DEFAULT = 'default'; + public const SOURCE_COMMAND = 'command'; + public const SOURCE_UNKNOWN = 'unknown'; - const RELATIVE_PATHS = 1; + public const RELATIVE_PATHS = 1; /** @var array */ public static $defaultConfig = array( diff --git a/src/Composer/DependencyResolver/Decisions.php b/src/Composer/DependencyResolver/Decisions.php index f9e349024..f06a25a8b 100644 --- a/src/Composer/DependencyResolver/Decisions.php +++ b/src/Composer/DependencyResolver/Decisions.php @@ -20,8 +20,8 @@ namespace Composer\DependencyResolver; */ class Decisions implements \Iterator, \Countable { - const DECISION_LITERAL = 0; - const DECISION_REASON = 1; + public const DECISION_LITERAL = 0; + public const DECISION_REASON = 1; /** @var Pool */ protected $pool; diff --git a/src/Composer/DependencyResolver/Operation/InstallOperation.php b/src/Composer/DependencyResolver/Operation/InstallOperation.php index 7f66d17e9..da31a52cc 100644 --- a/src/Composer/DependencyResolver/Operation/InstallOperation.php +++ b/src/Composer/DependencyResolver/Operation/InstallOperation.php @@ -21,7 +21,7 @@ use Composer\Package\PackageInterface; */ class InstallOperation extends SolverOperation implements OperationInterface { - const TYPE = 'install'; + protected const TYPE = 'install'; /** * @var PackageInterface diff --git a/src/Composer/DependencyResolver/Operation/MarkAliasInstalledOperation.php b/src/Composer/DependencyResolver/Operation/MarkAliasInstalledOperation.php index e1c21008b..8626813e2 100644 --- a/src/Composer/DependencyResolver/Operation/MarkAliasInstalledOperation.php +++ b/src/Composer/DependencyResolver/Operation/MarkAliasInstalledOperation.php @@ -21,7 +21,7 @@ use Composer\Package\AliasPackage; */ class MarkAliasInstalledOperation extends SolverOperation implements OperationInterface { - const TYPE = 'markAliasInstalled'; + protected const TYPE = 'markAliasInstalled'; /** * @var AliasPackage diff --git a/src/Composer/DependencyResolver/Operation/MarkAliasUninstalledOperation.php b/src/Composer/DependencyResolver/Operation/MarkAliasUninstalledOperation.php index 6cdd02837..1e858ef1e 100644 --- a/src/Composer/DependencyResolver/Operation/MarkAliasUninstalledOperation.php +++ b/src/Composer/DependencyResolver/Operation/MarkAliasUninstalledOperation.php @@ -21,7 +21,7 @@ use Composer\Package\AliasPackage; */ class MarkAliasUninstalledOperation extends SolverOperation implements OperationInterface { - const TYPE = 'markAliasUninstalled'; + protected const TYPE = 'markAliasUninstalled'; /** * @var AliasPackage diff --git a/src/Composer/DependencyResolver/Operation/SolverOperation.php b/src/Composer/DependencyResolver/Operation/SolverOperation.php index 5aa0957a7..094029af0 100644 --- a/src/Composer/DependencyResolver/Operation/SolverOperation.php +++ b/src/Composer/DependencyResolver/Operation/SolverOperation.php @@ -19,7 +19,10 @@ namespace Composer\DependencyResolver\Operation; */ abstract class SolverOperation implements OperationInterface { - const TYPE = null; + /** + * @abstract must be redefined by extending classes + */ + protected const TYPE = ''; /** * Returns operation type. diff --git a/src/Composer/DependencyResolver/Operation/UninstallOperation.php b/src/Composer/DependencyResolver/Operation/UninstallOperation.php index 7b4ff8ddb..878691508 100644 --- a/src/Composer/DependencyResolver/Operation/UninstallOperation.php +++ b/src/Composer/DependencyResolver/Operation/UninstallOperation.php @@ -21,7 +21,7 @@ use Composer\Package\PackageInterface; */ class UninstallOperation extends SolverOperation implements OperationInterface { - const TYPE = 'uninstall'; + protected const TYPE = 'uninstall'; /** * @var PackageInterface diff --git a/src/Composer/DependencyResolver/Operation/UpdateOperation.php b/src/Composer/DependencyResolver/Operation/UpdateOperation.php index e674376f5..728bb1511 100644 --- a/src/Composer/DependencyResolver/Operation/UpdateOperation.php +++ b/src/Composer/DependencyResolver/Operation/UpdateOperation.php @@ -22,7 +22,7 @@ use Composer\Package\Version\VersionParser; */ class UpdateOperation extends SolverOperation implements OperationInterface { - const TYPE = 'update'; + protected const TYPE = 'update'; /** * @var PackageInterface diff --git a/src/Composer/DependencyResolver/Request.php b/src/Composer/DependencyResolver/Request.php index dde4972f5..d7cde0793 100644 --- a/src/Composer/DependencyResolver/Request.php +++ b/src/Composer/DependencyResolver/Request.php @@ -26,19 +26,19 @@ class Request /** * Identifies a partial update for listed packages only, all dependencies will remain at locked versions */ - const UPDATE_ONLY_LISTED = 0; + public const UPDATE_ONLY_LISTED = 0; /** * Identifies a partial update for listed packages and recursively all their dependencies, however dependencies * also directly required by the root composer.json and their dependencies will remain at the locked version. */ - const UPDATE_LISTED_WITH_TRANSITIVE_DEPS_NO_ROOT_REQUIRE = 1; + public const UPDATE_LISTED_WITH_TRANSITIVE_DEPS_NO_ROOT_REQUIRE = 1; /** * Identifies a partial update for listed packages and recursively all their dependencies, even dependencies * also directly required by the root composer.json will be updated. */ - const UPDATE_LISTED_WITH_TRANSITIVE_DEPS = 2; + public const UPDATE_LISTED_WITH_TRANSITIVE_DEPS = 2; /** @var ?LockArrayRepository */ protected $lockedRepository; diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index bcf32fb03..55e75e624 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -29,19 +29,19 @@ use Composer\Semver\Constraint\ConstraintInterface; abstract class Rule { // reason constants and // their reason data contents - const RULE_ROOT_REQUIRE = 2; // array{packageName: string, constraint: ConstraintInterface} - const RULE_FIXED = 3; // array{package: BasePackage} - const RULE_PACKAGE_CONFLICT = 6; // Link - const RULE_PACKAGE_REQUIRES = 7; // Link - const RULE_PACKAGE_SAME_NAME = 10; // string (package name) - const RULE_LEARNED = 12; // int (rule id) - const RULE_PACKAGE_ALIAS = 13; // BasePackage - const RULE_PACKAGE_INVERSE_ALIAS = 14; // BasePackage + public const RULE_ROOT_REQUIRE = 2; // array{packageName: string, constraint: ConstraintInterface} + public const RULE_FIXED = 3; // array{package: BasePackage} + public const RULE_PACKAGE_CONFLICT = 6; // Link + public const RULE_PACKAGE_REQUIRES = 7; // Link + public const RULE_PACKAGE_SAME_NAME = 10; // string (package name) + public const RULE_LEARNED = 12; // int (rule id) + public const RULE_PACKAGE_ALIAS = 13; // BasePackage + public const RULE_PACKAGE_INVERSE_ALIAS = 14; // BasePackage // bitfield defs - const BITFIELD_TYPE = 0; - const BITFIELD_REASON = 8; - const BITFIELD_DISABLED = 16; + private const BITFIELD_TYPE = 0; + private const BITFIELD_REASON = 8; + private const BITFIELD_DISABLED = 16; /** @var int */ protected $bitfield; diff --git a/src/Composer/DependencyResolver/RuleSet.php b/src/Composer/DependencyResolver/RuleSet.php index d430b46a9..9d856c4b6 100644 --- a/src/Composer/DependencyResolver/RuleSet.php +++ b/src/Composer/DependencyResolver/RuleSet.php @@ -21,9 +21,9 @@ use Composer\Repository\RepositorySet; class RuleSet implements \IteratorAggregate, \Countable { // highest priority => lowest number - const TYPE_PACKAGE = 0; - const TYPE_REQUEST = 1; - const TYPE_LEARNED = 4; + public const TYPE_PACKAGE = 0; + public const TYPE_REQUEST = 1; + public const TYPE_LEARNED = 4; /** * READ-ONLY: Lookup table for rule id to rule object diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index e90c3b67e..0a0720398 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -23,8 +23,8 @@ use Composer\Package\BasePackage; */ class Solver { - const BRANCH_LITERALS = 0; - const BRANCH_LEVEL = 1; + private const BRANCH_LITERALS = 0; + private const BRANCH_LEVEL = 1; /** @var PolicyInterface */ protected $policy; diff --git a/src/Composer/DependencyResolver/SolverProblemsException.php b/src/Composer/DependencyResolver/SolverProblemsException.php index 9e4896e07..57dfcf000 100644 --- a/src/Composer/DependencyResolver/SolverProblemsException.php +++ b/src/Composer/DependencyResolver/SolverProblemsException.php @@ -22,7 +22,7 @@ use Composer\Repository\RepositorySet; */ class SolverProblemsException extends \RuntimeException { - const ERROR_DEPENDENCY_RESOLUTION_FAILED = 2; + public const ERROR_DEPENDENCY_RESOLUTION_FAILED = 2; /** @var Problem[] */ protected $problems; diff --git a/src/Composer/Downloader/PathDownloader.php b/src/Composer/Downloader/PathDownloader.php index c85cbef0f..0cf5d3edf 100644 --- a/src/Composer/Downloader/PathDownloader.php +++ b/src/Composer/Downloader/PathDownloader.php @@ -33,8 +33,8 @@ use Composer\DependencyResolver\Operation\UninstallOperation; */ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInterface { - const STRATEGY_SYMLINK = 10; - const STRATEGY_MIRROR = 20; + private const STRATEGY_SYMLINK = 10; + private const STRATEGY_MIRROR = 20; /** * @inheritDoc diff --git a/src/Composer/IO/IOInterface.php b/src/Composer/IO/IOInterface.php index 66fe735db..ba987cc8a 100644 --- a/src/Composer/IO/IOInterface.php +++ b/src/Composer/IO/IOInterface.php @@ -22,11 +22,11 @@ use Psr\Log\LoggerInterface; */ interface IOInterface extends LoggerInterface { - const QUIET = 1; - const NORMAL = 2; - const VERBOSE = 4; - const VERY_VERBOSE = 8; - const DEBUG = 16; + public const QUIET = 1; + public const NORMAL = 2; + public const VERBOSE = 4; + public const VERY_VERBOSE = 8; + public const DEBUG = 16; /** * Is this input means interactive? diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index d72525b33..162918a5e 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -70,12 +70,12 @@ use Composer\Util\Platform; */ class Installer { - const ERROR_NONE = 0; // no error/success state - const ERROR_GENERIC_FAILURE = 1; - const ERROR_NO_LOCK_FILE_FOR_PARTIAL_UPDATE = 3; - const ERROR_LOCK_FILE_INVALID = 4; + public const ERROR_NONE = 0; // no error/success state + public const ERROR_GENERIC_FAILURE = 1; + public const ERROR_NO_LOCK_FILE_FOR_PARTIAL_UPDATE = 3; + public const ERROR_LOCK_FILE_INVALID = 4; // used/declared in SolverProblemsException, carried over here for completeness - const ERROR_DEPENDENCY_RESOLUTION_FAILED = 2; + public const ERROR_DEPENDENCY_RESOLUTION_FAILED = 2; /** * @var IOInterface diff --git a/src/Composer/Installer/InstallerEvents.php b/src/Composer/Installer/InstallerEvents.php index f75b8bdd4..d536b459c 100644 --- a/src/Composer/Installer/InstallerEvents.php +++ b/src/Composer/Installer/InstallerEvents.php @@ -22,5 +22,5 @@ class InstallerEvents * * @var string */ - const PRE_OPERATIONS_EXEC = 'pre-operations-exec'; + public const PRE_OPERATIONS_EXEC = 'pre-operations-exec'; } diff --git a/src/Composer/Installer/PackageEvents.php b/src/Composer/Installer/PackageEvents.php index 1b48e4f69..852da58ff 100644 --- a/src/Composer/Installer/PackageEvents.php +++ b/src/Composer/Installer/PackageEvents.php @@ -26,7 +26,7 @@ class PackageEvents * * @var string */ - const PRE_PACKAGE_INSTALL = 'pre-package-install'; + public const PRE_PACKAGE_INSTALL = 'pre-package-install'; /** * The POST_PACKAGE_INSTALL event occurs after a package is installed. @@ -35,7 +35,7 @@ class PackageEvents * * @var string */ - const POST_PACKAGE_INSTALL = 'post-package-install'; + public const POST_PACKAGE_INSTALL = 'post-package-install'; /** * The PRE_PACKAGE_UPDATE event occurs before a package is updated. @@ -44,7 +44,7 @@ class PackageEvents * * @var string */ - const PRE_PACKAGE_UPDATE = 'pre-package-update'; + public const PRE_PACKAGE_UPDATE = 'pre-package-update'; /** * The POST_PACKAGE_UPDATE event occurs after a package is updated. @@ -53,7 +53,7 @@ class PackageEvents * * @var string */ - const POST_PACKAGE_UPDATE = 'post-package-update'; + public const POST_PACKAGE_UPDATE = 'post-package-update'; /** * The PRE_PACKAGE_UNINSTALL event occurs before a package has been uninstalled. @@ -62,7 +62,7 @@ class PackageEvents * * @var string */ - const PRE_PACKAGE_UNINSTALL = 'pre-package-uninstall'; + public const PRE_PACKAGE_UNINSTALL = 'pre-package-uninstall'; /** * The POST_PACKAGE_UNINSTALL event occurs after a package has been uninstalled. @@ -71,5 +71,5 @@ class PackageEvents * * @var string */ - const POST_PACKAGE_UNINSTALL = 'post-package-uninstall'; + public const POST_PACKAGE_UNINSTALL = 'post-package-uninstall'; } diff --git a/src/Composer/Installer/SuggestedPackagesReporter.php b/src/Composer/Installer/SuggestedPackagesReporter.php index 3b1c92651..f2cfafebd 100644 --- a/src/Composer/Installer/SuggestedPackagesReporter.php +++ b/src/Composer/Installer/SuggestedPackagesReporter.php @@ -25,9 +25,9 @@ use Symfony\Component\Console\Formatter\OutputFormatter; */ class SuggestedPackagesReporter { - const MODE_LIST = 1; - const MODE_BY_PACKAGE = 2; - const MODE_BY_SUGGESTION = 4; + public const MODE_LIST = 1; + public const MODE_BY_PACKAGE = 2; + public const MODE_BY_SUGGESTION = 4; /** * @var array diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index 3ec407f8a..fb6485b43 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -28,8 +28,8 @@ use Composer\Downloader\TransportException; */ class JsonFile { - const LAX_SCHEMA = 1; - const STRICT_SCHEMA = 2; + public const LAX_SCHEMA = 1; + public const STRICT_SCHEMA = 2; /** @deprecated Use \JSON_UNESCAPED_SLASHES */ public const JSON_UNESCAPED_SLASHES = 64; @@ -38,7 +38,7 @@ class JsonFile /** @deprecated Use \JSON_UNESCAPED_UNICODE */ public const JSON_UNESCAPED_UNICODE = 256; - const COMPOSER_SCHEMA_PATH = '/../../../res/composer-schema.json'; + public const COMPOSER_SCHEMA_PATH = __DIR__ . '/../../../res/composer-schema.json'; /** @var string */ private $path; @@ -200,7 +200,7 @@ class JsonFile $isComposerSchemaFile = false; if (null === $schemaFile) { $isComposerSchemaFile = true; - $schemaFile = __DIR__ . self::COMPOSER_SCHEMA_PATH; + $schemaFile = self::COMPOSER_SCHEMA_PATH; } // Prepend with file:// only when not using a special schema already (e.g. in the phar) diff --git a/src/Composer/Package/BasePackage.php b/src/Composer/Package/BasePackage.php index 35be9e75a..3ab352f6b 100644 --- a/src/Composer/Package/BasePackage.php +++ b/src/Composer/Package/BasePackage.php @@ -34,11 +34,11 @@ abstract class BasePackage implements PackageInterface 'require-dev' => array('description' => 'requires (for development)', 'method' => Link::TYPE_DEV_REQUIRE), ); - const STABILITY_STABLE = 0; - const STABILITY_RC = 5; - const STABILITY_BETA = 10; - const STABILITY_ALPHA = 15; - const STABILITY_DEV = 20; + public const STABILITY_STABLE = 0; + public const STABILITY_RC = 5; + public const STABILITY_BETA = 10; + public const STABILITY_ALPHA = 15; + public const STABILITY_DEV = 20; /** @var array */ public static $stabilities = array( diff --git a/src/Composer/Package/Link.php b/src/Composer/Package/Link.php index 481988c15..1430cd800 100644 --- a/src/Composer/Package/Link.php +++ b/src/Composer/Package/Link.php @@ -32,10 +32,7 @@ class Link * @internal */ public const TYPE_DOES_NOT_REQUIRE = 'does not require'; - /** - * TODO should be marked private once 5.3 is dropped - * @private - */ + private const TYPE_UNKNOWN = 'relates to'; /** diff --git a/src/Composer/Package/Loader/LoaderInterface.php b/src/Composer/Package/Loader/LoaderInterface.php index c81176ded..be2e47042 100644 --- a/src/Composer/Package/Loader/LoaderInterface.php +++ b/src/Composer/Package/Loader/LoaderInterface.php @@ -12,7 +12,6 @@ namespace Composer\Package\Loader; -use Composer\Package\CompletePackageInterface; use Composer\Package\CompletePackage; use Composer\Package\CompleteAliasPackage; use Composer\Package\RootAliasPackage; diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index 997287f44..eb7134eb9 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -24,9 +24,9 @@ use Composer\Spdx\SpdxLicenses; */ class ValidatingArrayLoader implements LoaderInterface { - const CHECK_ALL = 3; - const CHECK_UNBOUND_CONSTRAINTS = 1; - const CHECK_STRICT_CONSTRAINTS = 2; + public const CHECK_ALL = 3; + public const CHECK_UNBOUND_CONSTRAINTS = 1; + public const CHECK_STRICT_CONSTRAINTS = 2; /** @var LoaderInterface */ private $loader; diff --git a/src/Composer/Package/PackageInterface.php b/src/Composer/Package/PackageInterface.php index 31a0e78fb..e666e7139 100644 --- a/src/Composer/Package/PackageInterface.php +++ b/src/Composer/Package/PackageInterface.php @@ -26,9 +26,9 @@ use Composer\Repository\RepositoryInterface; */ interface PackageInterface { - const DISPLAY_SOURCE_REF_IF_DEV = 0; - const DISPLAY_SOURCE_REF = 1; - const DISPLAY_DIST_REF = 2; + public const DISPLAY_SOURCE_REF_IF_DEV = 0; + public const DISPLAY_SOURCE_REF = 1; + public const DISPLAY_DIST_REF = 2; /** * Returns the package's name without version info, thus not a unique identifier diff --git a/src/Composer/Package/RootPackage.php b/src/Composer/Package/RootPackage.php index 07bd31d6f..a0b7ec950 100644 --- a/src/Composer/Package/RootPackage.php +++ b/src/Composer/Package/RootPackage.php @@ -19,7 +19,7 @@ namespace Composer\Package; */ class RootPackage extends CompletePackage implements RootPackageInterface { - const DEFAULT_PRETTY_VERSION = '1.0.0+no-version-set'; + public const DEFAULT_PRETTY_VERSION = '1.0.0+no-version-set'; /** @var string */ protected $minimumStability = 'stable'; diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index faa5002c7..6c0345999 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -20,7 +20,7 @@ use Composer\Semver\Constraint\ConstraintInterface; class VersionParser extends SemverVersionParser { - const DEFAULT_BRANCH_ALIAS = '9999999-dev'; + public const DEFAULT_BRANCH_ALIAS = '9999999-dev'; /** @var array Constraint parsing cache */ private static $constraints = array(); diff --git a/src/Composer/Plugin/PluginEvents.php b/src/Composer/Plugin/PluginEvents.php index ff476ba40..c2e58d510 100644 --- a/src/Composer/Plugin/PluginEvents.php +++ b/src/Composer/Plugin/PluginEvents.php @@ -27,7 +27,7 @@ class PluginEvents * * @var string */ - const INIT = 'init'; + public const INIT = 'init'; /** * The COMMAND event occurs as a command begins @@ -37,7 +37,7 @@ class PluginEvents * * @var string */ - const COMMAND = 'command'; + public const COMMAND = 'command'; /** * The PRE_FILE_DOWNLOAD event occurs before downloading a file @@ -47,7 +47,7 @@ class PluginEvents * * @var string */ - const PRE_FILE_DOWNLOAD = 'pre-file-download'; + public const PRE_FILE_DOWNLOAD = 'pre-file-download'; /** * The POST_FILE_DOWNLOAD event occurs after downloading a package dist file @@ -57,7 +57,7 @@ class PluginEvents * * @var string */ - const POST_FILE_DOWNLOAD = 'post-file-download'; + public const POST_FILE_DOWNLOAD = 'post-file-download'; /** * The PRE_COMMAND_RUN event occurs before a command is executed and lets you modify the input arguments/options @@ -67,7 +67,7 @@ class PluginEvents * * @var string */ - const PRE_COMMAND_RUN = 'pre-command-run'; + public const PRE_COMMAND_RUN = 'pre-command-run'; /** * The PRE_POOL_CREATE event occurs before the Pool of packages is created, and lets @@ -78,5 +78,5 @@ class PluginEvents * * @var string */ - const PRE_POOL_CREATE = 'pre-pool-create'; + public const PRE_POOL_CREATE = 'pre-pool-create'; } diff --git a/src/Composer/Plugin/PluginInterface.php b/src/Composer/Plugin/PluginInterface.php index c2a35e50a..ae5139a84 100644 --- a/src/Composer/Plugin/PluginInterface.php +++ b/src/Composer/Plugin/PluginInterface.php @@ -32,7 +32,7 @@ interface PluginInterface * * @var string */ - const PLUGIN_API_VERSION = '2.3.0'; + public const PLUGIN_API_VERSION = '2.3.0'; /** * Apply plugin modifications to Composer diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 461191e4a..3c9c625fe 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -32,7 +32,11 @@ use Composer\XdebugHandler\XdebugHandler; */ class PlatformRepository extends ArrayRepository { - const PLATFORM_PACKAGE_REGEX = '{^(?:php(?:-64bit|-ipv6|-zts|-debug)?|hhvm|(?:ext|lib)-[a-z0-9](?:[_.-]?[a-z0-9]+)*|composer(?:-(?:plugin|runtime)-api)?)$}iD'; + /** + * @deprecated use PlatformRepository::isPlatformPackage(string $name) instead + * @private + */ + public const PLATFORM_PACKAGE_REGEX = '{^(?:php(?:-64bit|-ipv6|-zts|-debug)?|hhvm|(?:ext|lib)-[a-z0-9](?:[_.-]?[a-z0-9]+)*|composer(?:-(?:plugin|runtime)-api)?)$}iD'; /** * @var ?string diff --git a/src/Composer/Repository/RepositoryInterface.php b/src/Composer/Repository/RepositoryInterface.php index 0de31edd3..129a09498 100644 --- a/src/Composer/Repository/RepositoryInterface.php +++ b/src/Composer/Repository/RepositoryInterface.php @@ -25,9 +25,9 @@ use Composer\Semver\Constraint\ConstraintInterface; */ interface RepositoryInterface extends \Countable { - const SEARCH_FULLTEXT = 0; - const SEARCH_NAME = 1; - const SEARCH_VENDOR = 2; + public const SEARCH_FULLTEXT = 0; + public const SEARCH_NAME = 1; + public const SEARCH_VENDOR = 2; /** * Checks if specified package registered (installed). diff --git a/src/Composer/Repository/RepositorySet.php b/src/Composer/Repository/RepositorySet.php index d13a423e0..c0e39fd5f 100644 --- a/src/Composer/Repository/RepositorySet.php +++ b/src/Composer/Repository/RepositorySet.php @@ -34,11 +34,11 @@ class RepositorySet /** * Packages are returned even though their stability does not match the required stability */ - const ALLOW_UNACCEPTABLE_STABILITIES = 1; + public const ALLOW_UNACCEPTABLE_STABILITIES = 1; /** * Packages will be looked up in all repositories, even after they have been found in a higher prio one */ - const ALLOW_SHADOWED_REPOSITORIES = 2; + public const ALLOW_SHADOWED_REPOSITORIES = 2; /** * @var array[] diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index 047cefa24..13ecd755d 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -82,7 +82,7 @@ class GitLabDriver extends VcsDriver */ private $hasNonstandardOrigin = false; - const URL_REGEX = '#^(?:(?Phttps?)://(?P.+?)(?::(?P[0-9]+))?/|git@(?P[^:]+):)(?P.+)/(?P[^/]+?)(?:\.git|/)?$#'; + private const URL_REGEX = '#^(?:(?Phttps?)://(?P.+?)(?::(?P[0-9]+))?/|git@(?P[^:]+):)(?P.+)/(?P[^/]+?)(?:\.git|/)?$#'; /** * Extracts information from the repository url. diff --git a/src/Composer/Script/ScriptEvents.php b/src/Composer/Script/ScriptEvents.php index d2dc66625..33cc4f57d 100644 --- a/src/Composer/Script/ScriptEvents.php +++ b/src/Composer/Script/ScriptEvents.php @@ -27,7 +27,7 @@ class ScriptEvents * * @var string */ - const PRE_INSTALL_CMD = 'pre-install-cmd'; + public const PRE_INSTALL_CMD = 'pre-install-cmd'; /** * The POST_INSTALL_CMD event occurs after the install command is executed. @@ -36,7 +36,7 @@ class ScriptEvents * * @var string */ - const POST_INSTALL_CMD = 'post-install-cmd'; + public const POST_INSTALL_CMD = 'post-install-cmd'; /** * The PRE_UPDATE_CMD event occurs before the update command is executed. @@ -45,7 +45,7 @@ class ScriptEvents * * @var string */ - const PRE_UPDATE_CMD = 'pre-update-cmd'; + public const PRE_UPDATE_CMD = 'pre-update-cmd'; /** * The POST_UPDATE_CMD event occurs after the update command is executed. @@ -54,7 +54,7 @@ class ScriptEvents * * @var string */ - const POST_UPDATE_CMD = 'post-update-cmd'; + public const POST_UPDATE_CMD = 'post-update-cmd'; /** * The PRE_STATUS_CMD event occurs before the status command is executed. @@ -63,7 +63,7 @@ class ScriptEvents * * @var string */ - const PRE_STATUS_CMD = 'pre-status-cmd'; + public const PRE_STATUS_CMD = 'pre-status-cmd'; /** * The POST_STATUS_CMD event occurs after the status command is executed. @@ -72,7 +72,7 @@ class ScriptEvents * * @var string */ - const POST_STATUS_CMD = 'post-status-cmd'; + public const POST_STATUS_CMD = 'post-status-cmd'; /** * The PRE_AUTOLOAD_DUMP event occurs before the autoload file is generated. @@ -81,7 +81,7 @@ class ScriptEvents * * @var string */ - const PRE_AUTOLOAD_DUMP = 'pre-autoload-dump'; + public const PRE_AUTOLOAD_DUMP = 'pre-autoload-dump'; /** * The POST_AUTOLOAD_DUMP event occurs after the autoload file has been generated. @@ -90,7 +90,7 @@ class ScriptEvents * * @var string */ - const POST_AUTOLOAD_DUMP = 'post-autoload-dump'; + public const POST_AUTOLOAD_DUMP = 'post-autoload-dump'; /** * The POST_ROOT_PACKAGE_INSTALL event occurs after the root package has been installed. @@ -99,7 +99,7 @@ class ScriptEvents * * @var string */ - const POST_ROOT_PACKAGE_INSTALL = 'post-root-package-install'; + public const POST_ROOT_PACKAGE_INSTALL = 'post-root-package-install'; /** * The POST_CREATE_PROJECT event occurs after the create-project command has been executed. @@ -109,7 +109,7 @@ class ScriptEvents * * @var string */ - const POST_CREATE_PROJECT_CMD = 'post-create-project-cmd'; + public const POST_CREATE_PROJECT_CMD = 'post-create-project-cmd'; /** * The PRE_ARCHIVE_CMD event occurs before the update command is executed. @@ -118,7 +118,7 @@ class ScriptEvents * * @var string */ - const PRE_ARCHIVE_CMD = 'pre-archive-cmd'; + public const PRE_ARCHIVE_CMD = 'pre-archive-cmd'; /** * The POST_ARCHIVE_CMD event occurs after the status command is executed. @@ -127,5 +127,5 @@ class ScriptEvents * * @var string */ - const POST_ARCHIVE_CMD = 'post-archive-cmd'; + public const POST_ARCHIVE_CMD = 'post-archive-cmd'; } diff --git a/src/Composer/Util/Bitbucket.php b/src/Composer/Util/Bitbucket.php index 4ce3b7599..b80eb37be 100644 --- a/src/Composer/Util/Bitbucket.php +++ b/src/Composer/Util/Bitbucket.php @@ -35,7 +35,7 @@ class Bitbucket /** @var int|null */ private $time; - const OAUTH2_ACCESS_TOKEN_URL = 'https://bitbucket.org/site/oauth2/access_token'; + public const OAUTH2_ACCESS_TOKEN_URL = 'https://bitbucket.org/site/oauth2/access_token'; /** * Constructor. diff --git a/src/Composer/Util/ConfigValidator.php b/src/Composer/Util/ConfigValidator.php index 4d2f50d2d..ea84c10b2 100644 --- a/src/Composer/Util/ConfigValidator.php +++ b/src/Composer/Util/ConfigValidator.php @@ -29,7 +29,7 @@ use Composer\Spdx\SpdxLicenses; */ class ConfigValidator { - const CHECK_VERSION = 1; + public const CHECK_VERSION = 1; /** @var IOInterface */ private $io; diff --git a/src/Composer/Util/HttpDownloader.php b/src/Composer/Util/HttpDownloader.php index 80d1385c0..b39108724 100644 --- a/src/Composer/Util/HttpDownloader.php +++ b/src/Composer/Util/HttpDownloader.php @@ -32,11 +32,11 @@ use React\Promise\PromiseInterface; */ class HttpDownloader { - const STATUS_QUEUED = 1; - const STATUS_STARTED = 2; - const STATUS_COMPLETED = 3; - const STATUS_FAILED = 4; - const STATUS_ABORTED = 5; + private const STATUS_QUEUED = 1; + private const STATUS_STARTED = 2; + private const STATUS_COMPLETED = 3; + private const STATUS_FAILED = 4; + private const STATUS_ABORTED = 5; /** @var IOInterface */ private $io; diff --git a/src/Composer/Util/ProcessExecutor.php b/src/Composer/Util/ProcessExecutor.php index 429337708..aa9bb5eaf 100644 --- a/src/Composer/Util/ProcessExecutor.php +++ b/src/Composer/Util/ProcessExecutor.php @@ -25,11 +25,11 @@ use React\Promise\PromiseInterface; */ class ProcessExecutor { - const STATUS_QUEUED = 1; - const STATUS_STARTED = 2; - const STATUS_COMPLETED = 3; - const STATUS_FAILED = 4; - const STATUS_ABORTED = 5; + private const STATUS_QUEUED = 1; + private const STATUS_STARTED = 2; + private const STATUS_COMPLETED = 3; + private const STATUS_FAILED = 4; + private const STATUS_ABORTED = 5; /** @var int */ protected static $timeout = 300; diff --git a/src/Composer/Util/Svn.php b/src/Composer/Util/Svn.php index 86416e56d..00a090d5c 100644 --- a/src/Composer/Util/Svn.php +++ b/src/Composer/Util/Svn.php @@ -22,7 +22,7 @@ use Composer\Pcre\Preg; */ class Svn { - const MAX_QTY_AUTH_TRIES = 5; + private const MAX_QTY_AUTH_TRIES = 5; /** * @var ?array{username: string, password: string} diff --git a/src/bootstrap.php b/src/bootstrap.php index f61063a4a..3b2cb4d85 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -10,7 +10,9 @@ * file that was distributed with this source code. */ -function includeIfExists(string $file): ?\Composer\Autoload\ClassLoader +use Composer\Autoload\ClassLoader; + +function includeIfExists(string $file): ?ClassLoader { return file_exists($file) ? include $file : null; } diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 507d161b1..6a3fbec83 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -82,12 +82,9 @@ class AutoloadGeneratorTest extends TestCase * Map of setting name => return value configuration for the stub Config * object. * - * Note: must be public for compatibility with PHP 5.3 runtimes where - * closures cannot access private members of the classes they are created - * in. * @var array */ - public $configValueMap; + private $configValueMap; protected function setUp(): void { diff --git a/tests/Composer/Test/Command/InitCommandTest.php b/tests/Composer/Test/Command/InitCommandTest.php index 25af49ed5..f33f730b9 100644 --- a/tests/Composer/Test/Command/InitCommandTest.php +++ b/tests/Composer/Test/Command/InitCommandTest.php @@ -66,7 +66,8 @@ class InitCommandTest extends TestCase public function testParseValidAlias1AuthorString(): void { $command = new InitCommand; - $author = $this->callParseAuthorString($command, + $author = $this->callParseAuthorString( + $command, 'Johnathon "Johnny" Smith ' ); $this->assertEquals('Johnathon "Johnny" Smith', $author['name']); @@ -80,7 +81,8 @@ class InitCommandTest extends TestCase public function testParseValidAlias2AuthorString(): void { $command = new InitCommand; - $author = $this->callParseAuthorString($command, + $author = $this->callParseAuthorString( + $command, 'Johnathon (Johnny) Smith ' ); $this->assertEquals('Johnathon (Johnny) Smith', $author['name']); diff --git a/tests/Composer/Test/Repository/PlatformRepositoryTest.php b/tests/Composer/Test/Repository/PlatformRepositoryTest.php index 22445b4df..18c2a68d8 100644 --- a/tests/Composer/Test/Repository/PlatformRepositoryTest.php +++ b/tests/Composer/Test/Repository/PlatformRepositoryTest.php @@ -1271,7 +1271,7 @@ Linked Version => 1.2.11', class ResourceBundleStub { - const STUB_VERSION = '32.0.1'; + public const STUB_VERSION = '32.0.1'; /** * @param string $locale diff --git a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php index f1787e71c..fda883a43 100644 --- a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php @@ -57,9 +57,9 @@ class PerforceDriverTest extends TestCase */ protected $perforce; - const TEST_URL = 'TEST_PERFORCE_URL'; - const TEST_DEPOT = 'TEST_DEPOT_CONFIG'; - const TEST_BRANCH = 'TEST_BRANCH_CONFIG'; + private const TEST_URL = 'TEST_PERFORCE_URL'; + private const TEST_DEPOT = 'TEST_DEPOT_CONFIG'; + private const TEST_BRANCH = 'TEST_BRANCH_CONFIG'; protected function setUp(): void { diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index b42f484b3..7b524337f 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -32,12 +32,12 @@ class PerforceTest extends TestCase /** @var \PHPUnit\Framework\MockObject\MockObject&\Composer\IO\IOInterface */ protected $io; - const TEST_DEPOT = 'depot'; - const TEST_BRANCH = 'branch'; - const TEST_P4USER = 'user'; - const TEST_CLIENT_NAME = 'TEST'; - const TEST_PORT = 'port'; - const TEST_PATH = 'path'; + private const TEST_DEPOT = 'depot'; + private const TEST_BRANCH = 'branch'; + private const TEST_P4USER = 'user'; + private const TEST_CLIENT_NAME = 'TEST'; + private const TEST_PORT = 'port'; + private const TEST_PATH = 'path'; protected function setUp(): void {