Completed
Push — 4.0 ( 14a1f2...cbd7ec )
by David
02:31
created

AbstractBeanPropertyDescriptor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 8
c 5
b 0
f 0
lcom 2
cbo 1
dl 0
loc 114
rs 10

15 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A useAlternativeName() 0 4 1
getClassName() 0 1 ?
getParamAnnotation() 0 1 ?
A getVariableName() 0 4 1
A getLowerCamelCaseName() 0 4 1
getUpperCamelCaseName() 0 1 ?
A getSetterName() 0 4 1
A getGetterName() 0 4 1
A getConstructorAssignCode() 0 6 1
isCompulsory() 0 1 ?
isPrimaryKey() 0 1 ?
A getTable() 0 4 1
getGetterSetterCode() 0 1 ?
getJsonSerializeCode() 0 1 ?
1
<?php
2
3
namespace Mouf\Database\TDBM\Utils;
4
5
use Doctrine\DBAL\Schema\Table;
6
7
/**
8
 * This class represent a property in a bean (a property has a getter, a setter, etc...).
9
 */
10
abstract class AbstractBeanPropertyDescriptor
11
{
12
    /**
13
     * @var Table
14
     */
15
    protected $table;
16
17
    /**
18
     * Whether to use the more complex name in case of conflict.
19
     *
20
     * @var bool
21
     */
22
    protected $alternativeName = false;
23
24
    /**
25
     * @param Table $table
26
     */
27
    public function __construct(Table $table)
28
    {
29
        $this->table = $table;
30
    }
31
32
    /**
33
     * Use the more complex name in case of conflict.
34
     */
35
    public function useAlternativeName()
36
    {
37
        $this->alternativeName = true;
38
    }
39
40
    /**
41
     * Returns the name of the class linked to this property or null if this is not a foreign key.
42
     *
43
     * @return null|string
44
     */
45
    abstract public function getClassName();
46
47
    /**
48
     * Returns the param annotation for this property (useful for constructor).
49
     *
50
     * @return string
51
     */
52
    abstract public function getParamAnnotation();
53
54
    public function getVariableName()
55
    {
56
        return '$'.$this->getLowerCamelCaseName();
57
    }
58
59
    public function getLowerCamelCaseName()
60
    {
61
        return TDBMDaoGenerator::toVariableName($this->getUpperCamelCaseName());
62
    }
63
64
    abstract public function getUpperCamelCaseName();
65
66
    public function getSetterName()
67
    {
68
        return 'set'.$this->getUpperCamelCaseName();
69
    }
70
71
    public function getGetterName()
72
    {
73
        return 'get'.$this->getUpperCamelCaseName();
74
    }
75
76
    /**
77
     * Returns the PHP code used in the ben constructor for this property.
78
     *
79
     * @return string
80
     */
81
    public function getConstructorAssignCode()
82
    {
83
        $str = '        $this->%s(%s);';
84
85
        return sprintf($str, $this->getSetterName(), $this->getVariableName());
86
    }
87
88
    /**
89
     * Returns true if the property is compulsory (and therefore should be fetched in the constructor).
90
     *
91
     * @return bool
92
     */
93
    abstract public function isCompulsory();
94
95
    /**
96
     * Returns true if the property is the primary key.
97
     *
98
     * @return bool
99
     */
100
    abstract public function isPrimaryKey();
101
102
    /**
103
     * @return Table
104
     */
105
    public function getTable()
106
    {
107
        return $this->table;
108
    }
109
110
    /**
111
     * Returns the PHP code for getters and setters.
112
     *
113
     * @return string
114
     */
115
    abstract public function getGetterSetterCode();
116
117
    /**
118
     * Returns the part of code useful when doing json serialization.
119
     *
120
     * @return string
121
     */
122
    abstract public function getJsonSerializeCode();
123
}
124