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 ( d8ccfa...467c2a )
by Stuart
07:17
created

ExpectsRuntimeTable   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 15.58 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 5
dl 12
loc 77
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B hasEntry() 6 30 3
B hasNoEntry() 6 29 3

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
48
/**
49
 * ExpectsRuntimeTable
50
 *
51
 * @uses Prose
52
 * @author Michael Heap <[email protected]>
53
 */
54
class ExpectsRuntimeTable extends BaseRuntimeTable
55
{
56
    /**
57
     * hasEntry
58
     *
59
     * @param string $key key The key to look for inside the tableName table
60
     *
61
     * @return void
62
     */
63
    public function hasEntry($key)
64
    {
65
        // get our table name from the constructor
66
        $tableName = $this->args[0];
67
68
        // what are we doing?
69
        $log = Log::usingLog()->startAction("make sure host '{$key}' has an entry in the '{$tableName}' table");
70
71
        // get the table config
72
        $tables = $this->getAllTables();
73
74
        // make sure we have a hosts table
75
        if (!isset($tables->$tableName)) {
76
            $msg = "table is empty / does not exist";
77
            $log->endAction($msg);
78
79
            throw Exceptions::newExpectFailedException(__METHOD__, "{$tableName} table existed", "{$parent} table does not exist");
80
        }
81
82
        // make sure we don't have a duplicate entry
83 View Code Duplication
        if (!isset($tables->$tableName->$key)) {
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...
84
            $msg = "table does not contain an entry for '{$key}'";
85
            $log->endAction($msg);
86
87
            throw Exceptions::newExpectFailedException(__METHOD__, "{$tableName} table has an entry for '{$key}'", "{$parent} table has no entry for '{$key}'");
88
        }
89
90
        // all done
91
        $log->endAction();
92
    }
93
94
    /**
95
     * hasNoEntry
96
     *
97
     * @param string $key key The key to look for inside the tableName table
98
     *
99
     * @return void
100
     */
101
    public function hasNoEntry($key)
102
    {
103
        // get our table name from the constructor
104
        $tableName = $this->args[0];
105
106
        // what are we doing?
107
        $log = Log::usingLog()->startAction("make sure there is no existing entry for '{$key}' in '{$tableName}'");
108
109
        // get the table config
110
        $tables = $this->getAllTables();
111
112
        // make sure we have a hosts table
113
        if (!isset($tables->$tableName)) {
114
            $msg = "table is empty / does not exist";
115
            $log->endAction($msg);
116
            return;
117
        }
118
119
        // make sure we don't have a duplicate entry
120 View Code Duplication
        if (isset($tables->$tableName->$key)) {
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...
121
            $msg = "table already contains an entry for '{$key}'";
122
            $log->endAction($msg);
123
124
            throw Exceptions::newExpectFailedException(__METHOD__, "{$tableName} table has no entry for '{$key}'", "{$parent} table has an entry for '{$key}'");
125
        }
126
127
        // all done
128
        $log->endAction();
129
    }
130
}
131