Skip to content

Commit

Permalink
Fix warnings (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
allestuetsmerweh authored Jan 6, 2025
1 parent 3990b1c commit 74640d6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allestuetsmerweh/php-typescript-api",
"version": "2.6.9",
"version": "2.6.10",
"type": "library",
"description": "Build a typed Web API using PHP and TypeScript",
"keywords": ["PHP","TypeScript","API"],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "php-typescript-api",
"version": "2.6.9",
"version": "2.6.10",
"description": "Build a typed Web API using PHP and TypeScript",
"main": "client/lib/index.js",
"types": "client/lib/index.d.ts",
Expand Down
6 changes: 4 additions & 2 deletions server/lib/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Translator {
protected array $fallback_chain = ['en'];

public function readProjectLangs(): void {
$entries = scandir($this::$lang_path);
$entries = is_dir($this::$lang_path)
? scandir($this::$lang_path) : false;
if (!$entries) {
return;
}
Expand Down Expand Up @@ -120,7 +121,8 @@ protected function getLangMessage(string $id): ?array {
protected function readMessagesJson(string $lang): array {
$lang_path = $this::$lang_path;
$messages_json_path = "{$lang_path}{$lang}/messages.json";
$messages_json_content = file_get_contents($messages_json_path);
$messages_json_content = is_file($messages_json_path)
? file_get_contents($messages_json_path) : false;
if (!$messages_json_content) {
return [];
}
Expand Down
5 changes: 4 additions & 1 deletion server/lib/TypedEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ protected function getTemplateAliases(
$node = $template_nodes[$i];
$value = $args[$i] ?? $node->default;
if ($value === null) {
// @codeCoverageIgnoreStart
// Reason: phpstan does not allow testing this!
$pretty_generics = implode(', ', $args);
throw new \Exception("This should never happen: Template[{$i}] is null. Expected {$pretty_range} generic arguments, got '{$previous_extends_node?->type->type}<{$pretty_generics}>'");
// @codeCoverageIgnoreEnd
}
$aliases[$node->name] = $value;
}
Expand All @@ -109,7 +112,7 @@ protected function getResolvedExtendsNode(
?PhpDocNode $php_doc_node,
array $template_aliases,
): ?ExtendsTagValueNode {
$extends_type_node = $php_doc_node?->getExtendsTagValues()[0];
$extends_type_node = $php_doc_node?->getExtendsTagValues()[0] ?? null;
if (!$extends_type_node) {
return null;
}
Expand Down
8 changes: 8 additions & 0 deletions server/tests/UnitTests/TypedEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,14 @@ public function testFakeTypedEndpointRuntimeSetup(): void {
], $this->fakeLogHandler->getPrettyRecords());
}

public function testFakeTypedEndpointRuntimeSetupFallback(): void {
global $_GET, $_POST;
$endpoint = new FakeTypedEndpointWithErrors();
$endpoint->setLogger($this->fakeLogger);
$endpoint->setup();
$this->assertSame([], $this->fakeLogHandler->getPrettyRecords());
}

public function testFakeTypedEndpointWithThrottling(): void {
$endpoint = new FakeTypedEndpointWithErrors();
$endpoint->setLogger($this->fakeLogger);
Expand Down

0 comments on commit 74640d6

Please sign in to comment.