RandomValue::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 1
crap 3
1
<?php
2
3
namespace Graze\ArrayMerger\ValueMerger;
4
5
class RandomValue implements ValueMergerInterface
6
{
7
    use InvokeMergeTrait;
8
9
    /**
10
     * RandomValue constructor.
11
     *
12
     * @param int $seed
13
     */
14 3
    public function __construct($seed = null)
15
    {
16 3
        if (!is_null($seed) && is_int($seed)) {
17 1
            mt_srand($seed);
18
        }
19 3
    }
20
21
    /**
22
     * Return a random result
23
     *
24
     * @param mixed $value1
25
     * @param mixed $value2
26
     *
27
     * @return mixed
28
     */
29 3
    public function merge($value1, $value2)
30
    {
31 3
        return (mt_rand(1, 2) == 1) ? $value1 : $value2;
32
    }
33
}
34