Skip to content

Commit

Permalink
php stan (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleswita authored May 27, 2022
1 parent 4843099 commit cea48ff
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
43 changes: 43 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,46 @@ parameters:
count: 1
message: '#^Result of && is always false\.$#'
path: 'src/Latte/Macros.php'

# -------------------------------------------------------------------
# for back compatibility with old packages - will be remove in future
# -------------------------------------------------------------------
-
message: """
#^Fetching class constant class of deprecated class Nette\\\\Bridges\\\\ApplicationLatte\\\\ILatteFactory\\:
use Nette\\\\Bridges\\\\ApplicationLatte\\\\LatteFactory$#
"""
count: 1
path: src/DI/TranslationExtension.php

-
message: """
#^Fetching class constant class of deprecated class Nette\\\\Localization\\\\ITranslator\\:
use Nette\\\\Localization\\\\Translator$#
"""
count: 2
path: src/DI/TranslationExtension.php

-
count: 1
message: """
#^Parameter \\$translator of method Contributte\\\\Translation\\\\Latte\\\\Filters\\:\\:__construct\\(\\) has typehint with deprecated interface Nette\\\\Localization\\\\ITranslator\\:
use Nette\\\\Localization\\\\Translator$#
"""
path: src/Latte/Filters.php

-
count: 1
message: """
#^Class Contributte\\\\Translation\\\\PrefixedTranslator implements deprecated interface Nette\\\\Localization\\\\ITranslator\\:
use Nette\\\\Localization\\\\Translator$#
"""
path: src/PrefixedTranslator.php

-
count: 1
message: """
#^Class Contributte\\\\Translation\\\\Translator implements deprecated interface Nette\\\\Localization\\\\ITranslator\\:
use Nette\\\\Localization\\\\Translator$#
"""
path: src/Translator.php
14 changes: 9 additions & 5 deletions src/DI/TranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,28 +251,32 @@ public function beforeCompile(): void

if (count($this->config->dirs) > 0) {
foreach ($this->config->loaders as $k1 => $v1) {
foreach (Finder::find('*.' . $k1)->from($this->config->dirs) as $v2) {
$match = Strings::match($v2->getFilename(), '~^(?P<domain>.*?)\.(?P<locale>[^\.]+)\.(?P<format>[^\.]+)$~');
/** @var array<\SplFileInfo> $finder */
$finder = Finder::find('*.' . $k1)
->from($this->config->dirs);

foreach ($finder as $fileInfo) {
$match = Strings::match($fileInfo->getFilename(), '~^(?P<domain>.*?)\.(?P<locale>[^\.]+)\.(?P<format>[^\.]+)$~');

if ($match === null) {
continue;
}

if ($whitelistRegexp !== null && Strings::match($match['locale'], $whitelistRegexp) === null) {
if (isset($tracyPanel)) {
$tracyPanel->addSetup('addIgnoredResource', [$v2->getPathname(), $match['locale'], $match['domain']]);
$tracyPanel->addSetup('addIgnoredResource', [$fileInfo->getPathname(), $match['locale'], $match['domain']]);
}

continue;
}

$translator->addSetup('addResource', [$match['format'], $v2->getPathname(), $match['locale'], $match['domain']]);
$translator->addSetup('addResource', [$match['format'], $fileInfo->getPathname(), $match['locale'], $match['domain']]);

if (!isset($tracyPanel)) {
continue;
}

$tracyPanel->addSetup('addResource', [$v2->getPathname(), $match['locale'], $match['domain']]);
$tracyPanel->addSetup('addResource', [$fileInfo->getPathname(), $match['locale'], $match['domain']]);
}
}
}
Expand Down

0 comments on commit cea48ff

Please # to comment.