RetourWidget   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 11
eloc 33
c 2
b 0
f 0
dl 0
loc 102
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getBodyHtml() 0 22 4
A iconPath() 0 3 1
A maxColspan() 0 3 1
A rules() 0 11 1
A displayName() 0 3 1
A getSettingsHtml() 0 16 3
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) 2018 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\widgets;
13
14
use Craft;
15
use craft\base\Widget;
16
use nystudio107\retour\assetbundles\retour\RetourWidgetAsset;
17
use nystudio107\retour\Retour;
18
use Twig\Error\LoaderError;
19
use yii\base\Exception;
20
use yii\base\InvalidConfigException;
21
22
/** @noinspection MissingPropertyAnnotationsInspection */
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...
23
24
/**
25
 * Retour Widget
26
 *
27
 * @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...
28
 * @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...
29
 * @since     3.0.0
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...
30
 */
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...
31
class RetourWidget extends Widget
32
{
33
    // Public Properties
34
    // =========================================================================
35
36
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
37
     * @var int
38
     */
39
    public int $numberOfDays = 30;
40
41
    // Static Methods
42
    // =========================================================================
43
44
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
45
     * @inheritdoc
46
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
47
    public static function displayName(): string
48
    {
49
        return Retour::$settings->pluginName;
50
    }
51
52
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
53
     * @inheritdoc
54
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
55
    public static function iconPath(): bool|string
56
    {
57
        return Craft::getAlias("@nystudio107/retour/web/assets/dist/img/icon-mask.svg");
58
    }
59
60
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
61
     * @inheritdoc
62
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
63
    public static function maxColspan(): ?int
64
    {
65
        return 1;
66
    }
67
68
    // Public Methods
69
    // =========================================================================
70
71
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
72
     * @inheritdoc
73
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
74
    public function rules(): array
75
    {
76
        $rules = parent::rules();
77
        $rules = array_merge(
78
            $rules,
79
            [
80
                ['numberOfDays', 'integer', 'min' => 1],
81
                ['numberOfDays', 'default', 'value' => 30],
82
            ]
83
        );
84
        return $rules;
85
    }
86
87
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
88
     * @inheritdoc
89
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
90
    public function getSettingsHtml(): null|string
91
    {
92
        try {
93
            return Craft::$app->getView()->renderTemplate(
94
                'retour/_components/widgets/Retour_settings',
95
                [
96
                    'widget' => $this,
97
                ]
98
            );
99
        } catch (LoaderError $e) {
100
            Craft::error($e->getMessage(), __METHOD__);
101
        } catch (Exception $e) {
102
            Craft::error($e->getMessage(), __METHOD__);
103
        }
104
105
        return null;
106
    }
107
108
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
109
     * @inheritdoc
110
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
111
    public function getBodyHtml(): null|string
112
    {
113
        try {
114
            Craft::$app->getView()->registerAssetBundle(RetourWidgetAsset::class);
115
        } catch (InvalidConfigException $e) {
116
            Craft::error($e->getMessage(), __METHOD__);
117
        }
118
119
        try {
120
            return Craft::$app->getView()->renderTemplate(
121
                'retour/_components/widgets/Retour_body',
122
                [
123
                    'numberOfDays' => $this->numberOfDays,
124
                ]
125
            );
126
        } catch (LoaderError $e) {
127
            Craft::error($e->getMessage(), __METHOD__);
128
        } catch (Exception $e) {
129
            Craft::error($e->getMessage(), __METHOD__);
130
        }
131
132
        return null;
133
    }
134
}
135