Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
readonly class Configuration
{
public function __construct(
/** @var string[] $paths */
/**
* @var string[]
*/
public array $paths,
public string $outputPath,
public string $namespace,
Expand Down
4 changes: 3 additions & 1 deletion src/Model/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public function __construct(
public ClassReference|string|OneOfType $type,
public bool $nullable,
public string $docType,
/** @var string[] $imports */
/**
* @var string[]
*/
public array $imports = [],
) {
}
Expand Down
4 changes: 3 additions & 1 deletion src/Model/OneOfType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
readonly class OneOfType
{
public function __construct(
/** @var array<string | ArrayType> $types */
/**
* @var array<string | ArrayType>
*/
public array $types,
) {
}
Expand Down
4 changes: 3 additions & 1 deletion src/Model/ParserResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
{
public function __construct(
public OpenApi $openApi,
/** @var File[] $parsedFiles */
/**
* @var File[]
*/
public array $parsedFiles,
) {
}
Expand Down
10 changes: 6 additions & 4 deletions src/Writer/SingleNamespaceResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,21 @@ public function resolve(PhpNamespace $namespace, ClassType|InterfaceType|EnumTyp

if (str_contains($method->getBody(), $use)) {
$classOnlyNamespace->addUse($use);
$method->setBody(str_replace($use, $namespace->simplifyName($use), $method->getBody()));
$method->setBody(str_replace($use, $classOnlyNamespace->simplifyName($use), $method->getBody()));
}

if ($method->getComment() !== null && str_contains($method->getComment(), $use)) {
$classOnlyNamespace->addUse($use);
$method->setComment(str_replace($use, $namespace->simplifyName($use), $method->getComment()));
$method->setComment(
str_replace($use, $classOnlyNamespace->simplifyName($use), $method->getComment())
);
}

if ($returnType !== null && $returnType->allows('array') && $method->getComment() !== null) {
if (str_contains($method->getComment(), $use)) {
$namespace->addUse($use);
$method->setComment(
str_replace($use, $namespace->simplifyName($use), $method->getComment())
str_replace($use, $classOnlyNamespace->simplifyName($use), $method->getComment())
);
}
}
Expand All @@ -78,7 +80,7 @@ private function resolveUsagesForParameterOrProperty(
}

$type = $parameterOrProperty->getType(true);
if ($type !== null && $type->allows($use) || $parameterOrProperty->getType() === $use) {
if (($type !== null && $type->allows($use)) || $parameterOrProperty->getType() === $use) {
$namespace->addUse($use);
}

Expand Down
6 changes: 3 additions & 3 deletions test/Generator/ArrayObjectResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
use BadMethodCallException;
use Countable;
use IteratorAggregate;
use Nette\PhpGenerator\ClassLike;
use Nette\PhpGenerator\ClassType;
use Nette\PhpGenerator\Method;
use Nette\PhpGenerator\PhpNamespace;
use Nette\PhpGenerator\Visibility;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Reinfi\OpenApiModels\Generator\ArrayObjectResolver;
Expand Down Expand Up @@ -104,7 +104,7 @@ public function testItResolvesScalarNotNullableTypeToParameter(): void
$property = $class->getProperty('items');
self::assertEquals('array', $property->getType());
self::assertFalse($property->isNullable());
self::assertEquals(ClassLike::VisibilityPrivate, $property->getVisibility());
self::assertEquals(Visibility::Private->value, $property->getVisibility());
self::assertStringContainsString('docType', $property->getComment() ?: '');
}

Expand Down Expand Up @@ -166,7 +166,7 @@ public function testItResolvesReferenceToParameter(): void
$property = $class->getProperty('items');
self::assertEquals('array', $property->getType());
self::assertFalse($property->isNullable());
self::assertEquals(ClassLike::VisibilityPrivate, $property->getVisibility());
self::assertEquals(Visibility::Private->value, $property->getVisibility());
self::assertStringContainsString('docType', $property->getComment() ?: '');

$imports->copyImports();
Expand Down
4 changes: 2 additions & 2 deletions test/Generator/DictionaryResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Reinfi\OpenApiModels\Test\Generator;

use Nette\PhpGenerator\ClassLike;
use Nette\PhpGenerator\ClassType;
use Nette\PhpGenerator\PhpNamespace;
use Nette\PhpGenerator\Visibility;
use PHPUnit\Framework\TestCase;
use Reinfi\OpenApiModels\Generator\DictionaryResolver;
use Reinfi\OpenApiModels\Model\ArrayType;
Expand Down Expand Up @@ -53,7 +53,7 @@ public function testItResolvesDictionaryProperty(): void

$property = $class->getProperty('dictionaries');

self::assertEquals(ClassLike::VisibilityPrivate, $property->getVisibility());
self::assertEquals(Visibility::Private->value, $property->getVisibility());
self::assertEquals('array', $property->getType());
self::assertNotNull($property->getComment());
self::assertStringContainsString('@var Api\TestDictionary[]', $property->getComment());
Expand Down
Loading