CamelizeMatcher   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 14 6
A camelize() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the rafrsr/lib-array2object package.
5
 *
6
 * (c) Rafael SR <https://github.com/rafrsr>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Rafrsr\LibArray2Object\Matcher;
12
13
class CamelizeMatcher implements PropertyMatcherInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function match(\ReflectionProperty $property, $givenName)
19
    {
20
        $propertyName = $property->getName();
21
        if ($propertyName === $givenName
22
            || $propertyName === $this->camelize($givenName) //ErrorCode = error_code
23
            || $propertyName === lcfirst($this->camelize($givenName)) // errorCode => error_code
24
            || $propertyName === strtolower($this->camelize($givenName)) // errorcode => error_code
25
            || strtolower($propertyName) === strtolower($givenName) // errorCode => ErroRCODe
26
        ) {
27
            return true;
28
        }
29
30
        return false;
31
    }
32
33
    /**
34
     * @param $name
35
     *
36
     * @return string
37
     */
38
    private function camelize($name)
39
    {
40
        return strtr(ucwords(strtr($name, ['_' => ' '])), [' ' => '']);
41
    }
42
}
43