Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  Changed private static array-properties to const
  • Loading branch information
nicolas-grekas committed Jan 25, 2021
2 parents 538bd27 + d749132 commit 9427132
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 ? get_debug_type($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 @@ -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
18 changes: 9 additions & 9 deletions 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 @@ -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

0 comments on commit 9427132

Please sign in to comment.