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

src/validators/DbStringValidator.php (25 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\validators;
13
14
use nystudio107\retour\helpers\Text as TextHelper;
15
16
use craft\helpers\StringHelper;
17
18
use yii\base\InvalidConfigException;
19
use yii\validators\Validator;
20
21
/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
22
 * @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...
23
 * @package   Retour
0 ignored issues
show
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
24
 * @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...
25
 */
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...
26
class DbStringValidator extends Validator
27
{
28
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
29
     * @var null|int
30
     */
31
    public $max = null;
32
33
34
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
35
     * @inheritdoc
36
     * @throws InvalidConfigException
0 ignored issues
show
Tag value for @throws tag indented incorrectly; expected 5 spaces but found 1
Loading history...
37
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
38
    public function init()
39
    {
40
        parent::init();
41
        if ($this->max === null) {
42
            throw new InvalidConfigException('The "max" property must be set.');
43
        }
44
    }
45
46
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
Parameter $model should have a doc-comment as per coding-style.
Loading history...
Parameter $attribute should have a doc-comment as per coding-style.
Loading history...
47
     * @inheritdoc
48
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
49
    public function validateAttribute($model, $attribute)
50
    {
51
        $value = $model->$attribute;
52
        $value = TextHelper::cleanupText($value);
53
        $value = StringHelper::encodeMb4($value);
54
        $value = TextHelper::truncate($value, $this->max);
55
        $model->$attribute = $value;
56
    }
57
}
58