GithubIssueConvertTrait::convertIssue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 15

Duplication

Lines 20
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 20
loc 20
rs 9.4285
cc 1
eloc 15
nc 1
nop 1
1
<?php
2
3
namespace DevBoardLib\GithubObjectApiFacade\Repo\Issue\Converter;
4
5
use DateTime;
6
use DevBoardLib\GithubCore\Issue\GithubIssueId;
7
use DevBoardLib\GithubCore\Issue\GithubIssueSource;
8
use DevBoardLib\GithubCore\Issue\State\GithubIssueStateFactory;
9
10
/**
11
 * Class GithubIssueConvertTrait.
12
 */
13
trait GithubIssueConvertTrait
14
{
15
    /**
16
     * @param array $data
17
     *
18
     * @throws \Exception
19
     *
20
     * @return GithubIssueSource
21
     */
22 View Code Duplication
    protected function convertIssue(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
        return new GithubIssueSource(
25
            new GithubIssueId($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
            GithubIssueStateFactory::create($data['state']),
29
            $data['title'],
30
            $data['body'],
31
            $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...
32
            $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...
33
            $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...
34
            $data['comments'],
35
36
            new DateTime($data['created_at']),
37
            new DateTime($data['updated_at']),
38
            $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...
39
40
        );
41
    }
42
}
43