Passed
Pull Request — master (#166)
by
unknown
21:05
created

CreatorRoleViewHelper::render()   A

Complexity

Conditions 5
Paths 7

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 7
nop 1
dl 0
loc 21
rs 9.6111
c 0
b 0
f 0
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 \EWW\Dpf\Security\Security;
18
use \EWW\Dpf\Domain\Model\FrontendUser;
19
20
class CreatorRoleViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
21
{
22
    /**
23
     * frontendUserRepository
24
     *
25
     * @var \EWW\Dpf\Domain\Repository\FrontendUserRepository
26
     * @inject
27
     */
28
    protected $frontendUserRepository = null;
29
30
    /**
31
     * security
32
     *
33
     * @var \EWW\Dpf\Security\Security
34
     * @inject
35
     */
36
    protected $security = null;
37
38
    /**
39
     * Shows the frontend user name of the given frontenduser user id.
40
     *
41
     * @param int $feUserId
42
     * @return string
43
     */
44
    public function render($feUserId)
45
    {
46
        if ($this->security->getUser()->getUid() == $feUserId) {
47
            return "self";
48
        }
49
50
        $userRole = '';
51
        $feUser = $this->frontendUserRepository->findByUid($feUserId);
52
        if ($feUser instanceof FrontendUser) {
53
            $userRole = $feUserId->getUserRole();
0 ignored issues
show
Bug introduced by
The method getUserRole() does not exist on integer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
            /** @scrutinizer ignore-call */ 
54
            $userRole = $feUserId->getUserRole();

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...
54
        }
55
56
        if ($userRole === Security::ROLE_LIBRARIAN) {
57
            return "librarian";
58
        }
59
60
        if ($userRole == Security::ROLE_RESEARCHER) {
61
            return "user";
62
        }
63
64
        return null;
65
    }
66
}
67