TypeProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 5
c 4
b 0
f 1
lcom 0
cbo 0
dl 0
loc 54
ccs 22
cts 22
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypes() 0 8 1
A getTypeByName() 0 14 2
A getTypeByKey() 0 12 2
1
<?php
2
3
namespace Cp\Provider;
4
5
use Cp\DomainObject\TypeInterface;
6
7
/**
8
 * Class Type
9
 */
10
class TypeProvider
11
{
12
    /**
13
     * @return array
14
     */
15 5
    public function getTypes()
16
    {
17
        return [
18 5
            '10' => TypeInterface::TYPE_10K,
19 5
            '21' => TypeInterface::TYPE_SEMI,
20 5
            '42' => TypeInterface::TYPE_MARATHON,
21 5
        ];
22
    }
23
24
    /**
25
     * @param string $type
26
     *
27
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
28
     * @throws \Exception
29
     */
30 2
    public function getTypeByName($type)
31
    {
32 2
        $key = array_search($type, $this->getTypes());
33
34 2
        if (false !== $key) {
35 1
            return $key;
36
        }
37
38 1
        throw new \Exception(sprintf(
39 1
            'Type: "%s" not found, allowed %s',
40 1
            $type,
41 1
            implode(', ', $this->getTypes())
42 1
        ));
43
    }
44
45
    /**
46
     * @param string $key
47
     *
48
     * @return string
49
     * @throws \Exception
50
     */
51 2
    public function getTypeByKey($key)
52
    {
53 2
        if (isset($this->getTypes()[$key])) {
54 1
            return $this->getTypes()[$key];
55
        }
56
57 1
        throw new \Exception(sprintf(
58 1
            'Key: "%s" not found, allowed %s',
59 1
            $key,
60 1
            implode(', ', array_keys($this->getTypes()))
61 1
        ));
62
    }
63
}
64