AnnotationRequiredArgumentsException::createFor()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
nc 3
nop 3
dl 0
loc 20
ccs 13
cts 13
cp 1
crap 3
rs 9.8333
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Annotated\Exception;
6
7
class AnnotationRequiredArgumentsException extends AnnotationException
8
{
9 24
    public static function createFor(\ReflectionProperty $property, string $annotationClass, \Throwable $e): static
10
    {
11 24
        $column = new \ReflectionClass($annotationClass);
12
13 24
        $requiredArguments = [];
14 24
        foreach ($column->getConstructor()->getParameters() as $parameter) {
15 24
            if (!$parameter->isOptional()) {
16 24
                $requiredArguments[] = $parameter->getName();
17
            }
18
        }
19
20 24
        return new static(
21 24
            sprintf(
22 24
                'Some of required arguments [`%s`] is missed on `%s.%s.`',
23 24
                implode('`, `', $requiredArguments),
24 24
                $property->getDeclaringClass()->getName(),
25 24
                $property->getName()
26
            ),
27 24
            $e->getCode(),
28
            $e
29
        );
30
    }
31
}
32