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 |
||
| 42 | class FilesReportPlugin extends ServerPlugin { |
||
| 43 | |||
| 44 | // namespace |
||
| 45 | const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
||
| 46 | const REPORT_NAME = '{http://owncloud.org/ns}filter-files'; |
||
| 47 | const SYSTEMTAG_PROPERTYNAME = '{http://owncloud.org/ns}systemtag'; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Reference to main server object |
||
| 51 | * |
||
| 52 | * @var \Sabre\DAV\Server |
||
| 53 | */ |
||
| 54 | private $server; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var Tree |
||
| 58 | */ |
||
| 59 | private $tree; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var View |
||
| 63 | */ |
||
| 64 | private $fileView; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var ISystemTagManager |
||
| 68 | */ |
||
| 69 | private $tagManager; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var ISystemTagObjectMapper |
||
| 73 | */ |
||
| 74 | private $tagMapper; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var IUserSession |
||
| 78 | */ |
||
| 79 | private $userSession; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var IGroupManager |
||
| 83 | */ |
||
| 84 | private $groupManager; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var Folder |
||
| 88 | */ |
||
| 89 | private $userFolder; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @param Tree $tree |
||
| 93 | * @param View $view |
||
| 94 | */ |
||
| 95 | View Code Duplication | public function __construct(Tree $tree, |
|
| 111 | |||
| 112 | /** |
||
| 113 | * This initializes the plugin. |
||
| 114 | * |
||
| 115 | * This function is called by \Sabre\DAV\Server, after |
||
| 116 | * addPlugin is called. |
||
| 117 | * |
||
| 118 | * This method should set up the required event subscriptions. |
||
| 119 | * |
||
| 120 | * @param \Sabre\DAV\Server $server |
||
| 121 | * @return void |
||
| 122 | */ |
||
| 123 | public function initialize(\Sabre\DAV\Server $server) { |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Returns a list of reports this plugin supports. |
||
| 133 | * |
||
| 134 | * This will be used in the {DAV:}supported-report-set property. |
||
| 135 | * |
||
| 136 | * @param string $uri |
||
| 137 | * @return array |
||
| 138 | */ |
||
| 139 | public function getSupportedReportSet($uri) { |
||
| 142 | |||
| 143 | /** |
||
| 144 | * REPORT operations to look for files |
||
| 145 | * |
||
| 146 | * @param string $reportName |
||
| 147 | * @param [] $report |
||
|
|
|||
| 148 | * @param string $uri |
||
| 149 | * @return bool |
||
| 150 | * @throws NotFound |
||
| 151 | * @throws ReportNotSupported |
||
| 152 | */ |
||
| 153 | public function onReport($reportName, $report, $uri) { |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Find file ids matching the given filter rules |
||
| 207 | * |
||
| 208 | * @param array $filterRules |
||
| 209 | * @return array array of unique file id results |
||
| 210 | * |
||
| 211 | * @throws TagNotFoundException whenever a tag was not found |
||
| 212 | */ |
||
| 213 | protected function processFilterRules($filterRules) { |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Prepare propfind response for the given nodes |
||
| 265 | * |
||
| 266 | * @param string[] $requestedProps requested properties |
||
| 267 | * @param Node[] nodes nodes for which to fetch and prepare responses |
||
| 268 | * @return Response[] |
||
| 269 | */ |
||
| 270 | public function prepareResponses($requestedProps, $nodes) { |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Find Sabre nodes by file ids |
||
| 296 | * |
||
| 297 | * @param Node $rootNode root node for search |
||
| 298 | * @param array $fileIds file ids |
||
| 299 | * @return Node[] array of Sabre nodes |
||
| 300 | */ |
||
| 301 | public function findNodesByFileIds($rootNode, $fileIds) { |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Returns whether the currently logged in user is an administrator |
||
| 325 | */ |
||
| 326 | View Code Duplication | private function isAdmin() { |
|
| 333 | } |
||
| 334 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.