| Conditions | 15 |
| Paths | 1 |
| Total Lines | 265 |
| Code Lines | 184 |
| Lines | 8 |
| Ratio | 3.02 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
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 | function __construct($webRoot) { |
||
| 40 | parent::__construct(); |
||
| 41 | $this->webRoot = $webRoot; |
||
| 42 | |||
| 43 | $this->registerService('ContactsManager', function ($c) { |
||
|
|
|||
| 44 | return new ContactsManager(); |
||
| 45 | }); |
||
| 46 | $this->registerService('Request', function (Server $c) { |
||
| 47 | if (isset($c['urlParams'])) { |
||
| 48 | $urlParams = $c['urlParams']; |
||
| 49 | } else { |
||
| 50 | $urlParams = array(); |
||
| 51 | } |
||
| 52 | |||
| 53 | if ($c->getSession()->exists('requesttoken')) { |
||
| 54 | $requestToken = $c->getSession()->get('requesttoken'); |
||
| 55 | } else { |
||
| 56 | $requestToken = false; |
||
| 57 | } |
||
| 58 | |||
| 59 | if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
||
| 60 | && in_array('fakeinput', stream_get_wrappers()) |
||
| 61 | ) { |
||
| 62 | $stream = 'fakeinput://data'; |
||
| 63 | } else { |
||
| 64 | $stream = 'php://input'; |
||
| 65 | } |
||
| 66 | |||
| 67 | return new Request( |
||
| 68 | array( |
||
| 69 | 'get' => $_GET, |
||
| 70 | 'post' => $_POST, |
||
| 71 | 'files' => $_FILES, |
||
| 72 | 'server' => $_SERVER, |
||
| 73 | 'env' => $_ENV, |
||
| 74 | 'cookies' => $_COOKIE, |
||
| 75 | 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
||
| 76 | ? $_SERVER['REQUEST_METHOD'] |
||
| 77 | : null, |
||
| 78 | 'urlParams' => $urlParams, |
||
| 79 | 'requesttoken' => $requestToken, |
||
| 80 | ), $stream |
||
| 81 | ); |
||
| 82 | }); |
||
| 83 | $this->registerService('PreviewManager', function ($c) { |
||
| 84 | return new PreviewManager(); |
||
| 85 | }); |
||
| 86 | $this->registerService('TagMapper', function(Server $c) { |
||
| 87 | return new TagMapper($c->getDb()); |
||
| 88 | }); |
||
| 89 | $this->registerService('TagManager', function (Server $c) { |
||
| 90 | $tagMapper = $c->query('TagMapper'); |
||
| 91 | return new TagManager($tagMapper, $c->getUserSession()); |
||
| 92 | }); |
||
| 93 | $this->registerService('RootFolder', function (Server $c) { |
||
| 94 | // TODO: get user and user manager from container as well |
||
| 95 | $user = \OC_User::getUser(); |
||
| 96 | /** @var $c SimpleContainer */ |
||
| 97 | $userManager = $c->query('UserManager'); |
||
| 98 | $user = $userManager->get($user); |
||
| 99 | $manager = \OC\Files\Filesystem::getMountManager(); |
||
| 100 | $view = new View(); |
||
| 101 | return new Root($manager, $view, $user); |
||
| 102 | }); |
||
| 103 | $this->registerService('UserManager', function (Server $c) { |
||
| 104 | $config = $c->getConfig(); |
||
| 105 | return new \OC\User\Manager($config); |
||
| 106 | }); |
||
| 107 | $this->registerService('GroupManager', function (Server $c) { |
||
| 108 | $groupManager = new \OC\Group\Manager($this->getUserManager()); |
||
| 109 | $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
||
| 110 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
||
| 111 | }); |
||
| 112 | $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
||
| 113 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
||
| 114 | }); |
||
| 115 | $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
||
| 116 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
||
| 117 | }); |
||
| 118 | $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
||
| 119 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
||
| 120 | }); |
||
| 121 | $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
||
| 122 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 123 | }); |
||
| 124 | $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
||
| 125 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 126 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
||
| 127 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 128 | }); |
||
| 129 | return $groupManager; |
||
| 130 | }); |
||
| 131 | $this->registerService('UserSession', function (Server $c) { |
||
| 132 | $manager = $c->getUserManager(); |
||
| 133 | $userSession = new \OC\User\Session($manager, new \OC\Session\Memory('')); |
||
| 134 | $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
||
| 135 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
||
| 136 | }); |
||
| 137 | $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
||
| 138 | /** @var $user \OC\User\User */ |
||
| 139 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
||
| 140 | }); |
||
| 141 | $userSession->listen('\OC\User', 'preDelete', function ($user) { |
||
| 142 | /** @var $user \OC\User\User */ |
||
| 143 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
||
| 144 | }); |
||
| 145 | $userSession->listen('\OC\User', 'postDelete', function ($user) { |
||
| 146 | /** @var $user \OC\User\User */ |
||
| 147 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
||
| 148 | }); |
||
| 149 | View Code Duplication | $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 150 | /** @var $user \OC\User\User */ |
||
| 151 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
||
| 152 | }); |
||
| 153 | View Code Duplication | $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 154 | /** @var $user \OC\User\User */ |
||
| 155 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
||
| 156 | }); |
||
| 157 | $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
||
| 158 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
||
| 159 | }); |
||
| 160 | $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
||
| 161 | /** @var $user \OC\User\User */ |
||
| 162 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
||
| 163 | }); |
||
| 164 | $userSession->listen('\OC\User', 'logout', function () { |
||
| 165 | \OC_Hook::emit('OC_User', 'logout', array()); |
||
| 166 | }); |
||
| 167 | return $userSession; |
||
| 168 | }); |
||
| 169 | $this->registerService('NavigationManager', function ($c) { |
||
| 170 | return new \OC\NavigationManager(); |
||
| 171 | }); |
||
| 172 | $this->registerService('AllConfig', function (Server $c) { |
||
| 173 | return new \OC\AllConfig( |
||
| 174 | $c->getSystemConfig() |
||
| 175 | ); |
||
| 176 | }); |
||
| 177 | $this->registerService('SystemConfig', function ($c) { |
||
| 178 | return new \OC\SystemConfig(); |
||
| 179 | }); |
||
| 180 | $this->registerService('AppConfig', function ($c) { |
||
| 181 | return new \OC\AppConfig(\OC_DB::getConnection()); |
||
| 182 | }); |
||
| 183 | $this->registerService('L10NFactory', function ($c) { |
||
| 184 | return new \OC\L10N\Factory(); |
||
| 185 | }); |
||
| 186 | $this->registerService('URLGenerator', function (Server $c) { |
||
| 187 | $config = $c->getConfig(); |
||
| 188 | return new \OC\URLGenerator($config); |
||
| 189 | }); |
||
| 190 | $this->registerService('AppHelper', function ($c) { |
||
| 191 | return new \OC\AppHelper(); |
||
| 192 | }); |
||
| 193 | $this->registerService('UserCache', function ($c) { |
||
| 194 | return new UserCache(); |
||
| 195 | }); |
||
| 196 | $this->registerService('MemCacheFactory', function ($c) { |
||
| 197 | $instanceId = \OC_Util::getInstanceId(); |
||
| 198 | return new \OC\Memcache\Factory($instanceId); |
||
| 199 | }); |
||
| 200 | $this->registerService('ActivityManager', function ($c) { |
||
| 201 | return new ActivityManager(); |
||
| 202 | }); |
||
| 203 | $this->registerService('AvatarManager', function ($c) { |
||
| 204 | return new AvatarManager(); |
||
| 205 | }); |
||
| 206 | $this->registerService('Logger', function (Server $c) { |
||
| 207 | $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud'); |
||
| 208 | $logger = 'OC_Log_' . ucfirst($logClass); |
||
| 209 | call_user_func(array($logger, 'init')); |
||
| 210 | |||
| 211 | return new Log($logger); |
||
| 212 | }); |
||
| 213 | $this->registerService('JobList', function (Server $c) { |
||
| 214 | $config = $c->getConfig(); |
||
| 215 | return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config); |
||
| 216 | }); |
||
| 217 | $this->registerService('Router', function (Server $c) { |
||
| 218 | $cacheFactory = $c->getMemCacheFactory(); |
||
| 219 | if ($cacheFactory->isAvailable()) { |
||
| 220 | $router = new \OC\Route\CachingRouter($cacheFactory->create('route')); |
||
| 221 | } else { |
||
| 222 | $router = new \OC\Route\Router(); |
||
| 223 | } |
||
| 224 | return $router; |
||
| 225 | }); |
||
| 226 | $this->registerService('Search', function ($c) { |
||
| 227 | return new Search(); |
||
| 228 | }); |
||
| 229 | $this->registerService('SecureRandom', function ($c) { |
||
| 230 | return new SecureRandom(); |
||
| 231 | }); |
||
| 232 | $this->registerService('Crypto', function (Server $c) { |
||
| 233 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
||
| 234 | }); |
||
| 235 | $this->registerService('Hasher', function (Server $c) { |
||
| 236 | return new Hasher($c->getConfig()); |
||
| 237 | }); |
||
| 238 | $this->registerService('DatabaseConnection', function (Server $c) { |
||
| 239 | $factory = new \OC\DB\ConnectionFactory(); |
||
| 240 | $systemConfig = $c->getSystemConfig(); |
||
| 241 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
||
| 242 | if (!$factory->isValidType($type)) { |
||
| 243 | throw new \OC\DatabaseException('Invalid database type'); |
||
| 244 | } |
||
| 245 | $connectionParams = $factory->createConnectionParams($systemConfig); |
||
| 246 | $connection = $factory->getConnection($type, $connectionParams); |
||
| 247 | $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
||
| 248 | return $connection; |
||
| 249 | }); |
||
| 250 | $this->registerService('Db', function (Server $c) { |
||
| 251 | return new Db($c->getDatabaseConnection()); |
||
| 252 | }); |
||
| 253 | $this->registerService('HTTPHelper', function (Server $c) { |
||
| 254 | $config = $c->getConfig(); |
||
| 255 | $user = $c->getUserSession()->getUser(); |
||
| 256 | $uid = $user ? $user->getUID() : null; |
||
| 257 | return new HTTPHelper($config, new \OC\Security\CertificateManager($uid, new \OC\Files\View())); |
||
| 258 | }); |
||
| 259 | $this->registerService('EventLogger', function (Server $c) { |
||
| 260 | if (defined('DEBUG') and DEBUG) { |
||
| 261 | return new EventLogger(); |
||
| 262 | } else { |
||
| 263 | return new NullEventLogger(); |
||
| 264 | } |
||
| 265 | }); |
||
| 266 | $this->registerService('QueryLogger', function ($c) { |
||
| 267 | if (defined('DEBUG') and DEBUG) { |
||
| 268 | return new QueryLogger(); |
||
| 269 | } else { |
||
| 270 | return new NullQueryLogger(); |
||
| 271 | } |
||
| 272 | }); |
||
| 273 | $this->registerService('TempManager', function (Server $c) { |
||
| 274 | return new TempManager(get_temp_dir(), $c->getLogger()); |
||
| 275 | }); |
||
| 276 | $this->registerService('AppManager', function(Server $c) { |
||
| 277 | $userSession = $c->getUserSession(); |
||
| 278 | $appConfig = $c->getAppConfig(); |
||
| 279 | $groupManager = $c->getGroupManager(); |
||
| 280 | return new \OC\App\AppManager($userSession, $appConfig, $groupManager); |
||
| 281 | }); |
||
| 282 | $this->registerService('DateTimeZone', function(Server $c) { |
||
| 283 | return new DateTimeZone( |
||
| 284 | $c->getConfig(), |
||
| 285 | $c->getSession() |
||
| 286 | ); |
||
| 287 | }); |
||
| 288 | $this->registerService('DateTimeFormatter', function(Server $c) { |
||
| 289 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
||
| 290 | |||
| 291 | return new DateTimeFormatter( |
||
| 292 | $c->getDateTimeZone()->getTimeZone(), |
||
| 293 | $c->getL10N('lib', $language) |
||
| 294 | ); |
||
| 295 | }); |
||
| 296 | $this->registerService('MountConfigManager', function () { |
||
| 297 | $loader = \OC\Files\Filesystem::getLoader(); |
||
| 298 | return new \OC\Files\Config\MountProviderCollection($loader); |
||
| 299 | }); |
||
| 300 | $this->registerService('IniWrapper', function ($c) { |
||
| 301 | return new IniGetWrapper(); |
||
| 302 | }); |
||
| 303 | } |
||
| 304 | |||
| 742 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.