ValuelistService::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 5
rs 10
1
<?php
2
/**
3
 * Created by: Jens
4
 * Date: 12-10-2017
5
 */
6
7
namespace CloudControl\Cms\services;
8
9
10
use CloudControl\Cms\storage\entities\Valuelist;
11
use CloudControl\Cms\storage\Storage;
12
13
class ValuelistService
14
{
15
    private static $instance;
16
    /**
17
     * @var Storage
18
     */
19
    protected $storage;
20
21
    /**
22
     * FileService constructor.
23
     */
24
    protected function __construct()
25
    {
26
    }
27
28
    /**
29
     * @return ValuelistService
30
     */
31
    public static function getInstance()
32
    {
33
        if (!self::$instance instanceof ValuelistService) {
34
            self::$instance = new ValuelistService();
35
        }
36
        return self::$instance;
37
    }
38
39
    /**
40
     * @param $slug
41
     * @return Valuelist
42
     */
43
    public static function get($slug)
44
    {
45
        $instance = self::getInstance();
46
        $valuelist = $instance->storage->getValuelists()->getValuelistBySlug($slug);
47
        return $valuelist === null ? new Valuelist(new \stdClass()) : new Valuelist($valuelist);
48
49
    }
50
51
    /**
52
     * @param Storage $storage
53
     */
54
    public function init(Storage $storage)
55
    {
56
        $this->storage = $storage;
57
    }
58
}