GithubCommitConvertTrait::convertCommit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 12
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
3
namespace DevBoardLib\GithubObjectApiFacade\Repo\Commit\Converter;
4
5
use DevBoardLib\GithubCore\Commit\GithubCommitAuthor;
6
use DevBoardLib\GithubCore\Commit\GithubCommitCommitter;
7
use DevBoardLib\GithubCore\Commit\GithubCommitSha;
8
use DevBoardLib\GithubCore\Commit\GithubCommitSource;
9
use DevBoardLib\GithubCore\User\GithubUserId;
10
use DevBoardLib\GithubCore\User\GithubUserSource;
11
12
/**
13
 * Class GithubCommitConvertTrait.
14
 */
15
trait GithubCommitConvertTrait
16
{
17
    /**
18
     * @param array $data
19
     *
20
     * @return GithubCommitSource
21
     */
22
    protected function convertCommit(array $data)
23
    {
24
        return new GithubCommitSource(
25
            new GithubCommitSha($data['sha']),
26
            $this->githubRepo->getId(),
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...
27
            $this->getAuthor($data),
28
            $this->getCommitter($data),
29
            $data['commit']['message'],
30
            null
0 ignored issues
show
Unused Code introduced by
The call to GithubCommitSource::__construct() has too many arguments starting with null.

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...
31
32
        );
33
    }
34
35
    /**
36
     * @param array $data
37
     *
38
     * @return GithubUserSource
39
     */
40 View Code Duplication
    protected function getAuthor(array $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...
41
    {
42
        return new GithubCommitAuthor(
43
            $data['commit']['author']['name'],
44
            $data['commit']['author']['email'],
45
            new GithubUserId($data['author']['id']),
46
            $data['author']['login'],
47
            $data['author']['avatar_url']
48
49
        );
50
    }
51
52
    /**
53
     * @param array $data
54
     *
55
     * @return GithubUserSource
56
     */
57 View Code Duplication
    protected function getCommitter(array $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...
58
    {
59
        return new GithubCommitCommitter(
60
            $data['commit']['committer']['name'],
61
            $data['commit']['committer']['email'],
62
            new GithubUserId($data['committer']['id']),
63
            $data['committer']['login'],
64
            $data['committer']['avatar_url']
65
66
        );
67
    }
68
}
69