Completed
Push — master ( 468cfb...a6bc20 )
by Tim
06:21 queued 02:51
created

ServerVarsObjectTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setServerVar() 4 4 1
A unsetServerVar() 4 4 1
A getServerVar() 5 5 1
A getServerVars() 4 4 1
A hasServerVar() 5 5 1
A clearServerVars() 4 4 1

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
/**
4
 * \AppserverIo\Server\Traits\ServerVarsObjectTrait
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Johann Zelger <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/server
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Server\Traits;
22
23
/**
24
 * Trait ServerVarsObjectTrait
25
 *
26
 * @author    Johann Zelger <[email protected]>
27
 * @copyright 2015 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/appserver-io/server
30
 * @link      http://www.appserver.io
31
 */
32 View Code Duplication
trait ServerVarsObjectTrait
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...
33
{
34
    /**
35
     * Sets a value to specific server var
36
     *
37
     * @param string $serverVar The server var to set
38
     * @param string $value     The value to server var
39
     *
40
     * @return void
41
     */
42
    public function setServerVar($serverVar, $value)
43
    {
44
        $this->serverVars->add($serverVar, $value);
0 ignored issues
show
Bug introduced by
The property serverVars 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...
45
    }
46
47
    /**
48
     * Unsets a specific server var
49
     *
50
     * @param string $serverVar The server var to unset
51
     *
52
     * @return void
53
     */
54
    public function unsetServerVar($serverVar)
55
    {
56
        $this->serverVars->remove($serverVar);
57
    }
58
59
    /**
60
     * Returns a value for specific server var
61
     *
62
     * @param string $serverVar The server var to get value for
63
     *
64
     * @throws \AppserverIo\Server\Exceptions\ServerException
65
     *
66
     * @return string The value to given server var
67
     */
68
    public function getServerVar($serverVar)
69
    {
70
        // get from hash map
71
        return $this->serverVars->get($serverVar);
72
    }
73
74
    /**
75
     * Returns all the server vars as array key value pair format
76
     *
77
     * @return array The server vars as array
78
     */
79
    public function getServerVars()
80
    {
81
        return $this->serverVars->toIndexedArray();
82
    }
83
84
    /**
85
     * Checks if value exists for given server var
86
     *
87
     * @param string $serverVar The server var to check
88
     *
89
     * @return bool Weather it has serverVar (true) or not (false)
90
     */
91
    public function hasServerVar($serverVar)
92
    {
93
        // check if server var is set
94
        return $this->serverVars->exists($serverVar);
95
    }
96
97
    /**
98
     * Clears the server vars storage
99
     *
100
     * @return void
101
     */
102
    public function clearServerVars()
103
    {
104
        $this->serverVars->clear();
105
    }
106
}
107