RetourType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 16
dl 0
loc 38
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 21 5
A __construct() 0 7 1
1
<?php
2
/**
3
 * Retour plugin for Craft CMS
4
 *
5
 * Retour allows you to intelligently redirect legacy URLs, so that you don't
6
 * lose SEO value when rebuilding & restructuring a website
7
 *
8
 * @link      https://nystudio107.com/
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
9
 * @copyright Copyright (c) 2019 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
10
 */
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...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
11
12
namespace nystudio107\retour\gql\types;
13
14
use Craft;
15
16
use craft\gql\base\ObjectType;
17
use GraphQL\Type\Definition\ResolveInfo;
18
19
use nystudio107\retour\gql\interfaces\RetourInterface;
20
21
/**
22
 * Class RetourType
23
 *
24
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
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...
25
 * @package   Retour
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
26
 * @since     3.1.26
0 ignored issues
show
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
27
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @category tag in class comment
Loading history...
28
class RetourType extends ObjectType
29
{
30
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $config should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
31
     * @inheritdoc
32
     */
33
    public function __construct(array $config)
34
    {
35
        $config['interfaces'] = [
36
            RetourInterface::getType(),
37
        ];
38
39
        parent::__construct($config);
40
    }
41
42
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $resolveInfo should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $context should have a doc-comment as per coding-style.
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...
43
     * @inheritdoc
44
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
45
    protected function resolve(mixed $source, array $arguments, mixed $context, ResolveInfo $resolveInfo): mixed
46
    {
47
        $fieldName = $resolveInfo->fieldName;
48
        $result = $source[$fieldName] ?? '';
49
        // Handle the `site` virtual field
50
        if ($fieldName === 'site') {
51
            $result = null;
52
            $siteId = $source['siteId'] ?? null;
53
            if ($siteId) {
54
                $site = Craft::$app->getSites()->getSiteById($siteId);
55
                if ($site !== null) {
56
                    $result = $site->handle;
57
                }
58
            }
59
        }
60
61
        if (empty($result)) {
62
            $result = null;
63
        }
64
65
        return $result;
66
    }
67
}
68