Test Failed
Pull Request — master (#90)
by Maximo
07:11
created

FileSystemEntities::validation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 14
ccs 0
cts 12
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Canvas\Models;
5
6
use Phalcon\Validation;
7
use Phalcon\Validation\Validator\Uniqueness;
8
class FileSystemEntities extends AbstractModel
9
{
10
    /**
11
     *
12
     * @var integer
13
     */
14
    public $filesystem_id;
15
16
    /**
17
     *
18
     * @var integer
19
     */
20
    public $entity_id;
21
22
    /**
23
     *
24
     * @var integer
25
     */
26
    public $system_modules_id;
27
28
    /**
29
     *
30
     * @var string
31
     */
32
    public $field_name;
33
    
34
    /**
35
     *
36
     * @var string
37
     */
38
    public $created_at;
39
40
    /**
41
     *
42
     * @var string
43
     */
44
    public $updated_at;
45
46
    /**
47
     *
48
     * @var integer
49
     */
50
    public $is_deleted;
51
52
    /**
53
     * Initialize method for model.
54
     */
55
    public function initialize()
56
    {
57
        $this->setSource('filesystem_entities');
58
59
        $this->belongsTo(
60
            'filesystem_id',
61
            'Canvas\Models\Filesystem',
62
            'id',
63
            ['alias' => 'file']
64
        );
65
    }
66
67
    /**
68
     * Validate the model
69
     *
70
     * @return void
71
     */
72
    public function validation()
73
    {
74
        $validator = new Validation();
75
76
        $validator->add(
77
            ['filesystem_id', 'entity_id', 'system_modules_id'],
78
            new Uniqueness(
79
                [
80
                    'message' => 'Cant attach a file to a entity two times',
81
                ]
82
            )
83
        );
84
85
        return $this->validate($validator);
86
    }
87
88
    /**
89
     * Returns table name mapped in the model.
90
     *
91
     * @return string
92
     */
93
    public function getSource() : string
94
    {
95
        return 'filesystem_entities';
96
    }
97
}
98