Your project must not contain invalid instantiations 4
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_instantiation
- // Invokable shapes first — the is_object guard is load-bearing: a class-string naming
- // an invokable class must fall through to the ClassName arm (build, never invoke).
- FactoryEntry::isValid($factory) => new FactoryEntry($id, $factory),
- CallableEntry::isValid($factory) => new CallableEntry($id, $factory),
- ClassNameEntry::isValid($factory) => new ClassNameEntry($id, $factory),
- MethodPairEntry::isValid($factory) => new MethodPairEntry($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),
- // statement's begin line when a paren group survives to the `;` —
- // without them the closing `});` line can never be marked covered.
- $this->entries[$id] = (match (true) {
- // Invokable shapes first — the is_object guard is load-bearing: a class-string naming
- // an invokable class must fall through to the ClassName arm (build, never invoke).
- FactoryEntry::isValid($factory) => new FactoryEntry($id, $factory),
- CallableEntry::isValid($factory) => new CallableEntry($id, $factory),
- ClassNameEntry::isValid($factory) => new ClassNameEntry($id, $factory),
- MethodPairEntry::isValid($factory) => new MethodPairEntry($id, $factory),
- // any other string — incl. non-buildable type symbols (interface, trait, abstract
- // class, enum): must name a pre-registered entry (the typo catcher).
- $this->entries[$id] = (match (true) {
- // Invokable shapes first — the is_object guard is load-bearing: a class-string naming
- // an invokable class must fall through to the ClassName arm (build, never invoke).
- FactoryEntry::isValid($factory) => new FactoryEntry($id, $factory),
- CallableEntry::isValid($factory) => new CallableEntry($id, $factory),
- ClassNameEntry::isValid($factory) => new ClassNameEntry($id, $factory),
- MethodPairEntry::isValid($factory) => new MethodPairEntry($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)
- // without them the closing `});` line can never be marked covered.
- $this->entries[$id] = (match (true) {
- // Invokable shapes first — the is_object guard is load-bearing: a class-string naming
- // an invokable class must fall through to the ClassName arm (build, never invoke).
- FactoryEntry::isValid($factory) => new FactoryEntry($id, $factory),
- CallableEntry::isValid($factory) => new CallableEntry($id, $factory),
- ClassNameEntry::isValid($factory) => new ClassNameEntry($id, $factory),
- MethodPairEntry::isValid($factory) => new MethodPairEntry($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)
Your project must not contain invalid function or method calls
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_call
- // 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,
- );
- }
- }
- }
Your project should not use invalid parameter and return typehints 5
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_typehint
- /**
- * @template T of object
- *
- * @assert-if-true string|array{class-string<T>|T, string} $factory
- */
- public static function isValid(mixed $factory): bool
- {
- return (\is_string($factory) && \str_contains($factory, '::'))
- || (\is_array($factory) && count($factory) === 2);
- }
- }
- /**
- * A string "Class::method" or array pair "[class, method]" factory.
- */
- public static function invalidMethodPair(string $id, string|array $factory): static
- {
- if (is_array($factory)) {
- $class = var_export($factory[0] ?? null, true);
- $method = var_export($factory[1] ?? null, true);
- $factory = "[$class, $method]";
- /**
- * @template T of object
- *
- * @assert-if-true class-string<T> $factory
- */
- public static function isValid(mixed $factory): bool
- {
- return \is_string($factory) && \class_exists($factory)
- && (new ReflectionClass($factory))->isInstantiable();
- }
- /**
- * @template T of object
- *
- * @assert-if-true EntryFactory $factory
- */
- public static function isValid(mixed $factory): bool
- {
- return $factory instanceof EntryFactory;
- }
- /**
- /**
- * @template T of object
- *
- * @assert-if-true Closure|callable-string|callable $factory
- */
- public static function isValid(mixed $factory): bool
- {
- return $factory instanceof Closure
- || (\is_object($factory) && \method_exists($factory, '__invoke'))
- || (\is_string($factory) && \function_exists($factory));
- }