8000 Changed private static properties to private const by simonberger · Pull Request #38213 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Changed private static properties to private const #38213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Monolog/Command/ServerLogCommand.php
9E12
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
class ServerLogCommand extends Command
{
private static $bgColor = ['black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow'];
private const BG_COLOR = ['black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow'];

private $el;
private $handler;
Expand Down Expand Up @@ -151,7 +151,7 @@ private function displayLog(OutputInterface $output, int $clientId, array $recor
if (isset($record['log_id'])) {
$clientId = unpack('H*', $record['log_id'])[1];
}
$logBlock = sprintf('<bg=%s> </>', self::$bgColor[$clientId % 8]);
$logBlock = sprintf('<bg=%s> </>', self::BG_COLOR[$clientId % 8]);
$output->write($logBlock);

$this->handler->handle($record);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ConsoleFormatter implements FormatterInterface
const SIMPLE_FORMAT = "%datetime% %start_tag%%level_name%%end_tag% <comment>[%channel%]</> %message%%context%%extra%\n";
const SIMPLE_DATE = 'H:i:s';

private static $levelColorMap = [
private const LEVEL_COLOR_MAP = [
Logger::DEBUG => 'fg=white',
Logger::INFO => 'fg=green',
Logger::NOTICE => 'fg=blue',
Expand Down Expand Up @@ -100,7 +100,7 @@ public function format(array $record)
{
$record = $this->replacePlaceHolder($record);

$levelColor = self::$levelColorMap[$record['level']];
$levelColor = self::LEVEL_COLOR_MAP[$record['level']];

if (!$this->options['ignore_empty_context_and_extra'] || !empty($record['context'])) {
$context = ($this->options['multiline'] ? "\n" : ' ').$this->dumpData($record['context']);
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Bridge/PhpUnit/DnsMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class DnsMock
{
private static $hosts = [];
private static $dnsTypes = [
private const DNS_TYPES = [
'A' => DNS_A,
'MX' => DNS_MX,
'NS' => DNS_NS,
Expand Down Expand Up @@ -54,7 +54,7 @@ public static function checkdnsrr($hostname, $type = 'MX')
if ($record['type'] === $type) {
return true;
}
if ('ANY' === $type && isset(self::$dnsTypes[$record['type']]) && 'HINFO' !== $record['type']) {
if ('ANY' === $type && isset(self::DNS_TYPES[$record['type']]) && 'HINFO' !== $record['type']) {
return true;
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public static function dns_get_record($hostname, $type = DNS_ANY, &$authns = nul
$records = [];

foreach (self::$hosts[$hostname] as $record) {
if (isset(self::$dnsTypes[$record['type']]) && (self::$dnsTypes[$record['type']] & $type)) {
if (isset(self::DNS_TYPES[$record['type']]) && (self::DNS_TYPES[$record['type']] & $type)) {
$records[] = array_merge(['host' => $hostname, 'class' => 'IN', 'ttl' => 1, 'type' => $record['type']], $record);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

class TranslationDefaultDomainNodeVisitorTest extends TestCase
{
private static $message = 'message';
private static $domain = 'domain';
private const MESSAGE = 'message';
private const DOMAIN = 'domain';

/** @dataProvider getDefaultDomainAssignmentTestData */
public function testDefaultDomainAssignment(Node $node)
Expand All @@ -30,7 +30,7 @@ public function testDefaultDomainAssignment(Node $node)
$visitor = new TranslationDefaultDomainNodeVisitor();

// visit trans_default_domain tag
$defaultDomain = TwigNodeProvider::getTransDefaultDomainTag(self::$domain);
$defaultDomain = TwigNodeProvider::getTransDefaultDomainTag(self::DOMAIN);
$visitor->enterNode($defaultDomain, $env);
$visitor->leaveNode($defaultDomain, $env);

Expand All @@ -46,7 +46,7 @@ public function testDefaultDomainAssignment(Node $node)
$visitor->enterNode($node, $env);
$visitor->leaveNode($node, $env);

$this->assertEquals([[self::$message, self::$domain]], $visitor->getMessages());
$this->assertEquals([[self::MESSAGE, self::DOMAIN]], $visitor->getMessages());
}

/** @dataProvider getDefaultDomainAssignmentTestData */
Expand All @@ -72,16 +72,16 @@ public function testNewModuleWithoutDefaultDomainTag(Node $node)
$visitor->enterNode($node, $env);
$visitor->leaveNode($node, $env);

$this->assertEquals([[self::$message, null]], $visitor->getMessages());
$this->assertEquals([[self::MESSAGE, null]], $visitor->getMessages());
}

public function getDefaultDomainAssignmentTestData()
{
return [
[TwigNodeProvider::getTransFilter(self::$message)],
[TwigNodeProvider::getTransTag(self::$message)],
[TwigNodeProvider::getTransFilter(self::MESSAGE)],
[TwigNodeProvider::getTransTag(self::MESSAGE)],
// with named arguments
[TwigNodeProvider::getTransFilter(self::$message, null, [
[TwigNodeProvider::getTransFilter(self::MESSAGE, null, [
'arguments' => new ArrayExpression([], 0),
])],
];
Expand Down
18 changes: 9 additions & 9 deletions src/Symfony/Bridge/Twig/UndefinedCallableHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
*/
class UndefinedCallableHandler
{
private static $filterComponents = [
private const FILTER_COMPONENTS = [
'humanize' => 'form',
'trans' => 'translation',
'transchoice' => 'translation',
'yaml_encode' => 'yaml',
'yaml_dump' => 'yaml',
];

private static $functionComponents = [
private const FUNCTION_COMPONENTS = [
'asset' => 'asset',
'asset_version' => 'asset',
'dump' => 'debug-bundle',
Expand Down Expand Up @@ -57,7 +57,7 @@ class UndefinedCallableHandler
'workflow_marked_places' => 'workflow',
];

private static $fullStackEnable = [
private const FULL_STACK_ENABLE = [
'form' => 'enable "framework.form"',
'security-core' => 'add the "SecurityBundle"',
'security-http' => 'add the "SecurityBundle"',
Expand All @@ -67,30 +67,30 @@ class UndefinedCallableHandler

public static function onUndefinedFilter(string $name): bool
{
if (!isset(self::$filterComponents[$name])) {
if (!isset(self::FILTER_COMPONENTS[$name])) {
return false;
}

self::onUndefined($name, 'filter', self::$filterComponents[$name]);
self::onUndefined($name, 'filter', self::FILTER_COMPONENTS[$name]);

return true;
}

public static function onUndefinedFunction(string $name): bool
{
if (!isset(self::$functionComponents[$name])) {
if (!isset(self::FUNCTION_COMPONENTS[$name])) {
return false;
}

self::onUndefined($name, 'function', self::$functionComponents[$name]);
self::onUndefined($name, 'function', self::FUNCTION_COMPONENTS[$name]);

return true;
}

private static function onUndefined(string $name, string $type, string $component)
{
if (class_exists(FullStack::class) && isset(self::$fullStackEnable[$component])) {
throw new SyntaxError(sprintf('Did you forget to %s? Unknown %s "%s".', self::$fullStackEnable[$component], $type, $name));
if (class_exists(FullStack::class) && isset(self::FULL_STACK_ENABLE[$component])) {
throw new SyntaxError(sprintf('Did you forget to %s? Unknown %s "%s".', self::FULL_STACK_ENABLE[$component], $type, $name));
}

throw new SyntaxError(sprintf('Did you forget to run "composer require symfony/%s"? Unknown %s "%s".', $component, $type, $name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
*/
class RegisterGlobalSecurityEventListenersPass implements CompilerPassInterface
{
private static $eventBubblingEvents = [CheckPassportEvent::class, LoginFailureEvent::class, LoginSuccessEvent::class, LogoutEvent::class];
private const EVENT_BUBBLING_EVENTS = [
CheckPassportEvent::class,
LoginFailureEvent::class,
LoginSuccessEvent::class,
LogoutEvent::class,
];

/**
* {@inheritdoc}
Expand All @@ -58,7 +63,7 @@ public function process(ContainerBuilder $container)
}

$methodCallArguments = $methodCall[1];
if (!\in_array($methodCallArguments[0], self::$eventBubblingEvents, true)) {
if (!\in_array($methodCallArguments[0], self::EVENT_BUBBLING_EVENTS, true)) {
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/BrowserKit/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Cookie
* Handles dates as defined by RFC 2616 section 3.3.1, and also some other
* non-standard, but common formats.
*/
private static $dateFormats = [
private const DATE_FORMATS = [
'D, d M Y H:i:s T',
'D, d-M-y H:i:s T',
'D, d-M-Y H:i:s T',
Expand Down Expand Up @@ -92,7 +92,7 @@ public function __toString()

if (null !== $this->expires) {
$dateTime = \DateTime::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'));
$cookie .= '; expires='.str_replace('+0000', '', $dateTime->format(self::$dateFormats[0]));
$cookie .= '; expires='.str_replace('+0000', '', $dateTime->format(self::DATE_FORMATS[0]));
}

if ('' !== $this->domain) {
Expand Down Expand Up @@ -205,7 +205,7 @@ private static function parseDate(string $dateValue): ?string
$dateValue = substr($dateValue, 1, -1);
}

foreach (self::$dateFormats as $dateFormat) {
foreach (self::DATE_FORMATS as $dateFormat) {
if (false !== $date = \DateTime::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) {
return $date->format('U');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/DependencyInjection/Alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Alias
private $public;
private $deprecation = [];

private static $defaultDeprecationTemplate = 'The "%alias_id%" service alias is deprecated. You should stop using it, as it will be removed in the future.';
private const DEFAULT_DEPRECATION_TEMPLATE = 'The "%alias_id%" service alias is deprecated. You should stop using it, as it will be removed in the future.';

public function __construct(string $id, bool $public = false)
{
Expand Down Expand Up @@ -117,7 +117,7 @@ public function setDeprecated(/* string $package, string $version, string $messa
}
}

$this->deprecation = $status ? ['package' => $package, 'version' => $version, 'message' => $message ?: self::$defaultDeprecationTemplate] : [];
$this->deprecation = $status ? ['package' => $package, 'version' => $version, 'message' => $message ?: self::DEFAULT_DEPRECATION_TEMPLATE] : [];

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class RegisterEnvVarProcessorsPass implements CompilerPassInterface
{
private static $allowedTypes = ['array', 'bool', 'float', 'int', 'string'];
private const ALLOWED_TYPES = ['array', 'bool', 'float', 'int', 'string'];

public function process(ContainerBuilder $container)
{
Expand Down Expand Up @@ -65,8 +65,8 @@ private static function validateProvidedTypes(string $types, string $class): arr
$types = explode('|', $types);

foreach ($types as $type) {
if (!\in_array($type, self::$allowedTypes)) {
throw new InvalidArgumentException(sprintf('Invalid type "%s" returned by "%s::getProvidedTypes()", expected one of "%s".', $type, $class, implode('", "', self::$allowedTypes)));
if (!\in_array($type, self::ALLOWED_TYPES)) {
throw new InvalidArgumentException(sprintf('Invalid type "%s" returned by "%s::getProvidedTypes()", expected one of "%s".', $type, $class, implode('", "', self::ALLOWED_TYPES)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface

private $removedBindingIds = [];

private static $internalTypes = [
private const INTERNAL_TYPES = [
'int' => true,
'float' => true,
'string' => true,
Expand Down Expand Up @@ -334,7 +334,7 @@ public function getReflectionClass(?string $class, bool $throw = true): ?\Reflec
return null;
}

if (isset(self::$internalTypes[$class])) {
if (isset(self::INTERNAL_TYPES[$class])) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/DependencyInjection/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Definition

protected $arguments = [];

private static $defaultDeprecationTemplate = 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.';
private const DEFAULT_DEPRECATION_TEMPLATE = 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.';

/**
* @internal
Expand Down Expand Up @@ -744,7 +744,7 @@ public function setDeprecated(/* string $package, string $version, string $messa
}

$this->changes['deprecated'] = true;
$this->deprecation = $status ? ['package' => $package, 'version' => $version, 'message' => $message ?: self::$defaultDeprecationTemplate] : [];
$this->deprecation = $status ? ['package' => $package, 'version' => $version, 'message' => $message ?: self::DEFAULT_DEPRECATION_TEMPLATE] : [];

return $this;
}
Expand Down
20 changes: 10 additions & 10 deletions src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
class YamlFileLoader extends FileLoader
{
private static $serviceKeywords = [
private const SERVICE_KEYWORDS = [
'alias' => 'alias',
'parent' => 'parent',
'class' => 'class',
Expand All @@ -65,7 +65,7 @@ class YamlFileLoader extends FileLoader
'bind' => 'bind',
];

private static $prototypeKeywords = [
private const PROTOTYPE_KEYWORDS = [
'resource' => 'resource',
'namespace' => 'namespace',
'exclude' => 'exclude',
Expand All @@ -86,7 +86,7 @@ class YamlFileLoader extends FileLoader
'bind' => 'bind',
];

private static $instanceofKeywords = [
private const INSTANCEOF_KEYWORDS = [
'shared' => 'shared',
'lazy' => 'lazy',
'public' => 'public',
Expand All @@ -98,7 +98,7 @@ class YamlFileLoader extends FileLoader
'bind' => 'bind',
];

private static $defaultsKeywords = [
private const DEFAULTS_KEYWORDS = [
'public' => 'public',
'tags' => 'tags',
'autowire' => 'autowire',
Expand Down Expand Up @@ -251,8 +251,8 @@ private function parseDefaults(array &$content, string $file): array
}

foreach ($defaults as $key => $default) {
if (!isset(self::$defaultsKeywords[$key])) {
throw new InvalidArgumentException(sprintf('The configuration key "%s" cannot be used to define a default value in "%s". Allowed keys are "%s".', $key, $file, implode('", "', self::$defaultsKeywords)));
if (!isset(self::DEFAULTS_KEYWORDS[$key])) {
throw new InvalidArgumentException(sprintf('The configuration key "%s" cannot be used to define a default value in "%s". Allowed keys are "%s".', $key, $file, implode('", "', self::DEFAULTS_KEYWORDS)));
}
}

Expand Down Expand Up @@ -356,7 +356,7 @@ private function parseDefinition(string $id, $service, string $file, array $defa
$stack = [];

foreach ($service['stack'] as $k => $frame) {
if (\is_array($frame) && 1 === \count($frame) && !isset(self::$serviceKeywords[key($frame)])) {
if (\is_array($frame) && 1 === \count($frame) && !isset(self::SERVICE_KEYWORDS[key($frame)])) {
$frame = [
'class' => key($frame),
'arguments' => current($frame),
Expand Down Expand Up @@ -919,11 +919,11 @@ private function loadFromExtensions(array $content)
private function checkDefinition(string $id, array $definition, string $file)
{
if ($this->isLoadingInstanceof) {
$keywords = self::$instanceofKeywords;
$keywords = self::INSTANCEOF_KEYWORDS;
} elseif (isset($definition['resource']) || isset($definition['namespace'])) {
$keywords = self::$prototypeKeywords;
$keywords = self::PROTOTYPE_KEYWORDS;
} else {
$keywords = self::$serviceKeywords;
$keywords = self::SERVICE_KEYWORDS;
}

foreach ($definition as $key => $value) {
Expand Down
Loading
0