GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 264bc7...d8ccfa )
by Stuart
07:51
created

TestEnvironmentRuntimeConfig::removeEmptyTables()   B

Complexity

Conditions 7
Paths 12

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 21
rs 7.551
cc 7
eloc 11
nc 12
nop 0
1
<?php
2
3
/**
4
 * Copyright (c) 2011-present Mediasift Ltd
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 *
11
 *   * Redistributions of source code must retain the above copyright
12
 *     notice, this list of conditions and the following disclaimer.
13
 *
14
 *   * Redistributions in binary form must reproduce the above copyright
15
 *     notice, this list of conditions and the following disclaimer in
16
 *     the documentation and/or other materials provided with the
17
 *     distribution.
18
 *
19
 *   * Neither the names of the copyright holders nor the names of his
20
 *     contributors may be used to endorse or promote products derived
21
 *     from this software without specific prior written permission.
22
 *
23
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
 * POSSIBILITY OF SUCH DAMAGE.
35
 *
36
 * @category  Libraries
37
 * @package   Storyplayer/TestEnvironmentsLib
38
 * @author    Stuart Herbert <[email protected]>
39
 * @copyright 2011-2015 Mediasift Ltd www.datasift.com
40
 * @copyright 2015-present Ganbaro Digital Ltd www.ganbarodigital.com
41
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
42
 * @link      http://datasift.github.io/storyplayer
43
 */
44
45
namespace DataSift\Storyplayer\TestEnvironmentsLib;
46
47
use DataSift\Storyplayer\ConfigLib\WrappedConfig;
48
use DataSift\Stone\ObjectLib\BaseObject;
49
50
/**
51
 * the class for a test environment's runtime config
52
 *
53
 * the runtime config is the persistent state (e.g. hosts that have been
54
 * spun up) of the test environment
55
 *
56
 * @category  Libraries
57
 * @package   Storyplayer/TestEnvironmentsLib
58
 * @author    Stuart Herbert <[email protected]>
59
 * @copyright 2011-2015 Mediasift Ltd www.datasift.com
60
 * @copyright 2015-present Ganbaro Digital Ltd www.ganbarodigital.com
61
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
62
 * @link      http://datasift.github.io/storyplayer
63
 */
64
class TestEnvironmentRuntimeConfig extends WrappedConfig
65
{
66
    public function __construct()
67
    {
68
        parent::__construct(self::ROOT_IS_OBJECT);
69
    }
70
71
    public function validateConfig()
72
    {
73
        // do we have any config?
74
        $config = $this->getConfig();
0 ignored issues
show
Unused Code introduced by
$config is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
75
    }
76
77
    /**
78
     * set the name of this config by looking at the filename
79
     *
80
     * the 'name' is used as an array key elsewhere. if we get this wrong,
81
     * then Storyplayer isn't going to be able to find our config later on
82
     *
83
     * @param  string $filename
84
     *         the path/to/file/name.ext where we found this config
85
     * @return void
86
     */
87
    protected function setNameFromFilename($filename)
88
    {
89
        $this->setName(basename(dirname($filename)));
90
    }
91
92
    // ==================================================================
93
    //
94
    // This is the old RuntimeConfigManager API from SPv1 (more or less).
95
    //
96
    // It is part of our migration from a single runtime-v2.json file to
97
    // a per-test-environment runtime.json file scheme.
98
    //
99
    // ------------------------------------------------------------------
100
101
    /**
102
     * getAllTables
103
     *
104
     * Return our tables config that we can use for
105
     * in place editing
106
     *
107
     * @return BaseObject
108
     */
109
    public function getAllTables()
110
    {
111
        // make sure the storyplayer section exists
112
        if (!$this->hasData('tables')) {
113
            $this->setData('tables', new BaseObject);
114
        }
115
116
        // arrow-notation ensures we get a READ-WRITE object back
117
        return $this->tables;
0 ignored issues
show
Documentation introduced by
The property tables does not exist on object<DataSift\Storypla...vironmentRuntimeConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
118
    }
119
120
    /**
121
     * return a single table from the persistent state
122
     *
123
     * if the table does not exist, this will create an empty table
124
     * before returning it to the caller
125
     *
126
     * @param  string $tableName
127
     *         the name of the table we want
128
     * @return BaseObject
129
     */
130
    public function getTable($tableName)
131
    {
132
        // normalise!
133
        $tableName = lcfirst($tableName);
134
135
        // find it
136
        $tables = $this->getAllTables();
137
        if (!isset($tables->$tableName)) {
138
            // make sure the caller gets a table
139
            $tables->$tableName = new BaseObject;
140
        }
141
142
        // all done
143
        return $tables->$tableName;
144
    }
145
146
    /**
147
     * remove any empty tables from the runtime config
148
     *
149
     * @return void
150
     */
151
    public function removeEmptyTables()
152
    {
153
        $tables = $this->getAllTables();
154
155
        foreach ($tables as $tableName => $table) {
156
            if ($table instanceof BaseObject) {
157
                if (!$table->hasProperties()) {
158
                    unset($tables->$tableName);
159
                }
160
            }
161
            else if (is_array($table)) {
162
                if (empty($table)) {
163
                    unset($tables->$tableName);
164
                }
165
            }
166
        }
167
168
        if (!$tables->hasProperties()) {
169
            $this->unsetData('tables');
170
        }
171
    }
172
}
173