nystudio107 /
craft-units
| 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
Coding Style
introduced
by
Loading history...
|
|||
| 8 | * @copyright Copyright (c) nystudio107 |
||
|
0 ignored issues
–
show
|
|||
| 9 | */ |
||
|
0 ignored issues
–
show
|
|||
| 10 | |||
| 11 | namespace nystudio107\units\models; |
||
| 12 | |||
| 13 | use craft\base\Model; |
||
| 14 | use PhpUnitsOfMeasure\PhysicalQuantity\Length; |
||
| 15 | |||
| 16 | /** |
||
|
0 ignored issues
–
show
|
|||
| 17 | * @author nystudio107 |
||
|
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
|
|||
| 18 | * @package Units |
||
|
0 ignored issues
–
show
|
|||
| 19 | * @since 1.0.0 |
||
|
0 ignored issues
–
show
|
|||
| 20 | */ |
||
|
0 ignored issues
–
show
|
|||
| 21 | class Settings extends Model |
||
| 22 | { |
||
| 23 | // Public Properties |
||
| 24 | // ========================================================================= |
||
| 25 | |||
| 26 | /** |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 32 | * @var float The default value of the unit of measure |
||
| 33 | */ |
||
| 34 | public float $defaultValue = 0.0; |
||
| 35 | |||
| 36 | /** |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 42 | * @var bool Whether the units the field can be changed |
||
| 43 | */ |
||
| 44 | public bool $defaultChangeableUnits = true; |
||
| 45 | |||
| 46 | /** |
||
|
0 ignored issues
–
show
|
|||
| 47 | * @var int|float The default minimum allowed number |
||
| 48 | */ |
||
| 49 | public int|float $defaultMin = 0; |
||
| 50 | |||
| 51 | /** |
||
|
0 ignored issues
–
show
|
|||
| 52 | * @var int|float|null The default maximum allowed number |
||
| 53 | */ |
||
| 54 | public int|null|float $defaultMax = null; |
||
| 55 | |||
| 56 | /** |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 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
|
|||
| 70 | * @inheritdoc |
||
| 71 | */ |
||
|
0 ignored issues
–
show
|
|||
| 72 | public function rules(): array |
||
| 73 | { |
||
| 74 | $rules = parent::rules(); |
||
| 75 | $rules = array_merge($rules, [ |
||
|
0 ignored issues
–
show
|
|||
| 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 |