Completed
Push — master ( 8c2434...6692d3 )
by Sébastien
14:40
created

ShardPicker::pickShard()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Bdf\Prime\Sharding\Extension;
4
5
use Bdf\Prime\Sharding\ShardingConnection;
0 ignored issues
show
introduced by
Unused use statement
Loading history...
6
7
/**
8
 * Trait ShardPicker
9
 *
10
 * @property ShardingConnection $connection
11
 */
12
trait ShardPicker
13
{
14
    /**
15
     * @var null|string
16
     */
17
    private $shardId;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
18
19
    /**
20
     * Pick up a shard manually from the distribution value
21
     * This query will be executed only on the targeted shard
0 ignored issues
show
introduced by
Doc comment short description must be on a single line, further text should be a separate paragraph
Loading history...
22
     *
23
     * @param mixed $distributionValue
24
     *
25
     * @return $this
26
     */
27 6
    public function pickShard($distributionValue)
28
    {
29 6
        $this->shardId = $this->connection->getShardChoser()
30 6
            ->pick($distributionValue, $this->connection);
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
introduced by
Object operator not indented correctly; expected 10 spaces but found 12
Loading history...
31
32 6
        return $this;
33
    }
34
35
    /**
36
     * Set the shard manually
37
     * This query will be executed only on this shard
0 ignored issues
show
introduced by
Doc comment short description must be on a single line, further text should be a separate paragraph
Loading history...
38
     *
39
     * @param null|string $shardId
40
     *
41
     * @return $this
42
     */
43
    public function useShard(?string $shardId)
44
    {
45
        $this->shardId = $shardId;
46
47
        return $this;
48
    }
49
}