Passed
Pull Request — master (#32)
by
unknown
18:56
created

PutProductUnit::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 2
c 1
b 1
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Starweb\Api\Generated\Endpoint;
4
5
class PutProductUnit extends \Jane\OpenApiRuntime\Client\BaseEndpoint implements \Jane\OpenApiRuntime\Client\Psr7Endpoint
6
{
7
    protected $unitId;
8
    /**
9
     * Updates the `ProductUnit` object.
10
     *
11
     * @param int $unitId The units id
12
     * @param \Starweb\Api\Generated\Model\ProductUnitModelUpdatable $requestBody 
13
     */
14
    public function __construct(int $unitId, \Starweb\Api\Generated\Model\ProductUnitModelUpdatable $requestBody)
15
    {
16
        $this->unitId = $unitId;
17
        $this->body = $requestBody;
18
    }
19
    use \Jane\OpenApiRuntime\Client\Psr7EndpointTrait;
20
    public function getMethod() : string
21
    {
22
        return 'PUT';
23
    }
24
    public function getUri() : string
25
    {
26
        return str_replace(array('{unitId}'), array($this->unitId), '/product-units/{unitId}');
27
    }
28
    public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null) : array
29
    {
30
        if ($this->body instanceof \Starweb\Api\Generated\Model\ProductUnitModelUpdatable) {
31
            return array(array('Content-Type' => array('application/json')), $serializer->serialize($this->body, 'json'));
32
        }
33
        return array(array(), null);
34
    }
35
    public function getExtraHeaders() : array
36
    {
37
        return array('Accept' => array('application/json'));
38
    }
39
    /**
40
     * {@inheritdoc}
41
     *
42
     * @throws \Starweb\Api\Generated\Exception\PutProductUnitNotFoundException
43
     *
44
     * @return null|\Starweb\Api\Generated\Model\ProductUnitModelItem
45
     */
46
    protected function transformResponseBody(string $body, int $status, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null)
47
    {
48
        if (200 === $status && mb_strpos($contentType, 'application/json') !== false) {
0 ignored issues
show
Bug introduced by
It seems like $contentType can also be of type null; however, parameter $haystack of mb_strpos() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

48
        if (200 === $status && mb_strpos(/** @scrutinizer ignore-type */ $contentType, 'application/json') !== false) {
Loading history...
49
            return $serializer->deserialize($body, 'Starweb\\Api\\Generated\\Model\\ProductUnitModelItem', 'json');
50
        }
51
        if (404 === $status && mb_strpos($contentType, 'application/json') !== false) {
52
            throw new \Starweb\Api\Generated\Exception\PutProductUnitNotFoundException($serializer->deserialize($body, 'Starweb\\Api\\Generated\\Model\\ErrorModel', 'json'));
0 ignored issues
show
Bug introduced by
It seems like $serializer->deserialize...el\ErrorModel', 'json') can also be of type array; however, parameter $errorModel of Starweb\Api\Generated\Ex...xception::__construct() does only seem to accept Starweb\Api\Generated\Model\ErrorModel, maybe add an additional type check? ( Ignorable by Annotation )

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

52
            throw new \Starweb\Api\Generated\Exception\PutProductUnitNotFoundException(/** @scrutinizer ignore-type */ $serializer->deserialize($body, 'Starweb\\Api\\Generated\\Model\\ErrorModel', 'json'));
Loading history...
53
        }
54
    }
55
}