Skip to content

Commit

Permalink
add phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
cevro committed Jul 27, 2023
1 parent 6c299c7 commit a5ecc4b
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 11 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
},
"require-dev": {
"squizlabs/php_codesniffer": "3.6.0",
"nette/tester": "^v2.4.0"
"nette/tester": "^v2.4.0",
"phpstan/phpstan": "1.10.26"
},
"authors": [
{
Expand Down
64 changes: 63 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 9
paths:
- src
- tests
10 changes: 7 additions & 3 deletions src/BaseComponent/BaseComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

namespace Fykosak\Utils\BaseComponent;

use Fykosak\Utils\Localization\GettextTranslator;
use Nette\Application\UI\{Control, Template};
use Nette\DI\Container;
use Nette\Localization\Translator;

/**
* @property \Nette\Bridges\ApplicationLatte\Template $template
*/
abstract class BaseComponent extends Control
{
protected Container $container;
protected ?Translator $translator;
protected ?GettextTranslator $translator;

public function __construct(Container $container)
{
Expand All @@ -24,13 +27,14 @@ protected function getContext(): Container
return $this->container;
}

public function injectTranslator(?Translator $translator): void
public function injectTranslator(?GettextTranslator $translator): void
{
$this->translator = $translator;
}

protected function createTemplate(): Template
{
/** @var \Nette\Bridges\ApplicationLatte\Template $template */
$template = parent::createTemplate();
$template->setTranslator($this->translator);
return $template;
Expand Down
8 changes: 5 additions & 3 deletions src/Localization/GettextTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

class GettextTranslator implements Translator
{
/** @var array[lang] => locale */
/** @phpstan-var array<string,string> */
public array $locales;
private string $localeDir;
public ?string $lang = null;

/**
* @phpstan-param array<string,string> $locales
*/
public function __construct(array $locales, string $localeDir)
{
$this->locales = $locales;
Expand Down Expand Up @@ -50,8 +53,7 @@ public function getSupportedLanguages(): array

/**
* @param mixed|string $message
* @param array $parameters
* @return string
* @param string|int $parameters
*/
public function translate($message, ...$parameters): string
{
Expand Down
6 changes: 6 additions & 0 deletions src/Localization/LocalizedString.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

class LocalizedString
{
/**
* @phpstan-var array<string,string>
*/
private array $texts;

/**
* @phpstan-param array<string,string> $texts
*/
public function __construct(array $texts)
{
$this->texts = $texts;
Expand Down
1 change: 1 addition & 0 deletions src/Logging/MemoryLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class MemoryLogger implements Logger
{
/** @var Message[] */
private array $messages = [];

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Logging/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public function __construct(string $message, string $level)
$this->level = $level;
}

/**
* @phpstan-return array{'text':string,'level':string}
*/
public function __toArray(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions src/Price/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public function __construct(string $currency)
$this->value = $currency;
}

/**
* @return self[]
*/
public static function cases(): array
{
return [new self(self::CZK), new self(self::EUR)];
Expand Down
3 changes: 3 additions & 0 deletions src/Price/MultiCurrencyPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ final class MultiCurrencyPrice
/** @var Price[] */
private array $prices = [];

/**
* @param Price[]|null $prices
*/
public function __construct(?array $prices = [])
{
foreach ($prices as $price) {
Expand Down
5 changes: 5 additions & 0 deletions src/UI/Navigation/NavItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ class NavItem
use SmartObject;

public string $destination;
/** @phpstan-var array<string,int|string|bool> */
public array $linkParams;
public Title $title;
/** @var NavItem[] */
public array $children;
public bool $active;

/**
* @phpstan-param array<string,int|string|bool> $linkParams
* @phpstan-param NavItem[] $children
*/
public function __construct(
Title $title,
string $destination = '#',
Expand Down
3 changes: 1 addition & 2 deletions src/UI/Navigation/NavigationItemComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class NavigationItemComponent extends BaseComponent
{
public function render(NavItem $item): void
{
$this->template->item = $item;
$this->template->render(__DIR__ . DIRECTORY_SEPARATOR . 'navigationItem.latte');
$this->template->render(__DIR__ . DIRECTORY_SEPARATOR . 'navigationItem.latte', ['item' => $item]);
}
}
1 change: 0 additions & 1 deletion src/UI/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
class Title
{
public string $title;

public ?string $icon;
public ?string $id;

Expand Down

0 comments on commit a5ecc4b

Please sign in to comment.