Completed
Push — master ( 9bf722...8408f7 )
by Ryan
06:45
created

EntryFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A make() 0 23 2
1
<?php namespace Anomaly\Streams\Platform\Entry;
2
3
use Anomaly\Streams\Platform\Support\Hydrator;
4
use Anomaly\Streams\Platform\Traits\FiresCallbacks;
5
use Illuminate\Contracts\Container\Container;
6
use Illuminate\Foundation\Bus\DispatchesJobs;
7
8
/**
9
 * Class EntryFactory
10
 *
11
 * @link          http://anomaly.is/streams-platform
12
 * @author        AnomalyLabs, Inc. <[email protected]>
13
 * @author        Ryan Thompson <[email protected]>
14
 * @package       Anomaly\Streams\Platform\Entry
15
 */
16
class EntryFactory
17
{
18
19
    use DispatchesJobs;
20
    use FiresCallbacks;
21
22
    /**
23
     * The hydrator utility.
24
     *
25
     * @var Hydrator
26
     */
27
    protected $hydrator;
28
29
    /**
30
     * The service container.
31
     *
32
     * @var Container
33
     */
34
    protected $container;
35
36
    /**
37
     * Create a new StreamPluginFunctions instance.
38
     *
39
     * @param Hydrator  $hydrator
40
     * @param Container $container
41
     */
42
    public function __construct(Hydrator $hydrator, Container $container)
43
    {
44
        $this->hydrator  = $hydrator;
45
        $this->container = $container;
46
    }
47
48
    /**
49
     * Make a new EntryBuilder instance.
50
     *
51
     * @param        $namespace
52
     * @param        $stream
53
     * @param string $method
54
     * @return EntryCriteria|null
55
     */
56
    public function make($namespace, $stream, $method = 'get')
57
    {
58
        $stream    = ucfirst(camel_case($stream));
59
        $namespace = ucfirst(camel_case($namespace));
60
61
        if (!class_exists(
62
            $model = 'Anomaly\Streams\Platform\Model\\' . $namespace . '\\' . $namespace . $stream . 'EntryModel'
63
        )
64
        ) {
65
            return null;
66
        }
67
        /* @var EntryModel $model */
68
        $model = $this->container->make($model);
69
70
        return $this->container->make(
71
            $model->getCriteriaName(),
72
            [
73
                'query'  => $model->newQuery(),
74
                'stream' => $model->getStream(),
75
                'method' => $method
76
            ]
77
        );
78
    }
79
}
80