Completed
Push — master ( 4b86d5...24918a )
by steef
01:22
created

ManagesPeople::deletePerson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace TestMonitor\Custify\Actions;
4
5
use TestMonitor\Custify\Validator;
6
use TestMonitor\Custify\Resources\Person;
7
use TestMonitor\Custify\Transforms\TransformsPeople;
8
use TestMonitor\Custify\Exceptions\NotFoundException;
9
10
trait ManagesPeople
11
{
12
    use TransformsPeople;
13
14
    /**
15
     * Get a list of of people.
16
     *
17
     * @param int $page
18
     * @param int $limit
19
     *
20
     * @throws \TestMonitor\Custify\Exceptions\InvalidDataException
21
     * @return \TestMonitor\Custify\Resources\Person[]
22
     */
23 7 View Code Duplication
    public function people($page = 1, $limit = 10): array
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...
24
    {
25 7
        $response = $this->get('people/all', [
0 ignored issues
show
Bug introduced by
It seems like get() 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...
26 7
            'query' => ['itemsPerPage' => $limit, 'page' => $page],
27
        ]);
28
29 1
        return $this->fromCustifyPeople($response[0]['people']);
30
    }
31
32
    /**
33
     * Get a single person.
34
     *
35
     * @param string $id
36
     *
37
     * @throws \TestMonitor\Custify\Exceptions\InvalidDataException
38
     * @return \TestMonitor\Custify\Resources\Person
39
     */
40 2
    public function person(string $id): Person
41
    {
42 2
        $response = $this->get("people/{$id}");
0 ignored issues
show
Bug introduced by
It seems like get() 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...
43
44 1
        return $this->fromCustifyPerson($response);
45
    }
46
47
    /**
48
     * Get a single person by user id.
49
     *
50
     * @param string $userId
51
     *
52
     * @throws \TestMonitor\Custify\Exceptions\NotFoundException
53
     * @throws \TestMonitor\Custify\Exceptions\InvalidDataException
54
     * @return \TestMonitor\Custify\Resources\Person
55
     */
56 2 View Code Duplication
    public function personByUserId(string $userId): Person
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...
57
    {
58 2
        $response = $this->get("people?user_id={$userId}");
0 ignored issues
show
Bug introduced by
It seems like get() 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...
59
60 2
        Validator::keysExists($response[0], ['people']);
61
62
        // Simulate a not found response when the user_id does not exists.
63 2
        if (empty($response[0]['people'])) {
64 1
            throw new NotFoundException();
65
        }
66
67 1
        return $this->fromCustifyPerson($response[0]['people'][0]);
68
    }
69
70
    /**
71
     * Get a single person by email.
72
     *
73
     * @param string $email
74
     *
75
     * @throws \TestMonitor\Custify\Exceptions\NotFoundException
76
     * @throws \TestMonitor\Custify\Exceptions\InvalidDataException
77
     * @return \TestMonitor\Custify\Resources\Person
78
     */
79 View Code Duplication
    public function personByEmail(string $email): Person
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...
80
    {
81
        $response = $this->get("people?email={$email}");
0 ignored issues
show
Bug introduced by
It seems like get() 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...
82
83
        Validator::keysExists($response[0], ['people']);
84
85
        // Simulate a not found response when the user_id does not exists.
86
        if (empty($response[0]['people'])) {
87
            throw new NotFoundException();
88
        }
89
90
        return $this->fromCustifyPerson($response[0]['people'][0]);
91
    }
92
93
    /**
94
     * Create or update a person.
95
     *
96
     * @param \TestMonitor\Custify\Resources\Person $person
97
     *
98
     * @throws \TestMonitor\Custify\Exceptions\InvalidDataException
99
     * @return \TestMonitor\Custify\Resources\Person
100
     */
101 1
    public function createOrUpdatePerson(Person $person): Person
102
    {
103 1
        $response = $this->post('people', ['json' => $this->toCustifyPerson($person)]);
0 ignored issues
show
Bug introduced by
It seems like post() 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...
104
105 1
        return $this->fromCustifyPerson($response);
106
    }
107
108
    /**
109
     * Delete a person.
110
     *
111
     * @param \TestMonitor\Custify\Resources\Person $person
112
     *
113
     * @throws \TestMonitor\Custify\Exceptions\InvalidDataException
114
     * @return \TestMonitor\Custify\Resources\Person
115
     */
116
    public function deletePerson(Person $person): Person
117
    {
118
        return $this->delete("people/{$person->id}");
0 ignored issues
show
Bug introduced by
The method delete() does not exist on TestMonitor\Custify\Actions\ManagesPeople. Did you maybe mean deletePerson()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
119
    }
120
}
121