Completed
Push — master ( f56c57...fc32a9 )
by Tim
06:26 queued 04:29
created

Configuration::invokeTestSuite()   B

Complexity

Conditions 6
Paths 12

Size

Total Lines 54
Code Lines 30

Duplication

Lines 14
Ratio 25.93 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 30
c 1
b 0
f 0
nc 12
nop 0
dl 14
loc 54
rs 8.7449

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace SimpleSAML\Module\monitor\TestSuite;
4
5
use \SimpleSAML\Module\monitor\TestConfiguration as TestConfiguration;
6
use \SimpleSAML\Module\monitor\TestCase as TestCase;
7
use \SimpleSAML\Module\monitor\TestData as TestData;
8
use \SimpleSAML\Utils as Utils;
9
10
final class Configuration extends \SimpleSAML\Module\monitor\TestSuiteFactory
11
{
12
    /**
13
     * @param string|null
14
     */
15
    private $metadataCert = null;
16
17
    /**
18
     * @param string|null;
19
     */
20
    private $serverName = null;
21
22
    /**
23
     * @param integer|null;
24
     */
25
    private $serverPort = null;
26
27
    /**
28
     * @param TestConfiguration $configuration
29
     */
30
    public function __construct($configuration)
31
    {
32
        $globalConfig = $configuration->getGlobalConfig();
33
        $serverVars = $configuration->getServerVars();
34
35
        $this->metadataCert = $globalConfig->getString('metadata.sign.certificate', null);
36
        $this->serverName = $serverVars->get('SERVER_NAME');
37
        $this->serverPort = $serverVars->get('SERVER_PORT');
38
39
        parent::__construct($configuration);
40
    }
41
42
    /**
43
     * @return void
44
     */
45
    protected function invokeTestSuite()
46
    {
47
        // Check network connection to full public URL
48
        $input = [
49
            'connectString' => 'ssl://'.$hostname.':'.$port,
0 ignored issues
show
Bug introduced by
The variable $hostname does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $port does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
50
            'context' => stream_context_create([
51
                "ssl" => [
52
                    "capture_peer_cert" => true,
53
                    "verify_peer" => false,
54
                    "verify_peer_name" => false
55
                ]
56
            ]),
57
        ];
58
59
        $connTest = new TestCase\Network\ConnectUri($this, new TestData($input));
60
        $connTestResult = $connTest->getTestResult();
61
62
        $this->addTest($connTest);
63
64 View Code Duplication
        if ($connTestResult->getState() === State::OK) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
            // Check Service Communications Certificate
66
            $certData = $connTestResult->getOutput('certData');
67
            
68
            if (Utils\HTTP::isHTTPS() && $certData !== null) {
69
                $input = [
70
                    'category' => 'Service Communications Certificate',
71
                    'certData' => $certData,
72
                ];
73
74
                $certTest = new TestCase\Cert\Data($this, new TestData($input));
75
                $this->addTest($certTest);
76
            } // else {'Unable to capture peer certificate'}
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
77
        }
78
79
        // Check metadata signing certificate when available
80
        if (is_string($this->metadataCert)) {
81
            $input = array(
82
                'certFile' => Utils\Config::getCertPath($this->metadataCert),
83
                'category' => 'Metadata Signing Certificate'
84
            );
85
            $testData = new TestData($input);
86
87
            $test = new TestCase\Cert\File($this, $testData);
88
            $this->addTest($test);
89
        }
90
91
        $tests = $this->getTests();
92
        foreach ($tests as $test)
93
        {
94
            $this->addMessages($test->getMessages());
95
        }
96
97
        $this->calculateState();
98
    }
99
}
100