Test Failed
Branch development (5babc9)
by Jonathan
04:47
created

DeleteTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 62.5 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 40
loc 64
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
uri() 0 1 ?
request() 0 1 ?
A deleteApiKey() 20 20 3
A deleteTemplate() 20 20 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * ReportingCloud PHP Wrapper
5
 *
6
 * PHP wrapper for ReportingCloud Web API. Authored and supported by Text Control GmbH.
7
 *
8
 * @link      http://www.reporting.cloud to learn more about ReportingCloud
9
 * @link      https://github.com/TextControl/txtextcontrol-reportingcloud-php for the canonical source repository
10
 * @license   https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-php/master/LICENSE.md
11
 * @copyright © 2018 Text Control GmbH
12
 */
13
14
namespace TxTextControl\ReportingCloud;
15
16
use GuzzleHttp\Psr7\Response;
17
use GuzzleHttp\RequestOptions;
18
use TxTextControl\ReportingCloud\Exception\InvalidArgumentException;
19
use TxTextControl\ReportingCloud\Validator\StaticValidator;
20
21
trait DeleteTrait
22
{
23
    abstract protected function uri($uri);
24
25
    abstract protected function request($method, $uri, $options);
26
27
    /**
28
     * Delete an API key
29
     *
30
     * @param string $key API key
31
     *
32
     * @return bool
33
     */
34 View Code Duplication
    public function deleteApiKey($key)
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...
35
    {
36 11
        $ret = false;
37
38 11
        StaticValidator::execute($key, 'ApiKey');
39
40 11
        $options = [
41
            RequestOptions::QUERY => [
42
                'key' => $key,
43 10
            ],
44 10
        ];
45
46
        $response = $this->request('DELETE', $this->uri('/account/apikey'), $options);
47 10
48 10
        if ($response instanceof Response && 200 === $response->getStatusCode()) {
49
            $ret = true;
50 10
        }
51
52 9
        return $ret;
53 9
    }
54 9
55
    /**
56 9
     * Delete a template in template storage
57
     *
58
     * @param string $templateName Template name
59
     *
60
     * @throws InvalidArgumentException
61
     *
62
     * @return bool
63
     */
64 View Code Duplication
    public function deleteTemplate($templateName)
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...
65
    {
66
        $ret = false;
67
68
        StaticValidator::execute($templateName, 'TemplateName');
69
70
        $options = [
71
            RequestOptions::QUERY => [
72
                'templateName' => $templateName,
73
            ],
74
        ];
75
76
        $response = $this->request('DELETE', $this->uri('/templates/delete'), $options);
77
78
        if ($response instanceof Response && 204 === $response->getStatusCode()) {
79
            $ret = true;
80
        }
81
82
        return $ret;
83
    }
84
}
85