Enum   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 3
A getRequiredOptions() 0 4 1
1
<?php
2
/*
3
 * This file is part of the FreshDoctrineEnumBundle.
4
 *
5
 * (c) Artem Henvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Fresh\DoctrineEnumBundle\Validator\Constraints;
14
15
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
16
use Symfony\Component\Validator\Constraints\Choice;
17
18
/**
19
 * ENUM Constraint.
20
 *
21
 * @author Artem Henvald <[email protected]>
22
 *
23
 * @Annotation
24
 */
25
class Enum extends Choice
26
{
27
    /** @var string|AbstractEnumType */
28
    public $entity;
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function __construct($options = null)
34
    {
35
        $this->strict = true;
36
37
        if (isset($options['entity'])) {
38
            /** @var AbstractEnumType $entity */
39
            $entity = $options['entity'];
40
41
            if (\is_subclass_of($entity, AbstractEnumType::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Fresh\DoctrineEnumBundl...AbstractEnumType::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
42
                $this->choices = $entity::getValues();
43
            }
44
        }
45
46
        parent::__construct($options);
47
    }
48
49
    /**
50
     * @return string[]
51
     */
52
    public function getRequiredOptions(): array
53
    {
54
        return ['entity'];
55
    }
56
}
57