| Conditions | 11 |
| Paths | 48 |
| Total Lines | 57 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 78 | public function getChildren() { |
||
| 79 | if ($this->l10n === null) { |
||
| 80 | $this->l10n = \OC::$server->getL10N('dav'); |
||
| 81 | } |
||
| 82 | if ($this->config === null) { |
||
| 83 | $this->config = \OC::$server->getConfig(); |
||
| 84 | } |
||
| 85 | |||
| 86 | /** @var string|array $principal */ |
||
| 87 | $principal = $this->principalUri; |
||
| 88 | $addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); |
||
|
|
|||
| 89 | // add the system address book |
||
| 90 | $systemAddressBook = null; |
||
| 91 | if (is_string($principal) && $principal !== 'principals/system/system' && $this->carddavBackend instanceof CardDavBackend) { |
||
| 92 | $systemAddressBook = $this->carddavBackend->getAddressBooksByUri('principals/system/system', 'system'); |
||
| 93 | if ($systemAddressBook !== null) { |
||
| 94 | $systemAddressBook['uri'] = SystemAddressbook::URI_SHARED; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | if (!is_null($systemAddressBook)) { |
||
| 98 | $addressBooks[] = $systemAddressBook; |
||
| 99 | } |
||
| 100 | |||
| 101 | $objects = []; |
||
| 102 | if (!empty($addressBooks)) { |
||
| 103 | /** @var IAddressBook[] $objects */ |
||
| 104 | $objects = array_map(function (array $addressBook) { |
||
| 105 | $trustedServers = null; |
||
| 106 | $request = null; |
||
| 107 | try { |
||
| 108 | $trustedServers = \OC::$server->get(TrustedServers::class); |
||
| 109 | $request = \OC::$server->get(IRequest::class); |
||
| 110 | } catch (NotFoundExceptionInterface | ContainerExceptionInterface $e) { |
||
| 111 | // nothing to do, the request / trusted servers don't exist |
||
| 112 | } |
||
| 113 | if ($addressBook['principaluri'] === 'principals/system/system') { |
||
| 114 | return new SystemAddressbook( |
||
| 115 | $this->carddavBackend, |
||
| 116 | $addressBook, |
||
| 117 | $this->l10n, |
||
| 118 | $this->config, |
||
| 119 | \OCP\Server::get(IUserSession::class), |
||
| 120 | $request, |
||
| 121 | $trustedServers, |
||
| 122 | $this->groupManager |
||
| 123 | ); |
||
| 124 | } |
||
| 125 | |||
| 126 | return new AddressBook($this->carddavBackend, $addressBook, $this->l10n); |
||
| 127 | }, $addressBooks); |
||
| 128 | } |
||
| 129 | /** @var IAddressBook[][] $objectsFromPlugins */ |
||
| 130 | $objectsFromPlugins = array_map(function (IAddressBookProvider $plugin): array { |
||
| 131 | return $plugin->fetchAllForAddressBookHome($this->principalUri); |
||
| 132 | }, $this->pluginManager->getAddressBookPlugins()); |
||
| 133 | |||
| 134 | return array_merge($objects, ...$objectsFromPlugins); |
||
| 135 | } |
||
| 170 |