Completed
Branch master (691237)
by dima
02:39
created

UserRepo::findById()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Models\User;
4
5
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
6
7
use Models\User\User;
8
use Models\User\UserQuery;
9
10
/**
11
 * Description of UserRepo
12
 *
13
 * @author Dmitriy
14
 */
15
class UserRepo implements \Models\CrudInterface
16
{   
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
17
    
18
    public function find(array $conditions = [])
19
    {
20
        return UserQuery::create()->findOneByArray($conditions);  
21
    }
22
23
    /**
24
     * Поиск по id
25
     * @param type $id
26
     * @return \Models\User\User $User
27
     * @throws \InvalidArgumentException
28
     */
29
    public function findById($id)
30
    {
31
        if (!$User = UserQuery::create()->findPk($id)) {
32
            throw new \InvalidArgumentException(sprintf('User with ID %d does not exist',$id));
33
        }
34
35
        return $User;
36
    }
37
38
    public function findMany(array $conditions = [])
39
    {
40
        return UserQuery::create()->findByArray($conditions);    
41
    }
42
43
    public function delete(ActiveRecordInterface $Model)
44
    {
45
        
46
    }
47
48
    /**
49
     * Сохраняем
50
     * @param ActiveRecordInterface $Model
51
     * @return boolean
52
     * @throws \DomainException
53
     */
54
    public function save(ActiveRecordInterface $Model)
55
    {
56
        if (!$Model->save()) {
57
            throw new \DomainException(sprintf('User not save',$id));
58
        }
59
60
        return true;        
61
    }
62
63
}
64