StaticMethodDriver::getMetadataForClass()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5.0342

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 8
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 16
ccs 8
cts 9
cp 0.8889
crap 5.0342
rs 9.6111
1
<?php
2
3
namespace Bdf\Serializer\Metadata\Driver;
4
5
use Bdf\Serializer\Metadata\Builder\ClassMetadataBuilder;
6
use Bdf\Serializer\Metadata\ClassMetadata;
7
use ReflectionClass;
8
9
/**
10
 * StaticMethodDriver
11
 *
12
 * call a static method on the reflection class to set the class metadata
13
 *
14
 * @author  Seb
15
 */
16
class StaticMethodDriver implements DriverInterface
17
{
18
    /**
19
     * @var string
20
     */
21
    private $method;
22
23
    /**
24
     * Set the static method name for static method driver
25
     *
26
     * @param string $method
27
     */
28 180
    public function __construct(string $method = 'loadSerializerMetadata')
29
    {
30 180
        $this->method = $method;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 156
    public function getMetadataForClass(ReflectionClass $class): ?ClassMetadata
37
    {
38 156
        if ($class->isInterface() || !$class->hasMethod($this->method)) {
39 72
            return null;
40
        }
41
42 86
        $method = $class->getMethod($this->method);
43
44 86
        if ($method->isAbstract() || !$method->isStatic()) {
45
            return null;
46
        }
47
48 86
        $builder = new ClassMetadataBuilder($class);
49 86
        $method->invoke(null, $builder);
50
51 86
        return $builder->build();
52
    }
53
}
54