Completed
Pull Request — master (#478)
by Théo
03:07
created

Reflection::getProperty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ApiPlatform\Core\Metadata\Reflection;
13
14
/**
15
 * @author Kévin Dunglas <[email protected]>
16
 * @author Théo FIDRY <[email protected]>
17
 */
18
final class Reflection implements ReflectionInterface
19
{
20
    const ACCESSOR_PREFIXES = ['get', 'is', 'has', 'can'];
21
    const MUTATOR_PREFIXES = ['set', 'add', 'remove'];
22
23
    private static $prefixes;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function getAccessorPrefixes()
29
    {
30
        return self::ACCESSOR_PREFIXES;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getMutatorPrefixes()
37
    {
38
        return self::MUTATOR_PREFIXES;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getPrefixes()
45
    {
46
        if (null === self::$prefixes) {
47
            static::$prefixes = array_merge(self::ACCESSOR_PREFIXES, self::MUTATOR_PREFIXES);
0 ignored issues
show
Comprehensibility introduced by
Since ApiPlatform\Core\Metadata\Reflection\Reflection is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
48
        }
49
50
        return self::$prefixes;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getProperty($methodName)
57
    {
58
        $pattern = implode('|', self::getPrefixes());
59
60
        if (preg_match('/^('.$pattern.')(.+)$/i', $methodName, $matches)) {
61
            return $matches[2];
62
        }
63
    }
64
}
65