Completed
Pull Request — 3.4 (#46)
by David
22:22 queued 03:02
created

useAlternativeName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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