Failed Conditions
Push — type ( c389f1...fc7bda )
by Michael
02:26
created

AnnotationException   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 162
Duplicated Lines 0 %

Test Coverage

Coverage 85.37%

Importance

Changes 0
Metric Value
wmc 12
eloc 32
dl 0
loc 162
ccs 35
cts 41
cp 0.8537
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A semanticalError() 0 3 1
A typeError() 0 3 1
A syntaxError() 0 3 1
A semanticalErrorConstants() 0 6 2
A creationError() 0 3 1
A attributeTypeError() 0 8 1
A enumeratorError() 0 9 2
A optimizerPlusLoadComments() 0 4 1
A optimizerPlusSaveComments() 0 4 1
A requiredError() 0 8 1
1
<?php
2
3
namespace Doctrine\Annotations;
4
5
/**
6
 * Description of AnnotationException
7
 *
8
 * @since  2.0
9
 * @author Benjamin Eberlei <[email protected]>
10
 * @author Guilherme Blanco <[email protected]>
11
 * @author Jonathan Wage <[email protected]>
12
 * @author Roman Borschel <[email protected]>
13
 */
14
class AnnotationException extends \Exception
15
{
16
    /**
17
     * Creates a new AnnotationException describing a Syntax error.
18
     *
19
     * @param string $message Exception message
20
     *
21
     * @return AnnotationException
22
     */
23 11
    public static function syntaxError($message)
24
    {
25 11
        return new self('[Syntax Error] ' . $message);
26
    }
27
28
    /**
29
     * Creates a new AnnotationException describing a Semantical error.
30
     *
31
     * @param string $message Exception message
32
     *
33
     * @return AnnotationException
34
     */
35 10
    public static function semanticalError($message)
36
    {
37 10
        return new self('[Semantical Error] ' . $message);
38
    }
39
40
    /**
41
     * Creates a new AnnotationException describing an error which occurred during
42
     * the creation of the annotation.
43
     *
44
     * @since 2.2
45
     *
46
     * @param string $message
47
     *
48
     * @return AnnotationException
49
     */
50 3
    public static function creationError($message)
51
    {
52 3
        return new self('[Creation Error] ' . $message);
53
    }
54
55
    /**
56
     * Creates a new AnnotationException describing a type error.
57
     *
58
     * @since 1.1
59
     *
60
     * @param string $message
61
     *
62
     * @return AnnotationException
63
     */
64 110
    public static function typeError($message)
65
    {
66 110
        return new self('[Type Error] ' . $message);
67
    }
68
69
    /**
70
     * Creates a new AnnotationException describing a constant semantical error.
71
     *
72
     * @since 2.3
73
     *
74
     * @param string $identifier
75
     * @param string $context
76
     *
77
     * @return AnnotationException
78
     */
79 1
    public static function semanticalErrorConstants($identifier, $context = null)
80
    {
81 1
        return self::semanticalError(sprintf(
82 1
            "Couldn't find constant %s%s.",
83 1
            $identifier,
84 1
            $context ? ', ' . $context : ''
85
        ));
86
    }
87
88
    /**
89
     * Creates a new AnnotationException describing an type error of an attribute.
90
     *
91
     * @since 2.2
92
     *
93
     * @param string $attributeName
94
     * @param string $annotationName
95
     * @param string $context
96
     * @param string $expected
97
     *
98
     * @return AnnotationException
99
     */
100 108
    public static function attributeTypeError($attributeName, $annotationName, $context, $expected)
101
    {
102 108
        return self::typeError(sprintf(
103 108
            'Attribute "%s" of @%s declared on %s expects %s.',
104 108
            $attributeName,
105 108
            $annotationName,
106 108
            $context,
107 108
            $expected
108
        ));
109
    }
110
111
    /**
112
     * Creates a new AnnotationException describing an required error of an attribute.
113
     *
114
     * @since 2.2
115
     *
116
     * @param string $attributeName
117
     * @param string $annotationName
118
     * @param string $context
119
     * @param string $expected
120
     *
121
     * @return AnnotationException
122
     */
123 2
    public static function requiredError($attributeName, $annotationName, $context, $expected)
124
    {
125 2
        return self::typeError(sprintf(
126 2
            'Attribute "%s" of @%s declared on %s expects %s. This value should not be null.',
127 2
            $attributeName,
128 2
            $annotationName,
129 2
            $context,
130 2
            $expected
131
        ));
132
    }
133
134
    /**
135
     * Creates a new AnnotationException describing a invalid enummerator.
136
     *
137
     * @since 2.4
138
     *
139
     * @param string $attributeName
140
     * @param string $annotationName
141
     * @param string $context
142
     * @param array  $available
143
     * @param mixed  $given
144
     *
145
     * @return AnnotationException
146
     */
147 3
    public static function enumeratorError($attributeName, $annotationName, $context, $available, $given)
148
    {
149 3
        return new self(sprintf(
150 3
            '[Enum Error] Attribute "%s" of @%s declared on %s accept only [%s], but got %s.',
151 3
            $attributeName, 
152 3
            $annotationName,
153 3
            $context,
154 3
            implode(', ', $available),
155 3
            is_object($given) ? get_class($given) : $given
156
        ));
157
    }
158
159
    /**
160
     * @return AnnotationException
161
     */
162
    public static function optimizerPlusSaveComments()
163
    {
164
        return new self(
165
            "You have to enable opcache.save_comments=1 or zend_optimizerplus.save_comments=1."
166
        );
167
    }
168
169
    /**
170
     * @return AnnotationException
171
     */
172
    public static function optimizerPlusLoadComments()
173
    {
174
        return new self(
175
            "You have to enable opcache.load_comments=1 or zend_optimizerplus.load_comments=1."
176
        );
177
    }
178
}
179