Completed
Push — master ( 3f8b6c...ed0e69 )
by
unknown
06:31
created

AllTranslationsDirective::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace BBSLab\NovaTranslation\GraphQL\Directives;
4
5
use GraphQL\Language\AST\FieldDefinitionNode;
6
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
7
use GraphQL\Type\Definition\ResolveInfo;
8
use Nuwave\Lighthouse\Schema\AST\DocumentAST;
9
use Nuwave\Lighthouse\Schema\Directives\BaseDirective;
10
use Nuwave\Lighthouse\Schema\Values\FieldValue;
11
use Nuwave\Lighthouse\Support\Contracts\DefinedDirective;
12
use Nuwave\Lighthouse\Support\Contracts\FieldManipulator;
13
use Nuwave\Lighthouse\Support\Contracts\FieldResolver;
14
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;
15
16 View Code Duplication
class AllTranslationsDirective extends BaseDirective implements FieldResolver, FieldManipulator, DefinedDirective
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    use Traits\ExtendSchemaWithLocaleFields, Traits\LocaleFilters;
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function name(): string
24
    {
25
        return 'allTranslations';
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public static function definition(): string
32
    {
33
        return /* @lang GraphQL */ <<<'SDL'
34
directive @allTranslations(
35
  "Specify the class name of the model to use."
36
  model: String
37
  "Specify the GraphQL type to add the 'locale' field (if GraphQL type is different from model class basename)."
38
  type: String
39
) on ARGUMENT_DEFINITION
40
SDL;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function manipulateFieldDefinition(DocumentAST &$documentAST, FieldDefinitionNode &$fieldDefinition, ObjectTypeDefinitionNode &$parentType): void
47
    {
48
        $this->extendSchemaWithLocaleFields(
49
            $documentAST,
50
            $this->directiveArgValue('type', class_basename($this->getModelClass()))
51
        );
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function resolveField(FieldValue $fieldValue): FieldValue
58
    {
59
        return $fieldValue->setResolver(
60
            function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) {
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $resolveInfo is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
                return $this->localeFilters($this->getModelClass(), $args)->get();
62
            }
63
        );
64
    }
65
}
66