Skip to content

Commit

Permalink
Fix phpstan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
magicsunday committed Feb 3, 2025
1 parent fff3b45 commit fbcbb93
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 185 deletions.
1 change: 1 addition & 0 deletions Build/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ parameters:
excludePaths:
- %currentWorkingDirectory%/.build/*
- %currentWorkingDirectory%/ext_emconf.php
- %currentWorkingDirectory%/Configuration/Backend/Modules.php

treatPhpDocTypesAsCertain: false
26 changes: 13 additions & 13 deletions Classes/Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

use Netresearch\NrTextdb\Domain\Repository\TranslationRepository;
use Netresearch\NrTextdb\Service\ImportService;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -26,11 +24,11 @@
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException;
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;
use TYPO3\CMS\Extensionmanager\Utility\ListUtility;

use function count;
use function sprintf;

/**
* Class ImportCommand.
Expand All @@ -39,10 +37,8 @@
* @license Netresearch https://www.netresearch.de
* @link https://www.netresearch.de
*/
class ImportCommand extends Command implements LoggerAwareInterface
class ImportCommand extends Command
{
use LoggerAwareTrait;

/**
* Path for the language file within an extension.
*
Expand All @@ -53,7 +49,7 @@ class ImportCommand extends Command implements LoggerAwareInterface
/**
* @var PersistenceManagerInterface
*/
private PersistenceManagerInterface $persistenceManager;
private readonly PersistenceManagerInterface $persistenceManager;

/**
* @var TranslationRepository
Expand All @@ -78,7 +74,7 @@ class ImportCommand extends Command implements LoggerAwareInterface
/**
* @var ImportService
*/
private ImportService $importService;
private readonly ImportService $importService;

/**
* Constructor.
Expand Down Expand Up @@ -123,7 +119,7 @@ protected function configure(): void
$this
->setDescription('Imports textdb records from language files')
->setHelp(
'If you want to add textdb records to your extension. Create a file languagecode.textdb_import.xlf'
'If you want to add textdb records to your extension. Create a file <LanguageCode>.textdb_import.xlf'
)
->addArgument(
'extensionKey',
Expand All @@ -142,7 +138,6 @@ protected function configure(): void
*
* @return int
*
* @throws IllegalObjectTypeException
* @throws UnknownPackageException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down Expand Up @@ -229,8 +224,6 @@ protected function getLanguageKeyFromFile(string $file): string
* @param bool $forceUpdate
*
* @return void
*
* @throws IllegalObjectTypeException
*/
protected function importTranslationsFromFiles(OutputInterface $output, bool $forceUpdate = false): void
{
Expand Down Expand Up @@ -318,7 +311,14 @@ protected function importFile(
$languageKey = $this->getLanguageKeyFromFile($file);
$languageUid = $this->getLanguageId($languageKey);

$output->writeln(sprintf('Import translations from file %s for language %s (%d)', $file, $languageKey, $languageUid));
$output->writeln(
sprintf(
'Import translations from file %s for language %s (%d)',
$file,
$languageKey,
$languageUid
)
);

$this->importService
->importFile(
Expand Down
21 changes: 11 additions & 10 deletions Classes/Controller/TranslationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private function moduleResponse(): ResponseInterface
}

/**
* Shows the textDB entires.
* Shows the textDB entries.
*
* @return ResponseInterface
*
Expand Down Expand Up @@ -468,6 +468,7 @@ public function exportAction(): ResponseInterface
}
}

/** @var ZipArchive $archive */
$archive = GeneralUtility::makeInstance(ZipArchive::class);

if ($archive->open($archivePath, ZipArchive::CREATE) !== true) {
Expand Down Expand Up @@ -548,7 +549,7 @@ private function getExportFileNameForLanguage(SiteLanguage $language): string
}

/**
* Import translations from file.
* Import translations from a file.
*
* @param bool $update Check if entries should be updated
*
Expand Down Expand Up @@ -678,7 +679,7 @@ public function importAction(bool $update = false): ResponseInterface
}

/**
* Get the component from key.
* Get the component from a key.
*
* @param string $key
*
Expand Down Expand Up @@ -766,11 +767,11 @@ private function persistConfigInBeUserData(array $config): void
/**
* Write the translation file for export and returns the uid of entries written to file.
*
* @param SiteLanguage $language
* @param QueryResultInterface $translations
* @param string $exportDir
* @param string $filename
* @param bool $enableTargetMarker
* @param SiteLanguage $language
* @param QueryResultInterface<Translation> $translations
* @param string $exportDir
* @param string $filename
* @param bool $enableTargetMarker
*
* @return int[]
*/
Expand Down Expand Up @@ -924,8 +925,8 @@ private function getBackendUser(): BackendUserAuthentication
* - pagination disabled
* - itemsPerPage = 10
*
* @param QueryResultInterface $items
* @param array<string, int|bool> $settings
* @param QueryResultInterface<Translation> $items
* @param array<string, int|bool> $settings
*
* @return array<string, mixed>
*/
Expand Down
9 changes: 5 additions & 4 deletions Classes/Domain/Repository/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Exception;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;

/**
Expand All @@ -24,9 +25,9 @@
* @license Netresearch https://www.netresearch.de
* @link https://www.netresearch.de
*
* @template T of \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface
* @template T of DomainObjectInterface
*
* @extends Repository<T>
* @extends Repository<T>
*/
class AbstractRepository extends Repository
{
Expand Down Expand Up @@ -70,9 +71,9 @@ public function getConfiguredPageId(): int
*
* @param bool $createIfMissing
*
* @return $this
* @return static
*/
public function setCreateIfMissing(bool $createIfMissing): self
public function setCreateIfMissing(bool $createIfMissing): static
{
$this->createIfMissing = $createIfMissing;

Expand Down
2 changes: 2 additions & 0 deletions Classes/Domain/Repository/ComponentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* @author Rico Sonntag <[email protected]>
* @license Netresearch https://www.netresearch.de
* @link https://www.netresearch.de
*
* @extends AbstractRepository<Component>
*/
class ComponentRepository extends AbstractRepository
{
Expand Down
2 changes: 2 additions & 0 deletions Classes/Domain/Repository/EnvironmentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* @author Rico Sonntag <[email protected]>
* @license Netresearch https://www.netresearch.de
* @link https://www.netresearch.de
*
* @extends AbstractRepository<Environment>
*/
class EnvironmentRepository extends AbstractRepository
{
Expand Down
8 changes: 3 additions & 5 deletions Classes/Domain/Repository/TranslationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
* @license Netresearch https://www.netresearch.de
* @link https://www.netresearch.de
*
* @template T of \Netresearch\NrTextdb\Domain\Model\Translation
*
* @extends AbstractRepository<T>
* @extends AbstractRepository<Translation>
*/
class TranslationRepository extends AbstractRepository
{
Expand All @@ -54,7 +52,7 @@ public function initializeObject(): void
* @param int[] $originals
* @param int $languageUid
*
* @return QueryResultInterface
* @return QueryResultInterface<Translation>
*
* @throws InvalidQueryException
*/
Expand Down Expand Up @@ -114,7 +112,7 @@ public function findByPidAndLanguage(int $uid): array
* @param string|null $value Value to search for
* @param int $languageId Language ID
*
* @return QueryResultInterface
* @return QueryResultInterface<Translation>
*
* @throws InvalidQueryException
*/
Expand Down
2 changes: 2 additions & 0 deletions Classes/Domain/Repository/TypeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* @author Rico Sonntag <[email protected]>
* @license Netresearch https://www.netresearch.de
* @link https://www.netresearch.de
*
* @extends AbstractRepository<Type>
*/
class TypeRepository extends AbstractRepository
{
Expand Down
35 changes: 17 additions & 18 deletions Classes/Service/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
namespace Netresearch\NrTextdb\Service;

use Exception;
use Netresearch\NrTextdb\Domain\Model\Component;
use Netresearch\NrTextdb\Domain\Model\Environment;
use Netresearch\NrTextdb\Domain\Model\Translation;
use Netresearch\NrTextdb\Domain\Model\Type;
use Netresearch\NrTextdb\Domain\Repository\ComponentRepository;
use Netresearch\NrTextdb\Domain\Repository\EnvironmentRepository;
use Netresearch\NrTextdb\Domain\Repository\TranslationRepository;
use Netresearch\NrTextdb\Domain\Repository\TypeRepository;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use RuntimeException;
use TYPO3\CMS\Core\Localization\Parser\XliffParser;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
Expand All @@ -35,44 +36,42 @@
* @license Netresearch https://www.netresearch.de
* @link https://www.netresearch.de
*/
class ImportService implements LoggerAwareInterface
class ImportService
{
use LoggerAwareTrait;

/**
* @var PersistenceManagerInterface
*/
private PersistenceManagerInterface $persistenceManager;
private readonly PersistenceManagerInterface $persistenceManager;

/**
* @var XliffParser
*/
private XliffParser $xliffParser;
private readonly XliffParser $xliffParser;

/**
* @var TranslationService
*/
private TranslationService $translationService;
private readonly TranslationService $translationService;

/**
* @var TranslationRepository
*/
private TranslationRepository $translationRepository;
private readonly TranslationRepository $translationRepository;

/**
* @var ComponentRepository
*/
private ComponentRepository $componentRepository;
private readonly ComponentRepository $componentRepository;

/**
* @var TypeRepository
*/
private TypeRepository $typeRepository;
private readonly TypeRepository $typeRepository;

/**
* @var EnvironmentRepository
*/
private EnvironmentRepository $environmentRepository;
private readonly EnvironmentRepository $environmentRepository;

/**
* Constructor.
Expand Down Expand Up @@ -201,9 +200,9 @@ public function importEntry(
->findByName($typeName);

if (
($environment === null)
|| ($component === null)
|| ($type === null)
(!$environment instanceof Environment)
|| (!$component instanceof Component)
|| (!$type instanceof Type)
) {
return;
}
Expand Down Expand Up @@ -279,7 +278,7 @@ public function importEntry(
}
}

/**
/**<
* Returns the langauge key from the file name.
*
* @param string $file
Expand Down Expand Up @@ -335,7 +334,7 @@ private function getAllLanguages(): array
}

/**
* Get the component from key.
* Get the component from a key.
*
* @param string $key
*
Expand Down Expand Up @@ -363,7 +362,7 @@ private function getTypeFromKey(string $key): ?string
}

/**
* Get the placeholder from key.
* Get the placeholder from a key.
*
* @param string $key
*
Expand Down
Loading

0 comments on commit fbcbb93

Please sign in to comment.