Completed
Push — master ( 080b9b...8f9441 )
by Freek
01:54
created

TranslatableAttributeCollection::isTranslatable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Spatie\Translatable;
4
5
use Illuminate\Support\Collection;
6
7
class TranslatableAttributeCollection extends Collection
8
{
9
    public static function createForModel(Translatable $model)
10
    {
11
        $translatableFieldCollection = new static();
12
13
        foreach ($model->getTranslatableAttributes() as $key => $value) {
14
            $translatableFieldCollection->push(new TranslatableAttribute($key, $value));
15
        }
16
17
        return $translatableFieldCollection;
18
    }
19
20
    protected function find(string $attributeName)
21
    {
22
        foreach ($this->items as $translatableAttribute) {
23
            if ($translatableAttribute->name == $attributeName) {
24
                return $translatableAttribute;
25
            };
26
        }
27
28
        return;
29
    }
30
31
    public function isTranslatable(string $attributeName) : bool
32
    {
33
        return !is_null($this->find($attributeName));
34
    }
35
36
    public function getCast(string $attributeName) : string
37
    {
38
        $translatableAttribute = $this->find($attributeName);
39
40
        if (!$translatableAttribute) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
41
            // throw exception
42
        }
43
44
        return $this->find($attributeName)->cast;
45
    }
46
}
47