From b590ebc90d997d1f755e573cfd11ff3d213cbe82 Mon Sep 17 00:00:00 2001 From: Jean Pasqualini Date: Sat, 2 Jun 2018 11:18:18 +0200 Subject: [PATCH] fix/potential-risk: add strict type, property undeclared, .. --- .../RemoveUnconfigurableStepCompilerPass.php | 2 +- src/ImportBundle/Extractor/CsvExtractor.php | 9 +++++---- src/ImportBundle/Extractor/ExcelSplitter.php | 4 ++-- src/ImportBundle/Loader/AbstractLoader.php | 2 +- .../Serializer/Symfony/EntityNormalizer.php | 6 ++++++ .../TargetResolver/DoctrineTargetResolver.php | 2 -- .../Command/DebugProcessCommand.php | 8 ++++++-- .../Configuration/ConfigurationStep.php | 13 ++++++------- src/ProcessBundle/Console/ProgressBar.php | 4 +--- .../ProgressBarProcessNotifier.php | 11 +++-------- src/ProcessBundle/Runner/StepRunner.php | 2 +- src/ProcessBundle/State/ProcessState.php | 2 +- .../ProgressBarProcessNotifierTest.php | 18 ------------------ 13 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/ImportBundle/DependencyInjection/CompilerPass/RemoveUnconfigurableStepCompilerPass.php b/src/ImportBundle/DependencyInjection/CompilerPass/RemoveUnconfigurableStepCompilerPass.php index a08efe6..0e85307 100644 --- a/src/ImportBundle/DependencyInjection/CompilerPass/RemoveUnconfigurableStepCompilerPass.php +++ b/src/ImportBundle/DependencyInjection/CompilerPass/RemoveUnconfigurableStepCompilerPass.php @@ -4,7 +4,7 @@ namespace Darkilliant\ImportBundle\DependencyInjection\CompilerPass; -use Darkilliant\ImportBundle\Normalizer\EntityNormalizer; +use Darkilliant\ImportBundle\Serializer\Symfony\EntityNormalizer; use Darkilliant\ImportBundle\Persister\DoctrinePersister; use Darkilliant\ImportBundle\Step\ArrayTargetResolverStep; use Darkilliant\ImportBundle\Step\DoctrinePersisterStep; diff --git a/src/ImportBundle/Extractor/CsvExtractor.php b/src/ImportBundle/Extractor/CsvExtractor.php index 86c7993..be8d1ba 100644 --- a/src/ImportBundle/Extractor/CsvExtractor.php +++ b/src/ImportBundle/Extractor/CsvExtractor.php @@ -24,13 +24,14 @@ public function extract(string $csvFilePath, string $delimiter = ',', array $col $csvFileObjects->setFlags((\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY | \SplFileObject::DROP_NEW_LINE | \ SplFileObject::READ_AHEAD)); $csvFileObjects->setCsvControl($delimiter); - $arrayKeys = array_map([$this, 'slugify'], $columsNames ?? $csvFileObjects->current()); + $arrayKeys = array_map([$this, 'slugify'], $columsNames ?? (array) $csvFileObjects->current()); $arrayKeys = array_map('trim', $arrayKeys); foreach ($csvFileObjects as $loopIndex => $csvFileObjectRow) { - if ($csvFileObjects->key() > 0 && true === $this->isValidLine($csvFileObjectRow)) { - $csvFileObjectRow = array_map('trim', $csvFileObjectRow); - $arrayToYield = array_combine($arrayKeys, $csvFileObjectRow); + $currentData = (array) $csvFileObjectRow; + if ($csvFileObjects->key() > 0 && true === $this->isValidLine($currentData)) { + $currentData = array_map('trim', $currentData); + $arrayToYield = array_combine($arrayKeys, $currentData); yield $loopIndex => $arrayToYield; } } diff --git a/src/ImportBundle/Extractor/ExcelSplitter.php b/src/ImportBundle/Extractor/ExcelSplitter.php index f009f17..b47c0d8 100644 --- a/src/ImportBundle/Extractor/ExcelSplitter.php +++ b/src/ImportBundle/Extractor/ExcelSplitter.php @@ -4,7 +4,7 @@ use Cocur\Slugify\Slugify; use PhpOffice\PhpSpreadsheet\IOFactory; -use PhpOffice\PhpSpreadsheet\Writer\IWriter; +use PhpOffice\PhpSpreadsheet\Writer\Csv as CsvWriter; class ExcelSplitter { @@ -30,7 +30,7 @@ public function split($filePath): array $xlsFilePath = realpath($filePath); $xlsWorkSheet = IOFactory::load($filePath); - /** @var IWriter $csvWriter */ + /** @var CsvWriter $csvWriter */ $csvWriter = IOFactory::createWriter($xlsWorkSheet, 'Csv'); foreach ($xlsWorkSheet->getWorksheetIterator() as $sheetIndex => $workSheetTab) { $csvWriter->setSheetIndex($sheetIndex); diff --git a/src/ImportBundle/Loader/AbstractLoader.php b/src/ImportBundle/Loader/AbstractLoader.php index e9fa54a..5072227 100644 --- a/src/ImportBundle/Loader/AbstractLoader.php +++ b/src/ImportBundle/Loader/AbstractLoader.php @@ -11,7 +11,7 @@ */ abstract class AbstractLoader { - /** @var $accessor */ + /** @var PropertyAccessor */ protected $accessor; public function __construct(PropertyAccessor $accessor) diff --git a/src/ImportBundle/Serializer/Symfony/EntityNormalizer.php b/src/ImportBundle/Serializer/Symfony/EntityNormalizer.php index 1efa3b2..6522a57 100644 --- a/src/ImportBundle/Serializer/Symfony/EntityNormalizer.php +++ b/src/ImportBundle/Serializer/Symfony/EntityNormalizer.php @@ -10,6 +10,7 @@ use Symfony\Component\Serializer\NameConverter\NameConverterInterface; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; +use Symfony\Component\Serializer\Serializer; /** * @internal @@ -22,6 +23,11 @@ class EntityNormalizer extends ObjectNormalizer */ protected $managerRegistry; + /** + * @var Serializer + */ + protected $serializer; + /** @var array */ protected $config; diff --git a/src/ImportBundle/TargetResolver/DoctrineTargetResolver.php b/src/ImportBundle/TargetResolver/DoctrineTargetResolver.php index 8724cb0..9fe34d2 100644 --- a/src/ImportBundle/TargetResolver/DoctrineTargetResolver.php +++ b/src/ImportBundle/TargetResolver/DoctrineTargetResolver.php @@ -55,10 +55,8 @@ private function factoryCall(string $strategy, string $entityClass, array $optio switch ($strategy) { case 'findOneBy': return $this->factoryFindOneBy($options); - break; case 'find': return $this->factoryFind($entityClass, $options); - break; } return null; diff --git a/src/ProcessBundle/Command/DebugProcessCommand.php b/src/ProcessBundle/Command/DebugProcessCommand.php index 0c5ebc6..9f853bf 100644 --- a/src/ProcessBundle/Command/DebugProcessCommand.php +++ b/src/ProcessBundle/Command/DebugProcessCommand.php @@ -49,7 +49,7 @@ public function execute(InputInterface $input, OutputInterface $output) * * @throws \Exception */ - private function describeProcess(string $process, SymfonyStyle $outputHelper) + private function describeProcess(string $process, SymfonyStyle $outputHelper): int { $outputHelper->section(sprintf('Describe %s', $process)); @@ -61,14 +61,18 @@ private function describeProcess(string $process, SymfonyStyle $outputHelper) $stepDescripter->run($stepDescripter->buildConfigurationProcess($process)); $outputHelper->listing($inMemoryLogger->getMessages()); + + return 0; } - private function describeProcessList(array $config, SymfonyStyle $outputHelper) + private function describeProcessList(array $config, SymfonyStyle $outputHelper): int { $outputHelper->section('List of process'); $outputHelper->listing( array_keys($config['process']) ); + + return 0; } } diff --git a/src/ProcessBundle/Configuration/ConfigurationStep.php b/src/ProcessBundle/Configuration/ConfigurationStep.php index abeea27..345494e 100644 --- a/src/ProcessBundle/Configuration/ConfigurationStep.php +++ b/src/ProcessBundle/Configuration/ConfigurationStep.php @@ -1,19 +1,18 @@ progressBar->start(); } - public function renderRightbar(SymfonyProgressBar $bar) + public function renderRightbar() { return sprintf( 'MEMORY %s / ITEMS %s', @@ -88,8 +88,6 @@ public function advance() public function finish() { $this->progressBar->finish(); - - $this->itemCount = []; } private function init() diff --git a/src/ProcessBundle/ProcessNotifier/ProgressBarProcessNotifier.php b/src/ProcessBundle/ProcessNotifier/ProgressBarProcessNotifier.php index 779356d..5b2ee9f 100644 --- a/src/ProcessBundle/ProcessNotifier/ProgressBarProcessNotifier.php +++ b/src/ProcessBundle/ProcessNotifier/ProgressBarProcessNotifier.php @@ -5,7 +5,6 @@ use Darkilliant\ProcessBundle\Console\ProgressBar; use Darkilliant\ProcessBundle\State\ProcessState; use Darkilliant\ProcessBundle\Step\IterableStepInterface; -use Darkilliant\ProcessBundle\Step\StepInterface; use Symfony\Component\Console\ConsoleEvents; use Symfony\Component\Console\Event\ConsoleEvent; use Symfony\Component\Console\Output\NullOutput; @@ -38,12 +37,8 @@ public function onCommand(ConsoleEvent $event) $this->progressBar->setOutput($event->getOutput()); } - public function onStartProcess(ProcessState $state, StepInterface $step) + public function onStartProcess(ProcessState $state, IterableStepInterface $step) { - if (!$step instanceof IterableStepInterface) { - return null; - } - if (!$state->getOptions()['progress_bar']) { return null; } @@ -57,7 +52,7 @@ public function onStartProcess(ProcessState $state, StepInterface $step) $this->progressBar->create($count, get_class($step)); } - public function onUpdateProcess(ProcessState $state, StepInterface $step) + public function onUpdateProcess(ProcessState $state, IterableStepInterface $step) { if (!$state->getOptions()['progress_bar']) { return; @@ -66,7 +61,7 @@ public function onUpdateProcess(ProcessState $state, StepInterface $step) $this->progressBar->setProgress($step->getProgress($state)); } - public function onEndProcess(ProcessState $state, StepInterface $step) + public function onEndProcess(ProcessState $state) { if (!$state->getOptions()['progress_bar']) { return; diff --git a/src/ProcessBundle/Runner/StepRunner.php b/src/ProcessBundle/Runner/StepRunner.php index 42d5d39..3369bd4 100644 --- a/src/ProcessBundle/Runner/StepRunner.php +++ b/src/ProcessBundle/Runner/StepRunner.php @@ -165,7 +165,7 @@ protected function runStep(ProcessState $processState, ConfigurationStep $step): $processState->setIterator($iterator); $processState->setOptions($options); } - $this->notifier->onEndProcess($processState, $service); + $this->notifier->onEndProcess($processState); $this->finalizeSteps($processState, $step->getChildren()); } diff --git a/src/ProcessBundle/State/ProcessState.php b/src/ProcessBundle/State/ProcessState.php index 74557c8..b0bb97a 100644 --- a/src/ProcessBundle/State/ProcessState.php +++ b/src/ProcessBundle/State/ProcessState.php @@ -137,7 +137,7 @@ public function duplicate($logger = null): self } /** - * @return \Iterator|\Countable + * @return \ArrayIterator */ public function getIterator() { diff --git a/tests/ProcessBundle/ProcessNotitfier/ProgressBarProcessNotifierTest.php b/tests/ProcessBundle/ProcessNotitfier/ProgressBarProcessNotifierTest.php index 2a2afae..9cb72c1 100644 --- a/tests/ProcessBundle/ProcessNotitfier/ProgressBarProcessNotifierTest.php +++ b/tests/ProcessBundle/ProcessNotitfier/ProgressBarProcessNotifierTest.php @@ -8,7 +8,6 @@ use Darkilliant\ProcessBundle\ProcessNotifier\ProgressBarProcessNotifier; use Darkilliant\ProcessBundle\Runner\StepRunner; use Darkilliant\ProcessBundle\State\ProcessState; -use Darkilliant\ProcessBundle\Step\DebugStep; use Darkilliant\ProcessBundle\Step\IterateArrayStep; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -16,7 +15,6 @@ use Symfony\Component\Console\Event\ConsoleEvent; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Output\NullOutput; -use Tests\Darkilliant\ProcessBundle\Step\DebugStepTest; class ProgressBarProcessNotifierTest extends TestCase { @@ -130,22 +128,6 @@ public function testGetSubscribedEvents() $this->assertInternalType('array', ProgressBarProcessNotifier::getSubscribedEvents()); } - public function testNotStartWhenNotStepIterable() - { - $state = new ProcessState( - [], - $this->createMock(LoggerInterface::class), - $this->createMock(StepRunner::class) - ); - $step = new DebugStep(); - - $this->progressBar - ->expects($this->never()) - ->method('create'); - - $this->processNotifier->onStartProcess($state, $step); - } - public function testNotStartWhenNotOptionProgressBarIsDisable() { $state = new ProcessState(