Skip to content

Commit

Permalink
Add visibility to all consts, fixes composer#10550
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek authored and emahorvat52 committed Jan 18, 2023
1 parent 9c4b0ac commit c840a1d
Show file tree
Hide file tree
Showing 51 changed files with 163 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Expand Up @@ -65,7 +65,7 @@
// 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,
Expand Down
8 changes: 8 additions & 0 deletions phpstan/baseline.neon
Expand Up @@ -5495,6 +5495,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
Expand Down
8 changes: 4 additions & 4 deletions src/Composer/Command/BaseDependencyCommand.php
Expand Up @@ -36,10 +36,10 @@
*/
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;
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Command/SelfUpdateCommand.php
Expand Up @@ -36,8 +36,8 @@
*/
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
Expand Down
6 changes: 3 additions & 3 deletions src/Composer/Command/StatusCommand.php
Expand Up @@ -32,9 +32,9 @@
*/
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
Expand Down
14 changes: 9 additions & 5 deletions src/Composer/Composer.php
Expand Up @@ -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 = '';
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/Composer/Config.php
Expand Up @@ -24,11 +24,11 @@
*/
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<string, mixed> */
public static $defaultConfig = array(
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/DependencyResolver/Decisions.php
Expand Up @@ -20,8 +20,8 @@
*/
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;
Expand Down
Expand Up @@ -21,7 +21,7 @@
*/
class InstallOperation extends SolverOperation implements OperationInterface
{
const TYPE = 'install';
protected const TYPE = 'install';

/**
* @var PackageInterface
Expand Down
Expand Up @@ -21,7 +21,7 @@
*/
class MarkAliasInstalledOperation extends SolverOperation implements OperationInterface
{
const TYPE = 'markAliasInstalled';
protected const TYPE = 'markAliasInstalled';

/**
* @var AliasPackage
Expand Down
Expand Up @@ -21,7 +21,7 @@
*/
class MarkAliasUninstalledOperation extends SolverOperation implements OperationInterface
{
const TYPE = 'markAliasUninstalled';
protected const TYPE = 'markAliasUninstalled';

/**
* @var AliasPackage
Expand Down
Expand Up @@ -19,7 +19,10 @@
*/
abstract class SolverOperation implements OperationInterface
{
const TYPE = null;
/**
* @abstract must be redefined by extending classes
*/
protected const TYPE = '';

/**
* Returns operation type.
Expand Down
Expand Up @@ -21,7 +21,7 @@
*/
class UninstallOperation extends SolverOperation implements OperationInterface
{
const TYPE = 'uninstall';
protected const TYPE = 'uninstall';

/**
* @var PackageInterface
Expand Down
Expand Up @@ -22,7 +22,7 @@
*/
class UpdateOperation extends SolverOperation implements OperationInterface
{
const TYPE = 'update';
protected const TYPE = 'update';

/**
* @var PackageInterface
Expand Down
6 changes: 3 additions & 3 deletions src/Composer/DependencyResolver/Request.php
Expand Up @@ -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;
Expand Down
22 changes: 11 additions & 11 deletions src/Composer/DependencyResolver/Rule.php
Expand Up @@ -29,19 +29,19 @@
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;
Expand Down
6 changes: 3 additions & 3 deletions src/Composer/DependencyResolver/RuleSet.php
Expand Up @@ -21,9 +21,9 @@
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
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/DependencyResolver/Solver.php
Expand Up @@ -23,8 +23,8 @@
*/
class Solver
{
const BRANCH_LITERALS = 0;
const BRANCH_LEVEL = 1;
private const BRANCH_LITERALS = 0;
private const BRANCH_LEVEL = 1;

/** @var PolicyInterface */
protected $policy;
Expand Down
Expand Up @@ -22,7 +22,7 @@
*/
class SolverProblemsException extends \RuntimeException
{
const ERROR_DEPENDENCY_RESOLUTION_FAILED = 2;
public const ERROR_DEPENDENCY_RESOLUTION_FAILED = 2;

/** @var Problem[] */
protected $problems;
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Downloader/PathDownloader.php
Expand Up @@ -33,8 +33,8 @@
*/
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
Expand Down
10 changes: 5 additions & 5 deletions src/Composer/IO/IOInterface.php
Expand Up @@ -22,11 +22,11 @@
*/
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?
Expand Down
10 changes: 5 additions & 5 deletions src/Composer/Installer.php
Expand Up @@ -70,12 +70,12 @@
*/
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
Expand Down
2 changes: 1 addition & 1 deletion src/Composer/Installer/InstallerEvents.php
Expand Up @@ -22,5 +22,5 @@ class InstallerEvents
*
* @var string
*/
const PRE_OPERATIONS_EXEC = 'pre-operations-exec';
public const PRE_OPERATIONS_EXEC = 'pre-operations-exec';
}
12 changes: 6 additions & 6 deletions src/Composer/Installer/PackageEvents.php
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -71,5 +71,5 @@ class PackageEvents
*
* @var string
*/
const POST_PACKAGE_UNINSTALL = 'post-package-uninstall';
public const POST_PACKAGE_UNINSTALL = 'post-package-uninstall';
}
6 changes: 3 additions & 3 deletions src/Composer/Installer/SuggestedPackagesReporter.php
Expand Up @@ -25,9 +25,9 @@
*/
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<array{source: string, target: string, reason: string}>
Expand Down

0 comments on commit c840a1d

Please sign in to comment.