Passed
Pull Request — master (#528)
by Stefano
03:43
created

CategoriesController::beforeRender()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 14
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * BEdita, API-first content management framework
4
 * Copyright 2021 ChannelWeb Srl, Chialab Srl
5
 *
6
 * This file is part of BEdita: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
12
 */
13
namespace App\Controller\Model;
14
15
use Cake\Event\Event;
16
use Cake\Http\Response;
17
use Cake\Utility\Hash;
18
19
/**
20
 * Categories Model Controller: list, add, edit, remove categories
21
 *
22
 */
23
class CategoriesController extends ModelBaseController
24
{
25
    /**
26
     * Resource type currently used
27
     *
28
     * @var string
29
     */
30
    protected $resourceType = 'categories';
31
32
    /**
33
     * Single resource view exists
34
     *
35
     * @var bool
36
     */
37
    protected $singleView = false;
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function beforeRender(Event $event): ?Response
43
    {
44
        $features = $this->Schema->objectTypesFeatures();
45
        $categorized = (array)Hash::get($features, 'categorized');
46
        $schema = $this->Schema->getSchema();
47
        $schema['properties']['type']['enum'] = $categorized;
48
        $filter = (array)$this->request->getQuery('filter');
49
        if (!empty($filter['type'])) {
50
            $categorized = [$filter['type']];
51
        }
52
        $categorized = array_combine($categorized, $categorized);
53
        $this->set(compact('categorized', 'schema'));
54
55
        return parent::beforeRender($event);
0 ignored issues
show
Bug introduced by
Are you sure the usage of parent::beforeRender($event) targeting App\Controller\Model\Mod...troller::beforeRender() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
56
    }
57
}
58