Completed
Pull Request — master (#1)
by
unknown
16:41
created

ActivityLogController::cgetAction()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 40
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 27
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Bundle\ActivityLogBundle\Controller;
13
14
use FOS\RestBundle\Controller\Annotations\Get;
15
use FOS\RestBundle\Controller\FOSRestController;
16
use FOS\RestBundle\Routing\ClassResourceInterface;
17
use Sulu\Bundle\ActivityLogBundle\Compatibility\FieldDescriptor;
18
use Sulu\Component\ActivityLog\ActivityLoggerInterface;
19
use Sulu\Component\Rest\ListBuilder\ListRepresentation;
20
use Sulu\Component\Rest\ListBuilder\ListRestHelper;
21
use Symfony\Component\HttpFoundation\Request;
22
23
class ActivityLogController extends FOSRestController implements ClassResourceInterface
24
{
25
26
    /**
27
     * Returns all fields that can be used by list.
28
     *
29
     * @Get("activity-log/fields")
30
     *
31
     * @param Request $request
32
     *
33
     * @return mixed
34
     */
35
    public function getFieldsAction(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
    {
37
        // default contacts list
38
        return $this->handleView(
39
            $this->view(
0 ignored issues
show
Documentation introduced by
$this->view(array_values...eldDescriptors()), 200) is of type this<Sulu\Bundle\Activit...\ActivityLogController>, but the function expects a object<FOS\RestBundle\View\View>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
40
                array_values(
41
                    $this->getFieldDescriptors()
42
                ),
43
                200
44
            )
45
        );
46
    }
47
48
    /**
49
     * Create field-descriptor array.
50
     *
51
     * @return FieldDescriptor[]
52
     */
53
    private function getFieldDescriptors()
54
    {
55
        return [
56
            'uuid' => new FieldDescriptor('id', 'public.id', true, false),
57
            'source' => new FieldDescriptor('source', 'public.source', false, true),
58
            'action' => new FieldDescriptor('action', 'public.action', false, true),
59
            'value' => new FieldDescriptor('value', 'public.value', false, true),
60
            'timestamp' => new FieldDescriptor('timestamp', 'public.timestamp', false, true),
61
            'userId' => new FieldDescriptor('userId', 'public.userId', false, true),
62
            'userIP' => new FieldDescriptor('userIP', 'public.userIP', false, true),
63
        ];
64
    }
65
66
    /**
67
     * Shows all activity-log-items
68
     *
69
     * @param Request $request
70
     *
71
     * @Get("activity-log")
72
     *
73
     * @return \Symfony\Component\HttpFoundation\Response
74
     */
75
    public function cgetAction(Request $request)
76
    {
77
        $restHelper = new ListRestHelper($request);
0 ignored issues
show
Documentation introduced by
$request is of type object<Symfony\Component\HttpFoundation\Request>, but the function expects a object<Symfony\Component...oundation\RequestStack>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
78
79
        /** @var ActivityLoggerInterface $activityLogger */
80
        $activityLogger = $this->get('sulu_activity_log.activity_logger');
81
82
        $page = (int)$restHelper->getPage();
83
        $limit = (int)$restHelper->getLimit();
84
85
        $results = $activityLogger->findAll($page, $limit);
86
87
        $list = [];
88
        foreach ($results as $result) {
89
            $list[] = [
90
                'id' => $result['uuid'],
91
                'source' => $result['src'],
92
                'action' => $result['action'],
93
                'value' => $result['value'],
94
                'timestamp' => $result['ts'],
95
                'userId' => $result['uid'],
96
                'userIP' => $result['uip']
97
            ];
98
        }
99
        $list = array_values($list);
100
101
        $list = new ListRepresentation(
102
            $list,
103
            'activity-log-items',
104
            'get_activity_logs',
105
            $request->query->all(),
106
            $page,
107
            $limit,
108
            count($list)
109
        );
110
111
        $view = $this->view($list, 200);
112
113
        return $this->handleView($view);
0 ignored issues
show
Documentation introduced by
$view is of type this<Sulu\Bundle\Activit...\ActivityLogController>, but the function expects a object<FOS\RestBundle\View\View>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
114
    }
115
116
}
117