ConsumerRequest::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
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\InvalidResourceException;
0 ignored issues
show
Bug introduced by
The type CCT\Kong\Exception\InvalidResourceException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use CCT\Kong\Http\Definition\QueryParams;
9
use CCT\Kong\Http\Request;
10
use CCT\Kong\Http\ResponseInterface;
11
use CCT\Kong\Model\Consumer;
12
use JMS\Serializer\SerializationContext;
13
14
class ConsumerRequest extends Request
15
{
16 12
    protected function setUp()
17
    {
18 12
        $this->config->set(Config::URI_PREFIX, '/consumers/');
19 12
    }
20
21 2
    public function list(QueryParams $queryParams = null): ResponseInterface
22
    {
23 2
        $this->config->set('serialization_context', SerializationContext::create()->setGroups('read'));
24
25 2
        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...
26
    }
27
28 2
    public function create(Consumer $consumer): ResponseInterface
29
    {
30 2
        $this->config->set('serialization_context', SerializationContext::create()->setGroups('create'));
31
32 2
        return parent::requestPost($this->getUri(), $consumer, null);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::requestPo...Uri(), $consumer, null) 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...
33
    }
34
35 1
    public function update(Consumer $consumer): ResponseInterface
36
    {
37 1
        $this->validateObjectId($consumer);
38 1
        $this->config->set('serialization_context', SerializationContext::create()->setGroups('update'));
39
40 1
        return parent::requestPatch($this->appendToUri($consumer->getId()), $consumer, null);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::requestPa...Id()), $consumer, null) 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...
41
    }
42
43 1
    public function updateOrCreate(Consumer $consumer): ResponseInterface
44
    {
45 1
        $this->config->set('serialization_context', SerializationContext::create()->setGroups('update'));
46
47
        try {
48 1
            $this->validateObjectId($consumer);
49 1
            $uri = $this->appendToUri($consumer->getId());
50
        } catch (InvalidParameterException $e) {
51
            $uri = $this->getUri();
52
        }
53
54 1
        return parent::requestPut($uri, $consumer, null);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::requestPut($uri, $consumer, null) 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...
55
    }
56
57 5
    public function retrieve(string $usernameOrId): ResponseInterface
58
    {
59 5
        $this->config->set('serialization_context', SerializationContext::create()->setGroups('read'));
60
61 5
        return parent::requestGet($this->appendToUri($usernameOrId), null);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::requestGe...i($usernameOrId), null) 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...
62
    }
63
64 3
    public function delete(Consumer $consumer): ResponseInterface
65
    {
66 3
        $this->validateObjectId($consumer);
67 2
        $this->config->set('serialization_context', SerializationContext::create()->setGroups('delete'));
68
69 2
        return parent::requestDelete($this->appendToUri($consumer->getId()), null);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::requestDe...nsumer->getId()), null) 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...
70
    }
71
}
72