Completed
Push — master ( e377ec...621e91 )
by Ryan
07:42
created

GetFormCriteria::handle()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
rs 8.9197
cc 4
eloc 12
nc 8
nop 1
1
<?php namespace Anomaly\Streams\Platform\Ui\Form\Command;
2
3
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
4
use Anomaly\Streams\Platform\Support\Presenter;
5
use Anomaly\Streams\Platform\Ui\Form\FormCriteria;
6
use Anomaly\Streams\Platform\Ui\Form\FormFactory;
7
use Illuminate\Contracts\Bus\SelfHandling;
8
9
/**
10
 * Class GetFormCriteria
11
 *
12
 * @link          http://anomaly.is/streams-platform
13
 * @author        AnomalyLabs, Inc. <[email protected]>
14
 * @author        Ryan Thompson <[email protected]>
15
 * @package       Anomaly\Streams\Platform\Ui\Form\Command
16
 */
17
class GetFormCriteria implements SelfHandling
18
{
19
20
    /**
21
     * The builder parameters.
22
     *
23
     * @var array
24
     */
25
    protected $parameters;
26
27
    /**
28
     * Create a new GetFormCriteria instance.
29
     *
30
     * @param array $parameters
31
     */
32
    public function __construct($parameters)
33
    {
34
        $this->parameters = $parameters;
35
    }
36
37
    /**
38
     * Handle the command.
39
     *
40
     * @param FormFactory $factory
41
     * @return FormCriteria
42
     */
43
    public function handle(FormFactory $factory)
44
    {
45
        if (is_string($this->parameters)) {
46
            $this->parameters = [
47
                'builder' => $this->parameters
48
            ];
49
        }
50
51
        if ($this->parameters instanceof Presenter) {
52
            $this->parameters = $this->parameters->getObject();
53
        }
54
55
        if ($this->parameters instanceof EntryInterface) {
56
            $this->parameters = [
57
                'entry'     => $this->parameters->getId(),
58
                'stream'    => $this->parameters->getStreamSlug(),
59
                'namespace' => $this->parameters->getStreamNamespace(),
60
            ];
61
        }
62
63
        return $factory->make($this->parameters);
64
    }
65
}
66