Passed
Push — master ( 8e43c9...4981d1 )
by Tarmo
116:46 queued 51:34
created

PatchMethod   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 23
ccs 6
cts 6
cp 1
rs 10
wmc 2
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 12
    public function patchMethod(
32
        Request $request,
33
        RestDtoInterface $restDto,
34
        string $id,
35
        ?array $allowedHttpMethods = null,
36
    ): Response {
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected ')', expecting T_VARIABLE on line 36 at column 4
Loading history...
37 12
        $resource = $this->getResourceForMethod($request, $allowedHttpMethods ?? ['PATCH']);
38
39
        try {
40 3
            $data = $resource->patch($id, $restDto, true);
41
42 2
            return $this->getResponseHandler()->createResponse($request, $data, $resource);
43 1
        } catch (Throwable $exception) {
44 1
            throw $this->handleRestMethodException($exception, $id);
45
        }
46
    }
47
}
48