Completed
Push — master ( fef923...c0df34 )
by Rafael
03:03
created

CamelizeMatcher   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B match() 0 14 6
A camelize() 0 4 1
1
<?php
2
3
/**
4
 * LICENSE: This file is subject to the terms and conditions defined in
5
 * file 'LICENSE', which is part of this source code package.
6
 *
7
 * @copyright 2016 Copyright(c) - All rights reserved.
8
 */
9
10
namespace Rafrsr\LibArray2Object\Matcher;
11
12
class CamelizeMatcher implements PropertyMatcherInterface
13
{
14
    /**
15
     * @inheritDoc
16
     */
17
    public function match(\ReflectionProperty $property, $givenName)
18
    {
19
        $propertyName = $property->getName();
20
        if ($propertyName === $givenName
21
            || $propertyName === $this->camelize($givenName) //ErrorCode = error_code
22
            || $propertyName === lcfirst($this->camelize($givenName)) // errorCode => error_code
23
            || $propertyName === strtolower($this->camelize($givenName)) // errorcode => error_code
24
            || strtolower($propertyName) === $givenName // errorCode => errorcode
25
        ) {
26
            return true;
27
        }
28
29
        return false;
30
    }
31
32
    /**
33
     * @param $name
34
     *
35
     * @return string
36
     */
37
    private function camelize($name)
38
    {
39
        return strtr(ucwords(strtr($name, ['_' => ' '])), [' ' => '']);
40
    }
41
}