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

Model   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A or404() 0 7 2
A exists() 0 3 1
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