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

HasContent   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getFromRelationshipByName() 0 10 2
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