Passed
Push — v1 ( 3e1bfa...380a0b )
by Andrew
26:42 queued 14:59
created

OptimizedImagesType   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 41
c 0
b 0
f 0
dl 0
loc 75
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B resolve() 0 70 11
1
<?php
2
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
3
 * @link https://craftcms.com/
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
Coding Style introduced by
Tag value for @link tag indented incorrectly; expected 6 spaces but found 1
Loading history...
4
 * @copyright Copyright (c) Pixel & Tonic, Inc.
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
5
 * @license https://craftcms.github.io/license/
0 ignored issues
show
Coding Style introduced by
@license tag must contain a URL and a license name
Loading history...
Coding Style introduced by
Tag value for @license tag indented incorrectly; expected 3 spaces but found 1
Loading history...
6
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
7
8
namespace nystudio107\imageoptimize\gql\types;
9
10
use nystudio107\imageoptimize\models\OptimizedImage;
11
12
use craft\gql\base\ObjectType;
13
14
use GraphQL\Type\Definition\ResolveInfo;
15
16
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
17
 * @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...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
18
 * @package   ImageOptimize
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
19
 * @since     1.6.2
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
20
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
21
class OptimizedImagesType extends ObjectType
22
{
23
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $source should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $arguments should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $context should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $resolveInfo should have a doc-comment as per coding-style.
Loading history...
24
     * @inheritdoc
25
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
26
    protected function resolve($source, $arguments, $context, ResolveInfo $resolveInfo)
27
    {
28
        /** @var OptimizedImage $source */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
29
        $fieldName = $resolveInfo->fieldName;
30
31
        switch ($fieldName) {
32
            // Special-case the `src` field with arguments
33
            case 'src':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
34
                $width = $arguments['width'] ?? 0;
35
36
                return $source->src($width);
37
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
38
39
            // Special-case the `srcWebp` field with arguments
40
            case 'srcWebp':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
41
                $width = $arguments['width'] ?? 0;
42
43
                return $source->srcWebp($width);
44
                break;
45
46
            // Special-case the `srcset` field with arguments
47
            case 'srcset':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
48
                $dpr = $arguments['dpr'] ?? false;
49
50
                return $source->srcset($dpr);
51
                break;
52
53
            // Special-case the `srcsetWebp` field with arguments
54
            case 'srcsetWebp':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
55
                $dpr = $arguments['dpr'] ?? false;
56
57
                return $source->srcsetWebp($dpr);
58
                break;
59
60
            // Special-case the `maxSrcsetWidth` field
61
            case 'maxSrcsetWidth':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
62
                return $source->maxSrcsetWidth();
63
                break;
64
65
            // Special-case the `placeholderImage` field
66
            case 'placeholderImage':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
67
                return $source->placeholderImage();
68
                break;
69
70
            // Special-case the `placeholderBox` field
71
            case 'placeholderBox':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
72
                $color = $arguments['color'] ?? null;
73
74
                return $source->placeholderBox($color);
75
                break;
76
77
            // Special-case the `placeholderSilhouette` field
78
            case 'placeholderSilhouette':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
79
                return $source->placeholderSilhouette();
80
                break;
81
82
            // Special-case the `srcUrls` field
83
            case 'srcUrls':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
84
                $result = [];
85
                foreach ($source->optimizedImageUrls as $width => $url) {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
86
                    $result[] = ['width' => $width, 'url' => $url];
87
                }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
88
89
                return $result;
90
                break;
91
92
            // Default to just returning the field value
93
            default:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
94
                return $source[$fieldName];
95
                break;
96
        }
97
    }
98
}
99