Passed
Branch v1.5.1 (4f5540)
by Wanderson
05:07
created

Model::exists()   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
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Win\Models;
4
5
use Win\Request\HttpException;
6
7
abstract class Model
8
{
9
	/** @var int|null */
10
	public $id;
11
12
	abstract public function validate();
13
14
	/** @return boolean */
15
	public function exists()
16
	{
17
		return isset($this->id);
18
	}
19
20
	/**
21
	 * Retorna o model ou define página 404
22
	 * @return static
23
	 */
24
	public function or404()
25
	{
26
		if (!$this->exists()) {
27
			throw new HttpException('Model not found', 404);
28
		}
29
30
		return $this;
31
	}
32
}
33