Issues (462)

src/models/Settings.php (29 issues)

1
<?php
2
/**
3
 * Units plugin for Craft CMS
4
 *
5
 * A plugin for handling physical quantities and the units of measure in which they're represented.
6
 *
7
 * @link      https://nystudio107.com/
0 ignored issues
show
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) nystudio107
0 ignored issues
show
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
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...
10
11
namespace nystudio107\units\models;
12
13
use craft\base\Model;
14
use PhpUnitsOfMeasure\PhysicalQuantity\Length;
15
16
/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
17
 * @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...
18
 * @package   Units
0 ignored issues
show
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
19
 * @since     1.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...
20
 */
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...
21
class Settings extends Model
22
{
23
    // Public Properties
24
    // =========================================================================
25
26
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
27
     * @var string The default fully qualified class name of the unit of measure
28
     */
29
    public string $defaultUnitsClass = Length::class;
30
31
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
32
     * @var float The default value of the unit of measure
33
     */
34
    public float $defaultValue = 0.0;
35
36
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
37
     * @var string The default units that the unit of measure is in
38
     */
39
    public string $defaultUnits = 'ft';
40
41
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
42
     * @var bool Whether the units the field can be changed
43
     */
44
    public bool $defaultChangeableUnits = true;
45
46
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
47
     * @var int|float The default minimum allowed number
48
     */
49
    public int|float $defaultMin = 0;
50
51
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
52
     * @var int|float|null The default maximum allowed number
53
     */
54
    public int|null|float $defaultMax = null;
55
56
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
57
     * @var int The default number of digits allowed after the decimal point
58
     */
59
    public int $defaultDecimals = 3;
60
61
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
62
     * @var int|null The default size of the field
63
     */
64
    public ?int $defaultSize = 6;
65
66
    // Public Methods
67
    // =========================================================================
68
69
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
70
     * @inheritdoc
71
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
72
    public function rules(): array
73
    {
74
        $rules = parent::rules();
75
        $rules = array_merge($rules, [
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
76
            ['defaultUnitsClass', 'string'],
77
            ['defaultUnitsClass', 'default', 'value' => Length::class],
78
            ['defaultValue', 'number'],
79
            ['defaultValue', 'default', 'value' => 0.0],
80
            ['defaultUnits', 'string'],
81
            ['defaultUnits', 'default', 'value' => 'ft'],
82
            ['defaultChangeableUnits', 'boolean'],
83
            ['defaultChangeableUnits', 'default', 'value' => true],
84
            [['defaultMin', 'defaultMax'], 'number'],
85
            [
86
                ['defaultMax'],
87
                'compare',
88
                'compareAttribute' => 'defaultMin',
89
                'operator' => '>=',
90
            ],
91
            ['defaultMin', 'default', 'value' => 0],
92
            ['defaultMax', 'default', 'value' => null],
93
            [['defaultDecimals', 'defaultSize'], 'integer'],
94
            ['defaultDecimals', 'default', 'value' => 3],
95
            ['defaultSize', 'default', 'value' => 6],
96
        ]);
0 ignored issues
show
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
97
98
        if (!$this->defaultDecimals) {
99
            $rules[] = [['defaultMin', 'defaultMax'], 'integer'];
100
        }
101
102
        return $rules;
103
    }
104
}
105