HelperTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 42
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isValidModel() 0 12 3
A isValidIndex() 0 12 3
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