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

Configuration   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 90
Duplicated Lines 15.56 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 90
rs 10
wmc 7
lcom 1
cbo 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
B invokeTestSuite() 14 54 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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