Completed
Pull Request — master (#8)
by Miro
03:40
created

convertPullRequest()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 24
rs 8.9713
cc 1
eloc 19
nc 1
nop 1
1
<?php
2
namespace DevBoardLib\GithubObjectApiFacade\Repo\PullRequest\Converter;
3
4
use DateTime;
5
use DevBoardLib\GithubCore\Commit\GithubCommitId;
6
use DevBoardLib\GithubCore\Commit\GithubCommitSha;
7
use DevBoardLib\GithubCore\PullRequest\GithubPullRequestId;
8
use DevBoardLib\GithubCore\PullRequest\GithubPullRequestSource;
9
use DevBoardLib\GithubCore\PullRequest\State\GithubPullRequestStateFactory;
10
11
/**
12
 * Class GithubPullRequestConvertTrait.
13
 */
14
trait GithubPullRequestConvertTrait
15
{
16
    /**
17
     * @param $data
18
     *
19
     * @throws \Exception
20
     *
21
     * @return GithubPullRequestSource
22
     */
23
    protected function convertPullRequest($data)
24
    {
25
        return new GithubPullRequestSource(
26
            new GithubPullRequestId($data['id']),
27
            $this->githubRepo,
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...
28
            $data['number'],
29
            GithubPullRequestStateFactory::create($data['state']),
30
            $data['locked'],
31
            $data['merged_at'],
32
            $data['title'],
33
            $data['body'],
34
            new GithubCommitId(
35
                $this->githubRepo->getId(),
36
                new GithubCommitSha($data['head']['sha'])
37
            ),
38
            $this->getUser($data['user']),
0 ignored issues
show
Bug introduced by
It seems like getUser() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
39
            $this->getUserIfExists($data['assignee']),
0 ignored issues
show
Bug introduced by
It seems like getUserIfExists() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
40
            $this->getMilestoneIfExists($data['milestone']),
0 ignored issues
show
Bug introduced by
It seems like getMilestoneIfExists() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
41
            new DateTime($data['created_at']),
42
            new DateTime($data['updated_at']),
43
            $this->getDateIfExists($data['closed_at'])
0 ignored issues
show
Bug introduced by
It seems like getDateIfExists() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
44
45
        );
46
    }
47
}
48