-
-
Notifications
You must be signed in to change notification settings - Fork 220
Fix PhpStan suggestions #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 12 commits
57d7ec8
250c622
e3996eb
ee22c3c
1d8b780
fdaefa2
6060d6c
be818cc
dc60c08
6292e07
ae2c34f
85c9611
3e52f92
75fc178
5129995
8ba795c
982e85e
d66385c
b3218f8
bf35591
0843462
1f4e321
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| namespace Tracy\Bridges\Nette; | ||
|
|
||
| use Nette; | ||
| use Nette\Schema\Expect; | ||
| use Tracy; | ||
|
|
||
|
|
||
|
|
@@ -18,26 +19,6 @@ | |
| */ | ||
| class TracyExtension extends Nette\DI\CompilerExtension | ||
| { | ||
| public $defaults = [ | ||
| 'email' => null, | ||
| 'fromEmail' => null, | ||
| 'logSeverity' => null, | ||
| 'editor' => null, | ||
| 'browser' => null, | ||
| 'errorTemplate' => null, | ||
| 'strictMode' => null, | ||
| 'showBar' => null, | ||
| 'maxLen' => null, | ||
| 'maxLength' => null, | ||
| 'maxDepth' => null, | ||
| 'showLocation' => null, | ||
| 'scream' => null, | ||
| 'bar' => [], // of class name | ||
| 'blueScreen' => [], // of callback | ||
| 'editorMapping' => [], | ||
| 'netteMailer' => true, | ||
| ]; | ||
|
|
||
| /** @var bool */ | ||
| private $debugMode; | ||
|
|
||
|
|
@@ -52,9 +33,31 @@ public function __construct(bool $debugMode = false, bool $cliMode = false) | |
| } | ||
|
|
||
|
|
||
| public function getConfigSchema(): Nette\Schema\Schema | ||
| { | ||
| return Expect::structure([ | ||
| 'email' => Expect::email()->dynamic(), | ||
| 'fromEmail' => Expect::email()->dynamic(), | ||
| 'logSeverity' => Expect::scalar(), | ||
| 'editor' => Expect::string()->dynamic(), | ||
| 'browser' => Expect::string()->dynamic(), | ||
| 'errorTemplate' => Expect::string()->dynamic(), | ||
| 'strictMode' => Expect::bool()->dynamic(), | ||
| 'showBar' => Expect::bool()->dynamic(), | ||
| 'maxLength' => Expect::int()->dynamic(), | ||
| 'maxDepth' => Expect::int()->dynamic(), | ||
| 'showLocation' => Expect::bool()->dynamic(), | ||
| 'scream' => Expect::bool()->dynamic(), | ||
| 'bar' => Expect::listOf('class|Nette\DI\Definitions\Statement'), | ||
| 'blueScreen' => Expect::listOf('callable'), | ||
| 'editorMapping' => Expect::arrayOf('string')->dynamic(), | ||
| 'netteMailer' => Expect::bool(true), | ||
| ]); | ||
| } | ||
|
|
||
|
|
||
| public function loadConfiguration() | ||
| { | ||
| $this->validateConfig($this->defaults); | ||
| $builder = $this->getContainerBuilder(); | ||
|
|
||
| $builder->addDefinition($this->prefix('logger')) | ||
|
|
@@ -74,7 +77,7 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class) | |
| $initialize = $class->getMethod('initialize'); | ||
| $builder = $this->getContainerBuilder(); | ||
|
|
||
| $options = $this->config; | ||
| $options = (array) $this->config; | ||
| unset($options['bar'], $options['blueScreen'], $options['netteMailer']); | ||
| if (isset($options['logSeverity'])) { | ||
| $res = 0; | ||
|
|
@@ -94,21 +97,23 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class) | |
| } | ||
|
|
||
| $logger = $builder->getDefinition($this->prefix('logger')); | ||
| if ($logger->getFactory()->getEntity() !== [Tracy\Debugger::class, 'getLogger']) { | ||
| if (!$logger instanceof Nette\DI\ServiceDefinition || $logger->getFactory()->getEntity() !== [Tracy\Debugger::class, 'getLogger']) { | ||
| $initialize->addBody($builder->formatPhp('Tracy\Debugger::setLogger(?);', [$logger])); | ||
| } | ||
| if ($this->config['netteMailer'] && $builder->getByType(Nette\Mail\IMailer::class)) { | ||
| if ($this->config->netteMailer && $builder->getByType(Nette\Mail\IMailer::class)) { | ||
| $initialize->addBody($builder->formatPhp('Tracy\Debugger::getLogger()->mailer = ?;', [ | ||
| [new Nette\DI\Statement(Tracy\Bridges\Nette\MailSender::class, ['fromEmail' => $this->config['fromEmail']]), 'send'], | ||
| [new Nette\DI\Statement(Tracy\Bridges\Nette\MailSender::class, ['fromEmail' => $this->config->fromEmail]), 'send'], | ||
| ])); | ||
| } | ||
|
|
||
| if ($this->debugMode) { | ||
| foreach ((array) $this->config['bar'] as $item) { | ||
| if (is_string($item) && substr($item, 0, 1) === '@') { | ||
| $item = new Nette\DI\Statement(['@' . $builder::THIS_CONTAINER, 'getService'], [substr($item, 1)]); | ||
| } elseif (is_string($item)) { | ||
| $item = new Nette\DI\Statement($item); | ||
| foreach ($this->config->bar as $item) { | ||
| if (is_string($item)) { | ||
|
||
| if ($item[0] ?? '' === '@') { | ||
| $item = new Nette\DI\Statement(['@' . $builder::THIS_CONTAINER, 'getService'], [substr($item, 1)]); | ||
| } else { | ||
| $item = new Nette\DI\Statement($item); | ||
| } | ||
| } | ||
| $initialize->addBody($builder->formatPhp( | ||
| '$this->getService(?)->addPanel(?);', | ||
|
|
@@ -122,7 +127,7 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class) | |
| } | ||
| } | ||
|
|
||
| foreach ((array) $this->config['blueScreen'] as $item) { | ||
| foreach ($this->config->blueScreen as $item) { | ||
| $initialize->addBody($builder->formatPhp( | ||
| '$this->getService(?)->addPanel(?);', | ||
| Nette\DI\Helpers::filterArguments([$this->prefix('blueScreen'), $item]) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,6 +179,7 @@ private function asHtml($var): string | |
| ' title="%in file % on line %" data-tracy-href="%"', "$code\n", $file, $line, Helpers::editorUri($file, $line) | ||
| ) : null; | ||
|
|
||
| $options = []; | ||
| if (is_array($this->snapshot)) { | ||
| $options[self::SNAPSHOT] = &$this->snapshot; | ||
| } | ||
|
|
@@ -517,7 +518,7 @@ public static function encodeString(string $s, int $maxLength = null): string | |
| $i = $len = 0; | ||
| $maxI = $maxLength * 4; // max UTF-8 length | ||
| do { | ||
| if (($s[$i] < "\x80" || $s[$i] >= "\xC0") && (++$len > $maxLength) || $i >= $maxI) { | ||
| if (($s[$i] < "\x80" || $s[$i] >= "\xC0") && ((++$len > $maxLength) || $i >= $maxI)) { | ||
|
||
| $s = substr($s, 0, $i); | ||
| $shortened = true; | ||
| break; | ||
|
|
@@ -539,7 +540,7 @@ public static function encodeString(string $s, int $maxLength = null): string | |
|
|
||
|
|
||
| /** | ||
| * @param int|string $k | ||
| * @param int|string $key | ||
| * @return int|string | ||
| */ | ||
| private function encodeKey($key) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.