Passed
Push — v3 ( 2b006a...43f239 )
by Andrew
33:34 queued 16:32
created

src/widgets/RetourWidget.php (32 issues)

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
The tag in position 1 should be the @copyright tag
Loading history...
9
 * @copyright Copyright (c) 2018 nystudio107
0 ignored issues
show
@copyright tag must contain a year and the name of the copyright holder
Loading history...
10
 */
0 ignored issues
show
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
Missing @package tag in file comment
Loading history...
Missing @author tag in file comment
Loading history...
Missing @license tag in file comment
Loading history...
11
12
namespace nystudio107\retour\widgets;
13
14
use nystudio107\retour\Retour;
15
use nystudio107\retour\assetbundles\retour\RetourWidgetAsset;
16
17
use Craft;
18
use craft\base\Widget;
19
use yii\base\Exception;
20
use yii\base\InvalidConfigException;
21
22
/** @noinspection MissingPropertyAnnotationsInspection */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
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
The tag in position 1 should be the @package tag
Loading history...
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
28
 * @package   Retour
0 ignored issues
show
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
29
 * @since     3.0.0
0 ignored issues
show
The tag in position 3 should be the @author tag
Loading history...
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
30
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
31
class RetourWidget extends Widget
32
{
33
34
    // Public Properties
35
    // =========================================================================
36
37
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
38
     * @var int
39
     */
40
    public $numberOfDays = 30;
41
42
    // Static Methods
43
    // =========================================================================
44
45
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
46
     * @inheritdoc
47
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
48
    public static function displayName(): string
49
    {
50
        return Retour::$settings->pluginName;
51
    }
52
53
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
54
     * @inheritdoc
55
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
56
    public static function iconPath()
57
    {
58
        return Craft::getAlias("@nystudio107/retour/assetbundles/retour/dist/img/icon-mask.svg");
59
    }
60
61
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
62
     * @inheritdoc
63
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
64
    public static function maxColspan()
65
    {
66
        return 1;
67
    }
68
69
    // Public Methods
70
    // =========================================================================
71
72
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
73
     * @inheritdoc
74
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
75
    public function rules()
76
    {
77
        $rules = parent::rules();
78
        $rules = array_merge(
79
            $rules,
80
            [
81
                ['numberOfDays', 'integer', 'min' => 1],
82
                ['numberOfDays', 'default', 'value' => 30],
83
            ]
84
        );
85
        return $rules;
86
    }
87
88
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
89
     * @inheritdoc
90
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
91
    public function getSettingsHtml()
92
    {
93
        try {
94
            return Craft::$app->getView()->renderTemplate(
95
                'retour/_components/widgets/Retour_settings',
96
                [
97
                    'widget' => $this,
98
                ]
99
            );
100
        } catch (\Twig\Error\LoaderError $e) {
101
            Craft::error($e->getMessage(), __METHOD__);
102
        } catch (Exception $e) {
103
            Craft::error($e->getMessage(), __METHOD__);
104
        }
105
    }
106
107
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
108
     * @inheritdoc
109
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
110
    public function getBodyHtml()
111
    {
112
        try {
113
            Craft::$app->getView()->registerAssetBundle(RetourWidgetAsset::class);
114
        } catch (InvalidConfigException $e) {
115
            Craft::error($e->getMessage(), __METHOD__);
116
        }
117
118
        try {
119
            return Craft::$app->getView()->renderTemplate(
120
                'retour/_components/widgets/Retour_body',
121
                [
122
                    'numberOfDays' => $this->numberOfDays,
123
                ]
124
            );
125
        } catch (\Twig\Error\LoaderError $e) {
126
            Craft::error($e->getMessage(), __METHOD__);
127
        } catch (Exception $e) {
128
            Craft::error($e->getMessage(), __METHOD__);
129
        }
130
    }
131
}
132