Commits   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 12
loc 60
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A listCommits() 12 12 1
A getSingleCommit() 0 5 1
A compareTwoCommits() 0 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace FlexyProject\GitHub\Receiver\Repositories;
3
4
use FlexyProject\GitHub\AbstractApi;
5
6
/**
7
 * The Commits API class provides access to repository's commits.
8
 *
9
 * @link    https://developer.github.com/v3/repos/commits/
10
 * @package FlexyProject\GitHub\Receiver\Repositories
11
 */
12
class Commits extends AbstractRepositories
13
{
14
15
    /**
16
     * List commits on a repository
17
     *
18
     * @link https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
19
     *
20
     * @param string      $sha
21
     * @param string|null $path
22
     * @param string|null $author
23
     * @param string|null $since
24
     * @param string|null $until
25
     *
26
     * @return array
27
     */
28 View Code Duplication
    public function listCommits(string $sha = AbstractApi::BRANCH_MASTER, string $path = null, string $author = null,
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...
29
                                string $since = null, string $until = null): array
30
    {
31
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/commits?:args',
32
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), http_build_query([
33
                "sha"    => $sha,
34
                "path"   => $path,
35
                "author" => $author,
36
                "since"  => $since,
37
                "until"  => $until
38
            ])));
39
    }
40
41
    /**
42
     * Get a single commit
43
     *
44
     * @link https://developer.github.com/v3/repos/commits/#get-a-single-commit
45
     *
46
     * @param string $sha
47
     *
48
     * @return array
49
     */
50
    public function getSingleCommit(string $sha): array
51
    {
52
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/commits/:sha',
53
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $sha));
54
    }
55
56
    /**
57
     * Compare two commits
58
     *
59
     * @link https://developer.github.com/v3/repos/commits/#compare-two-commits
60
     *
61
     * @param string $base
62
     * @param string $head
63
     *
64
     * @return array
65
     */
66
    public function compareTwoCommits(string $base, string $head): array
67
    {
68
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/compare/:base...:head',
69
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $base, $head));
70
    }
71
} 
72