FindOneMethod   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 20
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A findOneMethod() 0 11 2
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Rest/Traits/Methods/FindOneMethod.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Rest\Traits\Methods;
10
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpFoundation\Response;
13
use Throwable;
14
15
/**
16
 * Trait FindOneMethod
17
 *
18
 * @package App\Rest\Traits\Methods
19
 * @author TLe, Tarmo Leppänen <[email protected]>
20
 */
21
trait FindOneMethod
22
{
23
    /**
24
     * Generic 'findOneMethod' method for REST resources.
25
     *
26
     * @param array<int, string>|null $allowedHttpMethods
27
     *
28
     * @throws Throwable
29
     */
30 36
    public function findOneMethod(Request $request, string $id, ?array $allowedHttpMethods = null): Response
31
    {
32 36
        $resource = $this->getResourceForMethod($request, $allowedHttpMethods ?? [Request::METHOD_GET]);
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

32
        /** @scrutinizer ignore-call */ 
33
        $resource = $this->getResourceForMethod($request, $allowedHttpMethods ?? [Request::METHOD_GET]);
Loading history...
33
34
        try {
35
            // Fetch data from database
36 27
            return $this
37 27
                ->getResponseHandler()
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

37
                ->/** @scrutinizer ignore-call */ getResponseHandler()
Loading history...
38 27
                ->createResponse($request, $resource->findOne($id, true), $resource);
39 12
        } catch (Throwable $exception) {
40 12
            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

40
            throw $this->/** @scrutinizer ignore-call */ handleRestMethodException($exception, $id);
Loading history...
41
        }
42
    }
43
}
44