CredoTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 73
ccs 12
cts 12
cp 1
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A credo() 0 5 1
A get() 0 3 1
A find() 0 3 1
A where() 0 5 1
A findBy() 0 3 1
1
<?php
2
3
namespace Rougin\Credo\Traits;
4
5
use Rougin\Credo\Credo;
6
7
/**
8
 * Credo Trait
9
 *
10
 * @method string table()
11
 *
12
 * @package Credo
13
 * @author  Rougin Gutib <[email protected]>
14
 */
15
trait CredoTrait
16
{
17
    /**
18
     * @var \Rougin\Credo\Credo
19
     */
20
    protected $credo;
21
22
    /**
23
     * Sets the Credo instance.
24
     *
25
     * @param  \Rougin\Credo\Credo $credo
26
     * @return self
27
     */
28 8
    public function credo(Credo $credo)
29
    {
30 8
        $this->credo = $credo;
31
32 8
        return $this;
33
    }
34
35
    /**
36
     * Finds the row from storage based on given identifier.
37
     *
38
     * @param  mixed        $id
39
     * @param  integer|null $mode
40
     * @param  integer|null $version
41
     * @return mixed
42
     */
43 7
    public function find($id, $mode = null, $version = null)
44
    {
45 7
        return $this->credo->find(get_class($this), $id, $mode, $version);
46
    }
47
48
    /**
49
     * Finds models by a set of criteria.
50
     *
51
     * @param  array        $criteria
52
     * @param  integer|null $limit
53
     * @param  integer|null $offset
54
     * @param  array|null   $order
55
     * @return array
56
     */
57 3
    public function findBy(array $criteria = array(), $limit = null, $offset = null, array $order = null)
58
    {
59 3
        return $this->credo->findBy(get_class($this), $criteria, $limit, $offset, $order);
0 ignored issues
show
Bug introduced by
It seems like $limit can also be of type integer; however, parameter $order of Rougin\Credo\Credo::findBy() does only seem to accept array|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

59
        return $this->credo->findBy(get_class($this), $criteria, /** @scrutinizer ignore-type */ $limit, $offset, $order);
Loading history...
Bug introduced by
It seems like $order can also be of type array; however, parameter $offset of Rougin\Credo\Credo::findBy() does only seem to accept integer|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

59
        return $this->credo->findBy(get_class($this), $criteria, $limit, $offset, /** @scrutinizer ignore-type */ $order);
Loading history...
60
    }
61
62
    /**
63
     * Returns an array of rows from a specified table.
64
     *
65
     * @param  string       $table
66
     * @param  integer|null $limit
67
     * @param  integer|null $offset
68
     * @param  array|null   $order
69
     * @return mixed
70
     */
71 7
    public function get($limit = null, $offset = null, array $order = null)
72
    {
73 7
        return $this->credo->get(get_class($this), $limit, $offset, $order);
74
    }
75
76
    /**
77
     * Sets the "WHERE" criteria.
78
     *
79
     * @param  array|string $key
80
     * @param  mixed|null   $value
81
     * @return self
82
     */
83 4
    public function where($key, $value = null)
84
    {
85 4
        $this->credo->where($key, $value);
86
87 4
        return $this;
88
    }
89
}
90