Completed
Push — master ( 64514c...d88910 )
by Andreas
11s
created

WriteConcern::setWriteConcernFromParameters()   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 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
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
     * @param string|int $wstring
54
     * @param int $wtimeout
55
     * @return bool
56
     */
57
    protected function setWriteConcernFromParameters($wstring, $wtimeout = 0)
58
    {
59
        $this->writeConcern = $this->createWriteConcernFromParameters($wstring, $wtimeout);
60
61
        return true;
62
    }
63
64
    /**
65
     * @param array $writeConcernArray
66
     * @return bool
67
     */
68
    protected function setWriteConcernFromArray($writeConcernArray)
69
    {
70
        $this->writeConcern = $this->createWriteConcernFromArray($writeConcernArray);
71
72
        return true;
73
    }
74
}
75