| Conditions | 6 |
| Paths | 25 |
| Total Lines | 52 |
| Code Lines | 28 |
| 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 |
||
| 64 | public function loadLazyPanels(): void { |
||
| 65 | $classes = $this->lazyWidgets; |
||
| 66 | foreach ($classes as $class) { |
||
| 67 | try { |
||
| 68 | /** @var IWidget $widget */ |
||
| 69 | $widget = $this->serverContainer->query($class); |
||
| 70 | } catch (QueryException $e) { |
||
| 71 | /* |
||
| 72 | * There is a circular dependency between the logger and the registry, so |
||
| 73 | * we can not inject it. Thus the static call. |
||
| 74 | */ |
||
| 75 | \OC::$server->getLogger()->logException($e, [ |
||
| 76 | 'message' => 'Could not load lazy dashbaord widget: ' . $e->getMessage(), |
||
| 77 | 'level' => ILogger::FATAL, |
||
|
|
|||
| 78 | ]); |
||
| 79 | } |
||
| 80 | /** |
||
| 81 | * Try to register the loaded reporter. Theoretically it could be of a wrong |
||
| 82 | * type, so we might get a TypeError here that we should catch. |
||
| 83 | */ |
||
| 84 | try { |
||
| 85 | $this->registerWidget($widget); |
||
| 86 | } catch (Throwable $e) { |
||
| 87 | /* |
||
| 88 | * There is a circular dependency between the logger and the registry, so |
||
| 89 | * we can not inject it. Thus the static call. |
||
| 90 | */ |
||
| 91 | \OC::$server->getLogger()->logException($e, [ |
||
| 92 | 'message' => 'Could not register lazy dashboard widget: ' . $e->getMessage(), |
||
| 93 | 'level' => ILogger::FATAL, |
||
| 94 | ]); |
||
| 95 | } |
||
| 96 | |||
| 97 | try { |
||
| 98 | $startTime = microtime(true); |
||
| 99 | $widget->load(); |
||
| 100 | $endTime = microtime(true); |
||
| 101 | $duration = $endTime - $startTime; |
||
| 102 | if ($duration > 1) { |
||
| 103 | \OC::$server->getLogger()->error('Dashboard widget {widget} took {duration} seconds to load.', [ |
||
| 104 | 'widget' => $widget->getId(), |
||
| 105 | 'duration' => round($duration, 2), |
||
| 106 | ]); |
||
| 107 | } |
||
| 108 | } catch (Throwable $e) { |
||
| 109 | \OC::$server->getLogger()->logException($e, [ |
||
| 110 | 'message' => 'Error during dashboard widget loading: ' . $e->getMessage(), |
||
| 111 | 'level' => ILogger::FATAL, |
||
| 112 | ]); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | $this->lazyWidgets = []; |
||
| 116 | } |
||
| 123 |
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.