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

ExpectsRuntimeTable   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 112
Duplicated Lines 35.71 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 8
dl 40
loc 112
c 3
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hasItem() 20 20 2
A doesNotHaveItem() 20 20 2
A exists() 0 20 2
A doesNotExist() 0 20 2

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
 * 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 Prose\Prose;
45
use Storyplayer\SPv2\Modules\Exceptions;
46
use Storyplayer\SPv2\Modules\Log;
47
use StoryplayerInternals\SPv2\Modules\RuntimeTable;
48
49
/**
50
 * ExpectsRuntimeTable
51
 *
52
 * @uses Prose
53
 * @author Michael Heap <[email protected]>
54
 */
55
class ExpectsRuntimeTable extends BaseRuntimeTable
56
{
57
    /**
58
     * hasItem
59
     *
60
     * @param string $key
61
     *        The key to look for inside the tableName table
62
     *
63
     * @return void
64
     */
65 View Code Duplication
    public function hasItem($key)
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...
66
    {
67
        // get our table name from the constructor
68
        $tableName = $this->args[0];
69
70
        // what are we doing?
71
        $log = Log::usingLog()->startAction("make sure item '{$key}' exists in the '{$tableName}' table");
72
73
        // does the item exist?
74
        $exists = RuntimeTable::fromRuntimeTable($tableName)->hasItem($key);
75
        if (!$exists) {
76
            $msg = "table does not contain item '{$key}'";
77
            $log->endAction($msg);
78
79
            throw Exceptions::newExpectFailedException(__METHOD__, "{$tableName} table has item '{$key}'", "{$tableName} table has no item '{$key}'");
80
        }
81
82
        // all done
83
        $log->endAction();
84
    }
85
86
    /**
87
     * doesNotHaveItem
88
     *
89
     * @param string $key
90
     *        The key to look for inside the tableName table
91
     *
92
     * @return void
93
     */
94 View Code Duplication
    public function doesNotHaveItem($key)
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...
95
    {
96
        // get our table name from the constructor
97
        $tableName = $this->args[0];
98
99
        // what are we doing?
100
        $log = Log::usingLog()->startAction("make sure there is no existing item '{$key}' in '{$tableName}'");
101
102
        // does the item exist?
103
        $exists = RuntimeTable::fromRuntimeTable($tableName)->hasItem($key);
104
        if ($exists) {
105
            $msg = "table contains item '{$key}'";
106
            $log->endAction($msg);
107
108
            throw Exceptions::newExpectFailedException(__METHOD__, "{$tableName} table has no item '{$key}'", "{$tableName} table has item '{$key}'");
109
        }
110
111
        // all done
112
        $log->endAction();
113
    }
114
115
    /**
116
     * exists
117
     *
118
     * @return void
119
     */
120
    public function exists()
121
    {
122
        // get our table name from the constructor
123
        $tableName = $this->args[0];
124
125
        // what are we doing?
126
        $log = Log::usingLog()->startAction("make sure runtime table '{$tableName}' exists");
127
128
        // does the table exist?
129
        $exists = RuntimeTable::fromRuntimeTables()->getTableExists($tableName);
130
131
        // make sure we have the named table
132
        if (!$exists) {
133
            $log->endAction("table does not exist");
134
            throw Exceptions::newExpectFailedException(__METHOD__, "runtime table '{$tableName}' exists", "runtime table '{$tableName}' does not exist");
135
        }
136
137
        // all done
138
        $log->endAction();
139
    }
140
141
    /**
142
     * doesNotExist
143
     *
144
     * @return void
145
     */
146
    public function doesNotExist()
147
    {
148
        // get our table name from the constructor
149
        $tableName = $this->args[0];
150
151
        // what are we doing?
152
        $log = Log::usingLog()->startAction("make sure runtime table '{$tableName}' does not exist");
153
154
        // does the table exist?
155
        $exists = RuntimeTable::fromRuntimeTables()->getTableExists($tableName);
156
157
        // make sure we do not have the named table
158
        if ($exists) {
159
            $log->endAction("table exists");
160
            throw Exceptions::newExpectFailedException(__METHOD__, "runtime table '{$tableName}' does not exist", "runtime table '{$tableName}' exists");
161
        }
162
163
        // all done
164
        $log->endAction();
165
    }
166
}
167