Completed
Push — master ( a6625c...029209 )
by Henry
08:49
created

User::getByEmail()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
namespace Redaxscript\Model;
3
4
/**
5
 * parent class to provide the user model
6
 *
7
 * @since 3.3.0
8
 *
9
 * @package Redaxscript
10
 * @category Model
11
 * @author Henry Ruhs
12
 */
13
14
class User extends ModelAbstract
15
{
16
	/**
17
	 * name of the table
18
	 *
19
	 * @var string
20
	 */
21
22
	protected $_table = 'users';
23
24
	/**
25
	 * get the user by user
26
	 *
27
	 * @since 4.0.0
28
	 *
29
	 * @param string $user name of the user
30
	 *
31
	 * @return object|null
32
	 */
33
34 2
	public function getByUser(string $user = null) : ?object
35
	{
36 2
		return $this->query()->where('user', $user)->findOne() ? : null;
37
	}
38
39
	/**
40
	 * get the user by email
41
	 *
42
	 * @since 4.0.0
43
	 *
44
	 * @param string $email email of the user
45
	 *
46
	 * @return object|null
47
	 */
48
49 1
	public function getByEmail(string $email) : ?object
50
	{
51
		return $this->query()->where('email', $email)->findOne() ? : null;
52 1
	}
53 1
54 1
	/**
55 1
	 * create the user by array
56
	 *
57
	 * @since 3.3.0
58
	 *
59
	 * @param array $createArray array of the create
60
	 *
61
	 * @return bool
62
	 */
63
64
	public function createByArray(array $createArray = []) : bool
65
	{
66
		return $this
67
			->query()
68
			->create()
69 2
			->set($createArray)
70
			->save();
71
	}
72 2
73 2
	/**
74 2
	 * reset the password by id
75 2
	 *
76 2
	 * @since 3.3.0
77
	 *
78
	 * @param int $userId identifier of the user
79
	 * @param string $password
80
	 *
81
	 * @return bool
82
	 */
83
84
	public function resetPasswordById(int $userId = null, string $password = null) : bool
85
	{
86
		return $this
87
			->query()
88
			->whereIdIs($userId)
89
			->findOne()
90
			->set('password', $password)
91
			->save();
92
	}
93
}
94