Passed
Pull Request — master (#2)
by David
03:49
created

AbstractNamingStrategy::getSetterName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
4
namespace TheCodingMachine\TDBM\Utils;
5
6
use Doctrine\DBAL\Schema\Index;
7
8
/**
9
 * An abstract class offering a common implementation for most names of the NamingStrategyInterface.
10
 * It assumes getters and setters will start with get... and set..., and so on.
11
 */
12
abstract class AbstractNamingStrategy implements NamingStrategyInterface
13
{
14
    protected abstract function getUpperCamelCaseName(AbstractBeanPropertyDescriptor $property): string;
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
15
16
    protected function getLowerCamelCaseName(AbstractBeanPropertyDescriptor $property): string
17
    {
18
        return lcfirst($this->getUpperCamelCaseName($property));
19
    }
20
21
    /**
22
     * Returns the getter name generated for the property passed in parameter.
23
     *
24
     * @param AbstractBeanPropertyDescriptor $property
25
     * @return string
26
     */
27
    public function getGetterName(AbstractBeanPropertyDescriptor $property): string
28
    {
29
        return 'get'.$this->getUpperCamelCaseName($property);
30
    }
31
32
    /**
33
     * Returns the setter name generated for the property passed in parameter.
34
     *
35
     * @param AbstractBeanPropertyDescriptor $property
36
     * @return string
37
     */
38
    public function getSetterName(AbstractBeanPropertyDescriptor $property): string
39
    {
40
        return 'set'.$this->getUpperCamelCaseName($property);
41
    }
42
43
    /**
44
     * Returns the variable name used in the setter generated for the property passed in parameter.
45
     *
46
     * @param AbstractBeanPropertyDescriptor $property
47
     * @return string
48
     */
49
    public function getVariableName(AbstractBeanPropertyDescriptor $property): string
50
    {
51
        return '$'.$this->getLowerCamelCaseName($property);
52
    }
53
54
    /**
55
     * Returns the label of the JSON property for the property passed in parameter.
56
     *
57
     * @param AbstractBeanPropertyDescriptor $property
58
     * @return string
59
     */
60
    public function getJsonProperty(AbstractBeanPropertyDescriptor $property): string
61
    {
62
        return $this->getLowerCamelCaseName($property);
63
    }
64
65
    /**
66
     * Returns the name of the find method attached to an index.
67
     *
68
     * @param AbstractBeanPropertyDescriptor[] $elements The list of properties in the index.
69
     * @return string
70
     */
71
    public function getFindByIndexMethodName(Index $index, array $elements): string
72
    {
73
        $methodNameComponent = array_map([$this, 'getUpperCamelCaseName'], $elements);
74
75
        if ($index->isUnique()) {
76
            return 'findOneBy'.implode('And', $methodNameComponent);
77
        } else {
78
            return 'findBy' . implode('And', $methodNameComponent);
79
        }
80
    }
81
}
82