NotificationType   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 42
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setType() 0 5 1
A checkTypeIsValid() 0 6 2
A availableTypes() 0 9 1
A type() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\Notifier\Domain\Model\Inbox\Notification;
16
17
class NotificationType
18
{
19
    private $type;
20
21
    public function __construct(string $type)
22
    {
23
        $this->setType($type);
24
    }
25
26
    private function setType(string $type) : void
27
    {
28
        $this->checkTypeIsValid($type);
29
        $this->type = $type;
30
    }
31
32
    private function checkTypeIsValid(string $type) : void
33
    {
34
        if (!in_array($type, $this->availableTypes(), true)) {
35
            throw new NotificationTypeIsNotValid($type);
36
        }
37
    }
38
39
    private function availableTypes() : array
40
    {
41
        return [
42
            'project_created',
43
            'project_edited',
44
            'task_created',
45
            'task_edited',
46
        ];
47
    }
48
49
    public function type() : string
50
    {
51
        return $this->type;
52
    }
53
54
    public function __toString() : string
55
    {
56
        return (string) $this->type();
57
    }
58
}
59