FindMethod::findMethod()   A
last analyzed

Complexity

Conditions 2
Paths 4

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 13
nc 4
nop 2
dl 0
loc 20
ccs 13
cts 13
cp 1
crap 2
rs 9.8333
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Rest/Traits/Methods/FindMethod.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Rest\Traits\Methods;
10
11
use App\Rest\RequestHandler;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
use Throwable;
15
16
/**
17
 * Trait FindMethod
18
 *
19
 * @package App\Rest\Traits\Methods
20
 * @author TLe, Tarmo Leppänen <[email protected]>
21
 */
22
trait FindMethod
23
{
24
    /**
25
     * Generic 'findMethod' method for REST resources.
26
     *
27
     * @param array<int, string>|null $allowedHttpMethods
28
     *
29
     * @throws Throwable
30
     */
31 50
    public function findMethod(Request $request, ?array $allowedHttpMethods = null): Response
32
    {
33 50
        $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

33
        /** @scrutinizer ignore-call */ 
34
        $resource = $this->getResourceForMethod($request, $allowedHttpMethods ?? [Request::METHOD_GET]);
Loading history...
34
35
        // Determine used parameters
36 41
        $orderBy = RequestHandler::getOrderBy($request);
37 41
        $limit = RequestHandler::getLimit($request);
38 41
        $offset = RequestHandler::getOffset($request);
39 41
        $search = RequestHandler::getSearchTerms($request);
40
41
        try {
42 41
            $criteria = RequestHandler::getCriteria($request);
43
44 40
            $this->processCriteria($criteria, $request, __METHOD__);
0 ignored issues
show
Bug introduced by
It seems like processCriteria() 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
            $this->/** @scrutinizer ignore-call */ 
45
                   processCriteria($criteria, $request, __METHOD__);
Loading history...
45
46 40
            return $this
47 40
                ->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

47
                ->/** @scrutinizer ignore-call */ getResponseHandler()
Loading history...
48 40
                ->createResponse($request, $resource->find($criteria, $orderBy, $limit, $offset, $search), $resource);
49 8
        } catch (Throwable $exception) {
50 8
            throw $this->handleRestMethodException($exception);
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

50
            throw $this->/** @scrutinizer ignore-call */ handleRestMethodException($exception);
Loading history...
51
        }
52
    }
53
}
54