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