Completed
Push — master ( 3b9644...b65440 )
by Zach
07:24 queued 02:31
created

HasContent::getFromRelationshipByName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 10
rs 9.4285
1
<?php
2
3
namespace Larafolio\Models;
4
5
use Larafolio\Models\Traits\HasLinks;
6
use Larafolio\Models\Traits\HasBlocks;
7
use Larafolio\Models\Traits\HasImages;
8
use Illuminate\Database\Eloquent\Model;
9
10
class HasContent extends Model
11
{
12
    use HasBlocks, HasImages, HasLinks;
13
14
    /**
15
     * Get a model from a relationship by model name.
16
     *
17
     * @param string $relationship Name of relationship.
18
     * @param string $name         Name of model to get.
19
     *
20
     * @return \Illuminate\Database\Eloquent\Model|null
21
     */
22
    protected function getFromRelationshipByName($relationship, $name)
23
    {
24
        $items = $this->{$relationship}->where('name', $name);
25
26
        if ($items->isEmpty()) {
27
            return;
28
        }
29
30
        return $items->first();
31
    }
32
}
33