Skip to content

Commit

Permalink
fix psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Oct 20, 2024
1 parent 5f1b773 commit 305116b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 3 additions & 1 deletion www/src/Controller/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ private function convert(string $type, string $file, ?string $namespace, ?array
if ($result instanceof Chunks && $generator instanceof FileAwareInterface) {
$chunks = [];
foreach ($result->getChunks() as $fileName => $code) {
$chunks[$generator->getFileName($fileName)] = $generator->getFileContent($code);
if (is_string($code)) {
$chunks[$generator->getFileName($fileName)] = $generator->getFileContent($code);
}
}
return $chunks;
} else {
Expand Down
23 changes: 16 additions & 7 deletions www/src/Controller/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public function generate(string $type, Generate $generate): mixed
if ($result instanceof Chunks && $generator instanceof FileAwareInterface) {
$chunks = [];
foreach ($result->getChunks() as $fileName => $code) {
$chunks[$generator->getFileName($fileName)] = $generator->getFileContent($code);
if (is_string($code)) {
$chunks[$generator->getFileName($fileName)] = $generator->getFileContent($code);
}
}
$output = $chunks;
} else {
Expand All @@ -104,7 +106,7 @@ public function generate(string $type, Generate $generate): mixed
'method' => explode('::', __METHOD__),
'parameters' => ['type' => $type],
'namespace' => $namespace,
'schema' => $schema ?? $this->getSchema(),
'schema' => $schema,
'type' => $type,
'typeName' => TypeName::getDisplayName($type),
'output' => $output,
Expand Down Expand Up @@ -133,9 +135,7 @@ public function download(#[Param] string $type, #[Body] Generate $generate): mix

if ($result instanceof Chunks && $generator instanceof FileAwareInterface) {
$output = new Chunks();
foreach ($result->getChunks() as $identifier => $code) {
$output->append($generator->getFileName($identifier), $generator->getFileContent($code));
}
$this->appendOutput($result, $output, $generator);

$output->writeToZip($zipFile);

Expand All @@ -148,8 +148,17 @@ public function download(#[Param] string $type, #[Body] Generate $generate): mix
}
}

private function appendOutput(Chunks $result, Chunks $output, FileAwareInterface $generator): void
{
foreach ($result->getChunks() as $identifier => $code) {
if (is_string($code)) {
$output->append($generator->getFileName($identifier), $generator->getFileContent($code));
}
}
}

/**
* @return array{string, string, SchemaInterface}
* @return array{string|null, string, Config, SchemaInterface}
*/
private function parse(string $type, Generate $generate): array
{
Expand All @@ -166,7 +175,7 @@ private function parse(string $type, Generate $generate): array
}

$config = new Config();
if (!empty($namespace)) {
if ($namespace !== null && $namespace !== '') {
$config->put(Config::NAMESPACE, $namespace);
}

Expand Down

0 comments on commit 305116b

Please sign in to comment.