Your project must not contain invalid instantiations 2
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_instantiation
- {
- if ($args === []) {
- return $this->resolver->resolveInstance($class);
- }
- $reflection = new ReflectionClass($class);
- if (! $reflection->isInstantiable()) {
- throw UnresolvableCallableException::notInstantiable($class);
- }
- // 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.
Your project must not contain invalid function or method calls 4
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_call
- * @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()) {
- // 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,
- );
- }
- }
- }
- 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.
Your project should not use invalid return types 2
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_return_typehint
- * Retrieve the effective service resolver — a singleton resolved through
- * the normal path, so a user override flows automatically.
- */
- final public function getResolver(): ResolverInterface
- {
- return $this->get(ResolverInterface::class);
- }
- /**
- * Resolve a registered entry, building and caching it on first use.
- *
- * When no implementation is provided by the developer, a minimalist
- * internal implementation is built lazily on first use.
- */
- final public function getEventDispatcher(): EventDispatcherInterface
- {
- return $this->get(EventDispatcherInterface::class);
- }
- /**
- * Assign a PSR-14 event dispatcher implementation.
- *
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 array<mixed> $args Positional/named arguments for the invocation or constructor.
- *
- * @throws InvalidArgumentException If the input matches no family.
- * @throws ResolutionException If a package call fails to resolve.
- */
- public function make(array|callable|object|string $instance, array $args = []): mixed
- {
- try {
- // A registered id wins even when it also looks like a
- // class or a function.
- if (\is_string($instance) && $this->entries->offsetExists($instance)) {
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]];
- }