Skip to content

Commit

Permalink
Use PhpStan level 9 rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Nov 3, 2021
1 parent ad5f198 commit d402c65
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 68 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"scripts": {
"phpstan": [
"vendor/bin/phpstan analyse src -c phpstan.neon --level 8 --no-progress"
"vendor/bin/phpstan analyse src -c phpstan.neon --level 9 --no-progress"
]
},
"minimum-stability": "stable"
Expand Down
45 changes: 32 additions & 13 deletions src/DomainAndLocaleTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,19 @@ private function editDomain(Domain $domain): void


/**
* @return mixed[][]
* @return array<int, array{
* id: int,
* locale: string,
* default: bool,
* active: bool,
* position: int,
* insertedDate: \DateTimeInterface
* }>
*/
private function selectLocales(): array
{
try {
/** @phpstan-ignore-next-line */
return $this->entityManager->getRepository(Locale::class)
->createQueryBuilder('locale')
->select('PARTIAL locale.{id, locale, default, active, position, insertedDate}')
Expand All @@ -271,8 +279,14 @@ private function selectLocales(): array
/**
* Render current locale table and return count of locales.
*
* @param mixed[][] $locales
* @return int
* @param array<int, array{
* id: int,
* locale: string,
* default: bool,
* active: bool,
* position: int,
* insertedDate: \DateTimeInterface
* }> $locales
*/
private function renderLocaleTable(array $locales): int
{
Expand All @@ -281,19 +295,11 @@ private function renderLocaleTable(array $locales): int
echo '|--------|---------|--------|----------|------------------|' . "\n";

foreach ($locales as $locale) {
$insertedDateCol = $locale['insertedDate'];
if ($insertedDateCol instanceof \DateTime) {
/** @var \DateTime $insertedDateCol */
$insertedDate = $insertedDateCol->format('Y-m-d H:i');
} else {
$insertedDate = (string) $insertedDateCol;
}

echo '|' . str_pad($locale['locale'], 8, ' ', STR_PAD_BOTH);
echo '|' . str_pad($locale['default'] ? 'y' : 'n', 9, ' ', STR_PAD_BOTH);
echo '|' . str_pad($locale['active'] ? 'y' : 'n', 8, ' ', STR_PAD_BOTH);
echo '|' . str_pad((string) $locale['position'], 10, ' ', STR_PAD_BOTH);
echo '|' . str_pad($insertedDate, 18, ' ', STR_PAD_BOTH);
echo '|' . str_pad($locale['insertedDate']->format('Y-m-d H:i'), 18, ' ', STR_PAD_BOTH);
echo '|' . "\n";
}

Expand All @@ -312,7 +318,20 @@ private function renderDomainTable(): int

echo "\n\n" . 'CURRENT DOMAIN TABLE:' . "\n\n";

/** @var mixed[][]|mixed[][][] $domains */
/** @var array<int, array{
* id: int,
* environment: string,
* https: bool,
* www: bool,
* protectedPassword: string|null,
* protected: bool,
* default: bool,
* insertedDate: \DateTimeInterface,
* updatedDate: \DateTimeInterface,
* domain: string,
* locale: array{id: int, locale: string}|null
* }> $domains
*/
$domains = $this->entityManager->getRepository(Domain::class)
->createQueryBuilder('domain')
->select('PARTIAL domain.{id, environment, https, www, protectedPassword, protected, default, insertedDate, updatedDate, domain}')
Expand Down
80 changes: 40 additions & 40 deletions src/Entity/LocalizationStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,62 @@

final class LocalizationStatus
{
/** @var string[] */
/** @var array<int, string> */
private array $availableLocales;

private string $defaultLocale;

/** @var string[][] */
/** @var array<string, array<int, string>> */
private array $fallbackLocales;

/** @var string[]|null[] */
/** @var array<string, string|null> */
private array $localeToTitleSuffix;

/** @var string[]|null[] */
/** @var array<string, string|null> */
private array $localeToTitleSeparator;

/** @var string[]|null[] */
/** @var array<string, string|null> */
private array $localeToTitleFormat;

/** @var string[]|null[] */
/** @var array<string, string|null> */
private array $localeToSiteName;

/** @var string[] */
/** @var array<string, string> */
private array $domainToLocale;

/** @var string[] */
/** @var array<string, string> */
private array $domainToEnvironment;

/** @var bool[] */
/** @var array<string, bool> */
private array $domainToProtected;

/** @var string[] */
/** @var array<string, string> */
private array $domainToScheme;

/** @var bool[] */
/** @var array<string, bool> */
private array $domainToUseWww;

/** @var string[][] */
/** @var array<string, array<string, string>> */
private array $domainByEnvironment;

/** @var mixed[][]|mixed[][][] */
/** @var array<int, array{id: int, locale: array{id: int, locale: string}|null, domain: string, environment: string, protected: bool, https: bool, www: bool, default: bool}> */
private array $domains;


/**
* @param string[] $availableLocales
* @param string[][] $fallbackLocales
* @param string[]|null[] $localeToTitleSuffix
* @param string[]|null[] $localeToTitleSeparator
* @param string[]|null[] $localeToTitleFormat
* @param string[]|null[] $localeToSiteName
* @param string[] $domainToLocale
* @param string[] $domainToEnvironment
* @param bool[] $domainToProtected
* @param string[] $domainToScheme
* @param bool[] $domainToUseWww
* @param string[][] $domainByEnvironment
* @param mixed[][]|mixed[][][] $domains
* @param array<int, string> $availableLocales
* @param array<string, array<int, string>> $fallbackLocales
* @param array<string, string|null> $localeToTitleSuffix
* @param array<string, string|null> $localeToTitleSeparator
* @param array<string, string|null> $localeToTitleFormat
* @param array<string, string|null> $localeToSiteName
* @param array<string, string> $domainToLocale
* @param array<string, string> $domainToEnvironment
* @param array<string, bool> $domainToProtected
* @param array<string, string> $domainToScheme
* @param array<string, bool> $domainToUseWww
* @param array<string, array<string, string>> $domainByEnvironment
* @param array<int, array{id: int, locale: array{id: int, locale: string}|null, domain: string, environment: string, protected: bool, https: bool, www: bool, default: bool}> $domains
*/
public function __construct(
array $availableLocales,
Expand Down Expand Up @@ -98,7 +98,7 @@ public function __construct(


/**
* @return string[]
* @return array<int, string>
*/
public function getAvailableLocales(): array
{
Expand All @@ -113,7 +113,7 @@ public function getDefaultLocale(): string


/**
* @return string[][]
* @return array<string, array<int, string>>
*/
public function getFallbackLocales(): array
{
Expand All @@ -122,7 +122,7 @@ public function getFallbackLocales(): array


/**
* @return string[]|null[]
* @return array<string, string|null>
*/
public function getLocaleToTitleSuffix(): array
{
Expand All @@ -131,7 +131,7 @@ public function getLocaleToTitleSuffix(): array


/**
* @return string[]|null[]
* @return array<string, string|null>
*/
public function getLocaleToTitleSeparator(): array
{
Expand All @@ -140,7 +140,7 @@ public function getLocaleToTitleSeparator(): array


/**
* @return string[]|null[]
* @return array<string, string|null>
*/
public function getLocaleToTitleFormat(): array
{
Expand All @@ -149,16 +149,16 @@ public function getLocaleToTitleFormat(): array


/**
* @return string[]|null[]
* @return array<string, string|null>
*/
public function getLocaleToSiteName(): ?array
public function getLocaleToSiteName(): array
{
return $this->localeToSiteName;
}


/**
* @return string[]
* @return array<string, string>
*/
public function getDomainToLocale(): array
{
Expand All @@ -167,7 +167,7 @@ public function getDomainToLocale(): array


/**
* @return string[]
* @return array<string, string>
*/
public function getDomainToEnvironment(): array
{
Expand All @@ -176,7 +176,7 @@ public function getDomainToEnvironment(): array


/**
* @return bool[]
* @return array<string, bool>
*/
public function getDomainToProtected(): array
{
Expand All @@ -185,7 +185,7 @@ public function getDomainToProtected(): array


/**
* @return string[]
* @return array<string, string>
*/
public function getDomainToScheme(): array
{
Expand All @@ -194,7 +194,7 @@ public function getDomainToScheme(): array


/**
* @return bool[]
* @return array<string, bool>
*/
public function getDomainToUseWww(): array
{
Expand All @@ -203,7 +203,7 @@ public function getDomainToUseWww(): array


/**
* @return string[][]
* @return array<string, array<string, string>>
*/
public function getDomainByEnvironment(): array
{
Expand All @@ -212,7 +212,7 @@ public function getDomainByEnvironment(): array


/**
* @return mixed[][]|mixed[][][]
* @return array<int, array{id: int, locale: array{id: int, locale: string}|null, domain: string, environment: string, protected: bool, https: bool, www: bool, default: bool}>
*/
public function getDomains(): array
{
Expand Down
Loading

0 comments on commit d402c65

Please sign in to comment.