Completed
Push — api/develop ( bb7641...13f8b0 )
by Bertrand
21:48 queued 18:59
created

JobTitleRequest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 86.67%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 50
ccs 13
cts 15
cp 0.8667
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 8 2
B authorize() 0 24 5
1
<?php
2
3
/**
4
 * This file is part of the HRis Software package.
5
 *
6
 * HRis - Human Resource and Payroll System
7
 *
8
 * @link    http://github.com/HB-Co/HRis
9
 */
10
namespace HRis\Api\Requests\Admin\Job;
11
12
use HRis\Http\Requests\Request;
13
14
class JobTitleRequest extends Request
15
{
16
    /**
17
     * Get the validation rules that apply to the request.
18
     *
19
     * @return array
20
     *
21
     * @author Bertrand Kintanar <[email protected]>
22
     */
23 12
    public function rules()
24
    {
25 12
        if ($this->isMethod('post')) {
26 8
            return ['name' => 'required|unique:job_titles'];
27
        }
28
29 8
        return [];
30
    }
31
32
    /**
33
     * Determine if the user is authorized to make this request.
34
     *
35
     * @return bool
36
     *
37
     * @author Bertrand Kintanar <[email protected]>
38
     */
39 12
    public function authorize()
40
    {
41 12
        $permission = 'admin.job.titles';
42
43
        // Create
44 12
        if ($this->isMethod('post')) {
45 8
            return $this->logged_user->hasAccess($permission.'.create');
0 ignored issues
show
Documentation introduced by
The property logged_user does not exist on object<HRis\Api\Requests...in\Job\JobTitleRequest>. 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...
46
        } // Delete
47
        else {
48 8
            if ($this->isMethod('delete')) {
49 4
                return $this->logged_user->hasAccess($permission.'.delete');
0 ignored issues
show
Documentation introduced by
The property logged_user does not exist on object<HRis\Api\Requests...in\Job\JobTitleRequest>. 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...
50
            } // View
51
            else {
52 4
                if ($this->isMethod('get')) {
53
                    return $this->logged_user->hasAccess($permission.'.view');
0 ignored issues
show
Documentation introduced by
The property logged_user does not exist on object<HRis\Api\Requests...in\Job\JobTitleRequest>. 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...
54
                } // Update
55
                else {
56 4
                    if ($this->isMethod('patch')) {
57 4
                        return $this->logged_user->hasAccess($permission.'.update');
0 ignored issues
show
Documentation introduced by
The property logged_user does not exist on object<HRis\Api\Requests...in\Job\JobTitleRequest>. 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...
58
                    }
59
                }
60
            }
61
        }
62
    }
63
}
64