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 |
||
9 | class MigrationGenerator extends Generator |
||
10 | { |
||
11 | /** |
||
12 | * Get stub name. |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $stub = 'migration/plain'; |
||
17 | |||
18 | /** |
||
19 | * Get base path of destination file. |
||
20 | * |
||
21 | * @return string |
||
22 | */ |
||
23 | public function getBasePath() |
||
27 | |||
28 | /** |
||
29 | * Get destination path for generated file. |
||
30 | * |
||
31 | * @return string |
||
32 | */ |
||
33 | public function getPath() |
||
37 | |||
38 | /** |
||
39 | * Get generator path config node. |
||
40 | * |
||
41 | * @return string |
||
42 | */ |
||
43 | public function getPathConfigNode() |
||
47 | |||
48 | /** |
||
49 | * Get root namespace. |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | public function getRootNamespace() |
||
57 | |||
58 | /** |
||
59 | * Get migration name. |
||
60 | * |
||
61 | * @return string |
||
62 | */ |
||
63 | public function getMigrationName() |
||
67 | |||
68 | /** |
||
69 | * Get file name. |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | public function getFileName() |
||
77 | |||
78 | /** |
||
79 | * Get schema parser. |
||
80 | * |
||
81 | * @return SchemaParser |
||
82 | */ |
||
83 | public function getSchemaParser() |
||
87 | |||
88 | /** |
||
89 | * Get name parser. |
||
90 | * |
||
91 | * @return NameParser |
||
92 | */ |
||
93 | public function getNameParser() |
||
97 | |||
98 | /** |
||
99 | * Get stub templates. |
||
100 | * |
||
101 | * @return Stub |
||
102 | */ |
||
103 | public function getStub() |
||
154 | } |
||
155 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.