Skip to content

Commit

Permalink
Changed private static array-properties to const
Browse files Browse the repository at this point in the history
  • Loading branch information
simonberger committed Jan 24, 2021
1 parent 1c6cd99 commit d749132
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions Compiler/RegisterEnvVarProcessorsPass.php
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
6 changes: 3 additions & 3 deletions Compiler/ValidateEnvPlaceholdersPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
class ValidateEnvPlaceholdersPass implements CompilerPassInterface
{
private static $typeFixtures = ['array' => [], 'bool' => false, 'float' => 0.0, 'int' => 0, 'string' => ''];
private const TYPE_FIXTURES = ['array' => [], 'bool' => false, 'float' => 0.0, 'int' => 0, 'string' => ''];

private $extensionConfig = [];

Expand All @@ -52,13 +52,13 @@ public function process(ContainerBuilder $container)
foreach ($resolvingBag->getEnvPlaceholders() + $resolvingBag->getUnusedEnvPlaceholders() as $env => $placeholders) {
$values = [];
if (false === $i = strpos($env, ':')) {
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::$typeFixtures['string'];
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::TYPE_FIXTURES['string'];
$defaultType = null !== $default ? self::getType($default) : 'string';
$values[$defaultType] = $default;
} else {
$prefix = substr($env, 0, $i);
foreach ($envTypes[$prefix] ?? ['string'] as $type) {
$values[$type] = self::$typeFixtures[$type] ?? null;
$values[$type] = self::TYPE_FIXTURES[$type] ?? null;
}
}
foreach ($placeholders as $placeholder) {
Expand Down
4 changes: 2 additions & 2 deletions ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,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 @@ -339,7 +339,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
18 changes: 9 additions & 9 deletions Loader/YamlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/
class YamlFileLoader extends FileLoader
{
private static $serviceKeywords = [
private const SERVICE_KEYWORDS = [
'alias' => 'alias',
'parent' => 'parent',
'class' => 'class',
Expand All @@ -64,7 +64,7 @@ class YamlFileLoader extends FileLoader
'bind' => 'bind',
];

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

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

private static $defaultsKeywords = [
private const DEFAULTS_KEYWORDS = [
'public' => 'public',
'tags' => 'tags',
'autowire' => 'autowire',
Expand Down Expand Up @@ -250,8 +250,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 @@ -864,11 +864,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

0 comments on commit d749132

Please sign in to comment.