PatchMethod::patchMethod()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 3
nop 4
dl 0
loc 14
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Rest/Traits/Methods/PatchMethod.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Rest\Traits\Methods;
10
11
use App\DTO\RestDtoInterface;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
use Throwable;
15
16
/**
17
 * Trait PatchMethod
18
 *
19
 * @package App\Rest\Traits\Methods
20
 * @author TLe, Tarmo Leppänen <[email protected]>
21
 */
22
trait PatchMethod
23
{
24
    /**
25
     * Generic 'patchMethod' method for REST resources.
26
     *
27
     * @param array<int, string>|null $allowedHttpMethods
28
     *
29
     * @throws Throwable
30
     */
31 29
    public function patchMethod(
32
        Request $request,
33
        RestDtoInterface $restDto,
34
        string $id,
35
        ?array $allowedHttpMethods = null,
36
    ): Response {
37 29
        $resource = $this->getResourceForMethod($request, $allowedHttpMethods ?? [Request::METHOD_PATCH]);
0 ignored issues
show
Bug introduced by
It seems like getResourceForMethod() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

37
        /** @scrutinizer ignore-call */ 
38
        $resource = $this->getResourceForMethod($request, $allowedHttpMethods ?? [Request::METHOD_PATCH]);
Loading history...
38
39
        try {
40 20
            $data = $resource->patch($id, $restDto, true);
41
42 13
            return $this->getResponseHandler()->createResponse($request, $data, $resource);
0 ignored issues
show
Bug introduced by
It seems like getResponseHandler() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

42
            return $this->/** @scrutinizer ignore-call */ getResponseHandler()->createResponse($request, $data, $resource);
Loading history...
43 7
        } catch (Throwable $exception) {
44 7
            throw $this->handleRestMethodException($exception, $id);
0 ignored issues
show
Bug introduced by
It seems like handleRestMethodException() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

44
            throw $this->/** @scrutinizer ignore-call */ handleRestMethodException($exception, $id);
Loading history...
45
        }
46
    }
47
}
48