Test Failed
Pull Request — master (#123)
by Maximo
06:15
created

NotificationsController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 45
ccs 0
cts 16
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onConstruct() 0 7 1
A processOutput() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Api\Controllers;
6
7
use Canvas\Models\Notifications;
8
use Canvas\Dto\Notification;
9
use Canvas\Mapper\NotificationMapper;
10
11
/**
12
 * Class LanguagesController.
13
 *
14
 * @package Canvas\Api\Controllers
15
 *
16
 */
17
class NotificationsController extends BaseController
18
{
19
    /*
20
     * fields we accept to create
21
     *
22
     * @var array
23
     */
24
    protected $createFields = ['read'];
25
26
    /*
27
     * fields we accept to create
28
     *
29
     * @var array
30
     */
31
    protected $updateFields = ['read'];
32
33
    /**
34
     * set objects.
35
     *
36
     * @return void
37
     */
38
    public function onConstruct()
39
    {
40
        $this->model = new Notifications();
41
        $this->additionalSearchFields = [
42
            ['is_deleted', ':', '0'],
43
            ['users_id', ':', $this->userData->getId()],
44
            ['companies_id', ':', $this->userData->currentCompanyId()],
45
        ];
46
    }
47
48
    /**
49
     * Pass the resultset to a DTO Mapper.
50
     *
51
     * @param mixed $results
52
     * @return void
53
     */
54
    protected function processOutput($results)
55
    {
56
        $this->dtoConfig->registerMapping(Notifications::class, Notification::class)
57
            ->useCustomMapper(new NotificationMapper());
58
59
        return is_iterable($results) ?
60
        $this->mapper->mapMultiple($results, Notification::class)
61
        : $this->mapper->map($results, Notification::class);
62
    }
63
}
64