Completed
Push — master ( 194832...e447f7 )
by Miro
02:25
created

GithubRepoSource   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 245
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 245
wmc 20
lcom 2
cbo 2
rs 10

20 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 35 1
A getId() 0 4 1
A getOwnerUserId() 0 4 1
A getOwnerUser() 0 4 1
A getOwner() 0 4 1
A getName() 0 4 1
A getFullName() 0 4 1
A getHtmlUrl() 0 4 1
A getDescription() 0 4 1
A isFork() 0 4 1
A getDefaultBranch() 0 4 1
A isPrivate() 0 4 1
A getGitUrl() 0 4 1
A getSshUrl() 0 4 1
A isAdmin() 0 4 1
A isPushAllowed() 0 4 1
A isReadAllowed() 0 4 1
A getGithubCreatedAt() 0 4 1
A getGithubUpdatedAt() 0 4 1
A getGithubPushedAt() 0 4 1
1
<?php
2
3
namespace DevBoardLib\GithubCore\Repo;
4
5
use DateTime;
6
use DevBoardLib\GithubCore\User\GithubUser;
7
use DevBoardLib\GithubCore\User\GithubUserId;
8
9
/**
10
 * Class GithubRepoSource.
11
 */
12
class GithubRepoSource implements GithubRepo, GithubRepoPermissonsInterface
13
{
14
    /** @var GithubRepoId */
15
    private $id;
16
    /** @var GithubUser */
17
    private $ownerUser;
18
    /** @var string */
19
    private $owner;
20
    /** @var string */
21
    private $name;
22
    /** @var string */
23
    private $fullName;
24
    /** @var string */
25
    private $htmlUrl;
26
    /** @var string */
27
    private $description;
28
    /** @var int */
29
    private $fork;
30
    /** @var string */
31
    private $defaultBranch;
32
    /** @var int */
33
    private $private;
34
    /** @var string */
35
    private $gitUrl;
36
    /** @var string */
37
    private $sshUrl;
38
    /** @var GithubRepoPermissions */
39
    private $permissions;
40
    /** @var DateTime */
41
    private $githubCreatedAt;
42
    /** @var DateTime */
43
    private $githubUpdatedAt;
44
    /** @var DateTime */
45
    private $githubPushedAt;
46
47
    /**
48
     * GithubRepoSource constructor.
49
     *
50
     * @param GithubRepoId          $id
51
     * @param GithubUser            $ownerUser
52
     * @param string                $owner
53
     * @param string                $name
54
     * @param string                $fullName
55
     * @param string                $htmlUrl
56
     * @param string                $description
57
     * @param bool                  $fork
58
     * @param string                $defaultBranch
59
     * @param bool                  $private
60
     * @param string                $gitUrl
61
     * @param string                $sshUrl
62
     * @param GithubRepoPermissions $permissions
63
     * @param DateTime              $githubCreatedAt
64
     * @param DateTime              $githubUpdatedAt
65
     * @param DateTime              $githubPushedAt
66
     *
67
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
68
     */
69
    public function __construct(
70
        GithubRepoId $id,
71
        GithubUser $ownerUser,
72
        $owner,
73
        $name,
74
        $fullName,
75
        $htmlUrl,
76
        $description,
77
        $fork,
78
        $defaultBranch,
79
        $private,
80
        $gitUrl,
81
        $sshUrl,
82
        GithubRepoPermissions $permissions = null,
83
        DateTime $githubCreatedAt,
84
        DateTime $githubUpdatedAt,
85
        DateTime $githubPushedAt
86
    ) {
87
        $this->id              = $id;
88
        $this->ownerUser       = $ownerUser;
89
        $this->owner           = $owner;
90
        $this->name            = $name;
91
        $this->fullName        = $fullName;
92
        $this->htmlUrl         = $htmlUrl;
93
        $this->description     = $description;
94
        $this->fork            = $fork;
0 ignored issues
show
Documentation Bug introduced by
The property $fork was declared of type integer, but $fork is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
95
        $this->defaultBranch   = $defaultBranch;
96
        $this->private         = $private;
0 ignored issues
show
Documentation Bug introduced by
The property $private was declared of type integer, but $private is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
97
        $this->gitUrl          = $gitUrl;
98
        $this->sshUrl          = $sshUrl;
99
        $this->permissions     = $permissions;
100
        $this->githubCreatedAt = $githubCreatedAt;
101
        $this->githubUpdatedAt = $githubUpdatedAt;
102
        $this->githubPushedAt  = $githubPushedAt;
103
    }
104
105
    /**
106
     * @return GithubRepoId
107
     */
108
    public function getId()
109
    {
110
        return $this->id;
111
    }
112
113
    /**
114
     * @return GithubUserId
115
     */
116
    public function getOwnerUserId()
117
    {
118
        return $this->ownerUser->getGithubUserId();
119
    }
120
121
    /**
122
     * @return GithubUser
123
     */
124
    public function getOwnerUser()
125
    {
126
        return $this->ownerUser;
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    public function getOwner()
133
    {
134
        return $this->owner;
135
    }
136
137
    /**
138
     * @return string
139
     */
140
    public function getName()
141
    {
142
        return $this->name;
143
    }
144
145
    /**
146
     * @return string
147
     */
148
    public function getFullName()
149
    {
150
        return $this->fullName;
151
    }
152
153
    /**
154
     * @return string
155
     */
156
    public function getHtmlUrl()
157
    {
158
        return $this->htmlUrl;
159
    }
160
161
    /**
162
     * @return string
163
     */
164
    public function getDescription()
165
    {
166
        return $this->description;
167
    }
168
169
    /**
170
     * @return int
171
     */
172
    public function isFork()
173
    {
174
        return $this->fork;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->fork; (integer) is incompatible with the return type declared by the interface DevBoardLib\GithubCore\Repo\GithubRepo::isFork of type boolean.

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...
175
    }
176
177
    /**
178
     * @return string
179
     */
180
    public function getDefaultBranch()
181
    {
182
        return $this->defaultBranch;
183
    }
184
185
    /**
186
     * @return int
187
     */
188
    public function isPrivate()
189
    {
190
        return $this->private;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->private; (integer) is incompatible with the return type declared by the interface DevBoardLib\GithubCore\Repo\GithubRepo::isPrivate of type boolean.

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...
191
    }
192
193
    /**
194
     * @return string
195
     */
196
    public function getGitUrl()
197
    {
198
        return $this->gitUrl;
199
    }
200
201
    /**
202
     * @return string
203
     */
204
    public function getSshUrl()
205
    {
206
        return $this->sshUrl;
207
    }
208
209
    /**
210
     * @return bool
211
     */
212
    public function isAdmin()
213
    {
214
        return $this->permissions->isAdmin();
215
    }
216
217
    /**
218
     * @return bool
219
     */
220
    public function isPushAllowed()
221
    {
222
        return $this->permissions->isPushAllowed();
223
    }
224
225
    /**
226
     * @return bool
227
     */
228
    public function isReadAllowed()
229
    {
230
        return $this->permissions->isReadAllowed();
231
    }
232
233
    /**
234
     * @return DateTime
235
     */
236
    public function getGithubCreatedAt()
237
    {
238
        return $this->githubCreatedAt;
239
    }
240
241
    /**
242
     * @return DateTime
243
     */
244
    public function getGithubUpdatedAt()
245
    {
246
        return $this->githubUpdatedAt;
247
    }
248
249
    /**
250
     * @return DateTime
251
     */
252
    public function getGithubPushedAt()
253
    {
254
        return $this->githubPushedAt;
255
    }
256
}
257