MethodPolicy::check()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jitamin\Policy;
13
14
use Jitamin\Foundation\Base;
15
use JsonRPC\Exception\AccessDeniedException;
16
17
/**
18
 * Class MethodPolicy.
19
 */
20
class MethodPolicy extends Base
21
{
22
    private $userSpecificMethods = [
23
        'getMe',
24
        'getMyDashboard',
25
        'getMyActivity',
26
        'createMyPrivateProject',
27
        'getMyProjectsList',
28
        'getMyProjects',
29
        'getMyOverdueTasks',
30
    ];
31
32
    /**
33
     * Determine if the current user has permissions.
34
     *
35
     * @param string $method
36
     *
37
     * @throws \JsonRPC\Exception\AccessDeniedException
38
     */
39
    public function check($method)
40
    {
41
        if (!$this->userSession->isLogged() && in_array($method, $this->userSpecificMethods)) {
0 ignored issues
show
Documentation introduced by
The property userSession does not exist on object<Jitamin\Policy\MethodPolicy>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
42
            throw new AccessDeniedException('This method is not available with the API credentials');
43
        }
44
    }
45
}
46