-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task.php
51 lines (42 loc) · 999 Bytes
/
Task.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace app\mock\repository;
use app\entity as Entity;
use app\repository as Repo;
class Task implements Repo\TaskInterface
{
/**
* Array of root Task Entities
* @var array
*/
protected $root = [];
/**
* {@inheritDoc}
*/
public function create($id, $userId, $title, $description, $notes)
{
return new Entity\Task($id, $userId, $title, $description, $notes);
}
/**
* {@inheritDoc}
*/
public function add(Entity\Task $task)
{
if ( ! $task->getId() or ! $this->isFreeId($task->getId())) {
$task->setId($this->getUniqId());
}
$this->root[$task->getId()] = $task;
return true;
}
protected function isFreeId($id)
{
return array_key_exists($id, $this->root);
}
protected function getUniqId()
{
$keys = array_keys($this->root);
if (empty($keys)) {
return 1;
}
return max($keys) + 1;
}
}