PaginatedKnpLabsRepoFacade::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
namespace DevBoardLib\GithubApiFacade\Repo;
4
5
use DevBoardLib\GithubCore\Repo\GithubRepo;
6
use Github\Client;
7
use Github\ResultPager;
8
9
/**
10
 * Class PaginatedKnpLabsRepoFacade.
11
 */
12
class PaginatedKnpLabsRepoFacade implements RepoFacade
13
{
14
    private $client;
15
    private $githubRepo;
16
17
    private $paginator;
18
19
    /**
20
     * PaginatedKnpLabsRepoFacade constructor.
21
     *
22
     * @param $client
23
     * @param $githubRepo
24
     */
25
    public function __construct(Client $client, GithubRepo $githubRepo)
26
    {
27
        $this->client     = $client;
28
        $this->githubRepo = $githubRepo;
29
30
        $this->paginator = new ResultPager($this->client);
31
    }
32
33
    /**
34
     * Fetches GithubRepo details.
35
     *
36
     * @return array
37
     */
38
    public function fetchDetails()
39
    {
40
        return $this->getRepoApi()
0 ignored issues
show
Bug introduced by
The call to show() misses a required argument $id.

This check looks for function calls that miss required arguments.

Loading history...
Bug introduced by
The method show does only exist in Github\Api\Authorization...epo and Github\Api\User, but not in Github\Api\Deployment an...t and Github\Api\Search.

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...
41
            ->show(
42
                $this->githubRepo->getOwner(),
0 ignored issues
show
Unused Code introduced by
The call to CurrentUser::show() has too many arguments starting with $this->githubRepo->getOwner().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
43
                $this->githubRepo->getName()
0 ignored issues
show
Unused Code introduced by
The call to Gists::show() has too many arguments starting with $this->githubRepo->getName().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to Organization::show() has too many arguments starting with $this->githubRepo->getName().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to Teams::show() has too many arguments starting with $this->githubRepo->getName().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to Authorizations::show() has too many arguments starting with $this->githubRepo->getName().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to User::show() has too many arguments starting with $this->githubRepo->getName().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
44
            );
45
    }
46
47
    /**
48
     * Fetches GithubBranch details.
49
     *
50
     * @param $branchName
51
     *
52
     * @return array
53
     */
54
    public function fetchBranch($branchName)
55
    {
56
        return $this->getRepoApi()
0 ignored issues
show
Bug introduced by
The method branches does only exist in Github\Api\Repo, but not in Github\Api\Authorization...rch and Github\Api\User.

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...
57
            ->branches(
58
                $this->githubRepo->getOwner(),
59
                $this->githubRepo->getName(),
60
                $branchName
61
            );
62
    }
63
64
    /** @return array */
65
    public function fetchAllBranches()
66
    {
67
        $results = [];
68
69
        foreach ($this->fetchAllBranchNames() as $branchData) {
70
            $results[] = $this->fetchBranch($branchData['name']);
71
        }
72
73
        return $results;
74
    }
75
76
    /** @return array */
77 View Code Duplication
    public function fetchAllBranchNames()
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...
78
    {
79
        $parameters = [
80
            $this->githubRepo->getOwner(),
81
            $this->githubRepo->getName(),
82
        ];
83
84
        return $this->paginator->fetchAll($this->getRepoApi(), 'branches', $parameters);
85
    }
86
87
    /** @return array */
88
    public function fetchAllTags()
89
    {
90
        $results = [];
91
92
        foreach ($this->fetchAllTagNames() as $tagData) {
93
            $tagData['commit'] = $this->fetchCommit($tagData['commit']['sha']);
94
            $results[]         = $tagData;
95
        }
96
97
        return $results;
98
    }
99
100
    /** @return array */
101 View Code Duplication
    public function fetchAllTagNames()
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...
102
    {
103
        $parameters = [
104
            $this->githubRepo->getOwner(),
105
            $this->githubRepo->getName(),
106
        ];
107
108
        return $this->paginator->fetchAll($this->getRepoApi(), 'tags', $parameters);
109
    }
110
111
    /**
112
     * Fetches GithubCommit details.
113
     *
114
     * @param $commitSha
115
     *
116
     * @return array
117
     */
118
    public function fetchCommit($commitSha)
119
    {
120
        return $this->getRepoApi()->commits()
0 ignored issues
show
Bug introduced by
The call to commits() misses a required argument $id.

This check looks for function calls that miss required arguments.

Loading history...
Bug introduced by
The call to commits() misses some required arguments starting with $username.
Loading history...
Bug introduced by
The method commits does only exist in Github\Api\Gists and Git...est and Github\Api\Repo, but not in Github\Api\Authorization...rch and Github\Api\User.

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...
121
            ->show(
122
                $this->githubRepo->getOwner(),
123
                $this->githubRepo->getName(),
124
                $commitSha
125
            );
126
    }
127
128
    /**
129
     * Fetches GithubCommit status.
130
     *
131
     * @param $commitSha
132
     *
133
     * @return array
134
     */
135
    public function fetchCommitStatus($commitSha)
136
    {
137
        return $this->getRepoApi()->statuses()
0 ignored issues
show
Bug introduced by
The method statuses does only exist in Github\Api\Repo, but not in Github\Api\Authorization...rch and Github\Api\User.

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...
138
            ->combined(
139
                $this->githubRepo->getOwner(),
140
                $this->githubRepo->getName(),
141
                $commitSha
142
            );
143
    }
144
145
    /**
146
     * Fetches list of GithubCommit statuses.
147
     *
148
     * @param $commitSha
149
     *
150
     * @return array
151
     */
152
    public function fetchCommitStatuses($commitSha)
153
    {
154
        return $this->getRepoApi()->statuses()
0 ignored issues
show
Bug introduced by
The method statuses does only exist in Github\Api\Repo, but not in Github\Api\Authorization...rch and Github\Api\User.

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...
155
            ->show(
156
                $this->githubRepo->getOwner(),
157
                $this->githubRepo->getName(),
158
                $commitSha
159
            );
160
    }
161
162
    /** @return array */
163 View Code Duplication
    public function fetchAllPullRequests()
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...
164
    {
165
        $parameters = [
166
            $this->githubRepo->getOwner(),
167
            $this->githubRepo->getName(),
168
            ['state' => 'all'],
169
        ];
170
171
        return $this->paginator->fetchAll($this->getPullRequestApi(), 'all', $parameters);
172
    }
173
174
    /** @return array */
175 View Code Duplication
    public function fetchAllMilestones()
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...
176
    {
177
        $parameters = [
178
            $this->githubRepo->getOwner(),
179
            $this->githubRepo->getName(),
180
            ['state' => 'all'],
181
        ];
182
183
        return $this->paginator->fetchAll($this->getMilestonesApi(), 'all', $parameters);
184
    }
185
186
    /**
187
     * Returns all issues.
188
     *
189
     * IMPORTANT:
190
     * - GitHub API v3 returns both issues and pullRequests together so filtering needs to be done
191
     * - Pull requests have 'pull_request' key.
192
     *
193
     * @return array
194
     */
195
    public function fetchAllIssues()
196
    {
197
        $results = [];
198
199
        foreach ($this->fetchAllIssuesAndPullRequests() as $result) {
200
            if (!array_key_exists('pull_request', $result)) {
201
                $results[] = $result;
202
            }
203
        }
204
205
        return $results;
206
    }
207
208
    /** @return array */
209 View Code Duplication
    public function fetchAllIssuesAndPullRequests()
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...
210
    {
211
        $parameters = [
212
            $this->githubRepo->getOwner(),
213
            $this->githubRepo->getName(),
214
            ['state' => 'all'],
215
        ];
216
217
        return $this->paginator->fetchAll($this->getIssueApi(), 'all', $parameters);
218
    }
219
220
    /**
221
     * @return \Github\Api\ApiInterface
222
     */
223
    private function getRepoApi()
224
    {
225
        return $this->client->api('repository');
226
    }
227
228
    /**
229
     * @return \Github\Api\ApiInterface
230
     */
231
    private function getIssueApi()
232
    {
233
        return $this->client->api('issues');
234
    }
235
236
    /**
237
     * @return \Github\Api\Issue\Milestones
238
     */
239
    private function getMilestonesApi()
240
    {
241
        return $this->getIssueApi()->milestones();
0 ignored issues
show
Bug introduced by
The call to milestones() misses some required arguments starting with $username.
Loading history...
Bug introduced by
The method milestones does only exist in Github\Api\Issue and Github\Api\Repo, but not in Github\Api\Authorization...rch and Github\Api\User.

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...
242
    }
243
244
    /**
245
     * @return \Github\Api\PullRequest
246
     */
247
    private function getPullRequestApi()
248
    {
249
        return $this->client->api('pull_requests');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->client->api('pull_requests'); (Github\Api\CurrentUser|G...pi\Meta|Github\Api\User) is incompatible with the return type documented by DevBoardLib\GithubApiFac...cade::getPullRequestApi of type Github\Api\PullRequest.

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...
250
    }
251
}
252