ServiceProvider   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 3
dl 0
loc 45
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 33 1
1
<?php
2
3
namespace CSSPrites;
4
5
use CSSPrites\ImageProcessor\ImageProcessorInterface;
6
use League\Container\ServiceProvider as BaseServiceProvider;
7
8
/**
9
 * ServiceProvider to register all the needed dependencies.
10
 *
11
 * @codeCoverageIgnore
12
 */
13
class ServiceProvider extends BaseServiceProvider
14
{
15
    protected $provides = [
16
        'configuration',
17
        'image.processor',
18
        'sprite.processor.horizontal',
19
        'sprite.processor.vertical',
20
        'sprite.processor.simplebinpacking',
21
        'commands.generate',
22
    ];
23
24
    public function register()
25
    {
26
        $container = $this->getContainer();
27
28
        // AutoConfigure ContainerAwareInterface
29
        $container->inflector('League\Container\ContainerAwareInterface')
30
            ->invokeMethod('setContainer', [$container]);
31
32
        // Registering Configuration as singleton
33
        $container->singleton('configuration', 'CSSPrites\Configuration');
34
35
        // Registering Slugifier as singleton
36
        $container->singleton('slugifier', 'CSSPrites\Slugifier\SlugifySlugifier');
37
38
        // Registering Image Processor
39
        $container->add('image.processor', 'CSSPrites\ImageProcessor\ImagineImageProcessor');
40
41
        // AutoConfigure Image Processor
42
        $container->inflector('CSSPrites\ImageProcessor\ImageProcessorInterface', function (ImageProcessorInterface $instance) use ($container) {
43
            $instance->setConfig($container->get('configuration')->get('image.processor'));
44
        });
45
46
        // Registering Sprites Processors
47
        $container->add('sprite.processor.horizontal', 'CSSPrites\SpriteProcessor\HorizontalSpriteProcessor')
0 ignored issues
show
Bug introduced by
The method withArgument does only exist in League\Container\Definition\DefinitionInterface, but not in League\Container\ContainerInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
48
             ->withArgument('image.processor');
49
        $container->add('sprite.processor.vertical', 'CSSPrites\SpriteProcessor\VerticalSpriteProcessor')
50
             ->withArgument('image.processor');
51
        $container->add('sprite.processor.simplebinpacking', 'CSSPrites\SpriteProcessor\SimpleBinPackingSpriteProcessor')
52
             ->withArgument('image.processor');
53
54
        // Registering ConsoleCommands
55
        $container->add('commands.generate', 'CSSPrites\Commands\GenerateCommand');
56
    }
57
}
58