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

NotificationsController::processOutput()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 8
ccs 0
cts 7
cp 0
crap 6
rs 10
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