CollectionLoaderAwareTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setCollectionLoader() 0 3 1
A collectionLoader() 0 10 2
1
<?php
2
3
namespace Charcoal\Loader;
4
5
use RuntimeException;
6
use Charcoal\Loader\CollectionLoader;
7
8
/**
9
 * Provides model collection features.
10
 *
11
 * Collection Loader Loader Aware Trait
12
 * @package Charcoal\Loader
13
 */
14
trait CollectionLoaderAwareTrait
15
{
16
    /**
17
     * Store the collection loader.
18
     *
19
     * @var CollectionLoader
20
     */
21
    protected $collectionLoader;
22
23
    /**
24
     * Set a model collection loader.
25
     *
26
     * @param  CollectionLoader $loader The model collection loader.
27
     * @return void
28
     */
29
    protected function setCollectionLoader(CollectionLoader $loader)
30
    {
31
        $this->collectionLoader = $loader;
32
    }
33
34
    /**
35
     * Retrieve the model collection loader.
36
     *
37
     * @throws RuntimeException If the collection loader is missing.
38
     * @return CollectionLoader
39
     */
40
    public function collectionLoader()
41
    {
42
        if (!isset($this->collectionLoader)) {
43
            throw new RuntimeException(sprintf(
44
                'Collection Loader is not defined for [%s]',
45
                get_class($this)
46
            ));
47
        }
48
49
        return $this->collectionLoader;
50
    }
51
}
52