SNIRequest::setUp()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace CCT\Kong\Http\Request;
4
5
use CCT\Kong\Config;
6
use CCT\Kong\Exception\InvalidParameterException;
7
use CCT\Kong\Exception\MethodNotImplementedException;
8
use CCT\Kong\Http\Definition\QueryParams;
9
use CCT\Kong\Http\Request;
10
use CCT\Kong\Http\Response;
11
use CCT\Kong\Http\ResponseInterface;
12
use CCT\Kong\Model\SNI;
13
14
class SNIRequest extends Request
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19 8
    protected function setUp()
20
    {
21 8
        if (!$this->config->has(Config::URI_PREFIX)) {
22 8
            $this->config->set(Config::URI_PREFIX, '/snis/');
23
        }
24 8
    }
25
26
    /**
27
     * Gets the list of SNIs.
28
     *
29
     * @param QueryParams|null $queryParams
30
     *
31
     * @return ResponseInterface|Response
32
     */
33 1
    public function list(QueryParams $queryParams = null): ResponseInterface
34
    {
35 1
        $this->setSerializationContextFor(['read']);
36
37 1
        return parent::requestGet($this->getUri(), $queryParams);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::requestGe...getUri(), $queryParams) could return the type Symfony\Component\HttpFoundation\Response which is incompatible with the type-hinted return CCT\Kong\Http\ResponseInterface. Consider adding an additional type-check to rule them out.
Loading history...
38
    }
39
40
    /**
41
     * Creates a SNI.
42
     *
43
     * @param SNI $sni
44
     *
45
     * @return ResponseInterface|Response
46
     */
47 2
    public function create(SNI $sni): ResponseInterface
48
    {
49 2
        $this->setSerializationContextFor(['create']);
50
51 2
        return parent::requestPost($this->getUri(), $sni);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::requestPost($this->getUri(), $sni) could return the type Symfony\Component\HttpFoundation\Response which is incompatible with the type-hinted return CCT\Kong\Http\ResponseInterface. Consider adding an additional type-check to rule them out.
Loading history...
52
    }
53
54
    /**
55
     * Retrieves a SNI by its name.
56
     *
57
     * @param string $name
58
     *
59
     * @return ResponseInterface|Response
60
     */
61 3
    public function retrieve(string $name): ResponseInterface
62
    {
63 3
        $this->setSerializationContextFor(['read']);
64
65 3
        return parent::requestGet($this->appendToUri($name));
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::requestGe...is->appendToUri($name)) could return the type Symfony\Component\HttpFoundation\Response which is incompatible with the type-hinted return CCT\Kong\Http\ResponseInterface. Consider adding an additional type-check to rule them out.
Loading history...
66
    }
67
68
    /**
69
     * Updates a SNI.
70
     *
71
     * @param SNI $sni
72
     *
73
     * @return ResponseInterface|Response
74
     */
75 1
    public function update(SNI $sni): ResponseInterface
76
    {
77 1
        $this->setSerializationContextFor(['update']);
78
79 1
        return parent::requestPatch($this->appendToUri($sni->getName()), $sni);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::requestPa...$sni->getName()), $sni) could return the type Symfony\Component\HttpFoundation\Response which is incompatible with the type-hinted return CCT\Kong\Http\ResponseInterface. Consider adding an additional type-check to rule them out.
Loading history...
80
    }
81
82
    /**
83
     * Method is not implemented.
84
     *
85
     * @param SNI $sni
86
     *
87
     * @throws MethodNotImplementedException
88
     */
89 1
    public function updateOrCreate(SNI $sni)
0 ignored issues
show
Unused Code introduced by
The parameter $sni is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

89
    public function updateOrCreate(/** @scrutinizer ignore-unused */ SNI $sni)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90
    {
91 1
        throw new MethodNotImplementedException('Please check the issue at: https://github.com/Kong/kong/issues/3168');
92
    }
93
94
    /**
95
     * Deletes a SNI.
96
     *
97
     * @param SNI $sni
98
     *
99
     * @return ResponseInterface
100
     */
101
    public function delete(SNI $sni): ResponseInterface
102
    {
103
        if (null === $sni->getName()) {
104
            throw new InvalidParameterException('The name must be defined to delete the SNI.');
105
        }
106
107
        $this->setSerializationContextFor(['delete']);
108
109
        return parent::requestDelete($this->appendToUri($sni->getName()));
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::requestDe...ToUri($sni->getName())) could return the type Symfony\Component\HttpFoundation\Response which is incompatible with the type-hinted return CCT\Kong\Http\ResponseInterface. Consider adding an additional type-check to rule them out.
Loading history...
110
    }
111
}
112