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.

DatabaseConnectionCheck   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 75
ccs 21
cts 21
cp 1
rs 10
c 1
b 0
f 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A check() 0 16 2
A getSuccessMessage() 0 8 1
A getFailureMessage() 0 8 1
A isOptional() 0 4 1
1
<?php
2
/**
3
 * This file is part of the Gerrie package.
4
 *
5
 * (c) Andreas Grunwald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Gerrie\Check;
12
13
use Gerrie\Component\Database\Database;
14
15
/**
16
 * Checks if the database connection works.
17
 *
18
 * @author Andreas Grunwald <[email protected]>
19
 */
20
class DatabaseConnectionCheck implements CheckInterface
21
{
22
23
    /**
24
     * Database object
25
     *
26
     * @var Database
27
     */
28
    protected $database;
29
30 5
    public function __construct(Database $database)
31
    {
32 5
        $this->database = $database;
33 5
    }
34
35
    /**
36
     * Executes the check itselfs
37
     *
38
     * @return boolean
39
     */
40 3
    public function check()
41
    {
42 3
        $result = true;
43
44
        // TODO This check tries only to connect to the database
45
        // But it would make sense to check
46
        //  a) insert, select, update, delete, etc. access
47
        //  a) a) Which access rights do i need? Topic hardening?
48
        try {
49 3
            $this->database->connect($this->database->getConfig());
50 3
        } catch (\Exception $e) {
51 1
            $result = false;
52
        }
53
54 3
        return $result;
55
    }
56
57
    /**
58
     * Returns the message, if the check succeeded
59
     *
60
     * @return string
61
     */
62 1
    public function getSuccessMessage()
63
    {
64 1
        $databaseConfig = $this->database->getConfig();
65 1
        $message = 'Database connection to host "%s" works as expected.';
66 1
        $message = sprintf($message, $databaseConfig['Host']);
67
68 1
        return $message;
69
    }
70
71
    /**
72
     * Returns the message, if the check fails
73
     *
74
     * @return string
75
     */
76 1
    public function getFailureMessage()
77
    {
78 1
        $databaseConfig = $this->database->getConfig();
79 1
        $message = 'Database connection to host "%s" works not as expected. Please check your credentials or setup.';
80 1
        $message = sprintf($message, $databaseConfig['Host']);
81
82 1
        return $message;
83
    }
84
85
    /**
86
     * Returns if this check is optional or required.
87
     *
88
     * @return bool
89
     */
90 1
    public function isOptional()
91
    {
92 1
        return false;
93
    }
94
}
95