Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#413)
by Vincent
17:38 queued 03:43
created

Connection::setTotalCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Relay\Connection\Output;
6
7
use Overblog\GraphQLBundle\Relay\Connection\ConnectionInterface;
8
9
class Connection implements ConnectionInterface
10
{
11
    /** @var Edge[] */
12
    protected $edges = [];
13
14
    /** @var PageInfo */
15
    protected $pageInfo = null;
16
17
    /** @var int */
18
    protected $totalCount = 0;
19
20 56
    public function __construct($edges = [], PageInfo $pageInfo = null)
21
    {
22 56
        $this->edges = $edges;
23 56
        $this->pageInfo = $pageInfo;
24 56
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 55
    public function getEdges()
30
    {
31 55
        return $this->edges;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->edges; (Overblog\GraphQLBundle\R...onnection\Output\Edge[]) is incompatible with the return type declared by the interface Overblog\GraphQLBundle\R...tionInterface::getEdges of type Overblog\GraphQLBundle\Relay\Connection\iterable.

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...
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 1
    public function setEdges(iterable $edges): void
38
    {
39 1
        $this->edges = $edges;
0 ignored issues
show
Documentation Bug introduced by
It seems like $edges of type object<Overblog\GraphQLB...ay\Connection\iterable> is incompatible with the declared type array<integer,object<Ove...onnection\Output\Edge>> of property $edges.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40 1
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 41
    public function getPageInfo(): ? PageInfo
46
    {
47 41
        return $this->pageInfo;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function setPageInfo(PageInfo $pageInfo): void
54
    {
55
        $this->pageInfo = $pageInfo;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 29
    public function getTotalCount(): int
62
    {
63 29
        return $this->totalCount;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 4
    public function setTotalCount(int $totalCount): void
70
    {
71 4
        $this->totalCount = $totalCount;
72 4
    }
73
}
74