Complex classes like FileSearchBackend often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FileSearchBackend, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 50 | class FileSearchBackend implements ISearchBackend { |
||
| 51 | /** @var Tree */ |
||
| 52 | private $tree; |
||
| 53 | |||
| 54 | /** @var IUser */ |
||
| 55 | private $user; |
||
| 56 | |||
| 57 | /** @var IRootFolder */ |
||
| 58 | private $rootFolder; |
||
| 59 | |||
| 60 | /** @var IManager */ |
||
| 61 | private $shareManager; |
||
| 62 | |||
| 63 | /** @var View */ |
||
| 64 | private $view; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * FileSearchBackend constructor. |
||
| 68 | * |
||
| 69 | * @param Tree $tree |
||
| 70 | * @param IUser $user |
||
| 71 | * @param IRootFolder $rootFolder |
||
| 72 | * @param IManager $shareManager |
||
| 73 | * @param View $view |
||
| 74 | * @internal param IRootFolder $rootFolder |
||
| 75 | */ |
||
| 76 | public function __construct(Tree $tree, IUser $user, IRootFolder $rootFolder, IManager $shareManager, View $view) { |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Search endpoint will be remote.php/dav |
||
| 86 | * |
||
| 87 | * @return string |
||
| 88 | */ |
||
| 89 | public function getArbiterPath() { |
||
| 92 | |||
| 93 | public function isValidScope($href, $depth, $path) { |
||
| 106 | |||
| 107 | public function getPropertyDefinitionsForScope($href, $path) { |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @param BasicSearch $search |
||
| 135 | * @return SearchResult[] |
||
| 136 | */ |
||
| 137 | public function search(BasicSearch $search) { |
||
| 138 | if (count($search->from) !== 1) { |
||
| 139 | throw new \InvalidArgumentException('Searching more than one folder is not supported'); |
||
| 140 | } |
||
| 141 | $query = $this->transformQuery($search); |
||
| 142 | $scope = $search->from[0]; |
||
| 143 | if ($scope->path === null) { |
||
| 144 | throw new \InvalidArgumentException('Using uri\'s as scope is not supported, please use a path relative to the search arbiter instead'); |
||
| 145 | } |
||
| 146 | $node = $this->tree->getNodeForPath($scope->path); |
||
| 147 | if (!$node instanceof Directory) { |
||
| 148 | throw new \InvalidArgumentException('Search is only supported on directories'); |
||
| 149 | } |
||
| 150 | |||
| 151 | $fileInfo = $node->getFileInfo(); |
||
| 152 | $folder = $this->rootFolder->get($fileInfo->getPath()); |
||
| 153 | /** @var Folder $folder $results */ |
||
| 154 | $results = $folder->search($query); |
||
| 155 | |||
| 156 | return array_map(function (Node $node) { |
||
| 157 | if ($node instanceof Folder) { |
||
| 158 | return new SearchResult(new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager), $this->getHrefForNode($node)); |
||
| 159 | } else { |
||
| 160 | return new SearchResult(new \OCA\DAV\Connector\Sabre\File($this->view, $node, $this->shareManager), $this->getHrefForNode($node)); |
||
| 161 | } |
||
| 162 | }, $results); |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @param Node $node |
||
| 167 | * @return string |
||
| 168 | */ |
||
| 169 | private function getHrefForNode(Node $node) { |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @param BasicSearch $query |
||
| 176 | * @return ISearchQuery |
||
| 177 | */ |
||
| 178 | private function transformQuery(BasicSearch $query) { |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @param Order $order |
||
| 186 | * @return ISearchOrder |
||
| 187 | */ |
||
| 188 | private function mapSearchOrder(Order $order) { |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @param Operator $operator |
||
| 194 | * @return ISearchOperator |
||
| 195 | */ |
||
| 196 | private function transformSearchOperation(Operator $operator) { |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @param string $propertyName |
||
| 229 | * @return string |
||
| 230 | */ |
||
| 231 | private function mapPropertyNameToCollumn($propertyName) { |
||
| 245 | |||
| 246 | private function castValue($propertyName, $value) { |
||
| 265 | } |
||
| 266 |
Scrutinizer analyzes your
composer.json/composer.lockfile if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.