StaticMethodDriver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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