Skip to content

Commit

Permalink
Additional codestyle tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
peldax committed Jul 18, 2024
1 parent 30d8db2 commit d5f72a3
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 72 deletions.
5 changes: 3 additions & 2 deletions src/Introspection/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
use Graphpinator\Typesystem\InterfaceSet;
use Graphpinator\Typesystem\InterfaceType;
use Graphpinator\Typesystem\ScalarType;
use Graphpinator\Typesystem\Type as TypesystemType;
use Graphpinator\Typesystem\TypeSet;
use Graphpinator\Typesystem\UnionType;

#[Description('Built-in introspection type')]
final class Type extends \Graphpinator\Typesystem\Type
final class Type extends TypesystemType
{
protected const NAME = '__Type';

Expand Down Expand Up @@ -118,7 +119,7 @@ function (TypeDef $definition) : ?TypeSet {
$subTypes = [];

foreach ($this->container->getTypes() as $type) {
if ($type instanceof \Graphpinator\Typesystem\Type &&
if ($type instanceof TypesystemType &&
$type->isInstanceOf($definition)) {
$subTypes[] = $type;
}
Expand Down
97 changes: 45 additions & 52 deletions src/Normalizer/Normalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Graphpinator\Common\Path;
use Graphpinator\Exception\GraphpinatorBase;
use Graphpinator\Normalizer\Directive\Directive;
use Graphpinator\Normalizer\Directive\DirectiveSet;
use Graphpinator\Normalizer\Exception\DirectiveIncorrectLocation;
use Graphpinator\Normalizer\Exception\DirectiveIncorrectUsage;
Expand All @@ -20,34 +21,44 @@
use Graphpinator\Normalizer\Exception\UnknownFragment;
use Graphpinator\Normalizer\Exception\UnknownType;
use Graphpinator\Normalizer\Exception\VariableTypeInputable;
use Graphpinator\Normalizer\Operation\Operation;
use Graphpinator\Normalizer\Operation\OperationSet;
use Graphpinator\Normalizer\Selection\Field;
use Graphpinator\Normalizer\Selection\FragmentSpread;
use Graphpinator\Normalizer\Selection\InlineFragment;
use Graphpinator\Normalizer\Selection\Selection;
use Graphpinator\Normalizer\Selection\SelectionSet;
use Graphpinator\Normalizer\Variable\Variable;
use Graphpinator\Normalizer\Variable\VariableSet;
use Graphpinator\Parser\Directive\Directive;
use Graphpinator\Parser\Field\Field;
use Graphpinator\Parser\Field\FieldSet;
use Graphpinator\Parser\Directive\Directive as ParserDirective;
use Graphpinator\Parser\Directive\DirectiveSet as ParserDirectiveSet;
use Graphpinator\Parser\Field\Field as ParserField;
use Graphpinator\Parser\Field\FieldSet as ParserFieldSet;
use Graphpinator\Parser\Fragment\FragmentSet;
use Graphpinator\Parser\FragmentSpread\FragmentSpread;
use Graphpinator\Parser\FragmentSpread\FragmentSpread as ParserFragmentSpread;
use Graphpinator\Parser\FragmentSpread\InlineFragmentSpread;
use Graphpinator\Parser\FragmentSpread\NamedFragmentSpread;
use Graphpinator\Parser\Operation\Operation;
use Graphpinator\Parser\Operation\OperationSet;
use Graphpinator\Parser\Operation\Operation as ParserOperation;
use Graphpinator\Parser\Operation\OperationSet as ParserOperationSet;
use Graphpinator\Parser\ParsedRequest;
use Graphpinator\Parser\TypeRef\ListTypeRef;
use Graphpinator\Parser\TypeRef\NamedTypeRef;
use Graphpinator\Parser\TypeRef\NotNullRef;
use Graphpinator\Parser\TypeRef\TypeRef;
use Graphpinator\Parser\Value\ArgumentValueSet;
use Graphpinator\Parser\Value\ArgumentValueSet as ParserArgumentValueSet;
use Graphpinator\Parser\Value\Value;
use Graphpinator\Parser\Variable\Variable as ParserVariable;
use Graphpinator\Parser\Variable\VariableSet as ParserVariableSet;
use Graphpinator\Tokenizer\TokenType;
use Graphpinator\Typesystem\Argument\ArgumentSet;
use Graphpinator\Typesystem\Contract\ExecutableDirective;
use Graphpinator\Typesystem\Contract\Inputable;
use Graphpinator\Typesystem\Contract\LeafType;
use Graphpinator\Typesystem\Contract\NamedType;
use Graphpinator\Typesystem\Contract\Type as TypesystemType;
use Graphpinator\Typesystem\Contract\TypeConditionable;
use Graphpinator\Typesystem\Directive as TypesystemDirective;
use Graphpinator\Typesystem\Field\Field as TypesystemField;
use Graphpinator\Typesystem\ListType;
use Graphpinator\Typesystem\Location\ExecutableDirectiveLocation;
use Graphpinator\Typesystem\Location\FieldLocation;
Expand All @@ -57,6 +68,7 @@
use Graphpinator\Typesystem\Type;
use Graphpinator\Typesystem\UnionType;
use Graphpinator\Value\ArgumentValue;
use Graphpinator\Value\ArgumentValueSet;
use Graphpinator\Value\ConvertParserValueVisitor;
use Graphpinator\Value\ConvertRawValueVisitor;

Expand Down Expand Up @@ -107,9 +119,7 @@ private static function typeCanOccur(NamedType $parentType, NamedType $typeCond)
return false;
}

private function normalizeOperationSet(
OperationSet $operationSet,
) : \Graphpinator\Normalizer\Operation\OperationSet
private function normalizeOperationSet(ParserOperationSet $operationSet,) : OperationSet
{
$normalized = [];

Expand All @@ -119,12 +129,10 @@ private function normalizeOperationSet(
$this->path->pop();
}

return new \Graphpinator\Normalizer\Operation\OperationSet($normalized);
return new OperationSet($normalized);
}

private function normalizeOperation(
Operation $operation,
) : \Graphpinator\Normalizer\Operation\Operation
private function normalizeOperation(ParserOperation $operation) : Operation
{
$rootObject = match ($operation->getType()) {
TokenType::QUERY->value => $this->schema->getQuery(),
Expand All @@ -147,7 +155,7 @@ private function normalizeOperation(

$this->scopeStack->pop();

return new \Graphpinator\Normalizer\Operation\Operation(
return new Operation(
$operation->getType(),
$operation->getName(),
$rootObject,
Expand All @@ -157,7 +165,7 @@ private function normalizeOperation(
);
}

private function normalizeVariables(\Graphpinator\Parser\Variable\VariableSet $variableSet) : VariableSet
private function normalizeVariables(ParserVariableSet $variableSet) : VariableSet
{
$normalized = [];

Expand All @@ -170,7 +178,7 @@ private function normalizeVariables(\Graphpinator\Parser\Variable\VariableSet $v
return new VariableSet($normalized);
}

private function normalizeVariable(\Graphpinator\Parser\Variable\Variable $variable) : Variable
private function normalizeVariable(ParserVariable $variable) : Variable
{
$type = $this->normalizeTypeRef($variable->getType());
$defaultValue = $variable->getDefault();
Expand Down Expand Up @@ -200,9 +208,7 @@ private function normalizeVariable(\Graphpinator\Parser\Variable\Variable $varia
return $normalized;
}

private function normalizeFieldSet(
FieldSet $fieldSet,
) : SelectionSet
private function normalizeFieldSet(ParserFieldSet $fieldSet) : SelectionSet
{
$normalized = [];

Expand All @@ -227,9 +233,7 @@ private function normalizeFieldSet(
return $result;
}

private function normalizeField(
Field $field,
) : \Graphpinator\Normalizer\Selection\Field
private function normalizeField(ParserField $field) : Field
{
$parentType = $this->scopeStack->top();

Expand All @@ -239,10 +243,10 @@ private function normalizeField(
$this->scopeStack->push($fieldType);

$arguments = $this->normalizeArgumentValueSet($field->getArguments(), $fieldDef->getArguments());
$directives = $field->getDirectives() instanceof \Graphpinator\Parser\Directive\DirectiveSet
$directives = $field->getDirectives() instanceof ParserDirectiveSet
? $this->normalizeDirectiveSet($field->getDirectives(), ExecutableDirectiveLocation::FIELD, $fieldDef)
: new DirectiveSet();
$children = $field->getFields() instanceof FieldSet
$children = $field->getFields() instanceof ParserFieldSet
? $this->normalizeFieldSet($field->getFields())
: null;

Expand All @@ -252,7 +256,7 @@ private function normalizeField(

$this->scopeStack->pop();

return new \Graphpinator\Normalizer\Selection\Field(
return new Field(
$fieldDef,
$field->getAlias()
?? $fieldDef->getName(),
Expand All @@ -263,9 +267,9 @@ private function normalizeField(
}

private function normalizeDirectiveSet(
\Graphpinator\Parser\Directive\DirectiveSet $directiveSet,
ParserDirectiveSet $directiveSet,
ExecutableDirectiveLocation $location,
\Graphpinator\Typesystem\Field\Field|Variable|null $usage = null,
TypesystemField|Variable|null $usage = null,
) : DirectiveSet
{
$normalized = [];
Expand Down Expand Up @@ -297,14 +301,14 @@ private function normalizeDirectiveSet(
}

private function normalizeDirective(
Directive $directive,
ParserDirective $directive,
ExecutableDirectiveLocation $location,
\Graphpinator\Typesystem\Field\Field|Variable|null $usage = null,
) : \Graphpinator\Normalizer\Directive\Directive
TypesystemField|Variable|null $usage = null,
) : Directive
{
$directiveDef = $this->schema->getContainer()->getDirective($directive->getName());

if (!$directiveDef instanceof \Graphpinator\Typesystem\Directive) {
if (!$directiveDef instanceof TypesystemDirective) {
throw new UnknownDirective($directive->getName());
}

Expand All @@ -326,15 +330,12 @@ private function normalizeDirective(
}
}

return new \Graphpinator\Normalizer\Directive\Directive($directiveDef, $arguments);
return new Directive($directiveDef, $arguments);
}

private function normalizeArgumentValueSet(
?ArgumentValueSet $argumentValueSet,
ArgumentSet $argumentSet,
) : \Graphpinator\Value\ArgumentValueSet
private function normalizeArgumentValueSet(?ParserArgumentValueSet $argumentValueSet, ArgumentSet $argumentSet) : ArgumentValueSet
{
$argumentValueSet ??= new ArgumentValueSet();
$argumentValueSet ??= new ParserArgumentValueSet();
$items = [];

foreach ($argumentValueSet as $value) {
Expand Down Expand Up @@ -373,12 +374,10 @@ private function normalizeArgumentValueSet(
$this->path->pop();
}

return new \Graphpinator\Value\ArgumentValueSet($items);
return new ArgumentValueSet($items);
}

private function normalizeFragmentSpread(
FragmentSpread $fragmentSpread,
) : Selection
private function normalizeFragmentSpread(ParserFragmentSpread $fragmentSpread) : Selection
{
return match ($fragmentSpread::class) {
NamedFragmentSpread::class =>
Expand All @@ -390,9 +389,7 @@ private function normalizeFragmentSpread(
};
}

private function normalizeNamedFragmentSpread(
NamedFragmentSpread $fragmentSpread,
) : \Graphpinator\Normalizer\Selection\FragmentSpread
private function normalizeNamedFragmentSpread(NamedFragmentSpread $fragmentSpread) : FragmentSpread
{
$this->path->add($fragmentSpread->getName() . ' <fragment spread>');

Expand All @@ -412,12 +409,10 @@ private function normalizeNamedFragmentSpread(
ExecutableDirectiveLocation::FRAGMENT_SPREAD,
);

return new \Graphpinator\Normalizer\Selection\FragmentSpread($fragmentSpread->getName(), $fields, $directives, $typeCond);
return new FragmentSpread($fragmentSpread->getName(), $fields, $directives, $typeCond);
}

private function normalizeInlineFragmentSpread(
InlineFragmentSpread $fragmentSpread,
) : InlineFragment
private function normalizeInlineFragmentSpread(InlineFragmentSpread $fragmentSpread) : InlineFragment
{
$this->path->add('<inline fragment>');

Expand All @@ -441,9 +436,7 @@ private function normalizeInlineFragmentSpread(
return new InlineFragment($fields, $directives, $typeCond);
}

private function normalizeTypeRef(
TypeRef $typeRef,
) : \Graphpinator\Typesystem\Contract\Type
private function normalizeTypeRef(TypeRef $typeRef) : TypesystemType
{
return match ($typeRef::class) {
NamedTypeRef::class =>
Expand Down
5 changes: 3 additions & 2 deletions src/Normalizer/Selection/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

use Graphpinator\Normalizer\Directive\DirectiveSet;
use Graphpinator\Normalizer\VariableValueSet;
use Graphpinator\Typesystem\Field\Field as TypesystemField;
use Graphpinator\Value\ArgumentValueSet;

final class Field implements Selection
{
public function __construct(
private \Graphpinator\Typesystem\Field\Field $field,
private TypesystemField $field,
private string $outputName,
private ArgumentValueSet $arguments,
private DirectiveSet $directives,
Expand All @@ -20,7 +21,7 @@ public function __construct(
{
}

public function getField() : \Graphpinator\Typesystem\Field\Field
public function getField() : TypesystemField
{
return $this->field;
}
Expand Down
5 changes: 3 additions & 2 deletions src/SimpleContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Graphpinator\Introspection\TypeKind;
use Graphpinator\Typesystem\Container;
use Graphpinator\Typesystem\Contract\NamedType;
use Graphpinator\Typesystem\Directive as TypesystemDirective;

/**
* Simple Container implementation
Expand All @@ -29,7 +30,7 @@ class SimpleContainer extends Container
* @phpcs:ignore SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax.DisallowedArrayTypeHintSyntax
* @param NamedType[] $types
* @phpcs:ignore SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax.DisallowedArrayTypeHintSyntax
* @param \Graphpinator\Typesystem\Directive[] $directives
* @param TypesystemDirective[] $directives
*/
public function __construct(array $types, array $directives)
{
Expand Down Expand Up @@ -81,7 +82,7 @@ public function getTypes(bool $includeBuiltIn = false) : array
: $this->types;
}

public function getDirective(string $name) : ?\Graphpinator\Typesystem\Directive
public function getDirective(string $name) : ?TypesystemDirective
{
return $this->combinedDirectives[$name]
?? null;
Expand Down
Loading

0 comments on commit d5f72a3

Please sign in to comment.