GitHubLintImplementation   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 7
dl 0
loc 43
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A analyse() 0 8 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace PurpleBooth\GitGitHubLint;
5
6
use Github\Client;
7
use PhpSpec\Exception\Exception;
8
use PurpleBooth\GitGitHubLint\Exception\GitHubLintException;
9
use PurpleBooth\GitLintValidators\ValidatorFactoryImplementation;
10
11
/**
12
 * A vanity interface to make it easier to use this library
13
 *
14
 * @package PurpleBooth\GitGitHubLint
15
 */
16
class GitHubLintImplementation implements GitHubLint
17
{
18
    /**
19
     * @var AnalysePullRequestCommits
20
     */
21
    private $analyser;
22
23
    /**
24
     * GitHubLintImplementation constructor.
25
     *
26
     * @param Client $client
27
     */
28
    public function __construct(Client $client)
29
    {
30
        $validatorFactory = new ValidatorFactoryImplementation();
31
32
        $this->analyser = new AnalysePullRequestCommitsImplementation(
33
            new CommitMessageServiceImplementation($client),
34
            new ValidateMessagesImplementation(
35
                $validatorFactory->getMessageValidator()
36
            ),
37
            new StatusSendServiceImplementation($client)
38
        );
39
    }
40
41
    /**
42
     * Analyse the commits on a pull request and set the statuses
43
     *
44
     * @param string $username
45
     * @param string $repository
46
     * @param int    $pullRequest
47
     *
48
     * @throws GitHubLintException if an undocumented exception is thrown, it'll be wrapped in this exception.
49
     */
50
    public function analyse(string $username, string $repository, int $pullRequest)
51
    {
52
        try {
53
            $this->analyser->check($username, $repository, $pullRequest);
54
        } catch (Exception $exception) {
55
            throw new GitHubLintException("An unexpected error has occurred", 0, $exception);
56
        }
57
    }
58
}
59