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.

MessageProvider::translateExceptions()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Inspector\Foundation;
4
5
use RuntimeException;
6
use Inspector\Analysis\Result\Issue;
7
use Inspector\Analysis\Exception\AnalysisException;
8
9
/**
10
 * @author Kabir Baidhya
11
 */
12
class MessageProvider
13
{
14
15
    /**
16
     * @var array
17
     */
18
    protected $messages;
19
20
    public function __construct(array $config)
21
    {
22
        $this->messages = $config['messages'];
23
    }
24
25
    /**
26
     * Gets a message for a key.
27
     *
28
     * @param string $key
29
     * @param array $params
30
     * @return string
31
     */
32
    public function getMessage($key, array $params)
33
    {
34
        if (!isset($this->messages[$key])) {
35
            throw new RuntimeException(
36
                sprintf('Message for %s not found. ', $key)
37
            );
38
        }
39
40
        $rawMessage = $this->messages[$key];
41
42
        return vsprintf($rawMessage, $params);
43
    }
44
45
    /**
46
     * Translates an array of AnalysisException instances to array of Issue
47
     *
48
     * @param AnalysisException[] $exceptions
49
     * @return Issue[]
50
     */
51
    public function translateExceptions(array $exceptions)
52
    {
53
        $classHelper = new ClassHelper();
54
        $issues = [];
55
        foreach ($exceptions as $exception) {
56
            $key = str_replace('Exception', '', $classHelper->shorten(get_class($exception)));
57
58
            $message = $this->getMessage($key, $exception->getMessageParams());
59
            $issues[] = new Issue($exception, $message);
60
        }
61
62
        return $issues;
63
    }
64
}
65