HelperTrait::isValidModel()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 12
rs 9.4285
c 1
b 0
f 1
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
3
namespace LarsJanssen\IncrementDecrement;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Facades\Schema;
7
use LarsJanssen\IncrementDecrement\Exceptions\Exceptions;
8
9
trait HelperTrait
10
{
11
    /**
12
     * @param Model $model
13
     *
14
     * @throws Exceptions
15
     *
16
     * @return bool
17
     */
18
    public function isValidModel(Model $model)
19
    {
20
        if (!empty(config('increment-decrement.order_column_name'))) {
21
            if (Schema::hasColumn($model->getTable(), config('increment-decrement.order_column_name'))) {
22
                return true;
23
            }
24
25
            throw Exceptions::columnNotFound($model);
26
        }
27
28
        throw Exceptions::columnNotSet();
29
    }
30
31
    /**
32
     * @param $index
33
     *
34
     * @throws Exceptions
35
     *
36
     * @return bool
37
     */
38
    public function isValidIndex($index)
39
    {
40
        if (is_numeric($index)) {
41
            if ($index > 0) {
42
                return true;
43
            }
44
45
            Exceptions::numberNotPositive($index);
46
        }
47
48
        Exceptions::numberUnValid($index);
49
    }
50
}
51