Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
9 / 9 |
Blacklist | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
9 / 9 |
getEmailAttribute | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
getExpirationTimeAttribute | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
setExpirationTimeAttribute | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
serializeDate | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\ConsumerBlacklist\Models; |
4 | |
5 | use Illuminate\Database\Eloquent\Model; |
6 | use Illuminate\Support\Facades\Crypt; |
7 | use Illuminate\Support\Str; |
8 | use DateTime; |
9 | use MongoDB\BSON\UTCDateTime; |
10 | |
11 | class Blacklist extends \Moloquent |
12 | { |
13 | protected $connection = 'consumerMongo'; |
14 | protected $collection = 'blacklist'; |
15 | protected $guarded = ['_id']; |
16 | protected $hidden = ['_id']; |
17 | protected $appends = ['id']; |
18 | protected $dates = ['created_at']; |
19 | |
20 | |
21 | /** |
22 | * Undocumented function |
23 | * |
24 | * @param [type] $value |
25 | * @return void |
26 | */ |
27 | public function getEmailAttribute($value) |
28 | { |
29 | return Crypt::decryptString($value); |
30 | } |
31 | |
32 | protected function getExpirationTimeAttribute($value) |
33 | { |
34 | if (is_a($value, 'MongoDB\BSON\UTCDateTime')) { |
35 | return $this->serializeDate($value->toDateTime()); |
36 | |
37 | } |
38 | return $value; |
39 | } |
40 | |
41 | protected function setExpirationTimeAttribute($value) |
42 | { |
43 | |
44 | if ($value != -1) { |
45 | $value = new UTCDateTime(DateTime::createFromFormat('Y-m-d', $value)); |
46 | } |
47 | |
48 | |
49 | $this->attributes['expiration_time'] = $value; |
50 | } |
51 | |
52 | /** |
53 | * Prepare a date for array / JSON serialization. |
54 | * |
55 | * @param \DateTimeInterface $date |
56 | * @return string |
57 | */ |
58 | protected function serializeDate(\DateTimeInterface $date) |
59 | { |
60 | return $date->format('Y-m-d H:i:s'); |
61 | } |
62 | } |