FixturesTrait::addFixture()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace ByTIC\Codeception\Helper\Traits;
4
5
use Codeception\Util\Fixtures;
6
use RuntimeException;
7
8
/**
9
 * Class QueryTrait
10
 * @package ByTIC\Common\Tests\Helper\Traits
11
 */
12
trait FixturesTrait
13
{
14
    use AbstractTrait;
15
16
    /**
17
     * @param $name
18
     * @param $value
19
     */
20
    public function pushFixture($name, $value)
21
    {
22
        if ($this->hasFixture($name)) {
23
            $array = $this->getFixture($name);
24
            $array = is_array($array) ? $array : [$array];
25
        } else {
26
            $array = [];
27
        }
28
        $array[] = $value;
29
        $this->addFixture($name, $array);
30
    }
31
32
    /**
33
     * @param $name
34
     *
35
     * @return bool
36
     */
37
    public function hasFixture($name)
38
    {
39
        try {
40
            Fixtures::get($name);
41
        } catch (RuntimeException $exception) {
42
            return false;
43
        }
44
45
        return true;
46
    }
47
48
    /**
49
     * @param $name
50
     *
51
     * @return mixed
52
     */
53
    public function getFixture($name)
54
    {
55
        return Fixtures::get($name);
56
    }
57
58
    /**
59
     * @param $name
60
     * @param $value
61
     */
62
    public function addFixture($name, $value)
63
    {
64
        Fixtures::add($name, $value);
65
    }
66
}
67