Passed
Push — develop ( ff7e62...18f528 )
by Andrew
07:05 queued 10s
created

SeomaticInterface::getFieldDefinitions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 12
rs 10
1
<?php
2
/**
3
 * SEOmatic plugin for Craft CMS 3.x
4
 *
5
 * A turnkey SEO implementation for Craft CMS that is comprehensive, powerful,
6
 * and flexible
7
 *
8
 * @link      https://nystudio107.com
9
 * @copyright Copyright (c) 2019 nystudio107
10
 */
11
12
namespace nystudio107\seomatic\gql\interfaces;
13
14
use nystudio107\seomatic\gql\types\generators\SeomaticGenerator;
15
16
use craft\gql\base\InterfaceType as BaseInterfaceType;
17
use craft\gql\TypeLoader;
18
use craft\gql\GqlEntityRegistry;
19
20
use GraphQL\Type\Definition\InterfaceType;
21
use GraphQL\Type\Definition\Type;
22
use nystudio107\seomatic\models\MetaJsonLdContainer;
23
use nystudio107\seomatic\models\MetaLinkContainer;
24
use nystudio107\seomatic\models\MetaScriptContainer;
25
use nystudio107\seomatic\models\MetaTagContainer;
26
use nystudio107\seomatic\models\MetaTitleContainer;
27
28
/**
29
 * Class SeomaticInterface
30
 *
31
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
32
 * @package   Seomatic
33
 * @since     3.2.8
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
34
 */
35
class SeomaticInterface extends BaseInterfaceType
36
{
37
    // Constants
38
    // =========================================================================
39
40
    const GRAPH_QL_FIELDS = [
41
        'metaTitleContainer' => MetaTitleContainer::CONTAINER_TYPE,
42
        'metaTagContainer' => MetaTagContainer::CONTAINER_TYPE,
43
        'metaLinkContainer' => MetaLinkContainer::CONTAINER_TYPE,
44
        'metaScriptContainer' => MetaScriptContainer::CONTAINER_TYPE,
45
        'metaJsonLdContainer' => MetaJsonLdContainer::CONTAINER_TYPE,
46
    ];
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public static function getTypeGenerator(): string
52
    {
53
        return SeomaticGenerator::class;
54
    }
55
56
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $fields should have a doc-comment as per coding-style.
Loading history...
57
     * @inheritdoc
58
     */
59
    public static function getType($fields = null): Type
0 ignored issues
show
Unused Code introduced by
The parameter $fields is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

59
    public static function getType(/** @scrutinizer ignore-unused */ $fields = null): Type

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

Loading history...
60
    {
61
        if ($type = GqlEntityRegistry::getEntity(self::class)) {
62
            return $type;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $type could return the type true which is incompatible with the type-hinted return GraphQL\Type\Definition\Type. Consider adding an additional type-check to rule them out.
Loading history...
63
        }
64
65
        $type = GqlEntityRegistry::createEntity(self::class, new InterfaceType([
66
            'name' => static::getName(),
67
            'fields' => self::class.'::getFieldDefinitions',
68
            'description' => 'This is the interface implemented by SEOmatic.',
69
            'resolveType' => function (array $value) {
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

69
            'resolveType' => function (/** @scrutinizer ignore-unused */ array $value) {

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

Loading history...
70
                return GqlEntityRegistry::getEntity(SeomaticGenerator::getName());
71
            },
72
        ]));
73
74
        foreach (SeomaticGenerator::generateTypes() as $typeName => $generatedType) {
75
            TypeLoader::registerType($typeName, function () use ($generatedType) {
76
                return $generatedType;
77
            });
78
        }
79
80
        return $type;
81
    }
82
83
    /**
84
     * @inheritdoc
85
     */
86
    public static function getName(): string
87
    {
88
        return 'SeomaticInterface';
89
    }
90
91
    /**
92
     * @inheritdoc
93
     */
94
    public static function getFieldDefinitions(): array
95
    {
96
        $fields = [];
97
        foreach (self::GRAPH_QL_FIELDS as $key => $value) {
98
            $fields[$key] = [
99
                'name' => $key,
100
                'type' => Type::string(),
101
                'description' => 'The '.$value.' SEOmatic container.',
102
            ];
103
        }
104
105
        return $fields;
106
    }
107
}
108