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
- $args[$position] = $param->getDefaultValue();
- }
- }
- return $args;
- }
- /**
- * @param \ReflectionParameter $param
- * @return string
- * When $className is not instantiable or its constructor depends on non-exists container entry.
- */
- private function createInstance(string $className, array $args = []): object
- {
- if ($this->container->has($className)) {
- return $this->container->get($className);
- }
- if (! \class_exists($className)) {
- throw new Exception(
- \sprintf('Cannot resolve an entry or class named "%s" of non-exists', $className)
Your project must not contain invalid instantiations 3
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_instantiation
- if (! \is_array($callable)) {
- return new \ReflectionFunction($callable);
- }
- try {
- $ref = new \ReflectionMethod($callable[0], $callable[1]);
- } catch (\ReflectionException $err) {
- throw new InvalidArgumentException($err->getMessage(), $err->getCode(), $err);
- }
- // If trying to statically call a non-static method (at least on PHP 7.x)
- /** @var array<string> */
- $callable = \explode('::', $callable);
- }
- if (! \is_array($callable)) {
- return new \ReflectionFunction($callable);
- }
- try {
- $ref = new \ReflectionMethod($callable[0], $callable[1]);
- } catch (\ReflectionException $err) {
- if (! \is_array($callable)) {
- return new \ReflectionFunction($callable);
- }
- try {
- $ref = new \ReflectionMethod($callable[0], $callable[1]);
- } catch (\ReflectionException $err) {
- throw new InvalidArgumentException($err->getMessage(), $err->getCode(), $err);
- }
- // If trying to statically call a non-static method (at least on PHP 7.x)
Your project must not contain invalid function or method calls 6
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_call
- }
- try {
- $params[] = $this->resolveArgs($ref, $args);
- return $ref->invokeArgs(...$params);
- } catch (Exception $err) {
- throw new Exception($caller . '(): ' . $err->getMessage(), $err->getPrevious());
- }
- }
- : $factory;
- $entry = $this->resolver->resolve($this->factories[$id]);
- if (\is_object($entry) && $this->isInjectable($entry)) {
- $entry->setContainer($this);
- }
- $this->entries[$id] = $entry;
- if (isset($this->handledEntries[$id])) {
- if ($callback) {
- $instance = $callback($instance) ?: $instance;
- }
- return $this->resolver->handle($instance, $args);
- }
- /**
- * Extending an entry.
- *
- if (\is_object($entry) && ! \is_callable($entry)) {
- return $entry;
- }
- return $this->handledEntries[$id] = $this->resolver->handle($entry);
- }
- /**
- * Determine whether the **entry** is registered.
- *
- self::class => $this,
- ContainerInterface::class => $this,
- ];
- foreach ($entries as $id => $instance) {
- $this->set($id, $instance);
- }
- }
- /**
- * Create new resolver instance when get cloned.
- );
- }
- $extended = $this->make($callback, [$entry]);
- if (! \is_a($extended, $class = \get_class($entry))) {
- throw new Container\Exception(
- \sprintf('Argument #2 callback must be returns of type "%s"', $class)
- );
- }
Your project gitignore file should not contain user-specific files 3
- Read doc
- Productivity
- Minor
More information: https://insight.symfony.com/what-we-analyse/git.user_specific_ignored_file
- # Generic
- # --------------------------
- Thumbs.db
- Desktop.ini
- .directory
- .DS_Store
- ._*
- *.cache
- *.crt
- *.log
- *.old
- vendor
- yarn.lock
- # IDE Project Configurations
- # --------------------------
- .idea
- .settings
- .vscode
- .project
- *.sublime-*
- # Generic
- # --------------------------
- Thumbs.db
- Desktop.ini
- .directory
- .DS_Store
- ._*
- *.cache
Interfaces names should end with "Interface"
- Read doc
- Productivity
- Info
More information: https://insight.symfony.com/what-we-analyse/php.interface_has_no_interface_suffix
- * Any class implements this interface could have instance of ContainerInterface
- * injected automtically.
- *
- * @package Projek\Container
- */
- interface ContainerAware
- {
- /**
- * Assign a container to the instance.
- *
- * @param \Projek\Container $container
Your project should use dedicated PHP string functions 2
- Read doc
- Productivity
- Info
More information: https://insight.symfony.com/what-we-analyse/php.use_string_function
- * @throws \Projek\Container\InvalidArgumentException
- */
- public function resolve($entry, array $args = [])
- {
- if (\is_string($entry) && ! \function_exists($entry)) {
- $entry = false === \strpos($entry, '::')
- ? $this->createInstance($entry, $args)
- : \explode('::', $entry);
- }
- if (\is_array($entry) && \is_string($entry[0])) {
- * @throws \Projek\Container\Exception
- * @throws \Projek\Container\InvalidArgumentException
- */
- private function createCallableReflection($callable)
- {
- if (\is_string($callable) && false !== \strpos($callable, '::')) {
- /** @var array<string> */
- $callable = \explode('::', $callable);
- }
- if (! \is_array($callable)) {
Your project uses legacy callable syntax instead of first-class callable syntax
- Read doc
- Productivity
- Info
More information: https://insight.symfony.com/what-we-analyse/php.use_first_class_callable_syntax
- if (! \is_callable($entry)) {
- return $entry;
- }
- // Otherwise convert it to closure.
- $entry = \Closure::fromCallable($entry);
- }
- $ref = $this->createCallableReflection($entry);
- $caller = $ref->getName();
- $params = [];