Passed
Push — v3 ( 451ce4...69a453 )
by Andrew
24:46 queued 16:55
created

RetourResolver::resolveAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 10
cc 1
nc 1
nop 4
crap 2
1
<?php
2
/**
3
 * Retour plugin for Craft CMS 3.x
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\resolvers;
13
14
use Craft;
15
use craft\base\Element;
16
use craft\gql\base\Resolver;
17
18
use craft\helpers\UrlHelper;
19
use GraphQL\Type\Definition\ResolveInfo;
20
use nystudio107\retour\Retour;
21
22
/**
23
 * Class RetourResolver
24
 *
25
 * @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...
26
 * @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...
27
 * @since     3.1.26
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...
28
 */
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...
29
class RetourResolver extends Resolver
30
{
31
    /**
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...
32
     * @inheritDoc
33
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
34
    public static function resolve($source, array $arguments, $context, ResolveInfo $resolveInfo)
35
    {
36
        // If our source is an Element, extract the URI and siteId from it
37
        if ($source instanceof Element) {
38
            /** Element $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
Doc comment short description must be on the first line
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
39
            $uri = $source->uri;
40
            $siteId = $source->siteId;
41
        } else {
42
            // Otherwise use the passed in arguments, or defaults
43
            $uri = $arguments['uri'] ?? '/';
44
            $siteId = $arguments['siteId'] ?? null;
45
        }
46
        $uri = trim($uri === '/' ? '__home__' : $uri);
47
48
        $redirect = null;
49
50
        // Strip the query string if `alwaysStripQueryString` is set
51
        if (Retour::$settings->alwaysStripQueryString) {
52
            $uri = UrlHelper::stripQueryString($uri);
53
        }
54
55
        if (!Retour::$plugin->redirects->excludeUri($uri)) {
56
            $redirect = Retour::$plugin->redirects->findRedirectMatch($uri, $uri, $siteId);
57
58
            if ($redirect === null && Craft::$app->getElements()->getElementByUri(trim($uri, '/'), $siteId) === null) {
59
                // Increment the stats
60
                Retour::$plugin->statistics->incrementStatistics($uri, false, $siteId);
61
            }
62
        }
63
64
        return $redirect;
65
    }
66
67
    /**
68
     * Return all static redirects for a site.
69
     *
70
     * @param $source
0 ignored issues
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
71
     * @param array $arguments
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
72
     * @param $context
0 ignored issues
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
73
     * @param ResolveInfo $resolveInfo
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
74
     * @return array
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
75
     * @throws \craft\errors\SiteNotFoundException
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
76
     */
77
    public static function resolveAll($source, array $arguments, $context, ResolveInfo $resolveInfo)
0 ignored issues
show
Unused Code introduced by
The parameter $source 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

77
    public static function resolveAll(/** @scrutinizer ignore-unused */ $source, array $arguments, $context, ResolveInfo $resolveInfo)

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...
Unused Code introduced by
The parameter $resolveInfo 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

77
    public static function resolveAll($source, array $arguments, $context, /** @scrutinizer ignore-unused */ ResolveInfo $resolveInfo)

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...
Unused Code introduced by
The parameter $context 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

77
    public static function resolveAll($source, array $arguments, /** @scrutinizer ignore-unused */ $context, ResolveInfo $resolveInfo)

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...
78
    {
79
        $siteId = $arguments['siteId'] ?? Craft::$app->getSites()->getCurrentSite()->id;
80
81
        $redirects = Retour::$plugin->redirects->getAllStaticRedirects(null, $siteId);
82
83
        return $redirects;
84
    }
85
}
86