Skip to content

Commit

Permalink
Merge pull request #3 from jean-pasqualini/fix/potential-risk
Browse files Browse the repository at this point in the history
fix/potential-risk: add strict type, property undeclared, ..
  • Loading branch information
jean-pasqualini authored Jun 2, 2018
2 parents 5300968 + b590ebc commit 7222a78
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/ImportBundle/Extractor/CsvExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ImportBundle/Extractor/ExcelSplitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/ImportBundle/Loader/AbstractLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
abstract class AbstractLoader
{
/** @var $accessor */
/** @var PropertyAccessor */
protected $accessor;

public function __construct(PropertyAccessor $accessor)
Expand Down
6 changes: 6 additions & 0 deletions src/ImportBundle/Serializer/Symfony/EntityNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +23,11 @@ class EntityNormalizer extends ObjectNormalizer
*/
protected $managerRegistry;

/**
* @var Serializer
*/
protected $serializer;

/** @var array */
protected $config;

Expand Down
2 changes: 0 additions & 2 deletions src/ImportBundle/TargetResolver/DoctrineTargetResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/ProcessBundle/Command/DebugProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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;
}
}
13 changes: 6 additions & 7 deletions src/ProcessBundle/Configuration/ConfigurationStep.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: darkilliant
* Date: 5/8/18
* Time: 11:04 AM.
*/

declare(strict_types=1);

namespace Darkilliant\ProcessBundle\Configuration;

class ConfigurationStep
{
private $next;
/** @var array */
private $children;

/** @var array */
private $options;

/** @var string */
private $service;

private function __construct(string $service, array $options, array $children)
Expand Down
4 changes: 1 addition & 3 deletions src/ProcessBundle/Console/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function create($size, $title = 'Progression', $maxMemory = 30, $minItemP
$this->progressBar->start();
}

public function renderRightbar(SymfonyProgressBar $bar)
public function renderRightbar()
{
return sprintf(
'MEMORY %s / ITEMS %s',
Expand Down Expand Up @@ -88,8 +88,6 @@ public function advance()
public function finish()
{
$this->progressBar->finish();

$this->itemCount = [];
}

private function init()
Expand Down
11 changes: 3 additions & 8 deletions src/ProcessBundle/ProcessNotifier/ProgressBarProcessNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ProcessBundle/Runner/StepRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion src/ProcessBundle/State/ProcessState.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function duplicate($logger = null): self
}

/**
* @return \Iterator|\Countable
* @return \ArrayIterator
*/
public function getIterator()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
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;
use Psr\Log\LoggerInterface;
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
{
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7222a78

Please sign in to comment.