Completed
Push — master ( 3656f0...5e866b )
by David
03:24 queued 01:33
created

CMSMiddlewareServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFactories() 0 4 1
A getExtensions() 0 4 1
A createCmsMiddleware() 0 3 1
A updatePriorityQueue() 0 4 1
1
<?php
2
3
4
namespace TheCodingMachine\CMS\Middleware;
5
6
7
use Interop\Container\ServiceProvider;
8
use Interop\Container\ServiceProviderInterface;
9
use Psr\Container\ContainerInterface;
10
use TheCodingMachine\CMS\Block\BlockRendererInterface;
11
use TheCodingMachine\CMS\Page\PageRegistryInterface;
12
use TheCodingMachine\CMS\Theme\ThemeFactoryInterface;
13
use TheCodingMachine\MiddlewareListServiceProvider;
14
use TheCodingMachine\MiddlewareOrder;
15
16
class CMSMiddlewareServiceProvider implements ServiceProviderInterface
17
{
18
19
    public function getFactories()
20
    {
21
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array(TheCodingMa...'createCmsMiddleware')) returns the type array<string,array<integer,string>> which is incompatible with the return type mandated by Interop\Container\Servic...terface::getFactories() of array<mixed,callable>.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
22
            CMSMiddleware::class => [self::class, 'createCmsMiddleware'],
23
        ];
24
    }
25
26
    public function getExtensions()
27
    {
28
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array(TheCodingMa...'updatePriorityQueue')) returns the type array<string,array<integer,string>> which is incompatible with the return type mandated by Interop\Container\Servic...erface::getExtensions() of array<mixed,callable>.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
29
            MiddlewareListServiceProvider::MIDDLEWARES_QUEUE => [self::class,'updatePriorityQueue'],
30
        ];
31
    }
32
33
34
    public static function createCmsMiddleware(ContainerInterface $container): CMSMiddleware
35
    {
36
        return new CMSMiddleware($container->get(PageRegistryInterface::class), $container->get(BlockRendererInterface::class));
37
    }
38
39
    public static function updatePriorityQueue(ContainerInterface $container, \SplPriorityQueue $queue = null) : \SplPriorityQueue
40
    {
41
        $queue->insert($container->get(CMSMiddleware::class), MiddlewareOrder::ROUTER);
0 ignored issues
show
Bug introduced by
The method insert() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        $queue->/** @scrutinizer ignore-call */ insert($container->get(CMSMiddleware::class), MiddlewareOrder::ROUTER);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
        return $queue;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $queue could return the type null which is incompatible with the type-hinted return SplPriorityQueue. Consider adding an additional type-check to rule them out.
Loading history...
43
    }
44
}
45