Conditions | 7 |
Paths | 40 |
Total Lines | 69 |
Code Lines | 47 |
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 |
||
29 | public function index(): ?string |
||
30 | { |
||
31 | // get cached statistics |
||
32 | $rootSize = App::$Cache->getItem('root.size'); |
||
33 | $loadAvg = App::$Cache->getItem('load.avarage'); |
||
34 | if (!$rootSize->isHit()) { |
||
35 | $calcSize = round(Directory::size('/') / (1024*1000), 2) . ' mb'; |
||
36 | $rootSize->set($calcSize); |
||
37 | $rootSize->expiresAfter(86400); |
||
38 | App::$Cache->save($rootSize); |
||
39 | } |
||
40 | if (!$loadAvg->isHit()) { |
||
41 | $loadAvg->set(Environment::loadAverage()); |
||
42 | $loadAvg->expiresAfter(300); |
||
43 | App::$Cache->save($loadAvg); |
||
44 | } |
||
45 | |||
46 | // prepare system statistic |
||
47 | $stats = [ |
||
48 | 'ff_version' => Version::VERSION . ' (' . Version::DATE . ')', |
||
49 | 'php_version' => Environment::phpVersion() . ' (' . Environment::phpSAPI() . ')', |
||
50 | 'os_name' => Environment::osName(), |
||
51 | 'database_name' => App::$Database->connection()->getDatabaseName() . ' (' . App::$Database->connection()->getDriverName() . ')', |
||
52 | 'file_size' => $rootSize->get(), |
||
53 | 'load_avg' => $loadAvg->get() |
||
54 | ]; |
||
55 | // check directory chmods and other environment features |
||
56 | $model = new EntityCheck(); |
||
57 | |||
58 | // work with yandex statistics |
||
59 | $yandexCfg = App::$Properties->getAll('Yandex'); |
||
60 | $tokenLifetime = $yandexCfg['oauth']['expires']; |
||
61 | $tokenActive = ($tokenLifetime && time() < $tokenLifetime); |
||
62 | |||
63 | $visits = null; |
||
64 | $sources = null; |
||
65 | if ($tokenActive) { |
||
66 | // initialize yandex.api client |
||
67 | $client = new Client($yandexCfg['oauth']['token'], $yandexCfg['metrika']['id']); |
||
68 | |||
69 | // get visit statistics |
||
70 | $visits = App::$Cache->getItem('metrika.visits'); |
||
71 | if (!$visits->isHit()) { |
||
72 | $calcVisit = $client->getVisits30days(); |
||
|
|||
73 | $visits->set($calcVisit) |
||
74 | ->expiresAfter(3600); // update 1 times at hour |
||
75 | App::$Cache->save($visits); |
||
76 | } |
||
77 | $visits = $visits->get(); |
||
78 | |||
79 | // get source distribution statistics |
||
80 | $sources = App::$Cache->getItem('metrika.sources'); |
||
81 | if (!$sources->isHit()) { |
||
82 | $calcSources = $client->getSourcesSummary30days(); |
||
83 | $sources->set($calcSources) |
||
84 | ->expiresAfter(3600); |
||
85 | App::$Cache->save($sources); |
||
86 | } |
||
87 | $sources = array_slice($sources->get(), 0, 5); |
||
88 | } |
||
89 | |||
90 | // render view output |
||
91 | return $this->view->render('main/index', [ |
||
92 | 'stats' => $stats, |
||
93 | 'check' => $model, |
||
94 | 'tokenActive' => $tokenActive, |
||
95 | 'yandexCfg' => $yandexCfg, |
||
96 | 'visits' => $visits, |
||
97 | 'sources' => $sources |
||
98 | ]); |
||
101 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.