Completed
Push — master ( 84bf1d...fc2ff6 )
by Miro
03:05
created

GithubCommitConvertTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 37.29 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 5
dl 22
loc 59
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A convertCommit() 0 17 1
A getAuthor() 11 11 1
A getCommitter() 11 11 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 DevBoardLib\GithubObjectApiFacade\Repo\Commit\Converter;
3
4
use DateTime;
5
use DevBoardLib\GithubCore\Commit\GithubCommitId;
6
use DevBoardLib\GithubCore\Commit\GithubCommitSha;
7
use DevBoardLib\GithubCore\Commit\GithubCommitSource;
8
use DevBoardLib\GithubCore\User\GithubUserId;
9
use DevBoardLib\GithubCore\User\GithubUserSource;
10
11
/**
12
 * Class GithubCommitConvertTrait.
13
 */
14
trait GithubCommitConvertTrait
15
{
16
    /**
17
     * @param $data
18
     *
19
     * @return GithubCommitSource
20
     */
21
    protected function convertCommit($data)
22
    {
23
        return new GithubCommitSource(
24
            new GithubCommitId($this->githubRepo->getId(), new GithubCommitSha($data['sha'])),
0 ignored issues
show
Bug introduced by
The property githubRepo does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
            $this->githubRepo,
26
            new GithubCommitSha($data['sha']),
27
            $data['commit']['author']['name'],
28
            $data['commit']['author']['email'],
29
            $this->getAuthor($data),
30
            new DateTime($data['commit']['author']['date']),
31
            $this->getCommitter($data),
32
            new DateTime($data['commit']['committer']['date']),
33
            $data['commit']['message'],
34
            null
35
36
        );
37
    }
38
39
    /**
40
     * @param $data
41
     *
42
     * @return GithubUserSource
43
     */
44 View Code Duplication
    protected function getAuthor($data)
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...
45
    {
46
        return new GithubUserSource(
47
            new GithubUserId($data['author']['id']),
48
            $data['author']['login'],
49
            $data['commit']['author']['email'],
50
            $data['commit']['author']['name'],
51
            $data['author']['avatar_url']
52
53
        );
54
    }
55
56
    /**
57
     * @param $data
58
     *
59
     * @return GithubUserSource
60
     */
61 View Code Duplication
    protected function getCommitter($data)
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...
62
    {
63
        return new GithubUserSource(
64
            new GithubUserId($data['committer']['id']),
65
            $data['committer']['login'],
66
            $data['commit']['committer']['email'],
67
            $data['commit']['committer']['name'],
68
            $data['committer']['avatar_url']
69
70
        );
71
    }
72
}
73