Passed
Branch v1.4.0 (ac3196)
by Wanderson
01:13
created

ReadTrait::all()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Win\Database\Orm\Traits;
4
5
trait ReadTrait
6
{
7
	/** @var Select */
0 ignored issues
show
Bug introduced by
The type Win\Database\Orm\Traits\Select was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
	private $query;
9
10
	/**
11
	 * Retorna o primeiro resultado da consulta
12
	 */
13
	public function one()
14
	{
15
		$rows = $this->query->execute();
16
17
		return $this->mapModel($rows[0]);
0 ignored issues
show
Bug introduced by
It seems like mapModel() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

17
		return $this->/** @scrutinizer ignore-call */ mapModel($rows[0]);
Loading history...
18
	}
19
20
	/**
21
	 * Retorna todos os resultado da consulta
22
	 */
23
	public function all()
24
	{
25
		$rows = $this->query->execute();
26
		$all = [];
27
		foreach ($rows as $row) {
28
			$all[] = $this->mapModel($row);
29
		}
30
31
		return $all;
32
	}
33
34
	/** @return int */
35
	public function numRows()
36
	{
37
		return $this->query->count();
38
	}
39
40
	/**
41
	 * Define as colunas do resultado
42
	 * @param string[] $columns
43
	 * @return static
44
	 */
45
	public function setColumns($columns)
46
	{
47
		$this->query->columns = $columns;
48
49
		return $this;
50
	}
51
52
	/**
53
	 * Adiciona uma coluna do resultado
54
	 * @param string $column
55
	 * @return static
56
	 */
57
	public function addColumn($column)
58
	{
59
		$this->query->columns[] = $column;
60
61
		return $this;
62
	}
63
64
	/**
65
	 * Filtra pelo id
66
	 * @param int $id
67
	 * @return static
68
	 */
69
	public function find($id)
70
	{
71
		$this->filterBy('id', $id);
72
73
		return $this;
74
	}
75
76
	/**
77
	 * Filtra pelo campo
78
	 * @param string $column
79
	 * @param mixed $value
80
	 * @return static
81
	 */
82
	public function filterBy($column, $value)
83
	{
84
		$this->filter($column, '=', $value);
85
86
		return $this;
87
	}
88
89
	/**
90
	 * Adiciona filtros para busca
91
	 * @return static
92
	 */
93
	public function filter($column, $operator, $value)
94
	{
95
		$this->query->where->add($column, $operator, $value);
96
97
		return $this;
98
	}
99
100
	/**
101
	 * Limita os resultados
102
	 * @param int $limit
103
	 * @return static
104
	 */
105
	public function limit($limit)
106
	{
107
		$this->query->limit->set($limit);
108
109
		return $this;
110
	}
111
}
112