Skip to content

Commit

Permalink
Add static code analysis and resulting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Richter committed Mar 4, 2024
1 parent e5282ba commit e766bec
Show file tree
Hide file tree
Showing 17 changed files with 743 additions and 585 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea/
.Build/
Build/testing-docker/.env
composer.lock
public/
51 changes: 22 additions & 29 deletions Classes/Command/CompleteGndWorksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
*
*/

namespace SLUB\MpdbCore\Command;
namespace Slub\MpdbCore\Command;

use Slub\DmNorm\Domain\Repository\GndInstrumentRepository;
use Slub\DmNorm\Domain\Repository\GndGenreRepository;
use Slub\DmNorm\Domain\Repository\GndPersonRepository;
use Slub\DmNorm\Domain\Repository\GndWorkRepository;
use Slub\MpdbCore\Lib\DbArray;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Core\Core\Bootstrap;
use SLUB\DMNorm\Domain\Repository\InstrumentRepository;
use SLUB\DMNorm\Domain\Repository\FormRepository;
use SLUB\MpdbCore\Lib\DbArray;
use SLUB\MpdbCore\Domain\Repository\PersonRepository;
use SLUB\MpdbCore\Domain\Repository\WorkRepository;
use \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;

/**
* CompleteGndWorks Command class
Expand Down Expand Up @@ -57,6 +57,10 @@ class CompleteGndWorksCommand extends Command
*/
protected $instrumentRepository = null;

protected ?SymfonyStyle $io = null;

protected ?ExtensionConfiguration $extConf = null;

/**
* formRepository
*
Expand All @@ -75,19 +79,8 @@ protected function initialize(InputInterface $input, OutputInterface $output) {
*
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): void
{
/*
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
$tmpConfiguration = $configurationManager->getConfiguration(
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK,
'publisherDb'
);
$configurationManager->setConfiguration($tmpConfiguration);
$om = GeneralUtility::makeInstance(ObjectManager::class);
$workRepository = $om->get(WorkRepository::class);
*/

$countWorks = $this->workRepository->findAll()->count();
$nonTitleWorks = $this->workRepository->findByTitle('');
$countNonTitleWorks = $nonTitleWorks->count();
Expand All @@ -113,7 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return Command::SUCCESS;
}

protected function configure()
protected function configure(): void
{
$this->setHelp('Fetch GND data for new works (works without title).');
$this->setDescription('Fetching GND data for new works (works without title).');
Expand All @@ -126,19 +119,19 @@ protected function configure()
*
* @param int $storagePid The storage pid
*
* @return bool
* @return void
*/
protected function initializeRepositories()
protected function initializeRepositories(): void
{
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
$frameworkConfiguration = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$frameworkConfiguration['persistence']['storagePid'] = 0;
$configurationManager->setConfiguration($frameworkConfiguration);
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->workRepository = $objectManager->get(WorkRepository::class);
$this->personRepository = $objectManager->get(PersonRepository::class);
$this->instrumentRepository = $objectManager->get(InstrumentRepository::class);
$this->formRepository = $objectManager->get(FormRepository::class);
$this->workRepository = $objectManager->get(GndWorkRepository::class);
$this->personRepository = $objectManager->get(GndPersonRepository::class);
$this->instrumentRepository = $objectManager->get(GndInstrumentRepository::class);
$this->formRepository = $objectManager->get(GndGenreRepository::class);
$this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('mpdb_core');
}

Expand Down
63 changes: 36 additions & 27 deletions Classes/Command/HealthCheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
*
*/

namespace SLUB\MpdbCore\Command;
namespace Slub\MpdbCore\Command;

use Slub\DmNorm\Domain\Repository\GndPersonRepository;
use Slub\DmNorm\Domain\Repository\GndWorkRepository;
use Slub\MpdbCore\Common\ElasticClientBuilder;
use Slub\MpdbCore\Domain\Repository\PublishedItemRepository;
use Slub\MpdbCore\Lib\DbArray;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Style\SymfonyStyle;
use SLUB\MpdbCore\Lib\DbArray;
use SLUB\MpdbCore\Common\ElasticClientBuilder;
use SLUB\MpdbCore\Domain\Repository\PublishedItemRepository;
use SLUB\MpdbCore\Domain\Repository\PersonRepository;
use SLUB\MpdbCore\Domain\Repository\WorkRepository;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;

/**
* HealthCheck Command class
Expand All @@ -40,17 +40,26 @@ class HealthCheckCommand extends Command
const choiceRemovePersonDoubles = 'Remove double persons';
const choiceAll = 'Perform all checks';

protected function initialize(InputInterface $input, OutputInterface $output) {
protected ?PublishedItemRepository $publishedItemRepository = null;

protected ?GndPersonRepository $personRepository = null;

protected ?GndWorkRepository $workRepository = null;

protected ?SymfonyStyle $io = null;

protected function initialize(InputInterface $input, OutputInterface $output): void
{
$this->io = new SymfonyStyle($input, $output);
$this->io->title($this->getDescription());
}

/**
* Executes the command to build indices from Database
*
* @return void
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$helper = $this->getHelper('question');
$question = new ChoiceQuestion(
Expand Down Expand Up @@ -79,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return Command::SUCCESS;
}

protected function checkMvdbIds()
protected function checkMvdbIds(): void
{
$this->io->section('Checking all MVDB IDs');
$publishedItems = $this->publishedItemRepository->findAll();
Expand All @@ -102,18 +111,18 @@ protected function checkMvdbIds()
/**
* Pre-Execution configuration
*
* @return array
* @return void
*/
protected function configure()
protected function configure(): void
{
$this->setHelp('Check Database Consistency');
}

protected function setFinal()
protected function setFinal(): void
{
}

protected function setWorkTitles()
protected function setWorkTitles(): void
{
$this->io->section('Checking all work titles');
$works = $this->workRepository->findAll();
Expand All @@ -134,11 +143,11 @@ protected function setWorkTitles()
$this->io->progressFinish();
}

protected function setInstrumentationNames()
protected function setInstrumentationNames(): void
{
}

protected function removeDoubleWorks()
protected function removeDoubleWorks(): void
{
$this->io->section('Removing double works');
$publishedItems = $this->publishedItemRepository->findAll();
Expand Down Expand Up @@ -175,7 +184,7 @@ protected function removeDoubleWorks()
$this->removeUnusedWorks();
}

protected function removeDoublePersons()
protected function removeDoublePersons(): void
{
$this->io->section('Removing double persons');
$works = $this->workRepository->findAll();
Expand Down Expand Up @@ -238,11 +247,11 @@ protected function removeDoublePersons()
$this->removeUnusedPersons();
}

protected function removeDoublePlaces()
protected function removeDoublePlaces(): void
{
}

protected function removeUnusedWorks()
protected function removeUnusedWorks(): void
{
$this->io->section('Removing unused works');
$publishedItems = $this->publishedItemRepository->findAll();
Expand All @@ -267,7 +276,7 @@ protected function removeUnusedWorks()
$this->io->progressFinish();
}

protected function removeUnusedPersons()
protected function removeUnusedPersons(): void
{
$this->io->section('Removing unused persons');
$works = $this->workRepository->findAll();
Expand Down Expand Up @@ -311,7 +320,7 @@ protected function removeUnusedPersons()
$this->io->progressFinish();
}

protected function removeUnusedPlaces()
protected function removeUnusedPlaces(): void
{
}

Expand All @@ -322,17 +331,17 @@ protected function removeUnusedPlaces()
*
* @param int $storagePid The storage pid
*
* @return bool
* @return void
*/
protected function initializeRepositories()
protected function initializeRepositories(): void
{
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
$frameworkConfiguration = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$frameworkConfiguration['persistence']['storagePid'] = 0;
$configurationManager->setConfiguration($frameworkConfiguration);
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->workRepository = $objectManager->get(WorkRepository::class);
$this->publishedItemRepository = $objectManager->get(publishedItemRepository::class);
$this->personRepository = $objectManager->get(PersonRepository::class);
$this->workRepository = $objectManager->get(GndWorkRepository::class);
$this->publishedItemRepository = $objectManager->get(PublishedItemRepository::class);
$this->personRepository = $objectManager->get(GndPersonRepository::class);
}
}
Loading

0 comments on commit e766bec

Please sign in to comment.