VichSerializableField   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 13
lcom 0
cbo 2
dl 0
loc 80
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 25 9
A getField() 0 4 1
A setField() 0 6 1
A isIncludeHost() 0 4 1
A setIncludeHost() 0 6 1
1
<?php
2
/*
3
 * This file is part of the FreshVichUploaderSerializationBundle
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\VichUploaderSerializationBundle\Annotation;
14
15
use Doctrine\Common\Annotations\Annotation;
16
use Fresh\VichUploaderSerializationBundle\Exception\InvalidArgumentException;
17
use Fresh\VichUploaderSerializationBundle\Exception\LogicException;
18
19
/**
20
 * VichSerializableField Annotation Class.
21
 *
22
 * @Annotation
23
 *
24
 * @Target({"PROPERTY", "METHOD"})
25
 *
26
 * @author Artem Henvald <[email protected]>
27
 */
28
final class VichSerializableField
29
{
30
    /** @var string */
31
    private $field;
32
33
    /** @var bool */
34
    private $includeHost = true;
35
36
    /**
37
     * @param mixed[] $options
38
     *
39
     * @throws LogicException
40
     * @throws InvalidArgumentException
41
     */
42
    public function __construct(array $options)
43
    {
44
        if (!isset($options['value']) && !isset($options['field'])) {
45
            throw new LogicException('Either "value" or "field" option must be set.');
46
        }
47
48
        if (isset($options['value'])) {
49
            if (!\is_string($options['value'])) {
50
                throw new InvalidArgumentException('Option "value" must be a string.');
51
            }
52
            $this->setField($options['value']);
53
        } elseif (isset($options['field'])) {
54
            if (!\is_string($options['field'])) {
55
                throw new InvalidArgumentException('Option "field" must be a string.');
56
            }
57
            $this->setField($options['field']);
58
        }
59
60
        if (isset($options['includeHost'])) {
61
            if (!\is_bool($options['includeHost'])) {
62
                throw new InvalidArgumentException('Option "includeHost" must be a boolean.');
63
            }
64
            $this->setIncludeHost($options['includeHost']);
65
        }
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function getField(): string
72
    {
73
        return $this->field;
74
    }
75
76
    /**
77
     * @param string $field
78
     *
79
     * @return $this
80
     */
81
    public function setField(string $field): self
82
    {
83
        $this->field = $field;
84
85
        return $this;
86
    }
87
88
    /**
89
     * @return bool
90
     */
91
    public function isIncludeHost(): bool
92
    {
93
        return $this->includeHost;
94
    }
95
96
    /**
97
     * @param bool $includeHost
98
     *
99
     * @return $this
100
     */
101
    public function setIncludeHost(bool $includeHost): self
102
    {
103
        $this->includeHost = $includeHost;
104
105
        return $this;
106
    }
107
}
108