Completed
Pull Request — master (#2)
by
unknown
13:54
created

ActivityLogController::getActivityLogs()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 39
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 39
rs 8.8571
cc 1
eloc 27
nc 1
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\Component\ActivityLog\ActivityLogger;
18
use Sulu\Component\Rest\Exception\EntityNotFoundException;
19
use Sulu\Component\Rest\ListBuilder\FieldDescriptor;
20
use Sulu\Component\Rest\ListBuilder\ListRepresentation;
21
use Symfony\Component\HttpFoundation\Request;
22
23
class ActivityLogController extends FOSRestController implements ClassResourceInterface
24
{
25
    const EXPORT_COLUMN_DELIMITER = ';';
26
    const EXPORT_FILENAME = 'activity-log-export';
27
28
    /**
29
     * Returns all fields that can be used by list.
30
     *
31
     * @Get("activity-log/fields")
32
     *
33
     * @param Request $request
34
     *
35
     * @return mixed
36
     */
37
    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...
38
    {
39
        // default contacts list
40
        return $this->handleView(
41
            $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...
42
                array_values(
43
                    $this->getFieldDescriptors()
44
                ),
45
                200
46
            )
47
        );
48
    }
49
50
    /**
51
     * Shows all activity-log-items.
52
     *
53
     * @param Request $request
54
     *
55
     * @Get("activity-log")
56
     *
57
     * @return \Symfony\Component\HttpFoundation\Response
58
     */
59
    public function cgetAction(Request $request)
60
    {
61
        $list = $this->getActivityLogs($request);
62
63
        $view = $this->view($list, 200);
64
65
        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...
66
    }
67
68
    /**
69
     * Create field-descriptor array.
70
     *
71
     * @return FieldDescriptor[]
72
     */
73
    protected function getFieldDescriptors()
74
    {
75
        return [
76
            'uuid' => new FieldDescriptor('id', 'public.id', true, false),
77
            'data' => new FieldDescriptor('data', 'public.data', false, true),
78
        ];
79
    }
80
81
    /**
82
     * returns view of files.
83
     *
84
     * @param Request $request
85
     *
86
     * @throws EntityNotFoundException
87
     *
88
     * @return ListRepresentation
89
     */
90
    protected function getActivityLogs(Request $request)
91
    {
92
        $restHelper = $this->get('sulu_core.list_rest_helper');
93
94
        /** @var ActivityLogger $activityLogger */
95
        $activityLogger = $this->get('sulu_activity_log.activity_logger');
96
97
        $page = (int) $restHelper->getPage();
98
        $limit = (int) $restHelper->getLimit();
99
        $sortColumn = $restHelper->getSortColumn();
100
        $sortOrder = $restHelper->getSortOrder();
101
        $searchPattern = $restHelper->getSearchPattern();
102
        $searchFields = $restHelper->getSearchFields();
103
104
        $list = $activityLogger->findAllWithSearch(
0 ignored issues
show
Bug introduced by
The method findAllWithSearch() does not exist on Sulu\Component\ActivityLog\ActivityLogger. Did you maybe mean findAll()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
105
            $searchPattern,
106
            $searchFields,
107
            $page,
108
            $limit,
109
            $sortColumn,
110
            $sortOrder
111
        );
112
113
        $total = $activityLogger->getCountForAllWithSearch($searchPattern, $searchFields);
0 ignored issues
show
Bug introduced by
The method getCountForAllWithSearch() does not seem to exist on object<Sulu\Component\ActivityLog\ActivityLogger>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
114
115
        $list = array_values($list);
116
117
        $list = new ListRepresentation(
118
            $list,
119
            'activity-log-items',
120
            'get_activity_logs',
121
            $request->query->all(),
122
            $page,
123
            $limit,
124
            $total
125
        );
126
127
        return $list;
128
    }
129
}
130