Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
58.33% covered (warning)
58.33%
7 / 12
CRAP
82.76% covered (warning)
82.76%
24 / 29
PropertyWriteInfo
0.00% covered (danger)
0.00%
0 / 1
58.33% covered (warning)
58.33%
7 / 12
18.48
82.76% covered (warning)
82.76%
24 / 29
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
5 / 5
 getType
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getName
0.00% covered (danger)
0.00%
0 / 1
2.15
66.67% covered (warning)
66.67%
2 / 3
 setAdderInfo
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getAdderInfo
0.00% covered (danger)
0.00%
0 / 1
2.15
66.67% covered (warning)
66.67%
2 / 3
 setRemoverInfo
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getRemoverInfo
0.00% covered (danger)
0.00%
0 / 1
2.15
66.67% covered (warning)
66.67%
2 / 3
 getVisibility
0.00% covered (danger)
0.00%
0 / 1
2.15
66.67% covered (warning)
66.67%
2 / 3
 isStatic
0.00% covered (danger)
0.00%
0 / 1
2.15
66.67% covered (warning)
66.67%
2 / 3
 setErrors
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getErrors
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 hasErrors
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\PropertyInfo;
13
14/**
15 * The write mutator defines how a property can be written.
16 *
17 * @author Joel Wurtz <jwurtz@jolicode.com>
18 *
19 * @internal
20 */
21final class PropertyWriteInfo
22{
23    public const TYPE_NONE = 'none';
24    public const TYPE_METHOD = 'method';
25    public const TYPE_PROPERTY = 'property';
26    public const TYPE_ADDER_AND_REMOVER = 'adder_and_remover';
27    public const TYPE_CONSTRUCTOR = 'constructor';
28
29    public const VISIBILITY_PUBLIC = 'public';
30    public const VISIBILITY_PROTECTED = 'protected';
31    public const VISIBILITY_PRIVATE = 'private';
32
33    private $type;
34    private $name;
35    private $visibility;
36    private $static;
37    private $adderInfo;
38    private $removerInfo;
39    private $errors = [];
40
41    public function __construct(string $type = self::TYPE_NONE, string $name = null, string $visibility = null, bool $static = null)
42    {
43        $this->type = $type;
44        $this->name = $name;
45        $this->visibility = $visibility;
46        $this->static = $static;
47    }
48
49    public function getType(): string
50    {
51        return $this->type;
52    }
53
54    public function getName(): string
55    {
56        if (null === $this->name) {
57            throw new \LogicException("Calling getName() when having a mutator of type {$this->type} is not tolerated.");
58        }
59
60        return $this->name;
61    }
62
63    public function setAdderInfo(self $adderInfo): void
64    {
65        $this->adderInfo = $adderInfo;
66    }
67
68    public function getAdderInfo(): self
69    {
70        if (null === $this->adderInfo) {
71            throw new \LogicException("Calling getAdderInfo() when having a mutator of type {$this->type} is not tolerated.");
72        }
73
74        return $this->adderInfo;
75    }
76
77    public function setRemoverInfo(self $removerInfo): void
78    {
79        $this->removerInfo = $removerInfo;
80    }
81
82    public function getRemoverInfo(): self
83    {
84        if (null === $this->removerInfo) {
85            throw new \LogicException("Calling getRemoverInfo() when having a mutator of type {$this->type} is not tolerated.");
86        }
87
88        return $this->removerInfo;
89    }
90
91    public function getVisibility(): string
92    {
93        if (null === $this->visibility) {
94            throw new \LogicException("Calling getVisibility() when having a mutator of type {$this->type} is not tolerated.");
95        }
96
97        return $this->visibility;
98    }
99
100    public function isStatic(): bool
101    {
102        if (null === $this->static) {
103            throw new \LogicException("Calling isStatic() when having a mutator of type {$this->type} is not tolerated.");
104        }
105
106        return $this->static;
107    }
108
109    public function setErrors(array $errors): void
110    {
111        $this->errors = $errors;
112    }
113
114    public function getErrors(): array
115    {
116        return $this->errors;
117    }
118
119    public function hasErrors(): bool
120    {
121        return (bool) \count($this->errors);
122    }
123}