Fix issues reported by static code analyzers

This commit is contained in:
Sebastian Meyer 2024-07-13 19:37:14 +02:00
parent 535f9e813e
commit e6ea34c151
9 changed files with 37 additions and 19 deletions

View File

@ -56,5 +56,5 @@ try {
} catch (Exception $exception) {
echo '[ERROR] Exception ' . $exception->getCode() . ' thrown:' . PHP_EOL;
echo $exception->getMessage() . PHP_EOL;
return 1;
exit(1);
}

View File

@ -71,8 +71,10 @@ abstract class Console extends Command
switch ($unit) {
case 'g':
$limit *= 1024;
// no break
case 'm':
$limit *= 1024;
// no break
case 'k':
$limit *= 1024;
}

View File

@ -91,7 +91,9 @@ class AddRecordCommand extends Console
/** @var string */
$identifier = $input->getArgument('identifier');
/** @var Format */
$format = Database::getInstance()->getEntityManager()->getReference(Format::class, $input->getArgument('format'));
$format = Database::getInstance()
->getEntityManager()
->getReference(Format::class, $input->getArgument('format'));
/** @var string */
$file = $input->getArgument('file');
/** @var string[] */
@ -105,7 +107,9 @@ class AddRecordCommand extends Console
}
foreach ($sets as $set) {
/** @var Set */
$setSpec = Database::getInstance()->getEntityManager()->getReference(Set::class, $set);
$setSpec = Database::getInstance()
->getEntityManager()
->getReference(Set::class, $set);
$record->addSet($setSpec);
}

View File

@ -125,7 +125,9 @@ class CsvImportCommand extends Console
/** @var array<string, string> */
$arguments = $input->getArguments();
/** @var Format */
$format = Database::getInstance()->getEntityManager()->getReference(Format::class, $arguments['format']);
$format = Database::getInstance()
->getEntityManager()
->getReference(Format::class, $arguments['format']);
/** @var bool */
$noValidation = $input->getOption('noValidation');
/** @var resource */
@ -152,7 +154,9 @@ class CsvImportCommand extends Console
$sets = $row[$columns['setColumn']];
foreach (explode(',', $sets) as $set) {
/** @var Set */
$setSpec = Database::getInstance()->getEntityManager()->getReference(Set::class, trim($set));
$setSpec = Database::getInstance()
->getEntityManager()
->getReference(Set::class, trim($set));
$record->addSet($setSpec);
}
}
@ -164,7 +168,9 @@ class CsvImportCommand extends Console
// Flush to database if memory usage reaches 50% or every 10.000 records.
if ((memory_get_usage() / $phpMemoryLimit) > 0.5 || ($count % 10000) === 0) {
$progressIndicator->setMessage('Importing... ' . (string) $count . ' records processed. Flushing to database...');
$progressIndicator->setMessage(
'Importing... ' . (string) $count . ' records processed. Flushing to database...'
);
Database::getInstance()->flush([Record::class]);
}
}
@ -211,7 +217,7 @@ class CsvImportCommand extends Console
'',
sprintf(
' [ERROR] File "%s" does not contain valid CSV. ',
stream_get_meta_data($file)['uri']
stream_get_meta_data($file)['uri'] ?? 'unknown'
),
''
]);
@ -228,7 +234,7 @@ class CsvImportCommand extends Console
'',
sprintf(
' [ERROR] File "%s" does not contain valid CSV. ',
stream_get_meta_data($file)['uri']
stream_get_meta_data($file)['uri'] ?? 'unknown'
),
''
]);

View File

@ -56,7 +56,9 @@ class UpdateFormatsCommand extends Console
{
$formats = Configuration::getInstance()->metadataPrefix;
$this->clearResultCache();
$inDatabase = Database::getInstance()->getMetadataFormats()->getQueryResult();
$inDatabase = Database::getInstance()
->getMetadataFormats()
->getQueryResult();
$added = 0;
$deleted = 0;
$failure = false;

View File

@ -322,8 +322,7 @@ class Database
?DateTime $from = null,
?DateTime $until = null,
?Set $set = null
): Result
{
): Result {
$maxRecords = Configuration::getInstance()->maxRecords;
$cursor = $counter * $maxRecords;

View File

@ -107,8 +107,10 @@ abstract class Entity
new Assert\NotBlank()
]
);
if ($violations->count() > 0
or simplexml_load_string($xml) === false) {
if (
$violations->count() > 0
or simplexml_load_string($xml) === false
) {
throw new ValidationFailedException(null, $violations);
}
return $xml;

View File

@ -201,7 +201,10 @@ class Set extends Entity
public function __construct(string $spec, ?string $name = null, string $description = null)
{
try {
$this->spec = $this->validateRegEx($spec, '/^([A-Za-z0-9\-_\.!~\*\'\(\)])+(:[A-Za-z0-9\-_\.!~\*\'\(\)]+)*$/');
$this->spec = $this->validateRegEx(
$spec,
'/^([A-Za-z0-9\-_\.!~\*\'\(\)])+(:[A-Za-z0-9\-_\.!~\*\'\(\)]+)*$/'
);
$this->setName($name);
$this->setDescription($description);
$this->records = new ArrayCollection();