Skip to content

Commit

Permalink
[console] Code cleanup. (#3066)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolivas committed Jan 3, 2017
1 parent 6937aa0 commit 84dcc4c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 83 deletions.
156 changes: 77 additions & 79 deletions src/Command/Database/DatabaseLogBase.php
@@ -1,9 +1,8 @@
<?php

/**
* Created by PhpStorm.
* User: twhiston
* Date: 09/12/16
* Time: 15:07
* @file
* Contains \Drupal\Console\Command\Database\DatabaseLogBase.
*/

namespace Drupal\Console\Command\Database;
Expand Down Expand Up @@ -34,58 +33,58 @@ abstract class DatabaseLogBase extends Command
use CommandTrait;

/**
* @var Connection
*/
* @var Connection
*/
protected $database;

/**
* @var DateFormatterInterface
*/
* @var DateFormatterInterface
*/
protected $dateFormatter;

/**
* @var EntityTypeManagerInterface
*/
* @var EntityTypeManagerInterface
*/
protected $entityTypeManager;

/**
* @var TranslationInterface
*/
* @var TranslationInterface
*/
protected $stringTranslation;

/**
* @var UserStorageInterface
*/
* @var UserStorageInterface
*/
protected $userStorage;

/**
* @var TranslatableMarkup[]
*/
* @var TranslatableMarkup[]
*/
protected $severityList;

/**
* @var null|string
*/
* @var null|string
*/
protected $eventType;

/**
* @var null|string
*/
* @var null|string
*/
protected $eventSeverity;

/**
* @var null|string
*/
* @var null|string
*/
protected $userId;

/**
* LogDebugCommand constructor.
*
* @param Connection $database
* @param DateFormatterInterface $dateFormatter
* @param EntityTypeManagerInterface $entityTypeManager
* @param \Drupal\Core\StringTranslation\TranslationInterface $stringTranslation
*/
* LogDebugCommand constructor.
*
* @param Connection $database
* @param DateFormatterInterface $dateFormatter
* @param EntityTypeManagerInterface $entityTypeManager
* @param TranslationInterface $stringTranslation
*/
public function __construct(
Connection $database,
DateFormatterInterface $dateFormatter,
Expand All @@ -102,8 +101,8 @@ public function __construct(
}

/**
*
*/
* addDefaultLoggingOptions.
*/
protected function addDefaultLoggingOptions()
{
$this
Expand All @@ -128,8 +127,8 @@ protected function addDefaultLoggingOptions()
}

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
*/
* @param InputInterface $input
*/
protected function getDefaultOptions(InputInterface $input)
{
$this->eventType = $input->getOption('type');
Expand All @@ -138,24 +137,24 @@ protected function getDefaultOptions(InputInterface $input)
}

/**
* @param \Drupal\Console\Core\Style\DrupalStyle $io
* @param null $offset
* @param int $range
* @return bool|\Drupal\Core\Database\Query\SelectInterface
*/
* @param DrupalStyle $io
* @param null $offset
* @param int $range
* @return bool|\Drupal\Core\Database\Query\SelectInterface
*/
protected function makeQuery(DrupalStyle $io, $offset = null, $range = 1000)
{
$query = $this->database->select('watchdog', 'w');
$query->fields(
'w',
[
'wid',
'uid',
'severity',
'type',
'timestamp',
'message',
'variables',
'wid',
'uid',
'severity',
'type',
'timestamp',
'message',
'variables',
]
);

Expand Down Expand Up @@ -196,10 +195,10 @@ protected function makeQuery(DrupalStyle $io, $offset = null, $range = 1000)
}

/**
* Generic logging table header
*
* @return array
*/
* Generic logging table header
*
* @return array
*/
protected function createTableHeader()
{
return [
Expand All @@ -212,45 +211,44 @@ protected function createTableHeader()
];
}


/**
* @param \stdClass $dblog
* @return array
*/
* @param \stdClass $dblog
* @return array
*/
protected function createTableRow(\stdClass $dblog)
{

/**
* @var User $user
*/
* @var User $user
*/
$user = $this->userStorage->load($dblog->uid);

return [
$dblog->wid,
$dblog->type,
$this->dateFormatter->format($dblog->timestamp, 'short'),
Unicode::truncate(
Html::decodeEntities(strip_tags($this->formatMessage($dblog))),
500,
true,
true
),
$user->getUsername() . ' (' . $user->id() . ')',
$this->severityList[$dblog->severity]->render(),
$dblog->wid,
$dblog->type,
$this->dateFormatter->format($dblog->timestamp, 'short'),
Unicode::truncate(
Html::decodeEntities(strip_tags($this->formatMessage($dblog))),
500,
true,
true
),
$user->getUsername() . ' (' . $user->id() . ')',
$this->severityList[$dblog->severity]->render(),
];
}

/**
* Formats a database log message.
*
* @param $event
* The record from the watchdog table. The object properties are: wid, uid,
* severity, type, timestamp, message, variables, link, name.
*
* @return string|false
* The formatted log message or FALSE if the message or variables properties
* are not set.
*/
* Formats a database log message.
*
* @param $event
* The record from the watchdog table. The object properties are: wid, uid,
* severity, type, timestamp, message, variables, link, name.
*
* @return string|false
* The formatted log message or FALSE if the message or variables properties
* are not set.
*/
protected function formatMessage(\stdClass $event)
{
$message = false;
Expand All @@ -272,9 +270,9 @@ protected function formatMessage(\stdClass $event)
}

/**
* @param $dblog
* @return array
*/
* @param $dblog
* @return array
*/
protected function formatSingle($dblog)
{
return array_combine(
Expand Down
7 changes: 3 additions & 4 deletions src/Utils/TranslatorManager.php
@@ -1,9 +1,8 @@
<?php

/**
* Created by PhpStorm.
* User: jmolivas
* Date: 1/2/17
* Time: 2:27 PM
* @file
* Contains \Drupal\Console\Utils\TranslatorManager.
*/

namespace Drupal\Console\Utils;
Expand Down

0 comments on commit 84dcc4c

Please sign in to comment.