Event::setupValidation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Model;
4
5
use App\Model\Deployment;
6
use App\Model\Finder\EventFinder;
7
use Respect\Validation\Validator;
8
use Ronanchilvers\Orm\Model;
9
use Ronanchilvers\Orm\Traits\HasValidationTrait;
10
11
/**
12
 * Model representing a deployment event
13
 *
14
 * @property int id
15
 * @property null|\App\Model\Deployment deployment
16
 * @property string type
17
 * @property string header
18
 * @property string detail
19
 * @property null|\Carbon\Carbon created
20
 * @property null|\Carbon\Carbon updated
21
 * @author Ronan Chilvers <[email protected]>
22
 */
23
class Event extends Model
24
{
25
    use HasValidationTrait;
26
27
    static protected $finder       = EventFinder::class;
28
    static protected $columnPrefix = 'event';
29
30
    /**
31
     * Boot the model
32
     *
33
     * @author Ronan Chilvers <[email protected]>
34
     */
35
    protected function boot()
36
    {
37
        $this->addType('model', 'deployment', [
38
            'class' => Deployment::class
39
        ]);
40
    }
41
42
    /**
43
     * @author Ronan Chilvers <[email protected]>
44
     */
45
    protected function setupValidation()
46
    {
47
        $this->registerRules([
48
            'deployment' => Validator::notEmpty()->intVal()->min(1),
49
            'type'       => Validator::notEmpty(),
50
            'header'     => Validator::notEmpty(),
51
        ]);
52
    }
53
54
    /**
55
     * Relationship with project
56
     *
57
     * @return \App\Model\Deployment
58
     * @author Ronan Chilvers <[email protected]>
59
     */
60
    protected function relateDeployment()
61
    {
62
        return $this->belongsTo(
63
            Deployment::class
64
        );
65
    }
66
}
67