10000 Changed private static array-properties to const · symfony/symfony@a2cf584 · GitHub
[go: up one dir, main page]

Skip to content

Commit a2cf584

Browse files
committed
Changed private static array-properties to const
1 parent 0c7eb27 commit a2cf584

File tree

62 files changed

+295
-298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+295
-298
lines changed

src/Symfony/Bridge/Monolog/Command/ServerLogCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class ServerLogCommand extends Command
3030
{
31-
private static $bgColor = ['black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow'];
31+
private const BG_COLOR = ['black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow'];
3232

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

157157
$this->handler->handle($record);

src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ConsoleFormatter implements FormatterInterface
3030
public const SIMPLE_FORMAT = "%datetime% %start_tag%%level_name%%end_tag% <comment>[%channel%]</> %message%%context%%extra%\n";
3131
public const SIMPLE_DATE = 'H:i:s';
3232

33-
private static $levelColorMap = [
33+
private const LEVEL_COLOR_MAP = [
3434
Logger::DEBUG => 'fg=white',
3535
Logger::INFO => 'fg=green',
3636
Logger::NOTICE => 'fg=blue',
@@ -104,8 +104,6 @@ public function format(array $record)
104104
{
105105
$record = $this->replacePlaceHolder($record);
106106

107-
$levelColor = self::$levelColorMap[$record['level']];
108-
109107
if (!$this->options['ignore_empty_context_and_extra'] || !empty($record['context'])) {
110108
$context = ($this->options['multiline'] ? "\n" : ' ').$this->dumpData($record['context']);
111109
} else {
@@ -122,7 +120,7 @@ public function format(array $record)
122120
'%datetime%' => $record['datetime'] instanceof \DateTimeInterface
123121
? $record['datetime']->format($this->options['date_format'])
124122
: $record['datetime'],
125-
'%start_tag%' => sprintf('<%s>', $levelColor),
123+
'%start_tag%' => sprintf('<%s>', self::LEVEL_COLOR_MAP[$record['level']]),
126124
'%level_name%' => sprintf($this->options['level_name_format'], $record['level_name']),
127125
'%end_tag%' => '</>',
128126
'%channel%' => $record['channel'],

src/Symfony/Bridge/Twig/UndefinedCallableHandler.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
*/
2020
class UndefinedCallableHandler
2121
{
22-
private static $filterComponents = [
22+
private const FILTER_COMPONENTS = [
2323
'humanize' => 'form',
2424
'trans' => 'translation',
2525
'transchoice' => 'translation',
2626
'yaml_encode' => 'yaml',
2727
'yaml_dump' => 'yaml',
2828
];
2929

30-
private static $functionComponents = [
30+
private const FUNCTION_COMPONENTS = [
3131
'asset' => 'asset',
3232
'asset_version' => 'asset',
3333
'dump' => 'debug-bundle',
@@ -57,7 +57,7 @@ class UndefinedCallableHandler
5757
'workflow_marked_places' => 'workflow',
5858
];
5959

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

6868
public static function onUndefinedFilter(string $name): bool
6969
{
70-
if (!isset(self::$filterComponents[$name])) {
70+
if (!isset(self::FILTER_COMPONENTS[$name])) {
7171
return false;
7272
}
7373

74-
self::onUndefined($name, 'filter', self::$filterComponents[$name]);
74+
self::onUndefined($name, 'filter', self::FILTER_COMPONENTS[$name]);
7575

7676
return true;
7777
}
7878

7979
public static function onUndefinedFunction(string $name): bool
8080
{
81-
if (!isset(self::$functionComponents[$name])) {
81+
if (!isset(self::FUNCTION_COMPONENTS[$name])) {
8282
return false;
8383
}
8484

85-
self::onUndefined($name, 'function', self::$functionComponents[$name]);
85+
self::onUndefined($name, 'function', self::FUNCTION_COMPONENTS[$name]);
8686

8787
return true;
8888
}
8989

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

9696
throw new SyntaxError(sprintf('Did you forget to run "composer require symfony/%s"? Unknown %s "%s".', $component, $type, $name));

src/Symfony/Bundle/WebServerBundle/Command/ServerLogCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
class ServerLogCommand extends Command
3232
{
33-
private static $bgColor = ['black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow'];
33+
private const BG_COLOR = ['black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow'];
3434

3535
private $el;
3636
private $handler;
@@ -155,7 +155,7 @@ private function displayLog(OutputInterface $output, int $clientId, array $recor
155155
if (isset($record['log_id'])) {
156156
$clientId = unpack('H*', $record['log_id'])[1];
157157
}
158-
$logBlock = sprintf('<bg=%s> </>', self::$bgColor[$clientId % 8]);
158+
$logBlock = sprintf('<bg=%s> </>', self::BG_COLOR[$clientId % 8]);
159159
$output->write($logBlock);
160160

161161
$this->handler->handle($record);

src/Symfony/Component/BrowserKit/Cookie.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Cookie
2222
* Handles dates as defined by RFC 2616 section 3.3.1, and also some other
2323
* non-standard, but common formats.
2424
*/
25-
private static $dateFormats = [
25+
private const DATE_FORMATS = [
2626
'D, d M Y H:i:s T',
2727
'D, d-M-y H:i:s T',
2828
'D, d-M-Y H:i:s T',
@@ -92,7 +92,7 @@ public function __toString()
9292

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

9898
if ('' !== $this->domain) {
@@ -208,7 +208,7 @@ private static function parseDate(string $dateValue): ?string
208208
$dateValue = substr($dateValue, 1, -1);
209209
}
210210

211-
foreach (self::$dateFormats as $dateFormat) {
211+
foreach (self::DATE_FORMATS as $dateFormat) {
212212
if (false !== $date = \DateTime::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) {
213213
return $date->format('U');
214214
}

src/Symfony/Component/DependencyInjection/Compiler/RegisterEnvVarProcessorsPass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
class RegisterEnvVarProcessorsPass implements CompilerPassInterface
2727
{
28-
private static $allowedTypes = ['array', 'bool', 'float', 'int', 'string'];
28+
private const ALLOWED_TYPES = ['array', 'bool', 'float', 'int', 'string'];
2929

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

6767
foreach ($types as $type) {
68-
if (!\in_array($type, self::$al B83A lowedTypes)) {
69-
throw new InvalidArgumentException(sprintf('Invalid type "%s" returned by "%s::getProvidedTypes()", expected one of "%s".', $type, $class, implode('", "', self::$allowedTypes)));
68+
if (!\in_array($type, self::ALLOWED_TYPES)) {
69+
throw new InvalidArgumentException(sprintf('Invalid type "%s" returned by "%s::getProvidedTypes()", expected one of "%s".', $type, $class, implode('", "', self::ALLOWED_TYPES)));
7070
}
7171
}
7272

src/Symfony/Component/DependencyInjection/Compiler/ValidateEnvPlaceholdersPass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
class ValidateEnvPlaceholdersPass implements CompilerPassInterface
2828
{
29-
private static $typeFixtures = ['array' => [], 'bool' => false, 'float' => 0.0, 'int' => 0, 'string' => ''];
29+
private const TYPE_FIXTURES = ['array' => [], 'bool' => false, 'float' => 0.0, 'int' => 0, 'string' => ''];
3030

3131
private $extensionConfig = [];
3232

@@ -52,13 +52,13 @@ public function process(ContainerBuilder $container)
5252
foreach ($resolvingBag->getEnvPlaceholders() + $resolvingBag->getUnusedEnvPlaceholders() as $env => $placeholders) {
5353
$values = [];
5454
if (false === $i = strpos($env, ':')) {
55-
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::$typeFixtures['string'];
55+
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::TYPE_FIXTURES['string'];
5656
$defaultType = null !== $default ? self::getType($default) : 'string';
5757
$values[$defaultType] = $default;
5858
} else {
5959
$prefix = substr($env, 0, $i);
6060
foreach ($envTypes[$prefix] ?? ['string'] as $type) {
61-
$values[$type] = self::$typeFixtures[$type] ?? null;
61+
$values[$type] = self::TYPE_FIXTURES[$type] ?? null;
6262
}
6363
}
6464
foreach ($placeholders as $placeholder) {

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
126126

127127
private $removedBindingIds = [];
128128

129-
private static $internalTypes = [
129+
private const INTERNAL_TYPES = [
130130
'int' => true,
131131
'float' => true,
132132
'string' => true,
@@ -339,7 +339,7 @@ public function getReflectionClass(?string $class, bool $throw = true): ?\Reflec
339339
return null;
340340
}
341341

342-
if (isset(self::$internalTypes[$class])) {
342+
if (isset(self::INTERNAL_TYPES[$class])) {
343343
return null;
344344
}
345345

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*/
3939
class YamlFileLoader extends FileLoader
4040
{
41-
private static $serviceKeywords = [
41+
private const SERVICE_KEYWORDS = [
4242
'alias' => 'alias',
4343
'parent' => 'parent',
4444
'class' => 'class',
@@ -64,7 +64,7 @@ class YamlFileLoader extends FileLoader
6464
'bind' => 'bind',
6565
];
6666

67-
private static $prototypeKeywords = [
67+
private const PROTOTYPE_KEYWORDS = [
6868
'resource' => 'resource',
6969
'namespace' => 'namespace',
7070
'exclude' => 'exclude',
@@ -85,7 +85,7 @@ class YamlFileLoader extends FileLoader
8585
'bind' => 'bind',
8686
];
8787

88-
private static $instanceofKeywords = [
88+
private const INSTANCEOF_KEYWORDS = [
8989
'shared' => 'shared',
9090
'lazy' => 'lazy',
9191
'public' => 'public',
@@ -97,7 +97,7 @@ class YamlFileLoader extends FileLoader
9797
'bind' => 'bind',
9898
];
9999

100-
private static $defaultsKeywords = [
100+
private const DEFAULTS_KEYWORDS = [
101101
'public' => 'public',
102102
'tags' => 'tags',
103103
'autowire' => 'autowire',
@@ -250,8 +250,8 @@ private function parseDefaults(array &$content, string $file): array
250250
}
251251

252252
foreach ($defaults as $key => $default) {
253-
if (!isset(self::$defaultsKeywords[$key])) {
254-
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)));
253+
if (!isset(self::DEFAULTS_KEYWORDS[$key])) {
254+
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)));
255255
}
256256
}
257257

@@ -864,11 +864,11 @@ private function loadFromExtensions(array $content)
864864
private function checkDefinition(string $id, array $definition, string $file)
865865
{
866866
if ($this->isLoadingInstanceof) {
867-
$keywords = self::$instanceofKeywords;
867+
$keywords = self::INSTANCEOF_KEYWORDS;
868868
} elseif (isset($definition['resource']) || isset($definition['namespace'])) {
869-
$keywords = self::$prototypeKeywords;
869+
$keywords = self::PROTOTYPE_KEYWORDS;
870870
} else {
871-
$keywords = self::$serviceKeywords;
871+
$keywords = self::SERVICE_KEYWORDS;
872872
}
873873

874874
foreach ($definition as $key => $value) {

src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
*/
2121
class BinaryNode extends Node
2222
{
23-
private static $operators = [
23+
private const OPERATORS = [
2424
'~' => '.',
2525
'and' => '&&',
2626
'or' => '||',
2727
];
2828

29-
private static $functions = [
29+
private const FUNCTIONS = [
3030
'**' => 'pow',
3131
'..' => 'range',
3232
'in' => 'in_array',
@@ -57,9 +57,9 @@ public function compile(Compiler $compiler)
5757
return;
5858
}
5959

60-
if (isset(self::$functions[$operator])) {
60+
if (isset(self::FUNCTIONS[$operator])) {
6161
$compiler
62-
->raw(sprintf('%s(', self::$functions[$operator]))
62+
->raw(sprintf('%s(', self::FUNCTIONS[$operator]))
6363
->compile($this->nodes['left'])
6464
->raw(', ')
6565
->compile($this->nodes['right'])
@@ -69,8 +69,8 @@ public function compile(Compiler $compiler)
6969
return;
7070
}
7171

72-
if (isset(self::$operators[$operator])) {
73-
$operator = self::$operators[$operator];
72+
if (isset(self::OPERATORS[$operator])) {
73+
$operator = self::OPERATORS[$operator];
7474
}
7575

7676
$compiler
@@ -89,13 +89,13 @@ public function evaluate($functions, $values)
8989
$operator = $this->attributes['operator'];
9090
$left = $this->nodes['left']->evaluate($functions, $values);
9191

92-
if (isset(self::$functions[$operator])) {
92+
if (isset(self::FUNCTIONS[$operator])) {
9393
$right = $this->nodes['right']->evaluate($functions, $values);
9494

9595
if ('not in' === $operator) {
9696
return !\in_array($left, $right);
9797
}
98-
$f = self::$functions[$operator];
98+
$f = self::FUNCTIONS[$operator];
9999

100100
return $f($left, $right);
101101
}

src/Symfony/Component/ExpressionLanguage/Node/UnaryNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class UnaryNode extends Node
2222
{
23-
private static $operators = [
23+
private const OPERATORS = [
2424
'!' => '!',
2525
'not' => '!',
2626
'+' => '+',
@@ -39,7 +39,7 @@ public function compile(Compiler $compiler)
3939
{
4040
$compiler
4141
->raw('(')
42-
->raw(self::$operators[$this->attributes['operator']])
42+
->raw(self::OPERATORS[$this->attributes['operator']])
4343
->compile($this->nodes['node'])
4444
->raw(')')
4545
;

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateIntervalToArrayTransformer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
3030
public const SECONDS = 'seconds';
3131
public const INVERT = 'invert';
3232

33-
private static $availableFields = [
33+
private const AVAILABLE_FIELDS = [
3434
self::YEARS => 'y',
3535
self::MONTHS => 'm',
3636
self::DAYS => 'd',
@@ -85,7 +85,7 @@ public function transform($dateInterval)
8585
throw new UnexpectedTypeException($dateInterval, \DateInterval::class);
8686
}
8787
$result = [];
88-
foreach (self::$availableFields as $field => $char) {
88+
foreach (self::AVAILABLE_FIELDS as $field => $char) {
8989
$result[$field] = $dateInterval->format('%'.($this->pad ? strtoupper($char) : $char));
9090
}
9191
if (\in_array('weeks', $this->fields, true)) {
@@ -134,7 +134,7 @@ public function reverseTransform($value)
134134
if (isset($value['invert']) && !\is_bool($value['invert'])) {
135135
throw new TransformationFailedException('The value of "invert" must be boolean.');
136136
}
137-
foreach (self::$availableFields as $field => $char) {
137+
foreach (self::AVAILABLE_FIELDS as $field => $char) {
138138
if ('invert' !== $field && isset($value[$field]) && !ctype_digit((string) $value[$field])) {
139139
throw new TransformationFailedException(sprintf('This amount of "%s" is invalid.', $field));
140140
}

src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DateIntervalType extends AbstractType
3737
'minutes',
3838
'seconds',
3939
];
40-
private static $widgets = [
40+
private const WIDGETS = [
4141
'text' => TextType::class,
4242
'integer' => IntegerType::class,
4343
'choice' => ChoiceType::class,
@@ -112,7 +112,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
112112
$childOptions['choices'] = $options[$part];
113113
$childOptions['placeholder'] = $options['placeholder'][$part];
114114
}
115-
$childForm = $builder->create($part, self::$widgets[$options['widget']], $childOptions);
115+
$childForm = $builder->create($part, self::WIDGETS[$options['widget']], $childOptions);
116116
if ('integer' === $options['widget']) {
117117
$childForm->addModelTransformer(
118118
new ReversedTransformer(

0 commit comments

Comments
 (0)
0