Organization   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 4
dl 0
loc 123
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getId() 0 4 1
A setId() 0 4 1
A getName() 0 4 1
A setName() 0 4 1
A getCode() 0 4 1
A setCode() 0 8 2
A getTenants() 0 4 1
A hasTenant() 0 4 1
A addTenant() 0 6 2
A removeTenant() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher MultiTenancy Component.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Component\MultiTenancy\Model;
16
17
use Doctrine\Common\Collections\ArrayCollection;
18
use Doctrine\Common\Collections\Collection;
19
use SWP\Component\Common\Model\EnableableTrait;
20
use SWP\Component\Common\Model\SoftDeletableTrait;
21
use SWP\Component\Common\Model\TimestampableTrait;
22
23
class Organization implements OrganizationInterface
24
{
25
    use SoftDeletableTrait;
26
    use TimestampableTrait;
27
    use EnableableTrait;
28
29
    /**
30
     * @var mixed
31
     */
32
    protected $id;
33
34
    /**
35
     * @var string
36
     */
37
    protected $name;
38
39
    /**
40
     * @var string
41
     */
42
    protected $code;
43
44
    /**
45
     * @var Collection|TenantInterface[]
46
     */
47
    protected $tenants;
48
49
    /**
50
     * Organization constructor.
51
     */
52
    public function __construct()
53
    {
54
        $this->createdAt = new \DateTime();
55
        $this->tenants = new ArrayCollection();
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getId()
62
    {
63
        return $this->id;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function setId($id)
70
    {
71
        $this->id = $id;
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function getName()
78
    {
79
        return $this->name;
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function setName($name)
86
    {
87
        $this->name = $name;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function getCode()
94
    {
95
        return $this->code;
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function setCode($code)
102
    {
103
        if (null !== $this->code) {
104
            throw new \LogicException('The code is already set. Can not change it.');
105
        }
106
107
        $this->code = $code;
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    public function getTenants()
114
    {
115
        return $this->tenants;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->tenants; of type Doctrine\Common\Collecti...Model\TenantInterface[] adds the type Doctrine\Common\Collections\Collection to the return on line 115 which is incompatible with the return type declared by the interface SWP\Component\MultiTenan...onInterface::getTenants of type SWP\Component\MultiTenancy\Model\TenantInterface[].
Loading history...
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121
    public function hasTenant(TenantInterface $tenant)
122
    {
123
        return $this->tenants->contains($tenant);
124
    }
125
126
    /**
127
     * {@inheritdoc}
128
     */
129
    public function addTenant(TenantInterface $tenant)
130
    {
131
        if (!$this->hasTenant($tenant)) {
132
            $this->tenants->add($tenant);
133
        }
134
    }
135
136
    /**
137
     * {@inheritdoc}
138
     */
139
    public function removeTenant(TenantInterface $tenant)
140
    {
141
        if ($this->hasTenant($tenant)) {
142
            $this->tenants->removeElement($tenant);
143
        }
144
    }
145
}
146