fix: SA: Fix "might not be defined" rule.

SA stands for Static Analysis.
This commit is contained in:
Pol Dellaiera
2021-11-16 11:41:12 +01:00
parent a7b96f1756
commit f8aeb08594
14 changed files with 365 additions and 620 deletions

View File

@@ -4,6 +4,8 @@ namespace Chill\PersonBundle\Command;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
@@ -360,6 +362,7 @@ EOF
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$headers = $rawHeaders = [];
$this->input = $input;
$this->output = $output;
@@ -453,15 +456,15 @@ EOF
}
/**
*
* @param type $firstRow
* @return array where keys are column number, and value is information mapped
*/
protected function processingHeaders($firstRow)
protected function processingHeaders(array $firstRow): array
{
$availableOptions = array_map(function($m) { return $m[0]; }, self::$mapping);
$matchedColumnHeaders = array();
$headers = array();
$availableOptions = array_map(
static fn (array $m) => $m[0],
self::$mapping
);
$matchedColumnHeaders = $headers = [];
foreach($availableOptions as $option) {
$matchedColumnHeaders[$option] = $this->input->getOption($option);
@@ -482,13 +485,10 @@ EOF
}
/**
*
* @param array $row
* @param array $headers the processed header : an array as prepared by self::processingHeaders
* @return Person
* @throws \Exception
*/
protected function createPerson($row, $headers)
protected function createPerson(array $row, array $headers): Person
{
// trying to get the opening date
$openingDateString = trim($row[array_search('opening_date', $headers)]);
@@ -580,30 +580,27 @@ EOF
}
/**
* @param $row
* @param $headers
* @return Center|mixed|null|object
*/
protected function getCenter($row, $headers)
protected function getCenter(array $row, array $headers)
{
if ($this->input->hasOption('force-center') && !empty($this->input->getOption('force-center'))) {
return $this->em->getRepository('ChillMainBundle:Center')
->find($this->input->getOption('force-center'));
} else {
$columnCenter = \array_search('center', $headers);
$centerName = \trim($row[$columnCenter]);
return $this->em->getRepository(Center::class)->find($this->input->getOption('force-center'));
}
try {
return $this->em->createQuery('SELECT c FROM ChillMainBundle:Center c '
. 'WHERE c.name = :center_name')
->setParameter('center_name', $centerName)
->getSingleResult()
;
} catch (\Doctrine\ORM\NonUniqueResultException $e) {
return $this->guessCenter($centerName);
} catch (\Doctrine\ORM\NoResultException $e) {
return $this->guessCenter($centerName);
}
$columnCenter = array_search('center', $headers);
$centerName = trim($row[$columnCenter]);
try {
return $this
->em
->createQuery('SELECT c FROM ChillMainBundle:Center c WHERE c.name = :center_name')
->setParameter('center_name', $centerName)
->getSingleResult();
} catch (NonUniqueResultException $e) {
return $this->guessCenter($centerName);
} catch (NoResultException $e) {
return $this->guessCenter($centerName);
}
}