| Conditions | 5 |
| Paths | 5 |
| Total Lines | 74 |
| Code Lines | 50 |
| 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 |
||
| 21 | * @var \MongoDB\Database |
||
| 22 | */ |
||
| 23 | protected $db; |
||
|
|
|||
| 24 | |||
| 25 | /** |
||
| 26 | * The logger channel service, used to log events. |
||
| 27 | * |
||
| 28 | * @var \Psr\Log\LoggerInterface |
||
| 29 | */ |
||
| 30 | protected $logger; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * The concrete logger instance, used to access data. |
||
| 34 | * |
||
| 35 | * @var \Drupal\mongodb_watchdog\Logger |
||
| 36 | */ |
||
| 37 | protected $watchdog; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * TopController constructor. |
||
| 41 | * |
||
| 42 | * @param \Psr\Log\LoggerInterface $logger |
||
| 43 | * The logger channel service, to log errors occurring. |
||
| 44 | * @param \Drupal\mongodb_watchdog\Logger $watchdog |
||
| 45 | * The MongoDB Logger service, to load the events. |
||
| 46 | * @param \MongoDB\Database $db |
||
| 47 | * Needed because there is no group() command in phplib yet. |
||
| 48 | * |
||
| 49 | * @see https://jira.mongodb.org/browse/PHPLIB-177 |
||
| 50 | */ |
||
| 51 | public function __construct(LoggerInterface $logger, Logger $watchdog, Database $db) { |
||
| 52 | $this->db = $db; |
||
| 53 | $this->logger = $logger; |
||
| 54 | $this->watchdog = $watchdog; |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * The controller for /admin/reports/mongodb/access-denied. |
||
| 59 | * |
||
| 60 | * @return array |
||
| 61 | * A render array. |
||
| 62 | */ |
||
| 63 | public function top403() { |
||
| 64 | $ret = $this->top('access denied'); |
||
| 65 | return $ret; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * The controller for /admin/reports/mongodb/page-not-found. |
||
| 70 | * |
||
| 71 | * @return array |
||
| 72 | * A render array. |
||
| 73 | */ |
||
| 74 | public function top404() { |
||
| 75 | $ret = $this->top('page not found'); |
||
| 76 | return $ret; |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Command wrapper for missing MongoDB group() implementation in PHPlib. |
||
| 81 | * |
||
| 82 | * @param \MongoDB\Collection $collection |
||
| 83 | * The collection on which to perform the command. |
||
| 84 | * @param object $key |
||
| 85 | * The grouping key. |
||
| 86 | * @param object $cond |
||
| 87 | * The condition. |
||
| 88 | * @param string $reduce |
||
| 89 | * The reducer function: must be valid JavaScript code. |
||
| 90 | * @param object $initial |
||
| 91 | * The initial document. |
||
| 92 | * |
||
| 93 | * @return array|void |
||
| 94 | * Void in case of error, otherwise an array with the following keys: |
||
| 95 | * - waitedMS: time spent waiting |
||
| 242 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.