GithubRepoConvertTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 10

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 2
c 4
b 0
f 2
lcom 0
cbo 10
dl 0
loc 38
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B convertRepo() 0 30 2
1
<?php
2
3
namespace DevBoardLib\GithubObjectApiFacade\Repo\Repo\Converter;
4
5
use DevBoardLib\GithubCore\Repo\GithubRepoCreatedAt;
6
use DevBoardLib\GithubCore\Repo\GithubRepoFullName;
7
use DevBoardLib\GithubCore\Repo\GithubRepoGitUrl;
8
use DevBoardLib\GithubCore\Repo\GithubRepoId;
9
use DevBoardLib\GithubCore\Repo\GithubRepoName;
10
use DevBoardLib\GithubCore\Repo\GithubRepoPermissions;
11
use DevBoardLib\GithubCore\Repo\GithubRepoPushedAt;
12
use DevBoardLib\GithubCore\Repo\GithubRepoSource;
13
use DevBoardLib\GithubCore\Repo\GithubRepoSshUrl;
14
use DevBoardLib\GithubCore\Repo\GithubRepoUpdatedAt;
15
16
/**
17
 * Class GithubRepoConvertTrait.
18
 */
19
trait GithubRepoConvertTrait
20
{
21
    /**
22
     * @param array $data
23
     *
24
     * @return GithubRepoSource
25
     */
26
    protected function convertRepo(array $data)
27
    {
28
        $permissions = null;
29
30
        if (array_key_exists('permissions', $data)) {
31
            $permissions = new GithubRepoPermissions(
32
                (bool) $data['permissions']['admin'],
33
                (bool) $data['permissions']['push'],
34
                (bool) $data['permissions']['pull']
35
            );
36
        }
37
38
        return new GithubRepoSource(
39
            new GithubRepoId($data['id']),
40
            $this->getGithubRepoOwner($data['owner']),
0 ignored issues
show
Bug introduced by
It seems like getGithubRepoOwner() 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 GithubRepoName($data['name']),
42
            new GithubRepoFullName($data['full_name']),
43
            $data['html_url'],
44
            $data['description'],
45
            $data['fork'],
46
            $data['default_branch'],
47
            $data['private'],
48
            new GithubRepoGitUrl($data['git_url']),
49
            new GithubRepoSshUrl($data['ssh_url']),
50
            $permissions,
51
            new GithubRepoCreatedAt($data['created_at']),
52
            new GithubRepoUpdatedAt($data['updated_at']),
53
            new GithubRepoPushedAt($data['pushed_at'])
54
        );
55
    }
56
}
57