Completed
Push — master ( 622c37...dca855 )
by Christian
04:12
created

SelfTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 62
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A perform() 0 10 2
A addTest() 0 4 1
A getAutoConfig() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of tenside/core.
5
 *
6
 * (c) Christian Schiffler <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * This project is provided in good faith and hope to be usable by anyone.
12
 *
13
 * @package    tenside/core
14
 * @author     Christian Schiffler <[email protected]>
15
 * @copyright  2015 Christian Schiffler <[email protected]>
16
 * @license    https://github.com/tenside/core/blob/master/LICENSE MIT
17
 * @link       https://github.com/tenside/core
18
 * @filesource
19
 */
20
21
namespace Tenside\Core\SelfTest;
22
23
/**
24
 * This class checks that the current environment is suitable for running tenside.
25
 */
26
class SelfTest
27
{
28
    /**
29
     * The registered self tests.
30
     *
31
     * @var AbstractSelfTest[]
32
     */
33
    private $tests = [];
34
35
    /**
36
     * The auto configuration.
37
     *
38
     * @var AutoConfig
39
     */
40
    private $config;
41
42
    /**
43
     * Create a new instance.
44
     */
45
    public function __construct()
46
    {
47
        $this->config = new AutoConfig();
48
    }
49
50
    /**
51
     * Run all tests and return the results as an error array.
52
     *
53
     * @return SelfTestResult[]
54
     */
55
    public function perform()
56
    {
57
        $results = [];
58
59
        foreach ($this->tests as $testInstance) {
60
            $results[] = $testInstance->perform($this->config);
61
        }
62
63
        return $results;
64
    }
65
66
    /**
67
     * Add a test instance to the list of tests to perform.
68
     *
69
     * @param AbstractSelfTest $test The test to add.
70
     *
71
     * @return void
72
     */
73
    public function addTest(AbstractSelfTest $test)
74
    {
75
        $this->tests[] = $test;
76
    }
77
78
    /**
79
     * Retrieve the auto config.
80
     *
81
     * @return AutoConfig
82
     */
83
    public function getAutoConfig()
84
    {
85
        return $this->config;
86
    }
87
}
88