Passed
Branch v1.4.0 (4c1e35)
by Wanderson
01:16
created

Orm::getRowValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Win\Database;
4
5
use Win\Database\Orm\Traits\DebugTrait;
6
use Win\Database\Orm\Traits\OrderTrait;
7
use Win\Database\Orm\Traits\ReadTrait;
8
use Win\Database\Orm\Traits\WriteTrait;
9
use Win\Database\Sql\Queries\Select;
10
use Win\Singleton\SingletonTrait;
11
12
/**
13
 * Object Relational Mapping
14
 */
15
abstract class Orm
16
{
17
	use SingletonTrait {
18
		__construct as finalConstruct;
19
	}
20
21
	use OrderTrait;
0 ignored issues
show
Bug introduced by
The trait Win\Database\Orm\Traits\OrderTrait requires the property $orderBy which is not provided by Win\Database\Orm.
Loading history...
22
	use DebugTrait;
23
	use ReadTrait;
0 ignored issues
show
introduced by
The trait Win\Database\Orm\Traits\ReadTrait requires some properties which are not provided by Win\Database\Orm: $where, $limit
Loading history...
24
	use WriteTrait;
0 ignored issues
show
Bug introduced by
The trait Win\Database\Orm\Traits\WriteTrait requires the property $where which is not provided by Win\Database\Orm.
Loading history...
25
26
	/** @var Connection */
27
	protected static $db;
28
29
	/** @var string */
30
	protected $table;
31
32
	/** @var Model */
0 ignored issues
show
Bug introduced by
The type Win\Database\Model 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...
33
	protected $model;
34
35
	/** @var Select */
36
	private $query;
37
38
	public function __construct()
39
	{
40
		$this->query = new Select($this);
41
	}
42
43
	/** @param Connection $db */
44
	public static function setConnection(Connection $db)
45
	{
46
		static::$db = $db;
47
	}
48
49
	/** @return Connection */
50
	public static function getConnection()
51
	{
52
		return static::$db;
53
	}
54
55
	/**
56
	 * @param Model $model
57
	 * @return mixed[]
58
	 */
59
	abstract public function mapRow($model);
60
61
	/**
62
	 * @param mixed[] $row
63
	 * @return Model
64
	 */
65
	abstract public function mapModel($row);
66
67
	/** @return mixed[] */
68
	public function getRowValues()
69
	{
70
		return $this->mapRow($this->getModel());
71
	}
72
73
	/** @return string */
74
	public function getTable()
75
	{
76
		return $this->table;
77
	}
78
79
	/** @return Model */
80
	public function getModel()
81
	{
82
		return $this->model;
83
	}
84
85
	/** @return bool */
86
	public function modelExists()
87
	{
88
		return $this->model->getId() > 0;
89
	}
90
}
91