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

NormalizeEvent   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
c 1
b 0
f 1
dl 0
loc 59
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setNormalizedData() 0 4 1
A hasNormalizedData() 0 3 1
A getNormalizedData() 0 3 1
1
<?php
2
3
namespace W2w\Lib\Apie\Events;
4
5
/**
6
 * Event mediator for normalizing a value from a hydrated resource to an array,
7
 */
8
class NormalizeEvent
9
{
10
    /**
11
     * @var object|iterable
12
     */
13
    private $resource;
14
15
    /**
16
     * @var string
17
     */
18
    private $acceptHeader;
19
20
    /**
21
     * This variable is added, because the normalized data could be null(DELETE for example) and still being normalized.
22
     *
23
     * @var bool
24
     */
25
    private $hasNormalizedData = false;
26
27
    /**
28
     * @var string|int|array|null|float
29
     */
30
    private $normalizedData;
31
32
    /**
33
     * @param object|iterable $resource
34
     * @param string $acceptHeader
35
     */
36
    public function __construct($resource, string $acceptHeader)
37
    {
38
        $this->resource = $resource;
39
        $this->acceptHeader = $acceptHeader;
40
    }
41
42
    /**
43
     * Returns true if the normalized data was filled in.
44
     *
45
     * @return bool
46
     */
47
    public function hasNormalizedData(): bool
48
    {
49
        return $this->hasNormalizedData;
50
    }
51
52
    /**
53
     * @return string|int|array|null|float
54
     */
55
    public function getNormalizedData()
56
    {
57
        return $this->normalizedData;
58
    }
59
60
    /**
61
     * @param mixed $normalizedData
62
     */
63
    public function setNormalizedData($normalizedData): void
64
    {
65
        $this->normalizedData = $normalizedData;
66
        $this->hasNormalizedData = true;
67
    }
68
}
69