Skip to content

Commit

Permalink
update psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Jan 29, 2025
1 parent f749218 commit 8ee969f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
php-versions:
- 8.2
- 8.3
- 8.4
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"twig/twig": "^2.4|^3.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"vimeo/psalm": "^5.0"
"phpunit/phpunit": "^10.0",
"vimeo/psalm": "^5.0|^6.0"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 10 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@
<directory name="src/Generator/Server/Template" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UnusedClass errorLevel="suppress" />
<UnusedForeachValue errorLevel="suppress" />
<UnusedVariable errorLevel="suppress" />
<UnusedClosureParam errorLevel="suppress" />
<UnusedProperty errorLevel="suppress" />
<PossiblyUnusedMethod errorLevel="suppress" />
<PossiblyUnusedReturnValue errorLevel="suppress" />
<PossiblyUnusedProperty errorLevel="suppress" />
</issueHandlers>
</psalm>
2 changes: 0 additions & 2 deletions src/Generator/Client/LanguageAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public function generate(SpecificationInterface $specification): Generator\Code\
}

foreach ($client->exceptions as $exception) {
/** @var Dto\Exception $exception */
$code = $this->engine->render($this->getExceptionTemplate(), [
'namespace' => $this->namespace,
'className' => $exception->className,
Expand Down Expand Up @@ -208,7 +207,6 @@ private function buildTag(Tag $tag, Generator\Code\Chunks $chunks): void
$imports = array_merge($imports, $operation->imports);
}

/** @var Tag $tag */
$operations = $this->engine->render($this->getOperationTemplate(), [
'className' => $tag->className,
'operations' => $tag->operations,
Expand Down
16 changes: 7 additions & 9 deletions src/Generator/Server/ServerAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

namespace PSX\Api\Generator\Server;

use PSX\Api\Exception\InvalidTypeException;
use PSX\Api\Generator\Client\Util\Naming;
use PSX\Api\Generator\ConfigurationTrait;
use PSX\Api\Generator\Server\Dto\Context;
Expand All @@ -32,7 +31,7 @@
use PSX\Api\SpecificationInterface;
use PSX\Schema\ContentType;
use PSX\Schema\DefinitionsInterface;
use PSX\Schema\Exception\TypeNotFoundException;
use PSX\Schema\Exception\GeneratorException;
use PSX\Schema\Generator;
use PSX\Schema\Generator\Code\Chunks;
use PSX\Schema\Generator\Normalizer\NormalizerInterface;
Expand Down Expand Up @@ -133,7 +132,7 @@ private function generateRecursive(Folder $folder, Chunks $chunks, Specification
}

foreach ($folder->getFiles() as $name => $file) {
$content = $this->generateControllerFile($file, $specification);
$content = $this->generateControllerFile($file);

$chunks->append($this->buildControllerFileName($name) . '.' . $this->getFileExtension(), $content);
}
Expand Down Expand Up @@ -181,10 +180,9 @@ protected function buildFolderStructure(SpecificationInterface $specification):
}

/**
* @throws InvalidTypeException
* @throws TypeNotFoundException
* @throws GeneratorException
*/
protected function newType(PropertyTypeAbstract|ContentType $type, DefinitionsInterface $definitions, int $context): Dto\Type
protected function newType(PropertyTypeAbstract|ContentType $type, int $context): Dto\Type
{
if ($type instanceof ContentType) {
$dataType = $this->typeGenerator->getContentType($type, $context);
Expand Down Expand Up @@ -213,7 +211,7 @@ protected function generateSchema(DefinitionsInterface $definitions, Generator\C
}
}

private function generateControllerFile(File $file, SpecificationInterface $specification): string
private function generateControllerFile(File $file): string
{
$controller = '';
$imports = [];
Expand All @@ -224,7 +222,7 @@ private function generateControllerFile(File $file, SpecificationInterface $spec
$rawName = $argumentName;
$variableName = $this->normalizer->argument($argumentName);
$argumentType = $argument->getSchema();
$type = $this->newType($argumentType, $specification->getDefinitions(), Type\GeneratorInterface::CONTEXT_SERVER | Type\GeneratorInterface::CONTEXT_REQUEST);
$type = $this->newType($argumentType, Type\GeneratorInterface::CONTEXT_SERVER | Type\GeneratorInterface::CONTEXT_REQUEST);

if ($argument->getIn() === ArgumentInterface::IN_PATH) {
$args[] = $this->generateArgumentPath($rawName, $variableName, $type->type, $argumentType);
Expand All @@ -242,7 +240,7 @@ private function generateControllerFile(File $file, SpecificationInterface $spec
}

$returnType = $operation->getReturn()->getSchema();
$type = $this->newType($returnType, $specification->getDefinitions(), Type\GeneratorInterface::CONTEXT_SERVER | Type\GeneratorInterface::CONTEXT_RESPONSE);
$type = $this->newType($returnType, Type\GeneratorInterface::CONTEXT_SERVER | Type\GeneratorInterface::CONTEXT_RESPONSE);

if ($returnType instanceof PropertyTypeAbstract) {
$this->resolveImport($returnType, $imports);
Expand Down
8 changes: 4 additions & 4 deletions src/Parser/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,14 @@ private function inspectTypeHints(ReflectionMethod $method, Meta $meta): void
$queryParams[] = $meta->getQueryParams()[$queryNames[$parameter->getName()]];
} elseif (in_array($parameter->getName(), $missingPathNames)) {
// in case the path contains a variable path fragment which is no yet mapped through a path param
$args = $this->getParamArgsFromType($parameter->getName(), $parameter->getType(), true);
$args = $this->getParamArgsFromType($parameter->getName(), $parameter->getType());
if (!empty($args)) {
$pathParams[] = new Attr\PathParam(...$args);
}
} else {
// in all other cases the parameter is either a query parameter in case it is a scalar value or a body
// parameter in case it is a class
$args = $this->getParamArgsFromType($parameter->getName(), $parameter->getType(), false);
$args = $this->getParamArgsFromType($parameter->getName(), $parameter->getType());
if (!empty($args)) {
$queryParams[] = new Attr\QueryParam(...$args);
} elseif (!$meta->hasIncoming() && in_array($meta->getMethod()->method, ['POST', 'PUT', 'PATCH'])) {
Expand Down Expand Up @@ -430,7 +430,7 @@ private function getFromAttribute(ReflectionParameter $parameter, ReflectionMeth
$attributes = $parameter->getAttributes();
foreach ($attributes as $attribute) {
$param = $attribute->newInstance();
$args = $this->getParamArgsFromType($parameter->getName(), $parameter->getType(), !$parameter->isOptional());
$args = $this->getParamArgsFromType($parameter->getName(), $parameter->getType());
if (empty($args)) {
continue;
}
Expand Down Expand Up @@ -507,7 +507,7 @@ private function getParamNames(array $params): array
return $result;
}

private function getParamArgsFromType(string $name, ?\ReflectionType $type, bool $required, ?array $enum = null): ?array
private function getParamArgsFromType(string $name, ?\ReflectionType $type): ?array
{
if (!$type instanceof \ReflectionNamedType) {
// @TODO maybe handle union type
Expand Down
7 changes: 0 additions & 7 deletions src/Parser/OpenAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ private function parseResponseInRange(OpenAPIOperation $operation, int $start, i
}

foreach ($responses as $statusCode => $response) {
/** @var \PSX\OpenAPI\Response $response */
$statusCode = (int) $statusCode;
if ($statusCode >= $start && $statusCode < $end) {
$mediaTypes = $response->getContent();
Expand Down Expand Up @@ -433,12 +432,6 @@ private function resolveReference(string $reference)
}
}

private function parseOpenAPI(string $data): void
{


}

private function getFirstSecurityScopes(array $security): ?array
{
foreach ($security as $securityRequirement) {
Expand Down

0 comments on commit 8ee969f

Please sign in to comment.