Passed
Push — develop ( 4ac642...83abb8 )
by Andrew
03:28
created

GetCraftQLSchema   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 58
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 40 1
1
<?php
2
3
namespace nystudio107\imageoptimize\listeners;
4
5
use Craft;
6
7
use markhuot\CraftQL\Events\GetFieldSchema;
0 ignored issues
show
Bug introduced by
The type markhuot\CraftQL\Events\GetFieldSchema was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
use GraphQL\Type\Definition\Type;
0 ignored issues
show
Bug introduced by
The type GraphQL\Type\Definition\Type was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
class GetCraftQLSchema
12
{
13
14
    // Constants
15
    // =========================================================================
16
17
    const EVENT_GET_FIELD_SCHEMA = 'craftQlGetFieldSchema';
18
19
    // Public methods
20
    // =========================================================================
21
22
    /**
23
     * Handle the request for the schema
24
     *
25
     * @param GetFieldSchema $event
26
     *
27
     * @return void
28
     */
29
    public function handle($event)
30
    {
31
        $event->handled = true;
32
        $field = $event->sender;
0 ignored issues
show
Unused Code introduced by
The assignment to $field is dead and can be removed.
Loading history...
33
34
        $fieldObject = $event->schema->createObjectType('OptimizedImagesData');
35
36
        // Primary getter functions
37
        $fieldObject->addStringField('src');
38
        $fieldObject->addStringField('srcset');
39
        $fieldObject->addStringField('srcWebp');
40
        $fieldObject->addStringField('srcsetWebp');
41
        $fieldObject->addIntField('maxSrcsetWidth');
42
        $fieldObject->addStringField('placeholderImage');
43
        $fieldObject->addStringField('placeholderBox');
44
        $fieldObject->addStringField('placeholderSilhouette');
45
46
        // Object properties
47
        $fieldObject->addStringField('optimizedImageUrls')
48
            ->lists()
49
            ->type(Type::string());
50
        $fieldObject->addStringField('optimizedWebPImageUrls')
51
            ->lists()
52
            ->type(Type::string());
53
        $fieldObject->addIntField('variantSourceWidths')
54
            ->lists()
55
            ->type(Type::int());
56
        $fieldObject->addIntField('originalImageWidth');
57
        $fieldObject->addIntField('originalImageHeight');
58
        $fieldObject->addStringField('placeholder');
59
        $fieldObject->addStringField('placeholderSvg');
60
        $fieldObject->addStringField('colorPalette')
61
            ->lists()
62
            ->type(Type::string());
63
        $fieldObject->addIntField('placeholderWidth');
64
        $fieldObject->addIntField('placeholderHeight');
65
66
        // Add the field object to the schema
67
        $event->schema->addField($event->sender)
68
            ->type($fieldObject);
69
    }
70
}
71