GithubMilestoneConvertTrait::convertMilestone()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 16

Duplication

Lines 21
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 21
loc 21
rs 9.3142
cc 1
eloc 16
nc 1
nop 1
1
<?php
2
3
namespace DevBoardLib\GithubObjectApiFacade\Repo\Milestone\Converter;
4
5
use DateTime;
6
use DevBoardLib\GithubCore\Milestone\GithubMilestoneId;
7
use DevBoardLib\GithubCore\Milestone\GithubMilestoneSource;
8
use DevBoardLib\GithubCore\Milestone\State\GithubMilestoneStateFactory;
9
10
/**
11
 * Class GithubMilestoneConvertTrait.
12
 */
13
trait GithubMilestoneConvertTrait
14
{
15
    /**
16
     * @param array $data
17
     *
18
     * @throws \Exception
19
     *
20
     * @return GithubMilestoneSource
21
     */
22 View Code Duplication
    protected function convertMilestone(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...
23
    {
24
        $milestone = new GithubMilestoneSource(
25
            new GithubMilestoneId($data['id']),
26
            $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...
27
            $data['number'],
28
            GithubMilestoneStateFactory::create($data['state']),
29
            $data['title'],
30
            $data['description'],
31
            $this->getUserIfExists($data['creator']),
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...
32
            $data['open_issues'],
33
            $data['closed_issues'],
34
            $this->getDateIfExists($data['due_on']),
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...
35
            new DateTime($data['created_at']),
36
            new DateTime($data['updated_at']),
37
            $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...
38
39
        );
40
41
        return $milestone;
42
    }
43
44
    /**
45
     * @param array|null $data
46
     *
47
     * @return GithubMilestoneSource|null
48
     */
49
    protected function getMilestoneIfExists(array $data = null)
50
    {
51
        if (empty($data)) {
52
            return null;
53
        }
54
55
        return $this->convertMilestone($data);
56
    }
57
}
58