OrganizerCreated::getAddresses()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @file
5
 * Contains \namespace CultuurNet\UDB3\Organizer\Events\OrganizerCreated.
6
 */
7
8
namespace CultuurNet\UDB3\Organizer\Events;
9
10
use CultuurNet\UDB3\Address\Address;
11
use CultuurNet\UDB3\Title;
12
13
final class OrganizerCreated extends OrganizerEvent
14
{
15
    /**
16
     * @var Title
17
     */
18
    public $title;
19
20
    /**
21
     * @var Address[]
22
     */
23
    public $addresses;
24
25
    /**
26
     * @var string[]
27
     */
28
    public $phones;
29
30
    /**
31
     * @var string[]
32
     */
33
    public $emails;
34
35
    /**
36
     * @var string[]
37
     */
38
    public $urls;
39
40
    /**
41
     * @param string $id
42
     * @param Title $title
43
     * @param Address[] $addresses
44
     * @param string[] $phones
45
     * @param string[] $emails
46
     * @param string[] $urls
47
     */
48
    public function __construct(string $id, Title $title, array $addresses, array $phones, array $emails, array $urls)
49
    {
50
        parent::__construct($id);
51
52
        $this->guardAddressTypes(...$addresses);
0 ignored issues
show
Unused Code introduced by
The call to the method CultuurNet\UDB3\Organize...ed::guardAddressTypes() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
53
54
        $this->title = $title;
55
        $this->addresses = $addresses;
56
        $this->phones = $phones;
57
        $this->emails = $emails;
58
        $this->urls = $urls;
59
    }
60
61
    private function guardAddressTypes(Address ...$addresses): void
0 ignored issues
show
Unused Code introduced by
The parameter $addresses is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
    {
63
    }
64
65
    public function getTitle(): Title
66
    {
67
        return $this->title;
68
    }
69
70
    /**
71
     * @return Address[]
72
     */
73
    public function getAddresses(): array
74
    {
75
        return $this->addresses;
76
    }
77
78
    /**
79
     * @return string[]
80
     */
81
    public function getPhones(): array
82
    {
83
        return $this->phones;
84
    }
85
86
    /**
87
     * @return string[]
88
     */
89
    public function getEmails(): array
90
    {
91
        return $this->emails;
92
    }
93
94
    /**
95
     * @return string[]
96
     */
97
    public function getUrls(): array
98
    {
99
        return $this->urls;
100
    }
101
102
    public function serialize(): array
103
    {
104
        $addresses = array();
105
        foreach ($this->getAddresses() as $address) {
106
            $addresses[] = $address->serialize();
107
        }
108
109
        return parent::serialize() + array(
110
          'title' => (string) $this->getTitle(),
111
          'addresses' => $addresses,
112
          'phones' => $this->getPhones(),
113
          'emails' => $this->getEmails(),
114
          'urls' => $this->getUrls(),
115
        );
116
    }
117
118
    public static function deserialize(array $data): OrganizerCreated
119
    {
120
        $addresses = array();
121
        foreach ($data['addresses'] as $address) {
122
            $addresses[] = Address::deserialize($address);
123
        }
124
125
        return new static(
126
            $data['organizer_id'], new Title($data['title']), $addresses, $data['phones'], $data['emails'], $data['urls']
127
        );
128
    }
129
}
130