Task::validators()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
rs 9.4285
nc 1
cc 1
eloc 8
nop 0
1
<?php
2
3
namespace Machdas\Model;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Respect\Validation\Validator;
7
8
/**
9
 * @property int     $id
10
 * @property string  $name
11
 * @property boolean $isDone
12
 * @property string  $priority
13
 * @property int     $cardId
14
 */
15
class Task extends Model
16
{
17
18
    /**
19
     * @return Validator[]
20
     */
21
    public static function validators() : array
22
    {
23
        return [
24
            'name'     => Validator::stringType()->notEmpty()->setName('name'),
25
            'isDone'   => Validator::boolType()->setName('isDone'),
26
            'priority' => Validator::intType()->between(1, 999)->setName('priority'),
27
            'cardId'   => Validator::intType()->notEmpty()->callback(function ($v) {
28
                return Card::query()->find($v) instanceof Card;
29
            })->setName('cardId')
30
        ];
31
    }
32
33
    /**
34
     * @var array
35
     */
36
    protected $casts = [
37
        'isDone' => 'boolean',
38
    ];
39
40
    /**
41
     * @var string
42
     */
43
    protected $table = 'tasks';
44
45
    /**
46
     * @var bool
47
     */
48
    public $timestamps = false;
49
}
50