Completed
Branch v4 (4e54dd)
by Pieter
03:26
created

createResponseForResource()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 5
nc 1
nop 2
dl 0
loc 7
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace W2w\Lib\Apie\Core;
4
5
use Psr\Http\Message\RequestInterface;
6
use W2w\Lib\Apie\Core\Models\ApiResourceFacadeResponse;
7
use W2w\Lib\Apie\Core\Models\ApiResourceListFacadeResponse;
8
use W2w\Lib\Apie\Core\SearchFilters\SearchFilterRequest;
9
use W2w\Lib\Apie\Interfaces\ResourceSerializerInterface;
10
use W2w\Lib\Apie\PluginInterfaces\ResourceLifeCycleInterface;
11
12
class ApiResourceFacadeResponseFactory
13
{
14
    /**
15
     * @var ResourceSerializerInterface
16
     */
17
    private $serializer;
18
19
    /**
20
     * @var ResourceLifeCycleInterface[]
21
     */
22
    private $resourceLifeCycles;
23
24
    public function __construct(
25
        ResourceSerializerInterface $serializer,
26
        iterable $resourceLifeCycles
27
    ) {
28
        $this->serializer = $serializer;
29
        $this->resourceLifeCycles = $resourceLifeCycles;
0 ignored issues
show
Documentation Bug introduced by
It seems like $resourceLifeCycles of type iterable is incompatible with the declared type W2w\Lib\Apie\PluginInter...rceLifeCycleInterface[] of property $resourceLifeCycles.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
30
    }
31
32
    public function createResponseForResource($resource, ?RequestInterface $request): ApiResourceFacadeResponse
33
    {
34
        return new ApiResourceFacadeResponse(
35
            $this->serializer,
36
            $resource,
37
            ($request && $request->hasHeader('Accept')) ? $request->getHeader('Accept')[0] : 'application/json',
38
            $this->resourceLifeCycles
39
        );
40
    }
41
42
    public function createResponseListForResource($resource, string $resourceClass, SearchFilterRequest $searchFilter, ?RequestInterface $request): ApiResourceListFacadeResponse
43
    {
44
        return new ApiResourceListFacadeResponse(
45
            $this->serializer,
46
            $resource,
47
            $resourceClass,
48
            $searchFilter,
49
            ($request && $request->hasHeader('Accept')) ? $request->getHeader('Accept')[0] : 'application/json',
50
            $this->resourceLifeCycles
51
        );
52
    }
53
}
54