diff --git a/src/Analyser/AffectedInspections.php b/src/Analyser/AffectedInspections.php index 1e209a8..00d70e6 100644 --- a/src/Analyser/AffectedInspections.php +++ b/src/Analyser/AffectedInspections.php @@ -39,6 +39,7 @@ public function addInspection(Inspection $inspection): self } $this->inspections->add($inspection); + return $this; } } diff --git a/src/Commands/AnalyseCommand.php b/src/Commands/AnalyseCommand.php index d647f2b..3b4ef79 100644 --- a/src/Commands/AnalyseCommand.php +++ b/src/Commands/AnalyseCommand.php @@ -28,8 +28,11 @@ class AnalyseCommand extends Command { private const ORIGINAL_SCHEMA = 'sdl'; + private const COMPILED_SCHEMA = 'compiled_schema'; + private const INPUT = 'input'; + private const FORMAT = 'format'; protected static $defaultName = 'analyse'; diff --git a/src/Configuration/Visitor.php b/src/Configuration/Visitor.php index 0c34e7c..dd4087f 100644 --- a/src/Configuration/Visitor.php +++ b/src/Configuration/Visitor.php @@ -7,5 +7,6 @@ class Visitor { public const ORIGINAL = 'graphlint.original_visitor'; + public const COMPILED = 'graphlint.compiled_visitor'; } diff --git a/src/Fixes/AddFieldFixer.php b/src/Fixes/AddFieldFixer.php index 341471a..5dc9d37 100644 --- a/src/Fixes/AddFieldFixer.php +++ b/src/Fixes/AddFieldFixer.php @@ -41,12 +41,14 @@ public function fix(ProblemDescriptor $problemDescriptor): void public function withFieldDefinitionNode(FieldDefinitionNode $fieldDefinitionNode): self { $this->fieldDefinitionNode = $fieldDefinitionNode; + return $this; } public function atTop(bool $top = true): self { $this->fieldAtTop = $top; + return $this; } } diff --git a/src/Fixes/RenameFixer.php b/src/Fixes/RenameFixer.php index 87f13b9..a0b1865 100644 --- a/src/Fixes/RenameFixer.php +++ b/src/Fixes/RenameFixer.php @@ -25,6 +25,7 @@ public function fix(ProblemDescriptor $problemDescriptor): void public function withName(string $name): self { $this->newName = $name; + return $this; } } diff --git a/src/Fixes/SuffixNameFixer.php b/src/Fixes/SuffixNameFixer.php index 8d3e0e6..961d457 100644 --- a/src/Fixes/SuffixNameFixer.php +++ b/src/Fixes/SuffixNameFixer.php @@ -31,6 +31,7 @@ public function fix(ProblemDescriptor $problemDescriptor): void public function withSuffix(string $suffix): self { $this->suffix = $suffix; + return $this; } } diff --git a/src/Graphlint.php b/src/Graphlint.php index 3633e2c..aa484bc 100644 --- a/src/Graphlint.php +++ b/src/Graphlint.php @@ -74,6 +74,7 @@ private function dispatchEvent(EventInterface $event): void public function addListener(GraphlintListener $listener): self { $this->listeners[] = $listener; + return $this; } } diff --git a/src/Inspections/CamelCaseFieldDefinitionInspection.php b/src/Inspections/CamelCaseFieldDefinitionInspection.php index 39d91b7..5c4fb77 100644 --- a/src/Inspections/CamelCaseFieldDefinitionInspection.php +++ b/src/Inspections/CamelCaseFieldDefinitionInspection.php @@ -49,7 +49,7 @@ public function visitFieldDefinition( public function definition(): InspectionDescription { return new InspectionDescription( - "Fields should always be written in CamelCase.", + 'Fields should always be written in CamelCase.', ); } } diff --git a/src/Inspections/DescriptionRequiredInspection.php b/src/Inspections/DescriptionRequiredInspection.php index 139b0c9..21ac29d 100644 --- a/src/Inspections/DescriptionRequiredInspection.php +++ b/src/Inspections/DescriptionRequiredInspection.php @@ -135,7 +135,7 @@ private function hasDescription(StringValueNode|null $descriptionNode): bool public function definition(): InspectionDescription { return new InspectionDescription( - "All definition nodes must have a description", + 'All definition nodes must have a description', ); } } diff --git a/src/Inspections/DisallowEnumInspection.php b/src/Inspections/DisallowEnumInspection.php index b5db4fe..b503763 100644 --- a/src/Inspections/DisallowEnumInspection.php +++ b/src/Inspections/DisallowEnumInspection.php @@ -23,7 +23,7 @@ public function visitEnumTypeDefinition( public function definition(): InspectionDescription { return new InspectionDescription( - "Enums are not allowed.", + 'Enums are not allowed.', ); } } diff --git a/src/Inspections/IgnoreNextLineSuppressorInspection.php b/src/Inspections/IgnoreNextLineSuppressorInspection.php index 6681ec4..4320b14 100644 --- a/src/Inspections/IgnoreNextLineSuppressorInspection.php +++ b/src/Inspections/IgnoreNextLineSuppressorInspection.php @@ -26,6 +26,6 @@ public function shouldSuppress(Node $node, array $parents, Inspection $inspectio return false; } - return Str::of($comment)->trim()->is("@graphlint-ignore-next-line"); + return Str::of($comment)->trim()->is('@graphlint-ignore-next-line'); } } diff --git a/src/Inspections/InputSuffixInputObjectTypeDefinitionInspection.php b/src/Inspections/InputSuffixInputObjectTypeDefinitionInspection.php index c938ff1..b3b53e3 100644 --- a/src/Inspections/InputSuffixInputObjectTypeDefinitionInspection.php +++ b/src/Inspections/InputSuffixInputObjectTypeDefinitionInspection.php @@ -43,7 +43,7 @@ public function visitInputObjectTypeDefinition( public function definition(): InspectionDescription { return new InspectionDescription( - "Input objects should always be suffixed with input.", + 'Input objects should always be suffixed with input.', ); } } diff --git a/src/Inspections/ModelDirectiveRequiresIdFieldInspection.php b/src/Inspections/ModelDirectiveRequiresIdFieldInspection.php index f358729..f75e552 100644 --- a/src/Inspections/ModelDirectiveRequiresIdFieldInspection.php +++ b/src/Inspections/ModelDirectiveRequiresIdFieldInspection.php @@ -25,7 +25,7 @@ public function visitObjectTypeDefinition( ): void { $hasModelDirective = $this->listFinder->contains( $objectTypeDefinitionNode->directives, - "model", + 'model', ); if (! $hasModelDirective) { @@ -34,7 +34,7 @@ public function visitObjectTypeDefinition( $hasIdField = $this->listFinder->contains( $objectTypeDefinitionNode->fields, - "id", + 'id', ); if ($hasIdField) { @@ -45,7 +45,7 @@ public function visitObjectTypeDefinition( $objectTypeDefinitionNode, $this->definition()->getTitle(), $this->addFieldFixer->withFieldDefinitionNode( - Parser::fieldDefinition("id: ID!") + Parser::fieldDefinition('id: ID!') )->atTop() ); } @@ -53,7 +53,7 @@ public function visitObjectTypeDefinition( public function definition(): InspectionDescription { return new InspectionDescription( - "Object types with @model directive on it, must have an id field.", + 'Object types with @model directive on it, must have an id field.', ); } } diff --git a/src/Inspections/MutationFieldArgumentNamedInputInspection.php b/src/Inspections/MutationFieldArgumentNamedInputInspection.php index 533b66d..27918d4 100644 --- a/src/Inspections/MutationFieldArgumentNamedInputInspection.php +++ b/src/Inspections/MutationFieldArgumentNamedInputInspection.php @@ -37,11 +37,11 @@ public function visitObjectTypeDefinition( // Take all the fields Collection::make($fields) // Get all arguments of the fields - ->flatMap(fn(FieldDefinitionNode $node) => iterator_to_array($node->arguments)) + ->flatMap(fn (FieldDefinitionNode $node) => iterator_to_array($node->arguments)) // Reject arguments which are named `input` - ->reject(fn(InputValueDefinitionNode $node) => $this->nameResolver->getName($node) === 'input') + ->reject(fn (InputValueDefinitionNode $node) => $this->nameResolver->getName($node) === 'input') // Register a problem on each of the arguments - ->each(fn(InputValueDefinitionNode $node) => $problemsHolder->registerProblemWithDescription( + ->each(fn (InputValueDefinitionNode $node) => $problemsHolder->registerProblemWithDescription( $node->name, $this->definition()->getTitle(), $this->renameFixer->withName('input'), @@ -51,7 +51,7 @@ public function visitObjectTypeDefinition( public function definition(): InspectionDescription { return new InspectionDescription( - "Mutation field may have one argument named input.", + 'Mutation field may have one argument named input.', ); } } diff --git a/src/Inspections/NonNullableIdInspection.php b/src/Inspections/NonNullableIdInspection.php index 8098a47..19d199c 100644 --- a/src/Inspections/NonNullableIdInspection.php +++ b/src/Inspections/NonNullableIdInspection.php @@ -45,7 +45,7 @@ public function visitFieldDefinition( public function definition(): InspectionDescription { return new InspectionDescription( - "Fields named ID must be non nullable.", + 'Fields named ID must be non nullable.', ); } } diff --git a/src/Inspections/NonNullableInsideListInspection.php b/src/Inspections/NonNullableInsideListInspection.php index 9f1b854..42d2218 100644 --- a/src/Inspections/NonNullableInsideListInspection.php +++ b/src/Inspections/NonNullableInsideListInspection.php @@ -47,7 +47,7 @@ public function visitListType( public function definition(): InspectionDescription { return new InspectionDescription( - "Type inside of a list must be non nullable.", + 'Type inside of a list must be non nullable.', ); } } diff --git a/src/Inspections/NonNullableListInspection.php b/src/Inspections/NonNullableListInspection.php index c3cd902..7adc129 100644 --- a/src/Inspections/NonNullableListInspection.php +++ b/src/Inspections/NonNullableListInspection.php @@ -63,7 +63,7 @@ public function visitListType( public function definition(): InspectionDescription { return new InspectionDescription( - "Lists must be non nullable.", + 'Lists must be non nullable.', ); } diff --git a/src/Inspections/PascalCaseObjectTypeDefinitionInspection.php b/src/Inspections/PascalCaseObjectTypeDefinitionInspection.php index 039a9e4..9bb0f9d 100644 --- a/src/Inspections/PascalCaseObjectTypeDefinitionInspection.php +++ b/src/Inspections/PascalCaseObjectTypeDefinitionInspection.php @@ -51,7 +51,7 @@ public function visitObjectTypeDefinition( public function definition(): InspectionDescription { return new InspectionDescription( - "Object types must be PascalCase.", + 'Object types must be PascalCase.', ); } } diff --git a/src/Inspections/UpperSnakeCaseEnumCaseDefinitionInspection.php b/src/Inspections/UpperSnakeCaseEnumCaseDefinitionInspection.php index 617a306..91549f8 100644 --- a/src/Inspections/UpperSnakeCaseEnumCaseDefinitionInspection.php +++ b/src/Inspections/UpperSnakeCaseEnumCaseDefinitionInspection.php @@ -51,7 +51,7 @@ public function visitEnumValueDefinition( public function definition(): InspectionDescription { return new InspectionDescription( - "Enum cases must be UPPER_CASE.", + 'Enum cases must be UPPER_CASE.', ); } } diff --git a/src/Listeners/CheckstyleListener.php b/src/Listeners/CheckstyleListener.php index 786bd75..b5db730 100644 --- a/src/Listeners/CheckstyleListener.php +++ b/src/Listeners/CheckstyleListener.php @@ -57,7 +57,7 @@ public function afterAnalyse(AfterAnalyseEvent $event): void $location = $this->compiledPath ?? $problem->getNode()->loc?->source?->name; if ($location === null) { - throw new ShouldNotHappenException("No location on node."); + throw new ShouldNotHappenException('No location on node.'); } /** @var DOMElement $file */ diff --git a/src/Listeners/ConsolePrinterListener.php b/src/Listeners/ConsolePrinterListener.php index 702645c..56028cb 100644 --- a/src/Listeners/ConsolePrinterListener.php +++ b/src/Listeners/ConsolePrinterListener.php @@ -29,7 +29,7 @@ public function __construct( public function beforeAnalyse(BeforeAnalyseEvent $event): void { - $this->style->info("Analysing schema..."); + $this->style->info('Analysing schema...'); } public function afterAnalyse(AfterAnalyseEvent $event): void @@ -45,6 +45,7 @@ public function afterAnalyse(AfterAnalyseEvent $event): void if ($problemCount === 0) { $this->style->success("No problems found in $type schema!"); + continue; } @@ -52,7 +53,7 @@ public function afterAnalyse(AfterAnalyseEvent $event): void $this->style->error("Found $problemCount problems in $type schema"); $unfixableErrors = Collection::make($problems) - ->filter(fn(ProblemDescriptor $descriptor) => $descriptor->getFix() === null) + ->filter(fn (ProblemDescriptor $descriptor) => $descriptor->getFix() === null) ->count(); $this->style->warning("$unfixableErrors cannot be automatically fixed in $type schema"); diff --git a/src/PostFixes/NodeReplacerPostFixer.php b/src/PostFixes/NodeReplacerPostFixer.php index 331bee2..dc088f4 100644 --- a/src/PostFixes/NodeReplacerPostFixer.php +++ b/src/PostFixes/NodeReplacerPostFixer.php @@ -14,7 +14,7 @@ public function __construct( ) { } - public function visitNode(Node $node): ?Node + public function visitNode(Node $node): Node|null { $nodes = $this->nodeReplacerCollector->getNodesToReplace(); diff --git a/src/PostFixes/PostFixer.php b/src/PostFixes/PostFixer.php index e55a767..ab249fb 100644 --- a/src/PostFixes/PostFixer.php +++ b/src/PostFixes/PostFixer.php @@ -8,5 +8,5 @@ abstract class PostFixer { - abstract public function visitNode(Node $node): ?Node; + abstract public function visitNode(Node $node): Node|null; } diff --git a/src/ProblemDescriptor.php b/src/ProblemDescriptor.php index eb0bb3f..bbad4e6 100644 --- a/src/ProblemDescriptor.php +++ b/src/ProblemDescriptor.php @@ -12,7 +12,7 @@ class ProblemDescriptor public function __construct( private readonly Node $node, private readonly string|null $description, - private readonly ?Fixer $fix, + private readonly Fixer|null $fix, ) { } @@ -21,7 +21,7 @@ public function getNode(): Node return $this->node; } - public function getFix(): ?Fixer + public function getFix(): Fixer|null { return $this->fix; } diff --git a/src/ProblemsHolder.php b/src/ProblemsHolder.php index 8ad0cd9..c6987a4 100644 --- a/src/ProblemsHolder.php +++ b/src/ProblemsHolder.php @@ -15,8 +15,7 @@ class ProblemsHolder private array $problems = []; public function registerProblem( - Node $node, - ?Fixer $fix = null, + Node $node, Fixer|null $fix = null, ): void { $this->problems[] = new ProblemDescriptor( $node, @@ -27,8 +26,7 @@ public function registerProblem( public function registerProblemWithDescription( Node $node, - string $description, - ?Fixer $fix = null, + string $description, Fixer|null $fix = null, ): void { $this->problems[] = new ProblemDescriptor( $node, diff --git a/src/Utils/NodeNameResolver.php b/src/Utils/NodeNameResolver.php index 0fb1b81..9609734 100644 --- a/src/Utils/NodeNameResolver.php +++ b/src/Utils/NodeNameResolver.php @@ -13,7 +13,7 @@ class NodeNameResolver /** * @param Node|NodeList|null $node */ - public function getName(Node|NodeList|null $node): ?string + public function getName(Node|NodeList|null $node): string|null { if (! $node instanceof Node) { return null; diff --git a/src/Utils/ProblemOutputGenerator.php b/src/Utils/ProblemOutputGenerator.php index 1bda206..75538d2 100644 --- a/src/Utils/ProblemOutputGenerator.php +++ b/src/Utils/ProblemOutputGenerator.php @@ -28,7 +28,7 @@ public function generate(): array private function title(): string { return sprintf( - "%s %d: %s %s", + '%s %d: %s %s', PHP_EOL . PHP_EOL, $this->index + 1, $this->descriptor->getDescription(), @@ -59,7 +59,7 @@ private function startToken(): Token $startToken = $this->descriptor->getNode()->loc?->startToken; if ($startToken === null) { - throw new ShouldNotHappenException("No location on node."); + throw new ShouldNotHappenException('No location on node.'); } return $startToken; @@ -70,7 +70,7 @@ private function endToken(): Token $endToken = $this->descriptor->getNode()->loc?->endToken; if ($endToken === null) { - throw new ShouldNotHappenException("No location on node."); + throw new ShouldNotHappenException('No location on node.'); } return $endToken; @@ -81,7 +81,7 @@ private function schemaBody(): string $body = $this->descriptor->getNode()->loc?->source?->body; if ($body === null) { - throw new ShouldNotHappenException("No source on node."); + throw new ShouldNotHappenException('No source on node.'); } return $body; diff --git a/src/Utils/RootTypeName.php b/src/Utils/RootTypeName.php index efe22c0..a474237 100644 --- a/src/Utils/RootTypeName.php +++ b/src/Utils/RootTypeName.php @@ -7,5 +7,5 @@ enum RootTypeName: string { case Query = 'Query'; - case Mutation = "Mutation"; + case Mutation = 'Mutation'; } diff --git a/src/Visitors/VisitorCollector.php b/src/Visitors/VisitorCollector.php index 6565975..376b730 100644 --- a/src/Visitors/VisitorCollector.php +++ b/src/Visitors/VisitorCollector.php @@ -49,79 +49,79 @@ public function getVisitor(ProblemsHolder $problemsHolder, AffectedInspections $ { /** @var array $visitors */ $visitors = array_map( - fn(Inspection $inspection) => [ + fn (Inspection $inspection) => [ NodeKind::FIELD_DEFINITION => $this->wrapper( - fn(FieldDefinitionNode $fieldDefinitionNode) => + fn (FieldDefinitionNode $fieldDefinitionNode) => $inspection->visitFieldDefinition($problemsHolder, $fieldDefinitionNode), $inspection, $affectedInspections, $problemsHolder, ), NodeKind::INPUT_OBJECT_TYPE_DEFINITION => $this->wrapper( - fn(InputObjectTypeDefinitionNode $node) => + fn (InputObjectTypeDefinitionNode $node) => $inspection->visitInputObjectTypeDefinition($problemsHolder, $node), $inspection, $affectedInspections, $problemsHolder, ), NodeKind::ARGUMENT => $this->wrapper( - fn(ArgumentNode $argumentNode) => + fn (ArgumentNode $argumentNode) => $inspection->visitArgumentNode($problemsHolder, $argumentNode), $inspection, $affectedInspections, $problemsHolder, ), NodeKind::OBJECT_TYPE_DEFINITION => $this->wrapper( - fn(ObjectTypeDefinitionNode $node) => + fn (ObjectTypeDefinitionNode $node) => $inspection->visitObjectTypeDefinition($problemsHolder, $node), $inspection, $affectedInspections, $problemsHolder, ), NodeKind::LIST_TYPE => $this->wrapper( - fn(ListTypeNode $node, Node $parent, array $ancestors) => + fn (ListTypeNode $node, Node $parent, array $ancestors) => $inspection->visitListType($problemsHolder, $node, $parent, $ancestors), $inspection, $affectedInspections, $problemsHolder, ), NodeKind::ENUM_TYPE_DEFINITION => $this->wrapper( - fn(EnumTypeDefinitionNode $node) => + fn (EnumTypeDefinitionNode $node) => $inspection->visitEnumTypeDefinition($problemsHolder, $node), $inspection, $affectedInspections, $problemsHolder, ), NodeKind::SCALAR_TYPE_DEFINITION => $this->wrapper( - fn(ScalarTypeDefinitionNode $node) => + fn (ScalarTypeDefinitionNode $node) => $inspection->visitScalarTypeDefinition($problemsHolder, $node), $inspection, $affectedInspections, $problemsHolder, ), NodeKind::INPUT_VALUE_DEFINITION => $this->wrapper( - fn(InputValueDefinitionNode $node) => + fn (InputValueDefinitionNode $node) => $inspection->visitInputValueDefinition($problemsHolder, $node), $inspection, $affectedInspections, $problemsHolder, ), NodeKind::INTERFACE_TYPE_DEFINITION => $this->wrapper( - fn(InterfaceTypeDefinitionNode $node) => + fn (InterfaceTypeDefinitionNode $node) => $inspection->visitInterfaceTypeDefinition($problemsHolder, $node), $inspection, $affectedInspections, $problemsHolder, ), NodeKind::UNION_TYPE_DEFINITION => $this->wrapper( - fn(UnionTypeDefinitionNode $node) => + fn (UnionTypeDefinitionNode $node) => $inspection->visitUnionTypeDefinition($problemsHolder, $node), $inspection, $affectedInspections, $problemsHolder, ), NodeKind::ENUM_VALUE_DEFINITION => $this->wrapper( - fn(EnumValueDefinitionNode $node) => + fn (EnumValueDefinitionNode $node) => $inspection->visitEnumValueDefinition($problemsHolder, $node), $inspection, $affectedInspections, @@ -181,6 +181,7 @@ private function shouldSkip(Node $node, array $parent, Inspection $inspection): return true; } } + return false; } } diff --git a/tests/Pest.php b/tests/Pest.php index 8daf640..591e332 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -58,10 +58,11 @@ if (Str::endsWith($smartFileInfo->getRealPath(), '.skip.graphql.inc')) { $descriptions = Collection::make($result->getProblemsHolder()->getProblems()) - ->map(fn(ProblemDescriptor $descriptor) => $descriptor->getDescription()) + ->map(fn (ProblemDescriptor $descriptor) => $descriptor->getDescription()) ->all(); expect($descriptions)->toEqual([]) ->and($result->getProblemsHolder()->getProblems())->toHaveCount(0); + return; }