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 ( fdb351...008b6e )
by Stuart
05:27
created

FromRuntimeTable::getItem()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 30
Code Lines 14

Duplication

Lines 5
Ratio 16.67 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 5
loc 30
rs 8.8571
cc 3
eloc 14
nc 3
nop 1
1
<?php
2
3
/**
4
 * Copyright (c) 2013-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
 * @author    Michael Heap <[email protected]>
37
 * @copyright 2013-present Mediasift Ltd www.datasift.com
38
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
39
 * @link      http://datasift.github.io/storyplayer
40
 */
41
42
namespace StoryplayerInternals\SPv2\Modules\RuntimeTable;
43
44
use DataSift\Stone\ObjectLib\BaseObject;
45
use Storyplayer\SPv2\Modules\Log;
46
47
/**
48
 * ExpectsRuntimeTable
49
 *
50
 * @uses Prose
51
 * @author Michael Heap <[email protected]>
52
 */
53
class FromRuntimeTable extends BaseRuntimeTable
54
{
55
    /**
56
     * getTable
57
     *
58
     *
59
     * @return object The table from the config
60
     */
61 View Code Duplication
    public function getTable()
62
    {
63
        // get our table name from the constructor
64
        $tableName = $this->args[0];
65
66
        // what are we doing?
67
        $log = Log::usingLog()->startAction("get '{$tableName}' table from runtime config");
68
69
        // get the table config
70
        $tables = $this->getAllTables();
71
72
        // make sure we have a table
73
        if (!isset($tables->$tableName)){
74
            $tables->$tableName = new BaseObject();
75
        }
76
77
        // all done
78
        $log->endAction();
79
        return $tables->$tableName;
80
    }
81
82 View Code Duplication
    public function getGroupFromTable($group)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
83
    {
84
        // get our table name from the constructor
85
        $tableName = $this->args[0];
86
87
        // what are we doing?
88
        $log = Log::usingLog()->startAction("get '{$tableName}->{$group}' table group from runtime config");
89
90
        // get the table config
91
        $tables = $this->getAllTables();
92
93
        // make sure we have a table
94
        if (!isset($tables->$tableName)){
95
            $tables->$tableName = new BaseObject();
96
        }
97
        // make sure we have a group
98
        if (!isset($tables->$tableName->$group)) {
99
            $tables->$tableName->$group = new BaseObject;
100
        }
101
102
        // all done
103
        $log->endAction();
104
        return $tables->$tableName->$group;
105
    }
106
107
    /**
108
     * getItem
109
     *
110
     * Get the value of a specific key
111
     *
112
     * @param string $key
113
     *        The key to look for inside the tableName table
114
     *
115
     * @return mixed
116
     *         The value of the key
117
     */
118
    public function getItem($key)
119
    {
120
        // get our table name from the constructor
121
        $tableName = $this->args[0];
122
123
        // what are we doing?
124
        $log = Log::usingLog()->startAction("get details for '{$key}' from {$tableName} table");
125
126
        // get the table config
127
        $tables = $this->getAllTables();
128
129
        // make sure we have a hosts table
130
        if (!isset($tables->$tableName)) {
131
            $msg = "table is empty / does not exist";
132
            $log->endAction($msg);
133
134
            return null;
135
        }
136
137
        // do we have the entry we're looking for?
138 View Code Duplication
        if (!isset($tables->$tableName->$key)) {
1 ignored issue
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...
139
            $msg = "table does not contain an entry for '{$key}'";
140
            $log->endAction($msg);
141
            return null;
142
        }
143
144
        // all done
145
        $log->endAction();
146
        return $tables->$tableName->$key;
147
    }
148
149
    /**
150
     * Get the value of a specific key from a group
151
     *
152
     * @param string $key
153
     *        The key to look for inside the tableName table
154
     *
155
     * @return mixed
156
     *         The value of the $key
157
     */
158
    public function getItemFromGroup($group, $key)
159
    {
160
        // get our table name from the constructor
161
        $tableName = $this->args[0];
162
163
        // what are we doing?
164
        $log = Log::usingLog()->startAction("get details for '{$group}->{$key}' from {$tableName} table");
165
166
        // get the table config
167
        $tables = $this->getAllTables();
168
169
        // make sure we have a table
170
        if (!isset($tables->$tableName)) {
171
            $msg = "table is empty / does not exist";
172
            $log->endAction($msg);
173
174
            return null;
175
        }
176
177
        // make sure we have the group
178 View Code Duplication
        if (!isset($tables->$tableName->$group)) {
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...
179
            $msg = "table has no group '{$group}'";
180
            $log->endAction($msg);
181
182
            return null;
183
        }
184
185
        // do we have the entry we're looking for?
186 View Code Duplication
        if (!isset($tables->$tableName->$group->$key)) {
1 ignored issue
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...
187
            $msg = "table does not contain an entry for '{$group}->{$key}'";
188
            $log->endAction($msg);
189
            return null;
190
        }
191
192
        // all done
193
        $log->endAction();
194
        return $tables->$tableName->$group->$key;
195
    }
196
}
197