Passed
Pull Request — master (#63)
by Saiful
01:59
created

SubscribeDoctrineEvents   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 19
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 25 9
1
<?php
2
3
/*
4
 * This file is part of the XiideaEasyAuditBundle package.
5
 *
6
 * (c) Xiidea <http://www.xiidea.net>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Xiidea\EasyAuditBundle\Attribute;
13
14
/**
15
 * Attribute for ORM Subscribed Event.
16
 *
17
 * @author Roni Saha <[email protected]>
18
 */
19
#[\Attribute(\Attribute::TARGET_CLASS)]
20
/* @final */
21
class SubscribeDoctrineEvents
22
{
23
    public array $events = [];
24
25
    public function __construct(array|string $values)
26
    {
27
        $validValues = [
28
            'created',
29
            'updated',
30
        ];
31
        $valueValueStr = [
32
            'created,updated',
33
            'created, updated',
34
            'updated,created',
35
            'updated, created',
36
        ];
37
        if (!empty($values) && is_string($values) && !in_array($values, $valueValueStr)) {
0 ignored issues
show
introduced by
The condition is_string($values) is always false.
Loading history...
38
            return;
39
        }
40
        if (!empty($values) && is_array($values)) {
41
            foreach ($values as $value) {
42
                if (!in_array($value, $validValues)) {
43
                    return;
44
                }
45
            }
46
        }
47
        $this->events = is_array($values) ? $values : array_map('trim', explode(',', $values));
48
49
        $this->events = array_filter($this->events);
50
    }
51
}
52