| 1 | <?php |
||
| 22 | class Logger extends AbstractLogger { |
||
| 23 | |||
| 24 | const TEMPLATE_COLLECTION = 'watchdog'; |
||
|
1 ignored issue
–
show
|
|||
| 25 | const EVENT_COLLECTION_PREFIX = 'watchdog_event_'; |
||
|
1 ignored issue
–
show
|
|||
| 26 | const EVENT_COLLECTIONS_PATTERN = '/watchdog_event_[[:xdigit:]]{32}$/'; |
||
| 27 | |||
| 28 | |||
| 29 | /** |
||
| 30 | * The logger storage. |
||
| 31 | * |
||
| 32 | * @var \MongoDB |
||
| 33 | */ |
||
| 34 | protected $database; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The collection holding message templates. |
||
| 38 | * |
||
| 39 | * @var \MongoCollection |
||
| 40 | */ |
||
| 41 | protected $templatesCollection; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The message's placeholders parser. |
||
| 45 | * |
||
| 46 | * @var \Drupal\Core\Logger\LogMessageParserInterface |
||
| 47 | */ |
||
| 48 | protected $parser; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Constructs a Logger object. |
||
| 52 | * |
||
| 53 | * @param \MongoDB $database |
||
| 54 | * The database object. |
||
| 55 | * @param \Drupal\Core\Logger\LogMessageParserInterface $parser |
||
| 56 | * The parser to use when extracting message variables. |
||
| 57 | */ |
||
| 58 | public function __construct(\MongoDB $database, LogMessageParserInterface $parser) { |
||
| 63 | |||
| 64 | /** |
||
| 65 | * {@inheritdoc} |
||
| 66 | */ |
||
| 67 | public function log($level, $message, array $context = []) { |
||
| 91 | |||
| 92 | /** |
||
| 93 | * List the event collections. |
||
| 94 | * |
||
| 95 | * @return \MongoCollection[] |
||
| 96 | * The collections with a name matching the event pattern. |
||
| 97 | */ |
||
| 98 | public function eventCollections() { |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Return a collection, given its template id. |
||
| 112 | * |
||
| 113 | * @param string $template_id |
||
| 114 | * The string representation of a template \MongoId. |
||
| 115 | * |
||
| 116 | * @return \MongoCollection |
||
| 117 | * A collection object for the specified template id. |
||
| 118 | */ |
||
| 119 | public function eventCollection($template_id) { |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Ensure indexes are set on the collections. |
||
| 127 | * |
||
| 128 | * First index is on <line, timestamp> instead of <function, line, timestamp>, |
||
| 129 | * because we write to this collection a lot, and the smaller index on two |
||
| 130 | * numbers should be much faster to create than one with a string included. |
||
| 131 | */ |
||
| 132 | public function ensureIndexes() { |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Load a MongoDB watchdog event. |
||
| 169 | * |
||
| 170 | * @param string $id |
||
| 171 | * The string representation of a MongoId. |
||
| 172 | * |
||
| 173 | * @return \Drupal\mongodb_watchdog\Event|bool |
||
| 174 | * FALSE if the event cannot be loaded. |
||
| 175 | */ |
||
| 176 | public function eventLoad($id) { |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Drop the logger collections. |
||
| 185 | * |
||
| 186 | * @return int |
||
| 187 | * The number of collections dropped. |
||
| 188 | */ |
||
| 189 | public function uninstall() { |
||
| 207 | } |
||
| 208 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.