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   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getMessage() 0 12 2
A translateExceptions() 0 13 2
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