GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

RisMappings   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 60
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A findRisFieldByType() 0 15 3
A mappings() 0 11 3
1
<?php
2
3
namespace Funstaff\RefLibRis;
4
5
/**
6
 * RisMappings
7
 *
8
 * @author Bertrand Zuchuat <[email protected]>
9
 */
10
class RisMappings implements RisMappingsInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    private $mappings;
16
17
    /**
18
     * @var string
19
     */
20
    private $fallback;
21
22
    /**
23
     * RisMappings constructor.
24
     * @param array  $mappings
25
     * @param string $fallback
26
     */
27
    public function __construct(array $mappings, string $fallback)
28
    {
29
        $this->mappings = $this->mappings($mappings);
30
        $this->fallback = $fallback;
31
    }
32
33
    /**
34
     * @param string $type
35
     * @return mixed
36
     * @throws \Exception
37
     */
38
    public function findRisFieldByType(string $type)
39
    {
40
        if (!array_key_exists($type, $this->mappings)) {
41
            $type = $this->fallback;
42
        }
43
44
        if (!array_key_exists($type, $this->mappings)) {
45
            throw new \InvalidArgumentException(sprintf(
46
                'Missing mapping for fallback: "%s"',
47
                $type
48
            ));
49
        }
50
51
        return $this->mappings[$type];
52
    }
53
54
    /**
55
     * @param $mappings
56
     * @return array
57
     */
58
    private function mappings(array $mappings)
59
    {
60
        $output = [];
61
        foreach ($mappings as $key => $mappingFields) {
62
            if (!array_key_exists($key, $output)) {
63
                $output[$key] = New RisFieldsMapping($mappingFields);
64
            }
65
        }
66
67
        return $output;
68
    }
69
}
70