Skip to content

Commit

Permalink
style: apply changes from ECS
Browse files Browse the repository at this point in the history
  • Loading branch information
owenvoke committed Dec 17, 2024
1 parent 7c0ea39 commit 49b95a9
Show file tree
Hide file tree
Showing 30 changed files with 59 additions and 48 deletions.
1 change: 1 addition & 0 deletions src/Analyser/AffectedInspections.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function addInspection(Inspection $inspection): self
}

$this->inspections->add($inspection);

return $this;
}
}
3 changes: 3 additions & 0 deletions src/Commands/AnalyseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
class Visitor
{
public const ORIGINAL = 'graphlint.original_visitor';

public const COMPILED = 'graphlint.compiled_visitor';
}
2 changes: 2 additions & 0 deletions src/Fixes/AddFieldFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/Fixes/RenameFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function fix(ProblemDescriptor $problemDescriptor): void
public function withName(string $name): self
{
$this->newName = $name;

return $this;
}
}
1 change: 1 addition & 0 deletions src/Fixes/SuffixNameFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function fix(ProblemDescriptor $problemDescriptor): void
public function withSuffix(string $suffix): self
{
$this->suffix = $suffix;

return $this;
}
}
1 change: 1 addition & 0 deletions src/Graphlint.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private function dispatchEvent(EventInterface $event): void
public function addListener(GraphlintListener $listener): self
{
$this->listeners[] = $listener;

return $this;
}
}
2 changes: 1 addition & 1 deletion src/Inspections/CamelCaseFieldDefinitionInspection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
}
}
2 changes: 1 addition & 1 deletion src/Inspections/DescriptionRequiredInspection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
}
}
2 changes: 1 addition & 1 deletion src/Inspections/DisallowEnumInspection.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function visitEnumTypeDefinition(
public function definition(): InspectionDescription
{
return new InspectionDescription(
"Enums are not allowed.",
'Enums are not allowed.',
);
}
}
2 changes: 1 addition & 1 deletion src/Inspections/IgnoreNextLineSuppressorInspection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
}
}
8 changes: 4 additions & 4 deletions src/Inspections/ModelDirectiveRequiresIdFieldInspection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function visitObjectTypeDefinition(
): void {
$hasModelDirective = $this->listFinder->contains(
$objectTypeDefinitionNode->directives,
"model",
'model',
);

if (! $hasModelDirective) {
Expand All @@ -34,7 +34,7 @@ public function visitObjectTypeDefinition(

$hasIdField = $this->listFinder->contains(
$objectTypeDefinitionNode->fields,
"id",
'id',
);

if ($hasIdField) {
Expand All @@ -45,15 +45,15 @@ public function visitObjectTypeDefinition(
$objectTypeDefinitionNode,
$this->definition()->getTitle(),
$this->addFieldFixer->withFieldDefinitionNode(
Parser::fieldDefinition("id: ID!")
Parser::fieldDefinition('id: ID!')
)->atTop()
);
}

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.',
);
}
}
8 changes: 4 additions & 4 deletions src/Inspections/MutationFieldArgumentNamedInputInspection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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.',
);
}
}
2 changes: 1 addition & 1 deletion src/Inspections/NonNullableIdInspection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
}
}
2 changes: 1 addition & 1 deletion src/Inspections/NonNullableInsideListInspection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
}
}
2 changes: 1 addition & 1 deletion src/Inspections/NonNullableListInspection.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function visitListType(
public function definition(): InspectionDescription
{
return new InspectionDescription(
"Lists must be non nullable.",
'Lists must be non nullable.',
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function visitObjectTypeDefinition(
public function definition(): InspectionDescription
{
return new InspectionDescription(
"Object types must be PascalCase.",
'Object types must be PascalCase.',
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
}
}
2 changes: 1 addition & 1 deletion src/Listeners/CheckstyleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 3 additions & 2 deletions src/Listeners/ConsolePrinterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,14 +45,15 @@ public function afterAnalyse(AfterAnalyseEvent $event): void

if ($problemCount === 0) {
$this->style->success("No problems found in $type schema!");

continue;
}

$this->hasErrors = true;
$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");

Expand Down
2 changes: 1 addition & 1 deletion src/PostFixes/NodeReplacerPostFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(
) {
}

public function visitNode(Node $node): ?Node
public function visitNode(Node $node): Node|null
{
$nodes = $this->nodeReplacerCollector->getNodesToReplace();

Expand Down
2 changes: 1 addition & 1 deletion src/PostFixes/PostFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

abstract class PostFixer
{
abstract public function visitNode(Node $node): ?Node;
abstract public function visitNode(Node $node): Node|null;
}
4 changes: 2 additions & 2 deletions src/ProblemDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand All @@ -21,7 +21,7 @@ public function getNode(): Node
return $this->node;
}

public function getFix(): ?Fixer
public function getFix(): Fixer|null
{
return $this->fix;
}
Expand Down
6 changes: 2 additions & 4 deletions src/ProblemsHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/NodeNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class NodeNameResolver
/**
* @param Node|NodeList<Node>|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;
Expand Down
8 changes: 4 additions & 4 deletions src/Utils/ProblemOutputGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function generate(): array
private function title(): string
{
return sprintf(
"<bg=red;options=bold>%s %d: %s %s</>",
'<bg=red;options=bold>%s %d: %s %s</>',
PHP_EOL . PHP_EOL,
$this->index + 1,
$this->descriptor->getDescription(),
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/RootTypeName.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
enum RootTypeName: string
{
case Query = 'Query';
case Mutation = "Mutation";
case Mutation = 'Mutation';
}
Loading

0 comments on commit 49b95a9

Please sign in to comment.