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 |
||
| 36 | class MiscCustomPropertiesBackend extends AbstractCustomPropertiesBackend { |
||
| 37 | |||
| 38 | const SELECT_BY_PATH_STMT = 'SELECT * FROM `*PREFIX*dav_properties` WHERE `propertypath` = ?'; |
||
| 39 | const INSERT_BY_PATH_STMT = 'INSERT INTO `*PREFIX*dav_properties`' |
||
| 40 | . ' (`propertypath`, `propertyname`, `propertyvalue`) VALUES(?,?,?)'; |
||
| 41 | const UPDATE_BY_PATH_STMT = 'UPDATE `*PREFIX*dav_properties`' |
||
| 42 | . ' SET `propertypath` = ? WHERE `propertypath` = ?'; |
||
| 43 | const UPDATE_BY_PATH_AND_NAME_STMT = 'UPDATE `*PREFIX*dav_properties` ' |
||
| 44 | . 'SET `propertyvalue` = ? WHERE `propertypath` = ? AND `propertyname` = ?'; |
||
| 45 | const DELETE_BY_PATH_STMT = 'DELETE FROM `*PREFIX*dav_properties` WHERE `propertypath` = ?'; |
||
| 46 | const DELETE_BY_PATH_AND_NAME_STMT = 'DELETE FROM `*PREFIX*dav_properties`' |
||
| 47 | . ' WHERE `propertypath` = ? AND `propertyname` = ?'; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * This method is called after a node is deleted. |
||
| 51 | * |
||
| 52 | * @param string $path path of node for which to delete properties |
||
| 53 | */ |
||
| 54 | View Code Duplication | public function delete($path) { |
|
| 65 | |||
| 66 | /** |
||
| 67 | * This method is called after a successful MOVE |
||
| 68 | * |
||
| 69 | * @param string $source |
||
| 70 | * @param string $destination |
||
| 71 | * |
||
| 72 | * @return void |
||
| 73 | */ |
||
| 74 | View Code Duplication | public function move($source, $destination) { |
|
| 84 | |||
| 85 | /** |
||
| 86 | * @inheritdoc |
||
| 87 | */ |
||
| 88 | View Code Duplication | protected function getProperties($path, INode $node, array $requestedProperties) { |
|
| 108 | |||
| 109 | /** |
||
| 110 | * @inheritdoc |
||
| 111 | */ |
||
| 112 | View Code Duplication | protected function updateProperties($path, INode $node, $changedProperties) { |
|
| 158 | |||
| 159 | /** |
||
| 160 | * Bulk load properties for children |
||
| 161 | * |
||
| 162 | * @param INode $node |
||
| 163 | * @param array $requestedProperties requested properties |
||
| 164 | * |
||
| 165 | * @return void |
||
| 166 | */ |
||
| 167 | protected function loadChildrenProperties(INode $node, $requestedProperties) { |
||
| 170 | |||
| 171 | } |
||
| 172 |