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 ( 0eaa4a...267174 )
by Stuart
05:30
created

UsingRuntimeTables::removeTableIfEmpty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 8

Duplication

Lines 18
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 18
loc 18
c 1
b 0
f 0
rs 9.4286
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
3
/**
4
 * Copyright (c) 2013-present Mediasift Ltd
5
 * Copyright (c) 2015-present Ganbaro Digital Ltd
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 *
12
 *   * Redistributions of source code must retain the above copyright
13
 *     notice, this list of conditions and the following disclaimer.
14
 *
15
 *   * Redistributions in binary form must reproduce the above copyright
16
 *     notice, this list of conditions and the following disclaimer in
17
 *     the documentation and/or other materials provided with the
18
 *     distribution.
19
 *
20
 *   * Neither the names of the copyright holders nor the names of his
21
 *     contributors may be used to endorse or promote products derived
22
 *     from this software without specific prior written permission.
23
 *
24
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
 * POSSIBILITY OF SUCH DAMAGE.
36
 *
37
 * @author    Stuart Herbert <[email protected]>
38
 * @copyright 2013-present Mediasift Ltd www.datasift.com
39
 * @copyright 2015-present Ganbaro Digital Ltd www.ganbarodigital.com
40
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
41
 * @link      http://datasift.github.io/storyplayer
42
 */
43
44
namespace StoryplayerInternals\SPv2\Modules\RuntimeTable;
45
46
use DataSift\Stone\ObjectLib\BaseObject;
47
use Prose\Prose;
48
use Storyplayer\SPv2\Modules\Log;
49
use StoryplayerInternals\SPv2\Modules\RuntimeTable;
50
51
/**
52
 * UsingRuntimeTables
53
 *
54
 * @uses Prose
55
 * @author Stuart Herbert <[email protected]>
56
 */
57
class UsingRuntimeTables extends Prose
58
{
59
    /**
60
     * create a runtime table
61
     *
62
     * if the table already exists, it will NOT be overwritten
63
     *
64
     * @param  string $tableName
65
     *         the table to create
66
     * @return BaseObject
67
     *         the created table, ready for use
68
     */
69 View Code Duplication
    public function createTable($tableName)
1 ignored issue
show
Duplication introduced by
This method 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...
70
    {
71
        // what are we doing?
72
        $log = Log::usingLog()->startAction("create runtime table '{$tableName}'");
73
74
        // get the current runtime tables
75
        $tables = RuntimeTable::fromRuntimeTables()->getAllTables();
76
        if (!isset($tables->$tableName)) {
77
            $log->writeToLog("table does not exist; creating");
78
            $tables->$tableName = new BaseObject;
79
        }
80
        else {
81
            $log->writeToLog("table already exists");
82
        }
83
84
        // all done
85
        $log->endAction();
86
        return $tables->$tableName;
87
    }
88
89
    /**
90
     * remove a runtime table, even if it has content
91
     *
92
     * @param  string $tableName
93
     *         the name of the table to use
94
     * @return void
95
     */
96 View Code Duplication
    public function removeTable($tableName)
1 ignored issue
show
Duplication introduced by
This method 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...
97
    {
98
        // what are we doing?
99
        $log = Log::usingLog()->startAction("remove table '{$tableName}' from the runtime tables");
100
101
        // does the table exist?
102
        if (!RuntimeTable::fromRuntimeTables()->getTableExists($tableName)) {
103
            $log->endAction();
104
            return;
105
        }
106
107
        // get the tables
108
        $tables = RuntimeTable::fromRuntimeTables()->getAllTablesSilently();
109
        unset($tables->$tableName);
110
111
        // all done
112
        $log->endAction("table '{$tableName}' removed");
113
    }
114
115
    /**
116
     * remove a table if, and only if, it is empty
117
     *
118
     * @param  string $tableName
119
     *         the name of the table to remove
120
     * @return void
121
     */
122 View Code Duplication
    public function removeTableIfEmpty($tableName)
1 ignored issue
show
Duplication introduced by
This method 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...
123
    {
124
        // what are we doing?
125
        $log = Log::usingLog()->startAction("remove table '{$tableName}' from the runtime tables if it is empty");
126
127
        // is the table empty?
128
        if (!RuntimeTable::fromRuntimeTable($tableName)->getIsEmpty()) {
129
            $log->endAction("not removing; table is not empty");
130
            return;
131
        }
132
133
        // if we get here, the table is empty
134
        $tables = RuntimeTable::fromRuntimeTables()->getAllTablesSilently();
135
        unset($tables->$tableName);
136
137
        // all done
138
        $log->endAction("table '{$tableName}' removed; table was empty");
139
    }
140
}
141