Completed
Pull Request — master (#78)
by Andreas
20:53 queued 18:19
created

WriteConcern::setWriteConcernFromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 1 Features 2
Metric Value
c 3
b 1
f 2
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
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
/**
19
 * @internal
20
 */
21
trait WriteConcern
22
{
23
    use WriteConcernConverter;
24
25
    /**
26
     * @var \MongoDB\Driver\WriteConcern
27
     */
28
    protected $writeConcern;
29
30
    /**
31
     * @param $wstring
32
     * @param int $wtimeout
33
     * @return bool
34
     */
35
    abstract public function setWriteConcern($wstring, $wtimeout = 0);
36
37
    /**
38
     * @return array
39
     */
40
    public function getWriteConcern()
41
    {
42
        if ($this->writeConcern === null) {
43
            $this->writeConcern = new \MongoDB\Driver\WriteConcern(1);
44
        }
45
46
        return [
47
            'w' => $this->writeConcern->getW(),
48
            'wtimeout' => $this->writeConcern->getWtimeout(),
49
        ];
50
51
    }
52
53
    /**
54
     * @param string|int $wstring
55
     * @param int $wtimeout
56
     * @return bool
57
     */
58
    protected function setWriteConcernFromParameters($wstring, $wtimeout = 0)
59
    {
60
        $this->writeConcern = $this->createWriteConcernFromParameters($wstring, $wtimeout);
61
62
        return true;
63
    }
64
65
    /**
66
     * @param array $writeConcernArray
67
     * @return bool
68
     */
69
    protected function setWriteConcernFromArray($writeConcernArray)
70
    {
71
        $this->writeConcern = $this->createWriteConcernFromArray($writeConcernArray);
72
73
        return true;
74
    }
75
}
76