AllInOnePass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 15 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MartinGeorgiev\SocialPostBundle\DependencyInjection\Compiler;
6
7
use MartinGeorgiev\SocialPost\Publisher;
8
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
11
use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
12
use Symfony\Component\DependencyInjection\Reference;
13
14
/**
15
 * @since 1.0.0
16
 * @license https://opensource.org/licenses/MIT
17
 * @link https://github.com/martin-georgiev/social-post-bundle
18
 */
19
class AllInOnePass implements CompilerPassInterface
20
{
21
    public function process(ContainerBuilder $container): void
22
    {
23
        $definition = $container->getDefinition('social_post');
24
        $publishOn = $container->getParameter('social_post.configuration.publish_on');
25
        foreach ($publishOn as $provider) {
26
            $serviceName = 'social_post.'.$provider;
27
            if (!$container->has($serviceName)) {
28
                throw new OutOfBoundsException(sprintf('Cannot find service %s when injecting dependencies for "social_post"', $serviceName));
29
            }
30
            if (!$container->get($serviceName) instanceof Publisher) {
0 ignored issues
show
Bug introduced by
The class MartinGeorgiev\SocialPost\Publisher does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
31
                throw new InvalidArgumentException(sprintf('Service %s should be an instance of %s', $serviceName, Publisher::class));
32
            }
33
            $definition->addArgument(new Reference($serviceName));
34
        }
35
    }
36
}
37