Passed
Push — master ( 19f06a...8d1e35 )
by Ralf
24:17
created

IsElementAllowedViewHelper::renderStatic()   A

Complexity

Conditions 6
Paths 9

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 22
rs 9.2222
c 2
b 0
f 0
cc 6
nc 9
nop 3
1
<?php
2
namespace EWW\Dpf\ViewHelpers;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use \TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
18
use \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
19
use TYPO3\CMS\Core\Utility\GeneralUtility;
20
use TYPO3\CMS\Extbase\Object\ObjectManager;
21
use \EWW\Dpf\Security\Security;
22
23
class IsElementAllowedViewHelper extends AbstractViewHelper
24
{
25
    /**
26
     * @param array $arguments
27
     * @param \Closure $renderChildrenClosure
28
     * @param RenderingContextInterface $renderingContext
29
     * @return boolean
30
     */
31
    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
32
    {
33
        $roles = array();
34
        if (key_exists('condition', $arguments)) {
35
            $roles = $arguments['condition'];
36
            if (!is_array($roles)) return FALSE;
0 ignored issues
show
Bug Best Practice introduced by
The expression return FALSE returns the type false which is incompatible with the return type mandated by TYPO3Fluid\Fluid\Core\Vi...terface::renderStatic() of string.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
37
        }
38
39
        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
40
        /** @var Security $security */
41
        $security = $objectManager->get(Security::class);
42
        $clientUserRole = $security->getUserRole();
43
44
        if (empty($roles)) {
45
            return TRUE;
0 ignored issues
show
Bug Best Practice introduced by
The expression return TRUE returns the type true which is incompatible with the return type mandated by TYPO3Fluid\Fluid\Core\Vi...terface::renderStatic() of string.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
46
        } else {
47
            foreach ($roles as $role) {
48
                if ($role === $clientUserRole) return TRUE;
0 ignored issues
show
Bug Best Practice introduced by
The expression return TRUE returns the type true which is incompatible with the return type mandated by TYPO3Fluid\Fluid\Core\Vi...terface::renderStatic() of string.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
49
            }
50
        }
51
52
        return FALSE;
0 ignored issues
show
Bug Best Practice introduced by
The expression return FALSE returns the type false which is incompatible with the return type mandated by TYPO3Fluid\Fluid\Core\Vi...terface::renderStatic() of string.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
53
    }
54
55
    public function initializeArguments()
56
    {
57
        parent::initializeArguments();
58
59
        $this->registerArgument('condition', 'array', 'The controller to be active.', true);
60
    }
61
62
    /**
63
     * @return bool
64
     */
65
    public function render()
66
    {
67
        $condition = $this->arguments['condition'];
68
69
        return self::renderStatic(
70
            array('condition' => $condition),
71
            $this->buildRenderChildrenClosure(),
72
            $this->renderingContext
73
        );
74
    }
75
76
}
77