Completed
Pull Request — master (#25)
by
unknown
03:13
created

WriteConcernRaw   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 23.33 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 77.78%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 0
cbo 0
dl 7
loc 30
ccs 7
cts 9
cp 0.7778
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createWriteConcernFromParameters() 0 10 3
A createWriteConcernFromArray() 7 7 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
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 */
15
16
namespace Alcaeus\MongoDbAdapter\Helper;
17
18
trait WriteConcernRaw
19
{
20
    /**
21
     * @param string|int $wstring
22
     * @param int $wtimeout
23
     * @return \MongoDB\Driver\WriteConcern
24
     */
25 120
    protected function createWriteConcernFromParameters($wstring, $wtimeout)
26
    {
27 120
        if (! is_string($wstring) && ! is_int($wstring)) {
28
            trigger_error("w for WriteConcern must be a string or integer", E_WARNING);
29
            return false;
30
        }
31
32
        // Ensure wtimeout is not < 0
33 120
        return new \MongoDB\Driver\WriteConcern($wstring, max($wtimeout, 0));
34
    }
35
36
    /**
37
     * @param array $writeConcernArray
38
     * @return \MongoDB\Driver\WriteConcern
39
     */
40 6 View Code Duplication
    protected function createWriteConcernFromArray($writeConcernArray)
0 ignored issues
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...
41
    {
42 6
        $wstring = isset($writeConcernArray['w']) ? $writeConcernArray['w'] : 1;
43 6
        $wtimeout = isset($writeConcernArray['wtimeout']) ? $writeConcernArray['wtimeout'] : 0;
44
45 6
        return $this->createWriteConcernFromParameters($wstring, $wtimeout);
46
    }
47
}
48