Completed
Push — master ( cd5f41...3e5383 )
by Miro
03:16
created

GithubRepoConvertTrait::convertRepo()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 31
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 31
rs 8.8571
cc 2
eloc 24
nc 2
nop 1
1
<?php
2
3
namespace DevBoardLib\GithubObjectApiFacade\Repo\Repo\Converter;
4
5
use DateTime;
6
use DevBoardLib\GithubCore\Repo\GithubRepoId;
7
use DevBoardLib\GithubCore\Repo\GithubRepoPermissions;
8
use DevBoardLib\GithubCore\Repo\GithubRepoSource;
9
10
/**
11
 * Class GithubRepoConvertTrait.
12
 */
13
trait GithubRepoConvertTrait
14
{
15
    /**
16
     * @param array $data
17
     *
18
     * @return GithubRepoSource
19
     */
20
    protected function convertRepo(array $data)
21
    {
22
        $permissions = null;
23
24
        if (array_key_exists('permissions', $data)) {
25
            $permissions = new GithubRepoPermissions(
26
                (bool) $data['permissions']['admin'],
27
                (bool) $data['permissions']['push'],
28
                (bool) $data['permissions']['pull']
29
            );
30
        }
31
32
        return new GithubRepoSource(
33
            new GithubRepoId($data['id']),
34
            $this->getUser($data['owner']),
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...
35
            $data['owner']['login'],
36
            $data['name'],
37
            $data['full_name'],
38
            $data['html_url'],
39
            $data['description'],
40
            $data['fork'],
41
            $data['default_branch'],
42
            $data['private'],
43
            $data['git_url'],
44
            $data['ssh_url'],
45
            $permissions,
46
            new DateTime($data['created_at']),
47
            new DateTime($data['updated_at']),
48
            new DateTime($data['pushed_at'])
49
        );
50
    }
51
}
52