diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8a7996 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +composer.lock +vendor/ diff --git a/.travis.yml b/.travis.yml index 193d0c3..9fa3cad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,10 @@ -language: php -php: - - 7.1 - - 7.2 - - 7.3 - - 7.4 +language: minimal +env: + - PHP_VERSION=7.4-dev + - PHP_VERSION=8.0-dev script: - - vendor/bin/phpstan analyse -l 5 src + - docker run --rm -it -v "$PWD":/var/www/html peckadesign/php:${PHP_VERSION} vendor/bin/phpstan analyse -l 7 src/ before_script: - - travis_retry composer install --no-interaction --prefer-dist - -sudo: false - -cache: - directories: - - $HOME/.composer/cache + - docker run --rm -it -v "$PWD":/var/www/html peckadesign/php:${PHP_VERSION} composer install --no-interaction --prefer-dist diff --git a/composer.json b/composer.json index 97f6703..93c1f91 100644 --- a/composer.json +++ b/composer.json @@ -16,10 +16,11 @@ } ], "require": { - "tracy/tracy": "~2.4.18" + "php": "7.4.* || 8.0.*", + "tracy/tracy": ">= 2.4.18" }, "require-dev": { - "phpstan/phpstan": "0.12.11" + "phpstan/phpstan": "0.12.*" }, "autoload": { "psr-0": { diff --git a/src/Pd/Diagnostics/DatabaseInfoPanel.php b/src/Pd/Diagnostics/DatabaseInfoPanel.php index 34bdf82..053466a 100644 --- a/src/Pd/Diagnostics/DatabaseInfoPanel.php +++ b/src/Pd/Diagnostics/DatabaseInfoPanel.php @@ -10,21 +10,20 @@ */ class DatabaseInfoPanel implements Tracy\IBarPanel { - /** @var string[] $databaseParams [{key => val}] */ - private $databaseParams; + /** @var array */ + private array $databaseParams; - /** @var string[] */ - private $possibleDbNameKeys = array('dbname', 'database'); + /** @var array */ + private array $possibleDbNameKeys = ['dbname', 'database']; - /** @var IDatabaseInfoPanelStyleHandler|NULL */ - private $styleCallback; + private ?IDatabaseInfoPanelStyleHandler$styleCallback; /** - * @param string[] $databaseParams All database parameters in [{key => val}] format - * @param string|NULL $customDbNameKey Custom key of DB name value - * @param IDatabaseInfoPanelStyleHandler $styleCallback Handler with formating of DB name label in panel + * @param array $databaseParams All database parameters in [{key => val}] format + * @param string|null $customDbNameKey Custom key of DB name value + * @param IDatabaseInfoPanelStyleHandler|null $styleCallback Handler with formating of DB name label in panel */ - public function __construct(array $databaseParams, $customDbNameKey = NULL, IDatabaseInfoPanelStyleHandler $styleCallback = NULL) + public function __construct(array $databaseParams, ?string $customDbNameKey = NULL, ?IDatabaseInfoPanelStyleHandler $styleCallback = NULL) { $this->setDatabaseParams($databaseParams); @@ -34,14 +33,17 @@ public function __construct(array $databaseParams, $customDbNameKey = NULL, IDat } - private function setDatabaseParams(array $databaseParams) + /** + * @param array $databaseParams + */ + private function setDatabaseParams(array $databaseParams): void { if (array_key_exists('password', $databaseParams)) unset($databaseParams['password']); $this->databaseParams = $databaseParams; } - private function getDatabaseName() + private function getDatabaseName(): string { foreach ($this->possibleDbNameKeys as $key) { if (array_key_exists($key, $this->databaseParams)) return $this->databaseParams[$key]; @@ -50,7 +52,7 @@ private function getDatabaseName() } - public function getTab() + public function getTab(): string { if ($this->styleCallback) $style = ' style="' . $this->styleCallback->getStyle($this->getDatabaseName(), $this->databaseParams) . '"'; else $style = ''; @@ -62,10 +64,11 @@ public function getTab() } - public function getPanel() + public function getPanel(): string { ob_start(); include __DIR__ . '/DatabaseInfoPanel.phtml'; - return ob_get_clean(); + return (string) ob_get_clean(); } + } diff --git a/src/Pd/Diagnostics/IDatabaseInfoPanelStyleHandler.php b/src/Pd/Diagnostics/IDatabaseInfoPanelStyleHandler.php index 23f7cb0..ff8f56f 100644 --- a/src/Pd/Diagnostics/IDatabaseInfoPanelStyleHandler.php +++ b/src/Pd/Diagnostics/IDatabaseInfoPanelStyleHandler.php @@ -10,9 +10,9 @@ interface IDatabaseInfoPanelStyleHandler { /** - * @var string $databaseName Database name - * @var string[] $databaseParams All database parameters + * @param string $databaseName Database name + * @param array $databaseParams All database parameters * @return string Content of DB name label style atribut */ - public function getStyle($databaseName, $databaseParams); + public function getStyle(string $databaseName, array $databaseParams): string; }