Passed
Branch development (83e590)
by Jonathan
04:53
created

DeleteTrait::deleteTemplate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 20
Code Lines 10

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 0
Metric Value
dl 20
loc 20
ccs 12
cts 12
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 2
nop 1
crap 3
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 2 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 2
        $ret = false;
37
38 2
        StaticValidator::execute($key, 'ApiKey');
39
40
        $options = [
41 2
            RequestOptions::QUERY => [
42 2
                'key' => $key,
43 2
            ],
44 2
        ];
45
46 2
        $response = $this->request('DELETE', $this->uri('/account/apikey'), $options);
47
48 2
        if ($response instanceof Response && 200 === $response->getStatusCode()) {
49 2
            $ret = true;
50 2
        }
51
52 2
        return $ret;
53
    }
54
55
    /**
56
     * Delete a template in template storage
57
     *
58
     * @param string $templateName Template name
59
     *
60
     * @throws InvalidArgumentException
61
     *
62
     * @return bool
63
     */
64 11 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 11
        $ret = false;
67
68 11
        StaticValidator::execute($templateName, 'TemplateName');
69
70
        $options = [
71 10
            RequestOptions::QUERY => [
72 10
                'templateName' => $templateName,
73 10
            ],
74 10
        ];
75
76 10
        $response = $this->request('DELETE', $this->uri('/templates/delete'), $options);
77
78 9
        if ($response instanceof Response && 204 === $response->getStatusCode()) {
79 9
            $ret = true;
80 9
        }
81
82 9
        return $ret;
83
    }
84
}
85