Skip to content

Commit

Permalink
Fix minor corrections. (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Oct 7, 2023
1 parent ab77cde commit 1c6b5a3
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 79 deletions.
29 changes: 10 additions & 19 deletions src/FlattenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,27 @@ class FlattenException
/**
* @var string
*/
protected string $message;
protected string $message = '';
/**
* @var int|mixed
*/
protected mixed $code;
protected mixed $code = null;
/**
* @var string
*/
protected string $file;
protected string $file = '';
/**
* @var int
*/
protected int $line;
protected int $line = 0;

/**
* @var FlattenException|null
*/
private ?FlattenException $_previous;
/**
* @var array
*/
private array $_trace;
/**
* @var string
*/
private string $_toString;
/**
* @var string
*/
private string $_class;
private FlattenException|null $_previous = null;
private array $_trace = [];
private string $_toString = '';
private string $_class = '';

/**
* FlattenException constructor.
Expand Down Expand Up @@ -138,9 +129,9 @@ public function getTrace(): array
/**
* Returns previous Exception
*
* @return FlattenException the previous `FlattenException` if available or null otherwise.
* @return FlattenException|null the previous `FlattenException` if available or null otherwise.
*/
public function getPrevious(): ?self
public function getPrevious(): self|null
{
return $this->_previous;
}
Expand Down
5 changes: 3 additions & 2 deletions src/LogTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ class LogTarget extends Target
/**
* @var string
*/
public string $tag;
public string $tag = '';

/**
* @param Module $module
* @param array $config
*/
public function __construct($module, array $config = [])
public function __construct(Module $module, array $config = [])
{
parent::__construct($config);

$this->module = $module;
$this->tag = uniqid();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Module extends \yii\base\Module implements BootstrapInterface
* This value will be used by PHP [[chmod()]] function. No umask will be applied.
* If not set, the permission will be determined by the current environment.
*/
public int $fileMode;
public int $fileMode = 0666;
/**
* @var int the permission to be set for newly created directories.
* This value will be used by PHP [[chmod()]] function. No umask will be applied.
Expand Down
25 changes: 16 additions & 9 deletions src/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ class Panel extends Component
* @var string panel unique identifier.
* It is set automatically by the container module.
*/
public string $id;
public string $id = '';
/**
* @var string request data set identifier.
*/
public string $tag;
/**
* @var Module
*/
public Module $module;
public string $tag = '';
public Module|null $module = null;
/**
* @var mixed data associated with panel
*/
Expand All @@ -46,7 +43,7 @@ class Panel extends Component
/**
* @var FlattenException|null Error while saving the panel
*/
protected FlattenException|null $error;
protected FlattenException|null $error = null;

/**
* @return string name of the panel
Expand Down Expand Up @@ -101,7 +98,7 @@ public function load(mixed $data): void
public function getUrl(array $additionalParams = null): string
{
$route = [
'/' . $this->module->getUniqueId() . '/default/view',
'/' . $this->module?->getUniqueId() . '/default/view',
'panel' => $this->id,
'tag' => $this->tag,
];
Expand All @@ -122,10 +119,16 @@ public function getUrl(array $additionalParams = null): string
*/
public function getTraceLine(array $options): string
{
if ($this->module === null) {
return '';
}

if (!isset($options['text'])) {
$options['text'] = "{$options['file']}:{$options['line']}";
}

$traceLine = $this->module->traceLine;

if ($traceLine === false) {
return $options['text'];
}
Expand All @@ -142,6 +145,7 @@ public function getTraceLine(array $options): string
}

$rawLink = $traceLine instanceof Closure ? $traceLine($options, $this) : $traceLine;

return strtr($rawLink, ['{file}' => $options['file'], '{line}' => $options['line'], '{text}' => $options['text']]);
}

Expand Down Expand Up @@ -192,7 +196,6 @@ public function isEnabled(): bool
*
* @return array the filtered messages.
*
* @since 2.1.4
* @see \yii\log\Target::filterMessages()
*/
protected function getLogMessages(
Expand All @@ -201,6 +204,10 @@ protected function getLogMessages(
array $except = [],
bool $stringify = false
): array {
if ($this->module === null) {
return [];
}

$target = $this->module->logTarget;
$messages = $target->filterMessages(...);

Expand Down
2 changes: 1 addition & 1 deletion src/components/search/matchers/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class Base extends Component implements MatcherInterface
/**
* @var mixed base value to check
*/
protected mixed $baseValue;
protected mixed $baseValue = null;

/**
* {@inheritdoc}
Expand Down
5 changes: 3 additions & 2 deletions src/components/search/matchers/SameAs.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ public function match(mixed $value): bool
if (!is_scalar($value)) {
$value = VarDumper::export($value);
}

if ($this->partial) {
return mb_stripos($value, $this->baseValue, 0, Yii::$app->charset) !== false;
}

return strcmp(
mb_strtoupper($this->baseValue, Yii::$app->charset),
mb_strtoupper($value, Yii::$app->charset)
mb_strtoupper((string) $this->baseValue, Yii::$app->charset),
mb_strtoupper((string) $value, Yii::$app->charset)
) === 0;
}
}
15 changes: 8 additions & 7 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,17 @@ class DefaultController extends Controller
/**
* @var array the summary data (e.g. URL, time)
*/
public array $summary;
public array $summary = [];

/**
* @var array
*/
private array $_manifest;
private array $_manifest = [];

/**
* {@inheritdoc}
*/
public function actions(): array
{
$actions = [];

foreach ($this->module->panels as $panel) {
$actions = array_merge($actions, $panel->actions);
}
Expand Down Expand Up @@ -181,8 +179,11 @@ public function actionDownloadMail(string $file): Response|\yii\console\Response
*/
protected function getManifest(bool $forceReload = false): array
{
if ($forceReload) {
clearstatcache();
if ($this->_manifest === [] || $forceReload) {
if ($forceReload) {
clearstatcache();
}

$this->_manifest = $this->module->logTarget->loadManifest();
}

Expand Down
12 changes: 4 additions & 8 deletions src/panels/DbPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DbPanel extends Panel
* If the number of queries exceeds this number, the execution is considered taking critical number of DB queries.
* If it is `null`, this feature is disabled.
*/
public int|null $criticalQueryThreshold;
public int|null $criticalQueryThreshold = null;
/**
* @var int|null the number of DB calls the same backtrace can make before considered an "Excessive Caller."
* If it is `null`, this feature is disabled.
Expand Down Expand Up @@ -67,27 +67,23 @@ class DbPanel extends Panel
/**
* @var array the default filter to apply to the database queries. In the format
* of [ property => value ], for example: [ 'type' => 'SELECT' ]
*
* @since 2.0.7
*/
public array $defaultFilter = [];
/**
* @var array db queries info extracted to array as models, to use with data provider.
*/
private array $_models;
private array $_models = [];
/**
* @var array current database request timings
*/
private array $_timings;
private array $_timings = [];
/**
* @var array current database profile logs
*/
private array $_profileLogs;
private array $_profileLogs = [];

/**
* @var array of event names used to get profile logs.
*
* @since 2.1.17
*/
public array $dbEventNames = ['yii\db\Command::query', 'yii\db\Command::execute'];

Expand Down
2 changes: 1 addition & 1 deletion src/panels/DumpPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DumpPanel extends Panel
/**
* @var array log messages extracted to array as models, to use with data provider.
*/
private array $_models;
private array $_models = [];

/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion src/panels/LogPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LogPanel extends Panel
/**
* @var array log messages extracted to array as models, to use with data provider.
*/
private array $_models;
private array $_models = [];

/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion src/panels/ProfilingPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ProfilingPanel extends Panel
/**
* @var array current request profile timings
*/
private array $_models;
private array $_models = [];

/**
* {@inheritdoc}
Expand Down
2 changes: 0 additions & 2 deletions src/panels/RequestPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class RequestPanel extends Panel
public array $censoredVariableNames = [];
/**
* @var string value to display instead of the variable value if the name is on the censor list
*
* @since 2.1.20
*/
public string $censorString = '****';

Expand Down
3 changes: 0 additions & 3 deletions src/panels/RouterPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
*/
class RouterPanel extends Panel
{
/**
* @var array
*/
private array $_categories = [
'yii\web\UrlManager::parseRequest',
'yii\web\UrlRule::parseRequest',
Expand Down
13 changes: 7 additions & 6 deletions src/panels/TimelinePanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ class TimelinePanel extends Panel
/**
* @var array log messages extracted to array as models, to use with data provider.
*/
private array $_models;
private array $_models = [];
/**
* @var float Start request, timestamp (obtained by microtime(true))
*/
private float $_start;
private float $_start = 0;
/**
* @var float End request, timestamp (obtained by microtime(true))
*/
private float $_end;
private float $_end = 0;
/**
* @var float Request duration, milliseconds
*/
private float $_duration;
private float $_duration = 0;
/**
* @var Svg|null
*/
private Svg|null $_svg;
private Svg|null $_svg = null;
/**
* @var array
*/
Expand All @@ -61,7 +61,7 @@ class TimelinePanel extends Panel
/**
* @var int Used memory in request
*/
private int $_memory;
private int $_memory = 0;

/**
* {@inheritdoc}
Expand Down Expand Up @@ -174,6 +174,7 @@ public function setSvgOptions(array $options): void
if ($this->_svg !== null) {
$this->_svg = null;
}

$this->_svgOptions = array_merge($this->_svgOptions, $options);
}

Expand Down
13 changes: 7 additions & 6 deletions src/views/default/panels/event/detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
'columns' => [
[
'attribute' => 'time',
'value' => static function ($data) {
$timeInSeconds = floor($data['time']);
$millisecondsDiff = (($data['time'] - (int)$timeInSeconds) * 1000);
'value' => static function ($data): string {
$timeInSeconds = (int) floor($data['time']);
$millisecondsDiff = (($data['time'] - $timeInSeconds) * 1000);

return date('H:i:s.', $timeInSeconds) . sprintf('%03d', $millisecondsDiff);
},
'headerOptions' => [
Expand All @@ -48,17 +49,17 @@
],
[
'attribute' => 'name',
/*'headerOptions' => [
'headerOptions' => [
'class' => 'sort-numerical'
],*/
],
],
[
'attribute' => 'class',
],
[
'header' => 'Sender',
'attribute' => 'senderClass',
'value' => static function ($data) {
'value' => static function ($data): string {
return $data['senderClass'];
},
],
Expand Down
Loading

0 comments on commit 1c6b5a3

Please sign in to comment.