Skip to content

Commit

Permalink
Fix issues reported by static code analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-meyer committed Jul 13, 2024
1 parent 535f9e8 commit e6ea34c
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ protected function loadConfigFile(): array
/**
* Load and validate configuration settings from YAML file.
*
* @throws FileNotFoundException|ValidationFailedException
* @throws FileNotFoundException | ValidationFailedException
*/
private function __construct()
{
try {
$this->settings = $this->loadConfigFile();
} catch (FileNotFoundException|ValidationFailedException $exception) {
} catch (FileNotFoundException | ValidationFailedException $exception) {
throw $exception;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ protected function getPhpMemoryLimit(): int
if ($limit < 0) {
return -1;
}
$unit = strtolower($ini[strlen($ini)-1]);
switch($unit) {
$unit = strtolower($ini[strlen($ini) - 1]);
switch ($unit) {
case 'g':
$limit *= 1024;
// no break
case 'm':
$limit *= 1024;
// no break
case 'k':
$limit *= 1024;
}
Expand Down
8 changes: 6 additions & 2 deletions src/Console/AddRecordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @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[] */
Expand All @@ -105,7 +107,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
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);
}

Expand Down
16 changes: 11 additions & 5 deletions src/Console/CsvImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @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 */
Expand All @@ -152,7 +154,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$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);
}
}
Expand All @@ -164,7 +168,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// 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]);
}
}
Expand Down Expand Up @@ -211,7 +217,7 @@ protected function getColumnNames(InputInterface $input, OutputInterface $output
'',
sprintf(
' [ERROR] File "%s" does not contain valid CSV. ',
stream_get_meta_data($file)['uri']
stream_get_meta_data($file)['uri'] ?? 'unknown'

Check failure on line 220 in src/Console/CsvImportCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan Scanner

Offset 'uri' on array{timed_out: bool, blocked: bool, eof: bool, unread_bytes: int, stream_type: string, wrapper_type: string, wrapper_data: mixed, mode: string, ...} on left side of ?? always exists and is not nullable.
),
''
]);
Expand All @@ -228,7 +234,7 @@ protected function getColumnNames(InputInterface $input, OutputInterface $output
'',
sprintf(
' [ERROR] File "%s" does not contain valid CSV. ',
stream_get_meta_data($file)['uri']
stream_get_meta_data($file)['uri'] ?? 'unknown'

Check failure on line 237 in src/Console/CsvImportCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan Scanner

Offset 'uri' on array{timed_out: bool, blocked: bool, eof: bool, unread_bytes: int, stream_type: string, wrapper_type: string, wrapper_data: mixed, mode: string, ...} on left side of ?? always exists and is not nullable.
),
''
]);
Expand Down
4 changes: 3 additions & 1 deletion src/Console/UpdateFormatsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$formats = Configuration::getInstance()->metadataPrefix;
$this->clearResultCache();
$inDatabase = Database::getInstance()->getMetadataFormats()->getQueryResult();
$inDatabase = Database::getInstance()
->getMetadataFormats()
->getQueryResult();
$added = 0;
$deleted = 0;
$failure = false;
Expand Down
5 changes: 2 additions & 3 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ public function getRecords(
?DateTime $from = null,
?DateTime $until = null,
?Set $set = null
): Result
{
): Result {
$maxRecords = Configuration::getInstance()->maxRecords;
$cursor = $counter * $maxRecords;

Expand Down Expand Up @@ -551,7 +550,7 @@ private function __construct()
)
);
$configuration->setSchemaAssetsFilter(
static function(string|AbstractAsset $assetName): bool {
static function (string|AbstractAsset $assetName): bool {
if ($assetName instanceof AbstractAsset) {
$assetName = $assetName->getName();
}
Expand Down
6 changes: 4 additions & 2 deletions src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ protected function validateXml(string $xml): string
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;
Expand Down
5 changes: 4 additions & 1 deletion src/Entity/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ public function setName(?string $name): void
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();
Expand Down

0 comments on commit e6ea34c

Please sign in to comment.