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 |
||
| 15 | class ServersPresenter extends BasePresenter |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Server instance holder. |
||
| 19 | * |
||
| 20 | * @var \WebCMS\DeployModule\Entity\Server |
||
| 21 | */ |
||
| 22 | private $server; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Server entity repository. |
||
| 26 | * |
||
| 27 | * @var Doctrine\ORM\EntityRepository |
||
| 28 | */ |
||
| 29 | private $repository; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * {@inheritdoc} |
||
| 33 | */ |
||
| 34 | 6 | protected function startup() |
|
| 40 | |||
| 41 | /** |
||
| 42 | * {@inheritdoc} |
||
| 43 | */ |
||
| 44 | 3 | protected function beforeRender() |
|
| 48 | |||
| 49 | /** |
||
| 50 | * Renders default template with datagrid. |
||
| 51 | * |
||
| 52 | * @param int $idPage Id of the page. |
||
| 53 | * |
||
| 54 | * @return void |
||
| 55 | */ |
||
| 56 | 1 | public function renderDefault($idPage) |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Creates datagrid with servers. |
||
| 64 | * |
||
| 65 | * @param string $name Name of the datagrid. |
||
| 66 | * |
||
| 67 | * @return \Grido\Grid Datagrid object. |
||
| 68 | */ |
||
| 69 | 1 | protected function createComponentServersGrid($name) |
|
| 82 | |||
| 83 | /** |
||
| 84 | * Display server form action. |
||
| 85 | * |
||
| 86 | * @param int $id Application's id. |
||
| 87 | * @param int $idPage Id of the page. |
||
| 88 | * |
||
| 89 | * @return void |
||
| 90 | */ |
||
| 91 | 4 | public function actionAddServer($id, $idPage) |
|
| 99 | |||
| 100 | /** |
||
| 101 | * Render method for server form. |
||
| 102 | * |
||
| 103 | * @param int $idPage |
||
| 104 | * |
||
| 105 | * @return void |
||
| 106 | */ |
||
| 107 | 2 | public function renderAddServer($idPage) |
|
| 112 | |||
| 113 | /** |
||
| 114 | * Creates server form component. |
||
| 115 | * |
||
| 116 | * @return \Nette\Application\UI\Form |
||
| 117 | */ |
||
| 118 | 4 | public function createComponentServerForm() |
|
| 133 | |||
| 134 | /** |
||
| 135 | * Saves form data into database. |
||
| 136 | * |
||
| 137 | * @param Nette\Forms\Form $form Server form. |
||
| 138 | * |
||
| 139 | * @return void |
||
| 140 | */ |
||
| 141 | 2 | public function serverFormSubmitted($form) |
|
| 157 | |||
| 158 | /** |
||
| 159 | * Deletes server. |
||
| 160 | * |
||
| 161 | * @param int $id Server's id to remove. |
||
| 162 | * |
||
| 163 | * @return void |
||
| 164 | */ |
||
| 165 | 1 | View Code Duplication | public function actionDeleteServer($id) |
| 177 | } |
||
| 178 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write 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.