GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

EntityContainerBuilder::buildWithoutCache()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpBoot\Entity;
4
5
use DI\FactoryInterface;
6
use DI\InvokerInterface as DIInvokerInterface;
7
use Doctrine\Common\Cache\Cache;
8
use PhpBoot\Entity\Annotations\ClassAnnotationHandler;
9
use PhpBoot\Entity\Annotations\PropertyAnnotationHandler;
10
use PhpBoot\Entity\Annotations\ValidateAnnotationHandler;
11
use PhpBoot\Entity\Annotations\VarAnnotationHandler;
12
use PhpBoot\Annotation\ContainerBuilder;
13
14
class EntityContainerBuilder extends ContainerBuilder
15
{
16
    static $DEFAULT_ANNOTATIONS=[
17
        [ClassAnnotationHandler::class, 'class'],
18
        [PropertyAnnotationHandler::class, 'properties'],
19
        [VarAnnotationHandler::class, "properties.*.children[?name=='var'][]"],
20
        [ValidateAnnotationHandler::class, "properties.*.children[?name=='v'][]"],
21
    ];
22
23
    /**
24
     * ControllerContainerBuilder constructor.
25
     * @param FactoryInterface $factory
26
     * @param DIInvokerInterface $diInvoker
27
     * @param Cache $cache
28
     *
29
     * @param array $annotations
30
     */
31 21 View Code Duplication
    public function __construct(FactoryInterface $factory,
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
                                DIInvokerInterface $diInvoker,
33
                                Cache $cache,
34
                                array $annotations = null
35
                                )
36
    {
37 21
        if($annotations){
38 11
            parent::__construct($annotations, $cache);
39 11
        }else{
40 10
            parent::__construct(self::$DEFAULT_ANNOTATIONS, $cache);
41
        }
42 21
        $this->factory = $factory;
43 21
        $this->diInvoker = $diInvoker;
44 21
    }
45
    /**
46
     * load from class with local cache
47
     * @param string $className
48
     * @return EntityContainer
49
     */
50 18
    public function build($className)
51
    {
52 18
        return parent::build($className);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return parent::build($className); (object|null|integer|double|array|boolean) is incompatible with the return type documented by PhpBoot\Entity\EntityContainerBuilder::build of type PhpBoot\Entity\EntityContainer|null.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
53
    }
54
55
    /**
56
     * @param $className
57
     * @return EntityContainer
58
     */
59 9
    public function buildWithoutCache($className)
60
    {
61 9
        return parent::buildWithoutCache($className);
62
    }
63
64
    /**
65
     * @param string $className
66
     * @return EntityContainer
67
     */
68 7
    protected function createContainer($className)
69
    {
70 7
        return $this->factory->make(EntityContainer::class, ['className'=>$className]);
71
    }
72
73 9
    protected function handleAnnotation($handlerName, $container, $ann)
74
    {
75 9
        $handler = $this->factory->make($handlerName);
76 9
        return $this->diInvoker->call($handler, [$container, $ann]);
0 ignored issues
show
Documentation introduced by
$handler is of type *, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
77
    }
78
79
80
    /**
81
     * @var FactoryInterface
82
     */
83
    protected $factory;
84
    /**
85
     * @var DIInvokerInterface
86
     */
87
    protected $diInvoker;
88
}