DeleteMethod   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 deleteMethod() 0 11 2
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Rest/Traits/Methods/DeleteMethod.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 DeleteMethod
17
 *
18
 * @package App\Rest\Traits\Methods
19
 * @author TLe, Tarmo Leppänen <[email protected]>
20
 */
21
trait DeleteMethod
22
{
23
    /**
24
     * Generic 'deleteMethod' method for REST resources.
25
     *
26
     * @param array<int, string>|null $allowedHttpMethods
27
     *
28
     * @throws Throwable
29
     */
30 31
    public function deleteMethod(Request $request, string $id, ?array $allowedHttpMethods = null): Response
31
    {
32 31
        $resource = $this->getResourceForMethod($request, $allowedHttpMethods ?? [Request::METHOD_DELETE]);
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_DELETE]);
Loading history...
33
34
        try {
35
            // Fetch data from database
36 22
            return $this
37 22
                ->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 22
                ->createResponse($request, $resource->delete($id), $resource);
39 7
        } catch (Throwable $exception) {
40 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

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