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

ManagesCompanies::deleteCompany()   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\Resources\Company;
8
use TestMonitor\Custify\Exceptions\NotFoundException;
9
use TestMonitor\Custify\Transforms\TransformsCompanies;
10
11
trait ManagesCompanies
12
{
13
    use TransformsCompanies;
14
15
    /**
16
     * Get a list of of companies.
17
     *
18
     * @param int $page
19
     * @param int $limit
20
     *
21
     * @throws \TestMonitor\Custify\Exceptions\InvalidDataException
22
     * @return \TestMonitor\Custify\Resources\Company[]
23
     */
24 7 View Code Duplication
    public function companies($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...
25
    {
26 7
        $response = $this->get('company/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...
27 7
            'query' => ['itemsPerPage' => $limit, 'page' => $page],
28
        ]);
29
30 1
        return $this->fromCustifyCompanies($response['companies']);
31
    }
32
33
    /**
34
     * Get a single company.
35
     *
36
     * @param string $id
37
     *
38
     * @throws \TestMonitor\Custify\Exceptions\NotFoundException
39
     * @throws \TestMonitor\Custify\Exceptions\InvalidDataException
40
     * @return \TestMonitor\Custify\Resources\Company
41
     */
42 1 View Code Duplication
    public function company(string $id): Company
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...
43
    {
44 1
        $response = $this->get("company/{$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...
45
46 1
        Validator::keysExists($response, ['companies']);
47
48
        // Simulate a not found response when the user_id does not exists.
49 1
        if (empty($response['companies'])) {
50
            throw new NotFoundException();
51
        }
52
53 1
        return $this->fromCustifyCompany($response['companies'][0]);
54
    }
55
56
    /**
57
     * Get a single company by company id.
58
     *
59
     * @param string $companyId
60
     *
61
     * @throws \TestMonitor\Custify\Exceptions\InvalidDataException
62
     * @throws \TestMonitor\Custify\Exceptions\NotFoundException
63
     * @return \TestMonitor\Custify\Resources\Company
64
     */
65 2 View Code Duplication
    public function companyByCompanyId(string $companyId): Company
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...
66
    {
67 2
        $response = $this->get("company?company_id={$companyId}");
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...
68
69 2
        Validator::keysExists($response, ['companies']);
70
71
        // Simulate a not found response when the user_id does not exists.
72 2
        if (empty($response['companies'])) {
73 1
            throw new NotFoundException();
74
        }
75
76 1
        return $this->fromCustifyCompany($response['companies'][0]);
77
    }
78
79
    /**
80
     * Create or update a company.
81
     *
82
     * @param \TestMonitor\Custify\Resources\Company $company
83
     *
84
     *@throws \TestMonitor\Custify\Exceptions\InvalidDataException
85
     * @return \TestMonitor\Custify\Resources\Company
86
     */
87 1
    public function createOrUpdateCompany(Company $company): Company
88
    {
89 1
        $response = $this->post('company', ['json' => $this->toCustifyCompany($company)]);
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...
90
91 1
        return $this->fromCustifyCompany($response);
92
    }
93
94
    /**
95
     * Delete a person.
96
     *
97
     * @param \TestMonitor\Custify\Resources\Company $company
98
     *
99
     * @throws \TestMonitor\Custify\Exceptions\InvalidDataException
100
     * @return \TestMonitor\Custify\Resources\Person
101
     */
102
    public function deleteCompany(Company $company)
103
    {
104
        return $this->delete("company/{$company->id}");
0 ignored issues
show
Bug introduced by
The method delete() does not exist on TestMonitor\Custify\Actions\ManagesCompanies. Did you maybe mean deleteCompany()?

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...
105
    }
106
}
107