Completed
Push — master ( b40085...1d81aa )
by Tim
02:16
created

TestResult   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 60
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 60
loc 60
rs 10
c 1
b 0
f 0
wmc 12
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
B setOutput() 14 14 5
A addOutput() 10 10 2
A getOutput() 5 5 4

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;
4
5 View Code Duplication
final class TestResult
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
6
{
7
    /**
8
     * @param array $output
9
     */
10
    public function __construct($output = array())
11
    {
12
        assert(is_array($output));
13
        $this->setInput($output);
0 ignored issues
show
Bug introduced by
The method setInput() does not seem to exist on object<SimpleSAML\Module\monitor\TestResult>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
14
    }
15
16
    /**
17
     * @param mixed|null $output
18
     * @param string|null $key
19
     *
20
     * @return void
21
     */
22
    public function setOutput($output, $key = null)
23
    {
24
        assert(is_string($key) || is_null($key));
25
        if (is_null($key)) {
26
            assert(is_array($output));
27
            foreach ($output as $key => $value) {
28
                $this->addOutput($key, $value);
29
            }
30
        } elseif (array_key_exists($key, $this->output)) {
0 ignored issues
show
Bug introduced by
The property output does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
            $this->output[$key] = $output;
32
        } else {
33
            $this->addOutput($key, $output);
34
        }
35
    }
36
37
    /**
38
     * @param string $key
39
     * @param mixed|null $value
40
     *
41
     * @return void
42
     */
43
    public function addOutput($key, $value = null)
44
    {
45
        assert(is_string($key));
46
        if (isSet($this->output[$key])) {
47
            assert(is_array($this->output[$key]));
48
            $this->output[$key] = array_merge($this->output[$key], $value);
49
        } else {
50
            $this->output[$key] = $value;
51
        }
52
    }
53
54
    /**
55
     * @param string|null $item
56
     *
57
     * @return mixed
58
     */
59
    public function getOutput($item = null)
60
    {
61
        assert(is_string($item) || is_null($item));
62
        return is_null($item) ? $this->output : (isSet($this->output[$item]) ? $this->output[$item] : null);
63
    }
64
}
65