| Conditions | 1 |
| Paths | 1 |
| Total Lines | 79 |
| Code Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 39 | public function __construct() { |
||
| 40 | $config = \OC::$server->getConfig(); |
||
| 41 | $db = \OC::$server->getDatabaseConnection(); |
||
| 42 | $dispatcher = \OC::$server->getEventDispatcher(); |
||
| 43 | $userPrincipalBackend = new Principal( |
||
| 44 | \OC::$server->getUserManager(), |
||
| 45 | \OC::$server->getGroupManager() |
||
| 46 | ); |
||
| 47 | $groupPrincipalBackend = new GroupPrincipalBackend( |
||
| 48 | \OC::$server->getGroupManager() |
||
| 49 | ); |
||
| 50 | // as soon as debug mode is enabled we allow listing of principals |
||
| 51 | $disableListing = !$config->getSystemValue('debug', false); |
||
| 52 | |||
| 53 | // setup the first level of the dav tree |
||
| 54 | $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
||
| 55 | $userPrincipals->disableListing = $disableListing; |
||
| 56 | $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
||
| 57 | $groupPrincipals->disableListing = $disableListing; |
||
| 58 | $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
||
| 59 | $systemPrincipals->disableListing = $disableListing; |
||
| 60 | $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
||
| 61 | $filesCollection->disableListing = $disableListing; |
||
| 62 | $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $config); |
||
| 63 | $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
||
| 64 | $calendarRoot->disableListing = $disableListing; |
||
| 65 | $publicCalendarRoot = new PublicCalendarRoot($caldavBackend); |
||
| 66 | $publicCalendarRoot->disableListing = $disableListing; |
||
| 67 | |||
| 68 | $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
||
| 69 | \OC::$server->getSystemTagManager(), |
||
| 70 | \OC::$server->getUserSession(), |
||
| 71 | \OC::$server->getGroupManager() |
||
| 72 | ); |
||
| 73 | $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
||
| 74 | \OC::$server->getSystemTagManager(), |
||
| 75 | \OC::$server->getSystemTagObjectMapper(), |
||
| 76 | \OC::$server->getUserSession(), |
||
| 77 | \OC::$server->getGroupManager(), |
||
| 78 | \OC::$server->getRootFolder() |
||
| 79 | ); |
||
| 80 | $commentsCollection = new Comments\RootCollection( |
||
| 81 | \OC::$server->getCommentsManager(), |
||
| 82 | \OC::$server->getUserManager(), |
||
| 83 | \OC::$server->getUserSession(), |
||
| 84 | \OC::$server->getEventDispatcher(), |
||
| 85 | \OC::$server->getLogger() |
||
| 86 | ); |
||
| 87 | |||
| 88 | $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $dispatcher); |
||
| 89 | $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); |
||
| 90 | $usersAddressBookRoot->disableListing = $disableListing; |
||
| 91 | |||
| 92 | $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $dispatcher); |
||
| 93 | $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); |
||
| 94 | $systemAddressBookRoot->disableListing = $disableListing; |
||
| 95 | |||
| 96 | $uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users'); |
||
| 97 | $uploadCollection->disableListing = $disableListing; |
||
| 98 | |||
| 99 | $children = [ |
||
| 100 | new SimpleCollection('principals', [ |
||
| 101 | $userPrincipals, |
||
| 102 | $groupPrincipals, |
||
| 103 | $systemPrincipals]), |
||
| 104 | $filesCollection, |
||
| 105 | $calendarRoot, |
||
| 106 | $publicCalendarRoot, |
||
| 107 | new SimpleCollection('addressbooks', [ |
||
| 108 | $usersAddressBookRoot, |
||
| 109 | $systemAddressBookRoot]), |
||
| 110 | $systemTagCollection, |
||
| 111 | $systemTagRelationsCollection, |
||
| 112 | $commentsCollection, |
||
| 113 | $uploadCollection, |
||
| 114 | ]; |
||
| 115 | |||
| 116 | parent::__construct('root', $children); |
||
| 117 | } |
||
| 118 | |||
| 120 |