1 | <?php |
||
2 | /** |
||
3 | * Base daft objects. |
||
4 | * |
||
5 | * @author SignpostMarv |
||
6 | */ |
||
7 | declare(strict_types=1); |
||
8 | |||
9 | namespace SignpostMarv\DaftObject\Exceptions; |
||
10 | |||
11 | use SignpostMarv\DaftObject\DaftJson; |
||
12 | use SignpostMarv\DaftObject\DaftObject; |
||
13 | use SignpostMarv\SprintfExceptionFactory\SprintfExceptionFactory; |
||
14 | use Throwable; |
||
15 | |||
16 | abstract class Factory extends SprintfExceptionFactory |
||
17 | { |
||
18 | const SPRINTF_PROPERTY_NOT_THINGABLE = 'Property not %s: %s::$%s'; |
||
19 | |||
20 | const SPRINTF_THING_DOES_NOT_IMPLEMENT_THING = '%s does not implement %s'; |
||
21 | |||
22 | /** |
||
23 | * @psalm-param class-string $class |
||
24 | * @psalm-param class-string $doesNotImplementClass |
||
25 | */ |
||
26 | 116 | public static function ClassDoesNotImplementClassException( |
|
27 | string $class, |
||
28 | string $doesNotImplementClass, |
||
29 | int $code = self::DEFAULT_INT_CODE, |
||
30 | Throwable $previous = null |
||
31 | ) : ClassDoesNotImplementClassException { |
||
32 | /** |
||
33 | * @var ClassDoesNotImplementClassException |
||
34 | */ |
||
35 | 116 | $out = static::Exception( |
|
36 | 116 | ClassDoesNotImplementClassException::class, |
|
37 | 58 | $code, |
|
38 | 58 | $previous, |
|
39 | 116 | ClassDoesNotImplementClassException::class, |
|
40 | 116 | self::SPRINTF_THING_DOES_NOT_IMPLEMENT_THING, |
|
41 | 58 | $class, |
|
42 | 58 | $doesNotImplementClass |
|
43 | ); |
||
44 | |||
45 | 116 | return $out; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @psalm-param class-string<DaftObject> $class |
||
50 | */ |
||
51 | 336 | public static function DaftObjectNotDaftJsonBadMethodCallException( |
|
52 | string $class, |
||
53 | int $code = self::DEFAULT_INT_CODE, |
||
54 | Throwable $previous = null |
||
55 | ) : DaftObjectNotDaftJsonBadMethodCallException { |
||
56 | /** |
||
57 | * @var DaftObjectNotDaftJsonBadMethodCallException |
||
58 | */ |
||
59 | 336 | $out = static::BadMethodCallException( |
|
60 | 336 | DaftObjectNotDaftJsonBadMethodCallException::class, |
|
61 | 168 | $code, |
|
62 | 168 | $previous, |
|
63 | 336 | self::SPRINTF_THING_DOES_NOT_IMPLEMENT_THING, |
|
64 | 168 | $class, |
|
65 | 336 | DaftJson::class |
|
66 | ); |
||
67 | |||
68 | 336 | return $out; |
|
0 ignored issues
–
show
|
|||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @psalm-param class-string $className |
||
73 | */ |
||
74 | 140 | public static function NotPublicGetterPropertyException( |
|
75 | string $className, |
||
76 | string $property, |
||
77 | int $code = self::DEFAULT_INT_CODE, |
||
78 | Throwable $previous = null |
||
79 | ) : NotPublicGetterPropertyException { |
||
80 | /** |
||
81 | * @var NotPublicGetterPropertyException |
||
82 | */ |
||
83 | 140 | $out = static::AbstractPropertyNotThingableException( |
|
84 | 140 | NotPublicGetterPropertyException::class, |
|
85 | 140 | 'a public getter', |
|
86 | 70 | $className, |
|
87 | 70 | $property, |
|
88 | 70 | $code, |
|
89 | 70 | $previous |
|
90 | ); |
||
91 | |||
92 | 140 | return $out; |
|
0 ignored issues
–
show
|
|||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @psalm-param class-string $className |
||
97 | */ |
||
98 | 4 | public static function NotPublicSetterPropertyException( |
|
99 | string $className, |
||
100 | string $property, |
||
101 | int $code = self::DEFAULT_INT_CODE, |
||
102 | Throwable $previous = null |
||
103 | ) : NotPublicSetterPropertyException { |
||
104 | /** |
||
105 | * @var NotPublicSetterPropertyException |
||
106 | */ |
||
107 | 4 | $out = static::AbstractPropertyNotThingableException( |
|
108 | 4 | NotPublicSetterPropertyException::class, |
|
109 | 4 | 'a public setter', |
|
110 | 2 | $className, |
|
111 | 2 | $property, |
|
112 | 2 | $code, |
|
113 | 2 | $previous |
|
114 | ); |
||
115 | |||
116 | 4 | return $out; |
|
0 ignored issues
–
show
|
|||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @psalm-param class-string $className |
||
121 | */ |
||
122 | 4 | public static function PropertyNotJsonDecodableException( |
|
123 | string $className, |
||
124 | string $property, |
||
125 | int $code = self::DEFAULT_INT_CODE, |
||
126 | Throwable $previous = null |
||
127 | ) : PropertyNotJsonDecodableException { |
||
128 | /** |
||
129 | * @var PropertyNotJsonDecodableException |
||
130 | */ |
||
131 | 4 | $out = static::AbstractPropertyNotThingableException( |
|
132 | 4 | PropertyNotJsonDecodableException::class, |
|
133 | 4 | 'json-decodable', |
|
134 | 2 | $className, |
|
135 | 2 | $property, |
|
136 | 2 | $code, |
|
137 | 2 | $previous |
|
138 | ); |
||
139 | |||
140 | 4 | return $out; |
|
0 ignored issues
–
show
|
|||
141 | } |
||
142 | |||
143 | /** |
||
144 | * @psalm-param class-string $className |
||
145 | */ |
||
146 | 12 | public static function PropertyNotJsonDecodableShouldBeArrayException( |
|
147 | string $className, |
||
148 | string $property, |
||
149 | int $code = self::DEFAULT_INT_CODE, |
||
150 | Throwable $previous = null |
||
151 | ) : PropertyNotJsonDecodableShouldBeArrayException { |
||
152 | /** |
||
153 | * @var PropertyNotJsonDecodableShouldBeArrayException |
||
154 | */ |
||
155 | 12 | $out = static::AbstractPropertyNotThingableException( |
|
156 | 12 | PropertyNotJsonDecodableShouldBeArrayException::class, |
|
157 | 12 | 'json-decodable (should be an array)', |
|
158 | 6 | $className, |
|
159 | 6 | $property, |
|
160 | 6 | $code, |
|
161 | 6 | $previous |
|
162 | ); |
||
163 | |||
164 | 12 | return $out; |
|
0 ignored issues
–
show
|
|||
165 | } |
||
166 | |||
167 | /** |
||
168 | * @psalm-param class-string $className |
||
169 | */ |
||
170 | 212 | public static function PropertyNotNullableException( |
|
171 | string $className, |
||
172 | string $property, |
||
173 | int $code = self::DEFAULT_INT_CODE, |
||
174 | Throwable $previous = null |
||
175 | ) : PropertyNotNullableException { |
||
176 | /** |
||
177 | * @var PropertyNotNullableException |
||
178 | */ |
||
179 | 212 | $out = static::AbstractPropertyNotThingableException( |
|
180 | 212 | PropertyNotNullableException::class, |
|
181 | 212 | 'nullable', |
|
182 | 106 | $className, |
|
183 | 106 | $property, |
|
184 | 106 | $code, |
|
185 | 106 | $previous |
|
186 | ); |
||
187 | |||
188 | 212 | return $out; |
|
0 ignored issues
–
show
|
|||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @psalm-param class-string $className |
||
193 | */ |
||
194 | 192 | public static function PropertyNotRewriteableException( |
|
195 | string $className, |
||
196 | string $property, |
||
197 | int $code = self::DEFAULT_INT_CODE, |
||
198 | Throwable $previous = null |
||
199 | ) : PropertyNotRewriteableException { |
||
200 | /** |
||
201 | * @var PropertyNotRewriteableException |
||
202 | */ |
||
203 | 192 | $out = static::AbstractPropertyNotThingableException( |
|
204 | 192 | PropertyNotRewriteableException::class, |
|
205 | 192 | 'rewriteable', |
|
206 | 96 | $className, |
|
207 | 96 | $property, |
|
208 | 96 | $code, |
|
209 | 96 | $previous |
|
210 | ); |
||
211 | |||
212 | 192 | return $out; |
|
0 ignored issues
–
show
|
|||
213 | } |
||
214 | |||
215 | /** |
||
216 | * @psalm-param class-string<DaftObject> $className |
||
217 | */ |
||
218 | 156 | public static function UndefinedPropertyException( |
|
219 | string $className, |
||
220 | string $property, |
||
221 | int $code = self::DEFAULT_INT_CODE, |
||
222 | Throwable $previous = null |
||
223 | ) : UndefinedPropertyException { |
||
224 | /** |
||
225 | * @var UndefinedPropertyException |
||
226 | */ |
||
227 | 156 | $out = static::AbstractPropertyNotThingableException( |
|
228 | 156 | UndefinedPropertyException::class, |
|
229 | 156 | 'defined', |
|
230 | 78 | $className, |
|
231 | 78 | $property, |
|
232 | 78 | $code, |
|
233 | 78 | $previous |
|
234 | ); |
||
235 | |||
236 | 156 | return $out; |
|
0 ignored issues
–
show
|
|||
237 | } |
||
238 | |||
239 | /** |
||
240 | * @psalm-param class-string<DaftObject> $className |
||
241 | */ |
||
242 | 20 | public static function PropertyValueNotOfExpectedTypeException( |
|
243 | string $class_name, |
||
244 | string $property, |
||
245 | string $expected_value, |
||
246 | int $code = self::DEFAULT_INT_CODE, |
||
247 | Throwable $previous = null |
||
248 | ) : PropertyValueNotOfExpectedTypeException { |
||
249 | /** |
||
250 | * @var PropertyValueNotOfExpectedTypeException |
||
251 | */ |
||
252 | 20 | $out = static::AbstractPropertyNotThingableException( |
|
253 | 20 | PropertyValueNotOfExpectedTypeException::class, |
|
254 | 20 | ('of expected type ' . $expected_value), |
|
255 | 10 | $class_name, |
|
256 | 10 | $property, |
|
257 | 10 | $code, |
|
258 | 10 | $previous |
|
259 | ); |
||
260 | |||
261 | 20 | return $out; |
|
0 ignored issues
–
show
|
|||
262 | } |
||
263 | |||
264 | /** |
||
265 | * @psalm-param class-string<AbstractPropertyNotThingableException> $type |
||
266 | */ |
||
267 | 740 | protected static function AbstractPropertyNotThingableException( |
|
268 | string $type, |
||
269 | string $thing, |
||
270 | string $className, |
||
271 | string $property, |
||
272 | int $code = self::DEFAULT_INT_CODE, |
||
273 | Throwable $previous = null |
||
274 | ) : AbstractPropertyNotThingableException { |
||
275 | /** |
||
276 | * @var AbstractPropertyNotThingableException |
||
277 | */ |
||
278 | 740 | $out = static::Exception( |
|
279 | 555 | $type, |
|
280 | 370 | $code, |
|
281 | 370 | $previous, |
|
282 | 740 | AbstractPropertyNotThingableException::class, |
|
283 | 740 | self::SPRINTF_PROPERTY_NOT_THINGABLE, |
|
284 | 370 | $thing, |
|
285 | 370 | $className, |
|
286 | 370 | $property |
|
287 | ); |
||
288 | |||
289 | 740 | return $out; |
|
0 ignored issues
–
show
|
|||
290 | } |
||
291 | } |
||
292 |