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

createWriteConcernFromParameters()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.576

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
ccs 3
cts 5
cp 0.6
rs 9.4286
cc 3
eloc 5
nc 2
nop 2
crap 3.576
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