Passed
Branch development (0505ff)
by Jonathan
08:42
created

DeleteTrait::deleteTemplate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 9.2
ccs 12
cts 12
cp 1
cc 3
eloc 11
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
    /**
24
     * Delete a template in template storage
25
     *
26
     * @param string $templateName Template name
27
     *
28
     * @throws InvalidArgumentException
29
     *
30
     * @return bool
31
     */
32 11
    public function deleteTemplate($templateName)
33
    {
34 11
        $ret = false;
35
36 11
        StaticValidator::execute($templateName, 'TemplateName');
37
38
        $query = [
39 10
            'templateName' => $templateName,
40 10
        ];
41
42
        $options = [
43 10
            RequestOptions::QUERY => $query,
44 10
        ];
45
46 10
        $response = $this->request('DELETE', $this->uri('/templates/delete'), $options);
0 ignored issues
show
Bug introduced by
It seems like uri() 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...
Bug introduced by
It seems like request() 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...
47
48 9
        if ($response instanceof Response && 204 === $response->getStatusCode()) {
49 9
            $ret = true;
50 9
        }
51
52 10
        return $ret;
53
    }
54
}
55