CategoryRegistry   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 54
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A has() 0 4 1
A get() 0 13 4
A addVendorCategories() 0 10 3
1
<?php
2
3
namespace Libcast\AssetDistributor\Configuration;
4
5
class CategoryRegistry
6
{
7
    /**
8
     *
9
     * @var array
10
     */
11
    protected static $categories = [];
12
13
    /**
14
     *
15
     * @param $category
16
     * @return bool
17
     */
18
    public static function has($category)
19
    {
20
        return in_array($category, array_keys(self::$categories));
21
    }
22
23
    /**
24
     *
25
     * @param $category
26
     * @param $vendor
27
     * @return mixed
28
     */
29
    public static function get($category, $vendor)
30
    {
31
        if (!self::has($category)) {
32
            return null;
33
        }
34
35
        $categoryVendors = self::$categories[$category];
36
        if (isset($categoryVendors[$vendor]) and $id = $categoryVendors[$vendor]) {
37
            return $id;
38
        }
39
40
        return null;
41
    }
42
43
    /**
44
     *
45
     * @param string $vendor
46
     * @param array  $map
47
     */
48
    public static function addVendorCategories($vendor, array $map)
49
    {
50
        foreach ($map as $category => $id) {
51
            if (!isset(self::$categories[$category])) {
52
                self::$categories[$category] = [];
53
            }
54
55
            self::$categories[$category][$vendor] = $id;
56
        }
57
    }
58
}
59