Skip to content

Commit

Permalink
Code cleanup and fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDragon-ru committed Jan 30, 2022
1 parent b3edd76 commit 70b8d3f
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 34 deletions.
1 change: 1 addition & 0 deletions src/SchemaPrinter/Blocks/Ast/ListValueList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Blocks\Ast;

use LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Blocks\Block;
use LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Blocks\BlockList;

/**
Expand Down
1 change: 1 addition & 0 deletions src/SchemaPrinter/Blocks/Ast/ObjectValueList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Blocks\Ast;

use LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Blocks\Block;
use LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Blocks\BlockList;

/**
Expand Down
2 changes: 0 additions & 2 deletions src/SchemaPrinter/Blocks/BlockList.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ protected function analyze(Block $block): Block {

/**
* @param TBlock $value
*
* @return mixed
*/
protected function isValidBlock(Block $value): bool {
return !$value->isEmpty();
Expand Down
6 changes: 3 additions & 3 deletions src/SchemaPrinter/Blocks/BlockListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ public function dataProviderToString(): array {
*/
class BlockListTest__BlockList extends BlockList {
public function __construct(
Settings $settings,
PrinterSettings $settings,
int $level,
int $used,
private bool $normalized,
Expand Down Expand Up @@ -813,8 +813,8 @@ protected function space(): string {
*/
class BlockListTest__StatisticsBlock extends Block {
/**
* @param array<string,string> $types
* @param array<string,string> $directives
* @param array<string> $types
* @param array<string> $directives
*
* @noinspection PhpMissingParentConstructorInspection
*/
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaPrinter/Blocks/BlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testIsEmpty(bool $expected, string $content): void {
// <editor-fold desc="DataProviders">
// =========================================================================
/**
* @return array<string, array{bool, PrinterSettings, string}>
* @return array<string, array{bool, Settings, string}>
*/
public function dataProviderIsMultiline(): array {
$settings = new TestSettings();
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaPrinter/Blocks/Types/DescriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testToString(
// <editor-fold desc="DataProviders">
// =========================================================================
/**
* @return array<string,array{string, \LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Contracts\Settings, int, int, ?string, array<DirectiveNode>|null}>
* @return array<string,array{string, Settings, int, int, ?string, array<DirectiveNode>|null}>
*/
public function dataProviderToString(): array {
$settings = (new TestSettings())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testToString(
// <editor-fold desc="DataProviders">
// =========================================================================
/**
* @return array<string,array{string, \LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Contracts\Settings, int, int, Closure():EnumType|EnumType}>
* @return array<string,array{string, Settings, int, int, Closure():EnumType|EnumType}>
*/
public function dataProviderToString(): array {
$settings = (new TestSettings())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testStatistics(): void {
// <editor-fold desc="DataProviders">
// =========================================================================
/**
* @return array<string,array{string, \LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Contracts\Settings, int, int, FieldDefinition}>
* @return array<string,array{string, Settings, int, int, FieldDefinition}>
*/
public function dataProviderToString(): array {
$settings = (new TestSettings())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testStatistics(): void {
// <editor-fold desc="DataProviders">
// =========================================================================
/**
* @return array<string,array{string, \LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Contracts\Settings, int, int, FieldArgument}>
* @return array<string,array{string, Settings, int, int, FieldArgument}>
*/
public function dataProviderToString(): array {
$settings = new TestSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function testStatistics(): void {
// <editor-fold desc="DataProviders">
// =========================================================================
/**
* @return array<string,array{string, \LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Contracts\Settings, int, int, InterfaceType}>
* @return array<string,array{string, Settings, int, int, InterfaceType}>
*/
public function dataProviderToString(): array {
$settings = (new TestSettings())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testToString(
// <editor-fold desc="DataProviders">
// =========================================================================
/**
* @return array<string,array{string, \LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Contracts\Settings, int, int, Schema}>
* @return array<string,array{string, Settings, int, int, Schema}>
*/
public function dataProviderToString(): array {
$settings = (new TestSettings())
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaPrinter/Blocks/Types/StringBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testToString(
// <editor-fold desc="DataProviders">
// =========================================================================
/**
* @return array<string,array{string, \LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Contracts\Settings, int, int, string}>
* @return array<string,array{string, Settings, int, int, string}>
*/
public function dataProviderToString(): array {
$settings = new TestSettings();
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaPrinter/Blocks/Types/TypeBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testStatistics(): void {
// <editor-fold desc="DataProviders">
// =========================================================================
/**
* @return array<string,array{string, \LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Contracts\Settings, int, int, Type}>
* @return array<string,array{string, Settings, int, int, Type}>
*/
public function dataProviderToString(): array {
$settings = new TestSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testStatistics(): void {
// <editor-fold desc="DataProviders">
// =========================================================================
/**
* @return array<string,array{string, \LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Contracts\Settings, int, int, UnionType}>
* @return array<string,array{string, Settings, int, int, UnionType}>
*/
public function dataProviderToString(): array {
$settings = (new TestSettings())
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaPrinter/IntrospectionPrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testPrint(string $expected, Settings $settings, int $level): voi
*/
public function dataProviderPrint(): array {
return [
GraphQLSettings::class => [
GraphQLSettings::class => [
'~graphql-settings.graphql',
new GraphQLSettings(),
0,
Expand Down
6 changes: 3 additions & 3 deletions src/SchemaPrinter/Misc/DirectiveResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DirectiveResolver {
protected array $directives;

/**
* @param array<string,GraphQLDirective> $directives
* @param array<GraphQLDirective> $directives
*/
public function __construct(
protected DirectiveLocator $locator,
Expand Down Expand Up @@ -68,8 +68,8 @@ public function getDefinitions(): array {
$directives = $this->directives;

foreach ($this->locator->definitions() as $definition) {
$directive = $this->factory->handle($definition);
$directives[$directives->name] = $directive;
$directive = $this->factory->handle($definition);
$directives[$directive->name] = $directive;
}

return $directives;
Expand Down
10 changes: 4 additions & 6 deletions src/SchemaPrinter/PrintedSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Contracts\Statistics;
use Stringable;

use function array_values;

class PrintedSchema implements Statistics, Stringable {
public function __construct(
protected Block $schema,
Expand All @@ -20,16 +18,16 @@ public function __toString(): string {
}

/**
* @return array<string>
* @inheritDoc
*/
public function getUsedTypes(): array {
return array_values($this->schema->getUsedTypes());
return $this->schema->getUsedTypes();
}

/**
* @return array<string>
* @inheritDoc
*/
public function getUsedDirectives(): array {
return array_values($this->schema->getUsedDirectives());
return $this->schema->getUsedDirectives();
}
}
10 changes: 5 additions & 5 deletions src/SchemaPrinter/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected function getUsedDefinitions(PrinterSettings $settings, Schema $schema,
} else {
$type = $schema->getType($name);

if ($this->isType($type)) {
if ($type && $this->isType($type)) {
$block = $this->getDefinitionBlock($settings, $type);
$types[$name] = $block;
}
Expand Down Expand Up @@ -198,11 +198,11 @@ protected function getDefinitionBlock(
return new DefinitionBlock($settings, $this->getLevel(), $definition);
}

private function isType(Type $type): bool {
return !Type::isBuiltInType($type);
private function isType(?Type $type): bool {
return $type && !Type::isBuiltInType($type);
}

private function isDirective(Directive $directive): bool {
return !Directive::isSpecifiedDirective($directive);
private function isDirective(?Directive $directive): bool {
return $directive && !Directive::isSpecifiedDirective($directive);
}
}
10 changes: 6 additions & 4 deletions src/SchemaPrinter/PrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use Nuwave\Lighthouse\Schema\Directives\BaseDirective;
use Nuwave\Lighthouse\Schema\TypeRegistry;

use function array_values;

/**
* @internal
* @coversDefaultClass \LastDragon_ru\LaraASP\GraphQL\SchemaPrinter\Printer
Expand All @@ -32,7 +34,7 @@ class PrinterTest extends TestCase {
*
* @dataProvider dataProviderPrint
*
* @param array{schema: string, types: array<string>, directives: array<string>}
* @param array{schema: string, types: array<string>, directives: array<string>} $expected
*/
public function testPrint(array $expected, ?Settings $settings, int $level): void {
// Types
Expand Down Expand Up @@ -115,15 +117,15 @@ public static function definition(): string {
$actual = $printer->print($schema);

self::assertEquals($output, (string) $actual);
self::assertEqualsCanonicalizing($expected['types'], $actual->getUsedTypes());
self::assertEqualsCanonicalizing($expected['directives'], $actual->getUsedDirectives());
self::assertEqualsCanonicalizing($expected['types'], array_values($actual->getUsedTypes()));
self::assertEqualsCanonicalizing($expected['directives'], array_values($actual->getUsedDirectives()));
}
// </editor-fold>

// <editor-fold desc="DataProviders">
// =========================================================================
/**
* @return array<string, array{string, Settings, int}>
* @return array<string, array<mixed>>
*/
public function dataProviderPrint(): array {
return [
Expand Down

0 comments on commit 70b8d3f

Please sign in to comment.