Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
39 | class Advice |
||
40 | { |
||
41 | |||
42 | /** |
||
43 | * Name of the aspect the advice is defined in |
||
44 | * |
||
45 | * @var string $aspectName |
||
46 | */ |
||
47 | protected $aspectName; |
||
48 | |||
49 | /** |
||
50 | * The code hook this advice is designed for |
||
51 | * |
||
52 | * @var string $codeHook |
||
53 | * |
||
54 | * @Enum({"After", "AfterReturning", "AfterThrowing", "Around", "Before"}) |
||
55 | */ |
||
56 | protected $codeHook; |
||
57 | |||
58 | /** |
||
59 | * Name of the advice itself |
||
60 | * |
||
61 | * @var string $name |
||
62 | */ |
||
63 | protected $name; |
||
64 | |||
65 | /** |
||
66 | * List of pointcuts referenced by this advice |
||
67 | * |
||
68 | * @var \AppserverIo\Doppelgaenger\Entities\Lists\TypedList $pointcuts |
||
69 | */ |
||
70 | protected $pointcuts; |
||
71 | |||
72 | /** |
||
73 | * Default constructor |
||
74 | */ |
||
75 | public function __construct() |
||
79 | |||
80 | /** |
||
81 | * Getter for the $aspectName property |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | public function getAspectName() |
||
89 | |||
90 | /** |
||
91 | * Getter for the $codeHook property |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | public function getCodeHook() |
||
99 | |||
100 | /** |
||
101 | * Getter for the $name property |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getName() |
||
109 | |||
110 | /** |
||
111 | * Getter for the $pointcuts property |
||
112 | * |
||
113 | * @return \AppserverIo\Doppelgaenger\Entities\Lists\TypedList |
||
114 | */ |
||
115 | public function getPointcuts() |
||
119 | |||
120 | /** |
||
121 | * Will return the qualified name of an advice. |
||
122 | * Will have the form or <CONTAINING ASPECT>-><ADVICE NAME> |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | View Code Duplication | public function getQualifiedName() |
|
135 | |||
136 | /** |
||
137 | * Setter for the $aspectName property |
||
138 | * |
||
139 | * @param string $aspectName Name of the aspect the advice is defined in |
||
140 | * |
||
141 | * @return null |
||
142 | */ |
||
143 | public function setAspectName($aspectName) |
||
147 | |||
148 | /** |
||
149 | * Setter for the $codeHook property |
||
150 | * |
||
151 | * @param string $codeHook The code hook this advice is designed for |
||
152 | * |
||
153 | * @return null |
||
154 | */ |
||
155 | public function setCodeHook($codeHook) |
||
159 | |||
160 | /** |
||
161 | * Setter for the $name property |
||
162 | * |
||
163 | * @param string $name Name of the advice itself |
||
164 | * |
||
165 | * @return null |
||
166 | */ |
||
167 | public function setName($name) |
||
171 | } |
||
172 |