Passed
Branch 3.3 (35580f)
by Pieter
15:26
created

RetrieveSingleResourceEvent::getResourceClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace W2w\Lib\Apie\Events;
4
5
use Psr\Http\Message\RequestInterface;
6
use W2w\Lib\Apie\Exceptions\InvalidReturnTypeOfApiResourceException;
7
8
/**
9
 * Event mediator for retrieving a specific resource with identifier.
10
 */
11
class RetrieveSingleResourceEvent
12
{
13
    /**
14
     * @var string
15
     */
16
    private $resourceClass;
17
18
    /**
19
     * @var string
20
     */
21
    private $id;
22
23
    /**
24
     * @var object|null
25
     */
26
    private $resource;
27
28
    /**
29
     * @var RequestInterface|null
30
     */
31
    private $request;
32
33
    /**
34
     * @param string $resourceClass
35
     * @param string $id
36
     * @param RequestInterface|null $request
37
     */
38
    public function __construct(string $resourceClass, string $id, ?RequestInterface $request)
39
    {
40
        $this->resourceClass = $resourceClass;
41
        $this->id = $id;
42
        $this->request = $request;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getResourceClass(): string
49
    {
50
        return $this->resourceClass;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getId(): string
57
    {
58
        return $this->id;
59
    }
60
61
    /**
62
     * @param object $resource
63
     */
64
    public function setResource(object $resource)
65
    {
66
        if (!$resource instanceof $this->resourceClass) {
67
            throw new InvalidReturnTypeOfApiResourceException(null, get_class($resource), $this->resourceClass);
68
        }
69
        $this->resource = $resource;
70
    }
71
72
    /**
73
     * @return object|null
74
     */
75
    public function getResource(): ?object
76
    {
77
        return $this->resource;
78
    }
79
80
    /**
81
     * @return RequestInterface|null
82
     */
83
    public function getRequest(): ?RequestInterface
84
    {
85
        return $this->request;
86
    }
87
}
88