Passed
Push — 3.x ( 885785...4e5cb3 )
by Aleksei
01:36
created

AnnotationRequiredArgumentsException::createFor()   A

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 12
    public static function createFor(\ReflectionProperty $property, string $annotationClass, \Throwable $e): static
10
    {
11 12
        $column = new \ReflectionClass($annotationClass);
12
13 12
        $requiredArguments = [];
14 12
        foreach ($column->getConstructor()->getParameters() as $parameter) {
15 12
            if (! $parameter->isOptional()) {
16 12
                $requiredArguments[] = $parameter->getName();
17
            }
18
        }
19
20 12
        return new static(
21 12
            sprintf(
22 12
                'Some of required arguments [`%s`] is missed on `%s.%s.`',
23 12
                implode('`, `', $requiredArguments),
24 12
                $property->getDeclaringClass()->getName(),
25 12
                $property->getName()
26
            ),
27 12
            $e->getCode(),
28
            $e
29
        );
30
    }
31
}
32