Conditions | 20 |
Paths | 6496 |
Total Lines | 107 |
Code Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 420 |
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 |
||
43 | public function boot(ServiceProvider $services) { |
||
44 | $db = $services->db; |
||
45 | $config = $services->config; |
||
46 | |||
47 | // set cookie values for session and remember me |
||
48 | $config->getCookieConfig(); |
||
49 | |||
50 | // defaults in case these aren't in config table |
||
51 | if ($config->boot_cache_ttl === null) { |
||
52 | $config->boot_cache_ttl = self::DEFAULT_BOOT_CACHE_TTL; |
||
53 | } |
||
54 | if ($config->simplecache_enabled === null) { |
||
55 | $config->simplecache_enabled = 0; |
||
56 | } |
||
57 | if ($config->system_cache_enabled === null) { |
||
58 | $config->system_cache_enabled = false; |
||
59 | } |
||
60 | if ($config->simplecache_lastupdate === null) { |
||
61 | $config->simplecache_lastupdate = 0; |
||
62 | } |
||
63 | |||
64 | // we were using NOTICE temporarily so we can't just check for null |
||
65 | if (!$config->hasInitialValue('debug') && !$config->debug) { |
||
1 ignored issue
–
show
|
|||
66 | $config->debug = ''; |
||
67 | } |
||
68 | |||
69 | // copy all table values into config |
||
70 | $config->mergeValues($services->configTable->getAll()); |
||
71 | |||
72 | // needs to be set before [init, system] for links in html head |
||
73 | $config->lastcache = (int) $config->simplecache_lastupdate; |
||
74 | |||
75 | if (!$config->elgg_config_set_secret) { |
||
76 | $site_secret = SiteSecret::fromConfig($config); |
||
77 | if (!$site_secret) { |
||
78 | // The 2.3 installer doesn't create a site key (it's created on-demand on the first request) |
||
79 | // so for our Travis upgrade testing we need to check for this and create one on the spot. |
||
80 | if (defined('UPGRADING')) { |
||
81 | $site_secret = SiteSecret::regenerate($services->crypto, $services->configTable); |
||
82 | } |
||
83 | } |
||
84 | if ($site_secret) { |
||
85 | $services->setValue('siteSecret', $site_secret); |
||
86 | } else { |
||
87 | throw new \RuntimeException('The site secret is not set.'); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | $installed = isset($config->installed); |
||
92 | |||
93 | if ($this->timer) { |
||
94 | $this->timer->begin([__CLASS__ . '::getBootData']); |
||
95 | } |
||
96 | |||
97 | // early config is done, now get the core boot data |
||
98 | $data = $this->getBootData($config, $db, $installed); |
||
99 | |||
100 | $site = $data->getSite(); |
||
101 | if (!$site) { |
||
102 | // must be set in config |
||
103 | $site = $config->site; |
||
104 | if (!$site instanceof \ElggSite) { |
||
105 | throw new \RuntimeException('Before installation, config->site must have an unsaved ElggSite.'); |
||
106 | } |
||
107 | } |
||
108 | $config->site = $site; |
||
109 | $config->sitename = $site->name; |
||
110 | $config->sitedescription = $site->description; |
||
111 | |||
112 | $services->subtypeTable->setCachedValues($data->getSubtypeData()); |
||
113 | |||
114 | $services->plugins->setBootPlugins($data->getActivePlugins()); |
||
115 | |||
116 | $services->pluginSettingsCache->setCachedValues($data->getPluginSettings()); |
||
117 | |||
118 | $services->logger->setLevel($config->debug); |
||
119 | if ($config->debug) { |
||
1 ignored issue
–
show
|
|||
120 | $services->logger->setDisplay(true); |
||
121 | } |
||
122 | |||
123 | // finish boot sequence |
||
124 | _elgg_session_boot($services); |
||
125 | |||
126 | if ($config->system_cache_enabled) { |
||
127 | $config->system_cache_loaded = false; |
||
128 | |||
129 | if ($services->views->configureFromCache($services->systemCache)) { |
||
130 | $config->system_cache_loaded = true; |
||
131 | } |
||
132 | } |
||
133 | |||
134 | // we don't store langs in boot data because it varies by user |
||
135 | $services->translator->loadTranslations(); |
||
136 | |||
137 | // we always need site->email and user->icontime, so load them together |
||
138 | $user_guid = $services->session->getLoggedInUserGuid(); |
||
139 | if ($user_guid) { |
||
140 | $services->metadataCache->populateFromEntities([$user_guid]); |
||
141 | } |
||
142 | |||
143 | // invalidate on some actions just in case other invalidation triggers miss something |
||
144 | $services->hooks->registerHandler('action', 'all', function ($action) { |
||
145 | if (0 === strpos($action, 'admin/' || $action === 'plugins/settings/save')) { |
||
146 | $this->invalidateCache(); |
||
147 | } |
||
148 | }, 1); |
||
149 | } |
||
150 | |||
226 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: