Your project must not contain invalid function or method calls 8
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_call
- foreach ($defaults as $id => $factory) {
- $this->entries[$id] = new CallableEntry($id, $factory, auto: true);
- }
- foreach ($entries as $id => $factory) {
- $this->set($id, $factory);
- }
- }
- /**
- * Clone the container: every entry is cloned (singleton caches reset,
- foreach ($defaults as $id => $factory) {
- $this->entries[$id] = new CallableEntry($id, $factory, auto: true);
- }
- foreach ($entries as $id => $factory) {
- $this->set($id, $factory);
- }
- }
- /**
- * Clone the container: every entry is cloned (singleton caches reset,
- // Recreate the factory closure against the clone; rebinding
- // keeps any captured value (the ctor-provided dispatcher)
- // while re-pointing the captured container.
- $this->entries[$id] = new CallableEntry(
- $id,
- Closure::bind($entry->factory, $this, self::class),
- auto: true,
- );
- }
- }
- }
- && (new ReflectionClass($factory))->isInstantiable() => new ClassNameEntry($id, $factory),
- \is_string($factory) && \function_exists($factory) => new CallableEntry($id, $factory),
- // any other string — incl. non-buildable type symbols (interface,
- // trait, abstract class, enum): must name a pre-registered entry
- // (the typo catcher).
- \is_string($factory) => $this->has($factory)
- ? new AliasEntry($id, $factory)
- : throw InvalidArgumentException::unresolvableString($id, $factory),
- \is_array($factory) => new MethodPairEntry($id, $factory), // pair validation in its ctor
- // Plain objects only; invokables matched the arm above.
- // (\is_object, not `instanceof object` — the latter always
- default => false,
- });
- if ($shape) {
- return $this->injectContainer(
- $this->getHandler()->handle($instance, $args)
- );
- }
- // Thrown from inside the boundary: the InvalidArgumentException
- // passes it untouched — the boundary never wraps a user-facing InvalidArgumentException.
- if ($name === 'self' || $name === 'static') {
- return $scope?->getName() ?? $name;
- }
- if ($name === 'parent') {
- return $scope?->getParentClass()?->getName() ?? $name;
- }
- return $name;
- };
- * @throws UnresolvableCallableException When the class is not instantiable (defensive).
- */
- private function instantiate(string $class, array $args): object
- {
- if ($args === []) {
- return $this->resolver->resolveInstance($class);
- }
- $reflection = new ReflectionClass($class);
- if (! $reflection->isInstantiable()) {
- * @throws UnresolvableCallableException When the class is not instantiable (defensive).
- */
- private function instantiate(string $class, array $args): object
- {
- if ($args === []) {
- return $this->resolver->resolveInstance($class);
- }
- $reflection = new ReflectionClass($class);
- if (! $reflection->isInstantiable()) {
Your project must not contain invalid instantiations 2
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_instantiation
- // trait, abstract class, enum): must name a pre-registered entry
- // (the typo catcher).
- \is_string($factory) => $this->has($factory)
- ? new AliasEntry($id, $factory)
- : throw InvalidArgumentException::unresolvableString($id, $factory),
- \is_array($factory) => new MethodPairEntry($id, $factory), // pair validation in its ctor
- // Plain objects only; invokables matched the arm above.
- // (\is_object, not `instanceof object` — the latter always
- // evaluates false: `object` is parsed as a class name.)
- \is_object($factory) => throw InvalidArgumentException::plainObjectNotAFactory($id, $factory),
- // Invalid factory of type %s.
- {
- if ($args === []) {
- return $this->resolver->resolveInstance($class);
- }
- $reflection = new ReflectionClass($class);
- if (! $reflection->isInstantiable()) {
- throw UnresolvableCallableException::notInstantiable($class);
- }
Your project should not use invalid parameter and return typehints
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_typehint
- * @param Closure(T|mixed $instance, mixed ...$args):T|mixed $callback Decorator declaring an explicit single class return type.
- *
- * @throws NotFoundException If the entry id is absent.
- * @throws InvalidArgumentException If the target or the callback return type is invalid.
- */
- public function extend(string $id, Closure $callback): static
- {
- $entry = $this->entries->offsetGet($id);
- $target = $entry->extensionTarget($this->entries);
- if ($target === null) {
Your project is using a unnecessary isset call 2
- Read doc
- Productivity
- Minor
More information: https://insight.symfony.com/what-we-analyse/php.invalid_isset_use
- throw InvalidArgumentException::notClassMethodString($id, $factory);
- }
- [$class, $method] = \explode('::', $factory, 2);
- } else {
- if (\count($factory) !== 2 || ! isset($factory[0], $factory[1])) {
- throw InvalidArgumentException::invalidPairSize($id);
- }
- [$class, $method] = [$factory[0], $factory[1]];
- }
- throw InvalidArgumentException::notClassMethodString($id, $factory);
- }
- [$class, $method] = \explode('::', $factory, 2);
- } else {
- if (\count($factory) !== 2 || ! isset($factory[0], $factory[1])) {
- throw InvalidArgumentException::invalidPairSize($id);
- }
- [$class, $method] = [$factory[0], $factory[1]];
- }