Skip to content

Commit fef50c9

Browse files
Leverage PHP8's get_debug_type()
1 parent 6e9eff3 commit fef50c9

26 files changed

+49
-62
lines changed

Argument/ReferenceSetArgumentTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function setValues(array $values)
4545
{
4646
foreach ($values as $k => $v) {
4747
if (null !== $v && !$v instanceof Reference) {
48-
throw new InvalidArgumentException(sprintf('A "%s" must hold only Reference instances, "%s" given.', __CLASS__, \is_object($v) ? \get_class($v) : \gettype($v)));
48+
throw new InvalidArgumentException(sprintf('A "%s" must hold only Reference instances, "%s" given.', __CLASS__, get_debug_type($v)));
4949
}
5050
}
5151

Compiler/AbstractRecursivePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private function getExpressionLanguage(): ExpressionLanguage
209209
$arg = $this->processValue(new Reference($id));
210210
$this->inExpression = false;
211211
if (!$arg instanceof Reference) {
212-
throw new RuntimeException(sprintf('"%s::processValue()" must return a Reference when processing an expression, "%s" returned for service("%s").', static::class, \is_object($arg) ? \get_class($arg) : \gettype($arg), $id));
212+
throw new RuntimeException(sprintf('"%s::processValue()" must return a Reference when processing an expression, "%s" returned for service("%s").', static::class, get_debug_type($arg), $id));
213213
}
214214
$arg = sprintf('"%s"', $arg);
215215
}

Compiler/CheckTypeDeclarationsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
265265
$checkFunction = sprintf('is_%s', $parameter->getType()->getName());
266266

267267
if (!$parameter->getType()->isBuiltin() || !$checkFunction($value)) {
268-
throw new InvalidParameterTypeException($this->currentId, \is_object($value) ? $class : \gettype($value), $parameter);
268+
throw new InvalidParameterTypeException($this->currentId, \is_object($value) ? $class : get_debug_type($value), $parameter);
269269
}
270270
}
271271

Compiler/MergeExtensionConfigurationPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ public function __construct(ExtensionInterface $extension, ParameterBagInterface
169169
*/
170170
public function addCompilerPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0): self
171171
{
172-
throw new LogicException(sprintf('You cannot add compiler pass "%s" from extension "%s". Compiler passes must be registered before the container is compiled.', \get_class($pass), $this->extensionClass));
172+
throw new LogicException(sprintf('You cannot add compiler pass "%s" from extension "%s". Compiler passes must be registered before the container is compiled.', get_debug_type($pass), $this->extensionClass));
173173
}
174174

175175
/**
176176
* {@inheritdoc}
177177
*/
178178
public function registerExtension(ExtensionInterface $extension)
179179
{
180-
throw new LogicException(sprintf('You cannot register extension "%s" from "%s". Extensions must be registered before the container is compiled.', \get_class($extension), $this->extensionClass));
180+
throw new LogicException(sprintf('You cannot register extension "%s" from "%s". Extensions must be registered before the container is compiled.', get_debug_type($extension), $this->extensionClass));
181181
}
182182

183183
/**

Compiler/PriorityTaggedServiceTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static function getDefaultIndex(ContainerBuilder $container, string $serv
125125
$defaultIndex = $rm->invoke(null);
126126

127127
if (!\is_string($defaultIndex)) {
128-
throw new InvalidArgumentException(sprintf('Either method "%s::%s()" should return a string (got "%s") or tag "%s" on service "%s" is missing attribute "%s".', $class, $defaultIndexMethod, \gettype($defaultIndex), $tagName, $serviceId, $indexAttribute));
128+
throw new InvalidArgumentException(sprintf('Either method "%s::%s()" should return a string (got "%s") or tag "%s" on service "%s" is missing attribute "%s".', $class, $defaultIndexMethod, get_debug_type($defaultIndex), $tagName, $serviceId, $indexAttribute));
129129
}
130130

131131
return $defaultIndex;
@@ -154,7 +154,7 @@ public static function getDefaultPriority(ContainerBuilder $container, string $s
154154
$defaultPriority = $rm->invoke(null);
155155

156156
if (!\is_int($defaultPriority)) {
157-
throw new InvalidArgumentException(sprintf('Method "%s::%s()" should return an integer (got "%s") or tag "%s" on service "%s" is missing attribute "priority".', $class, $defaultPriorityMethod, \gettype($defaultPriority), $tagName, $serviceId));
157+
throw new InvalidArgumentException(sprintf('Method "%s::%s()" should return an integer (got "%s") or tag "%s" on service "%s" is missing attribute "priority".', $class, $defaultPriorityMethod, get_debug_type($defaultPriority), $tagName, $serviceId));
158158
}
159159

160160
return $defaultPriority;

Compiler/RegisterServiceSubscribersPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function processValue($value, bool $isRoot = false)
7171

7272
foreach ($class::getSubscribedServices() as $key => $type) {
7373
if (!\is_string($type) || !preg_match('/^\??[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+$/', $type)) {
74-
throw new InvalidArgumentException(sprintf('"%s::getSubscribedServices()" must return valid PHP types for service "%s" key "%s", "%s" returned.', $class, $this->currentId, $key, \is_string($type) ? $type : \gettype($type)));
74+
throw new InvalidArgumentException(sprintf('"%s::getSubscribedServices()" must return valid PHP types for service "%s" key "%s", "%s" returned.', $class, $this->currentId, $key, \is_string($type) ? $type : get_debug_type($type)));
7575
}
7676
if ($optionalBehavior = '?' === $type[0]) {
7777
$type = substr($type, 1);

Compiler/ResolveBindingsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected function processValue($value, bool $isRoot = false)
134134
}
135135

136136
if (null !== $bindingValue && !$bindingValue instanceof Reference && !$bindingValue instanceof Definition && !$bindingValue instanceof TaggedIteratorArgument && !$bindingValue instanceof ServiceLocatorArgument) {
137-
throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected null, "%s", "%s", "%s" or ServiceLocatorArgument, "%s" given.', $key, $this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class, \gettype($bindingValue)));
137+
throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected null, "%s", "%s", "%s" or ServiceLocatorArgument, "%s" given.', $key, $this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class, get_debug_type($bindingValue)));
138138
}
139139
}
140140

Compiler/ResolveNamedArgumentsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function processValue($value, bool $isRoot = false)
7676
}
7777

7878
if (null !== $argument && !$argument instanceof Reference && !$argument instanceof Definition) {
79-
throw new InvalidArgumentException(sprintf('Invalid service "%s": the value of argument "%s" of method "%s()" must be null, an instance of "%s" or an instance of "%s", "%s" given.', $this->currentId, $key, $class !== $this->currentId ? $class.'::'.$method : $method, Reference::class, Definition::class, \gettype($argument)));
79+
throw new InvalidArgumentException(sprintf('Invalid service "%s": the value of argument "%s" of method "%s()" must be null, an instance of "%s" or an instance of "%s", "%s" given.', $this->currentId, $key, $class !== $this->currentId ? $class.'::'.$method : $method, Reference::class, Definition::class, get_debug_type($argument)));
8080
}
8181

8282
$typeFound = false;

Compiler/ServiceLocatorTagPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected function processValue($value, bool $isRoot = false)
5959
continue;
6060
}
6161
if (!$v instanceof Reference) {
62-
throw new InvalidArgumentException(sprintf('Invalid definition for service "%s": an array of references is expected as first argument when the "container.service_locator" tag is set, "%s" found for key "%s".', $this->currentId, \is_object($v) ? \get_class($v) : \gettype($v), $k));
62+
throw new InvalidArgumentException(sprintf('Invalid definition for service "%s": an array of references is expected as first argument when the "container.service_locator" tag is set, "%s" found for key "%s".', $this->currentId, get_debug_type($v), $k));
6363
}
6464

6565
if ($i === $k) {
@@ -98,7 +98,7 @@ public static function register(ContainerBuilder $container, array $refMap, stri
9898
{
9999
foreach ($refMap as $id => $ref) {
100100
if (!$ref instanceof Reference) {
101-
throw new InvalidArgumentException(sprintf('Invalid service locator definition: only services can be referenced, "%s" found for key "%s". Inject parameter values using constructors instead.', \is_object($ref) ? \get_class($ref) : \gettype($ref), $id));
101+
throw new InvalidArgumentException(sprintf('Invalid service locator definition: only services can be referenced, "%s" found for key "%s". Inject parameter values using constructors instead.', get_debug_type($ref), $id));
102102
}
103103
$refMap[$id] = new ServiceClosureArgument($ref);
104104
}

Compiler/ValidateEnvPlaceholdersPass.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function process(ContainerBuilder $container)
5252
$values = [];
5353
if (false === $i = strpos($env, ':')) {
5454
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::$typeFixtures['string'];
55-
$defaultType = null !== $default ? self::getType($default) : 'string';
55+
$defaultType = null !== $default ? get_debug_type($default) : 'string';
5656
$values[$defaultType] = $default;
5757
} else {
5858
$prefix = substr($env, 0, $i);
@@ -99,18 +99,4 @@ public function getExtensionConfig(): array
9999
$this->extensionConfig = [];
100100
}
101101
}
102-
103-
private static function getType($value): string
104-
{
105-
switch ($type = \gettype($value)) {
106-
case 'boolean':
107-
return 'bool';
108-
case 'double':
109-
return 'float';
110-
case 'integer':
111-
return 'int';
112-
}
113-
114-
return $type;
115-
}
116102
}

0 commit comments

Comments
 (0)