UserRepository   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 51
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 3 1
A findById() 0 7 2
A findMany() 0 8 1
A delete() 0 3 1
A save() 0 3 1
A build() 0 3 1
1
<?php
2
namespace Core\Models\User;
3
4
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
5
use Frameworkless\Exceptions\ValidationException;
6
7
/**
8
 * Description of UserRepo
9
 *
10
 * @author Dmitriy
11
 */
12
class UserRepository implements \Frameworkless\CrudInterface{
13
14
    public function find(array $conditions = []){
15
	return UserQuery::create()->findOneByArray($conditions);
16
    }
17
18
    /**
19
     * Поиск по id
20
     * @param type $id
21
     * @return \Models\User\User $User
22
     * @throws \InvalidArgumentException
23
     */
24
    public function findById($id){
25
	if(!$User = UserQuery::create()->findPk($id)){
26
	    throw new \InvalidArgumentException(sprintf('User with ID %d does not exist', $id));
27
	}
28
29
	return $User;
30
    }
31
32
    public function findMany(array $conditions = [], $limit = false){
33
	$Users = UserQuery::create()
34
		->_if($limit)
35
		->limit($limit)
36
		->_endif()
37
		->findByArray($conditions);
38
	return $Users;
39
    }
40
41
    public function delete(ActiveRecordInterface $Model){
42
	return $Model->delete();
43
    }
44
45
    /**
46
     * Сохраняем
47
     * @param ActiveRecordInterface $Model
48
     * @return boolean
49
     * @throws \DomainException
50
     */
51
    public function save(ActiveRecordInterface $Model){
52
	return $Model->save();
53
    }
54
55
    /**
56
     * 
57
     * @return \Core\Models\User\User $User
58
     */
59
    public function build(){
60
	return new User;
61
    }
62
}
63