Completed
Push — master ( 16ebaf...a3d07b )
by Arjay
14:09
created

Repository::findOrFail()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 8
rs 9.4285
1
<?php
2
3
namespace Yajra\CMS\Widgets;
4
5
use Illuminate\Support\Collection;
6
7
class Repository
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $widgets = [];
13
14
    /**
15
     * @param string $widget
16
     * @param string $description
17
     * @param string $classPath
18
     * @param array $templates
19
     * @return $this
20
     */
21
    public function register($widget, $description, $classPath, $templates = [])
22
    {
23
        $this->widgets[$widget] = new Widget($widget, $description, $classPath, $templates);
24
25
        return $this;
26
    }
27
28
    /**
29
     * Find or fail a widget.
30
     *
31
     * @param string $widget
32
     * @return \Yajra\CMS\Widgets\Widget
33
     * @throws \Yajra\CMS\Widgets\NotFoundException
34
     */
35
    public function findOrFail($widget)
36
    {
37
        if (in_array($widget, array_keys($this->widgets))) {
38
            return $this->widgets[$widget];
39
        }
40
41
        throw new NotFoundException('Widget not found!');
42
    }
43
44
    /**
45
     * Get all registered widgets.
46
     *
47
     * @return \Illuminate\Support\Collection
48
     */
49
    public function all()
50
    {
51
        return new Collection($this->widgets);
52
    }
53
}
54