Passed
Push — master ( e1e679...09e224 )
by Quentin
10:29
created

IsTranslatable::isTranslatable()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.016

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 22
ccs 9
cts 10
cp 0.9
crap 4.016
rs 9.9666
1
<?php
2
3
namespace A17\Twill\Models\Behaviors;
4
5
trait IsTranslatable
6
{
7 27
    public function isTranslatable($columns = null)
8
    {
9
        // Model must have the trait
10 27
        if (!classHasTrait($this, 'A17\Twill\Models\Behaviors\HasTranslation')) {
11 1
            return false;
12
        }
13
14
        // Model must have the translatedAttributes property
15 26
        if (!property_exists($this, 'translatedAttributes')) {
16
            return false;
17
        }
18
19
        // If it's a check on certain columns
20
        // They must be present in the translatedAttributes
21 26
        if (filled($columns)) {
22 5
            return collect($this->translatedAttributes)
23 5
                ->intersect(collect($columns))
24 5
                ->isNotEmpty();
25
        }
26
27
        // The translatedAttributes property must be filled
28 26
        return collect($this->translatedAttributes)->isNotEmpty();
29
    }
30
}
31