Skip to content

Commit

Permalink
Don't use named parameters in code
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-meyer committed Oct 14, 2024
1 parent 97fee92 commit 396f8dc
Show file tree
Hide file tree
Showing 36 changed files with 532 additions and 703 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"ext-dom": "*",
"ext-libxml": "*",
"ext-sqlite3": "*",
"doctrine/dbal": "^4.1",
"doctrine/orm": "^3.2",
"doctrine/dbal": "^4.2",
"doctrine/orm": "^3.3",
"opencultureconsulting/basics": "^2.1",
"opencultureconsulting/psr15": "^1.2",
"symfony/cache": "^6.4",
Expand Down
53 changes: 28 additions & 25 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class App
*/
public function __construct()
{
$this->requestHandler = new QueueRequestHandler(middlewares: [new Dispatcher()]);
$this->requestHandler = new QueueRequestHandler([new Dispatcher()]);
}

/**
Expand Down
20 changes: 9 additions & 11 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,20 @@ final class Configuration
*/
private function __construct()
{
$configPath = Path::canonicalize(path: self::CONFIG_FILE);
if (!is_readable(filename: $configPath)) {
$configPath = Path::canonicalize(self::CONFIG_FILE);
if (!is_readable($configPath)) {
throw new FileNotFoundException(
message: 'Configuration file not found or not readable.',
code: 500,
path: $configPath
'Configuration file not found or not readable.',
500,
null,
$configPath
);
}
/** @var array<TKey, TValue> */
$config = Yaml::parseFile(filename: $configPath);
$violations = ConfigurationValidator::validate(config: $config);
$config = Yaml::parseFile($configPath);
$violations = ConfigurationValidator::validate($config);
if ($violations->count() > 0) {
throw new ValidationFailedException(
value: null,
violations: $violations
);
throw new ValidationFailedException(null, $violations);
}
$this->settings = $config;
}
Expand Down
70 changes: 31 additions & 39 deletions src/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,11 @@ protected function clearResultCache(): void
/** @var Application */
$app = $this->getApplication();
$app->doRun(
input: new ArrayInput(
parameters: [
'command' => 'orm:clear-cache:result',
'--flush' => true
]
),
output: new NullOutput()
new ArrayInput([
'command' => 'orm:clear-cache:result',
'--flush' => true
]),
new NullOutput()
);
}

Expand All @@ -109,7 +107,7 @@ protected function clearResultCache(): void
protected function getPhpMemoryLimit(): int
{
if (!isset($this->memoryLimit)) {
$ini = trim(string: ini_get(option: 'memory_limit'));
$ini = trim(ini_get('memory_limit'));
$limit = (int) $ini;
if ($limit < 0) {
return -1;
Expand Down Expand Up @@ -146,47 +144,41 @@ protected function validateInput(InputInterface $input, OutputInterface $output)

if (array_key_exists('format', $this->arguments)) {
$formats = $this->em->getMetadataFormats();
if (!$formats->containsKey(key: $this->arguments['format'])) {
$output->writeln(
messages: [
'',
sprintf(
format: ' [ERROR] Metadata format "%s" is not supported. ',
values: $this->arguments['format']
),
''
]
);
return false;
}
}
if (array_key_exists('file', $this->arguments) && !is_readable(filename: $this->arguments['file'])) {
$output->writeln(
messages: [
if (!$formats->containsKey($this->arguments['format'])) {
$output->writeln([
'',
sprintf(
format: ' [ERROR] File "%s" not found or not readable. ',
values: $this->arguments['file']
' [ERROR] Metadata format "%s" is not supported. ',
$this->arguments['format']
),
''
]
);
]);
return false;
}
}
if (array_key_exists('file', $this->arguments) && !is_readable($this->arguments['file'])) {
$output->writeln([
'',
sprintf(
' [ERROR] File "%s" not found or not readable. ',
$this->arguments['file']
),
''
]);
return false;
}
if (array_key_exists('sets', $this->arguments)) {
$sets = $this->em->getSets();
$invalidSets = array_diff($this->arguments['sets'], $sets->getKeys());
if (count($invalidSets) !== 0) {
$output->writeln(
messages: [
'',
sprintf(
format: ' [ERROR] Sets "%s" are not supported. ',
values: implode('", "', $invalidSets)
),
''
]
);
$output->writeln([
'',
sprintf(
' [ERROR] Sets "%s" are not supported. ',
implode('", "', $invalidSets)
),
''
]);
return false;
}
}
Expand Down
19 changes: 8 additions & 11 deletions src/Console/AddRecordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,27 @@ protected function configure(): void
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
if (!$this->validateInput(input: $input, output: $output)) {
if (!$this->validateInput($input, $output)) {
return Command::INVALID;
}

/** @var Format */
$format = $this->em->getMetadataFormat(prefix: $this->arguments['format']);
$content = file_get_contents(filename: $this->arguments['file']) ?: '';
$format = $this->em->getMetadataFormat($this->arguments['format']);
$content = file_get_contents($this->arguments['file']) ?: '';

$record = new Record(
identifier: $this->arguments['identifier'],
format: $format
);
$record = new Record($this->arguments['identifier'], $format);
if (trim($content) !== '') {
$record->setContent(data: $content);
$record->setContent($content);
}
if (array_key_exists('sets', $this->arguments)) {
foreach ($this->arguments['sets'] as $set) {
/** @var Set */
$setSpec = $this->em->getSet(spec: $set);
$record->addSet(set: $setSpec);
$setSpec = $this->em->getSet($set);
$record->addSet($setSpec);
}
}

$this->em->addOrUpdate(entity: $record);
$this->em->addOrUpdate($record);
$this->em->pruneOrphanedSets();

$this->clearResultCache();
Expand Down
12 changes: 4 additions & 8 deletions src/Console/AddSetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,16 @@ function (): array {
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
if (!$this->validateInput(input: $input, output: $output)) {
if (!$this->validateInput($input, $output)) {
return Command::INVALID;
}

if (array_key_exists('file', $this->arguments)) {
$description = file_get_contents(filename: $this->arguments['file']) ?: null;
$description = file_get_contents($this->arguments['file']) ?: null;
}

$set = new Set(
spec: $this->arguments['setSpec'],
name: $this->arguments['setName'],
description: $description ?? null
);
$this->em->addOrUpdate(entity: $set);
$set = new Set($this->arguments['setSpec'], $this->arguments['setName'], $description ?? null);
$this->em->addOrUpdate($set);

return Command::SUCCESS;
}
Expand Down
Loading

0 comments on commit 396f8dc

Please sign in to comment.