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

WriteConcern   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 54
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
setWriteConcern() 0 1 ?
A getWriteConcern() 0 11 2
A setWriteConcernFromParameters() 0 6 1
A setWriteConcernFromArray() 0 6 1
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