Passed
Branch ops-updates (277b44)
by Björn
05:09
created

Isallowed   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 55
ccs 0
cts 14
cp 0
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAuthService() 0 3 1
A setAuthService() 0 4 1
A __invoke() 0 20 4
1
<?php
2
/**
3
 * BB's Zend Framework 2 Components
4
 * 
5
 * AdminModule
6
 *
7
 * @package   [MyApplication]
8
 * @package   BB's Zend Framework 2 Components
9
 * @package   AdminModule
10
 * @author    Björn Bartels <[email protected]>
11
 * @link      https://gitlab.bjoernbartels.earth/groups/zf2
12
 * @license   http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
13
 * @copyright copyright (c) 2016 Björn Bartels <[email protected]>
14
 */
15
16
namespace Admin\View\Helper;
17
18
use Zend\View\Helper\AbstractHelper;
19
20
class Isallowed extends AbstractHelper
21
{
22
    /**
23
     * @var AuthenticationService
0 ignored issues
show
Bug introduced by
The type Admin\View\Helper\AuthenticationService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
     */
25
    protected $authService;
26
    
27
    /**
28
     * __invoke
29
     *
30
     * @access public
31
     * @return \ZfcUser\Entity\UserInterface
32
     */
33
    public function __invoke( $resource )
34
    {
35
        /**
36
 * @var Zend\Permissions\Acl\Acl $acl 
37
**/
38
        $acl = $this->view->navigation()->getAcl();
0 ignored issues
show
Bug introduced by
The method navigation() does not exist on Zend\View\Renderer\RendererInterface. It seems like you code against a sub-type of Zend\View\Renderer\RendererInterface such as Zend\View\Renderer\PhpRenderer. ( Ignorable by Annotation )

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

38
        $acl = $this->view->/** @scrutinizer ignore-call */ navigation()->getAcl();
Loading history...
39
        if (empty($resource) || !$acl->hasResource($resource) ) {
40
            return true;
0 ignored issues
show
Bug Best Practice introduced by
The expression return true returns the type true which is incompatible with the documented return type ZfcUser\Entity\UserInterface.
Loading history...
41
        }    
42
        /**
43
 * @var \Admin\Entity\User $user 
44
**/
45
        $user = $this->view->zfcUserIdentity(); // ->getIdentity();
0 ignored issues
show
Bug introduced by
The method zfcUserIdentity() does not exist on Zend\View\Renderer\RendererInterface. It seems like you code against a sub-type of Zend\View\Renderer\RendererInterface such as Zend\View\Renderer\PhpRenderer. ( Ignorable by Annotation )

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

45
        /** @scrutinizer ignore-call */ 
46
        $user = $this->view->zfcUserIdentity(); // ->getIdentity();
Loading history...
46
        if ($user) { // ($this->getAuthService()->hasIdentity()) {
0 ignored issues
show
introduced by
$user is of type Admin\Entity\User, thus it always evaluated to true.
Loading history...
47
            //$user = $this->getAuthService()->getIdentity();
48
            $role = $user->getAclrole();
49
        } else {
50
            $role = 'public';
51
        }
52
        return ( $acl->isAllowed($role, $resource) );
53
    }
54
    
55
    /**
56
     * Get authService.
57
     *
58
     * @return AuthenticationService
59
     */
60
    public function getAuthService()
61
    {
62
        return $this->authService;
63
    }
64
    
65
    /**
66
     * Set authService.
67
     *
68
     * @param  AuthenticationService $authService
69
     * @return \ZfcUser\View\Helper\ZfcUserIdentity
70
     */
71
    public function setAuthService(AuthenticationService $authService)
72
    {
73
        $this->authService = $authService;
74
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Admin\View\Helper\Isallowed which is incompatible with the documented return type ZfcUser\View\Helper\ZfcUserIdentity.
Loading history...
75
    }
76
    
77
}