RouteResourceTrait::privilege()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Cheka - Authorization
4
 *
5
 * PHP version 5
6
 *
7
 * Copyright (C) 2016 Jake Johns
8
 *
9
 * This software may be modified and distributed under the terms
10
 * of the MIT license.  See the LICENSE file for details.
11
 *
12
 * @category  Router
13
 * @package   Jnjxp\Cheka
14
 * @author    Jake Johns <[email protected]>
15
 * @copyright 2016 Jake Johns
16
 * @license   http://jnj.mit-license.org/2016 MIT License
17
 * @link      https://github.com/jnjxp/jnjxp.cheka
18
 */
19
20
namespace Jnjxp\Cheka\Route;
21
22
use Jnjxp\Cheka\ResourceRouteAwareTrait;
23
24
/**
25
 * Route resource trait
26
 *
27
 * @category Route
28
 * @package  Jnjxp\Cheka
29
 * @author   Jake Johns <[email protected]>
30
 * @license  http://jnj.mit-license.org/ MIT License
31
 * @link     https://github.com/jnjxp/jnjxp.cheka
32
 */
33
trait RouteResourceTrait
34
{
35
    use ResourceRouteAwareTrait;
36
37
    /**
38
     * Get resourceId
39
     *
40
     * @return string|null
41
     *
42
     * @access public
43
     */
44 1
    public function getResourceId()
45
    {
46 1
        return $this->getResourceIdFromRoute($this);
47
    }
48
49
    /**
50
     * Set resourceId extra key
51
     *
52
     * @param string $resource resourceId
53
     *
54
     * @return $this
55
     *
56
     * @access public
57
     */
58 2
    public function resource($resource)
59
    {
60 2
        return $this->extras([$this->resourceIdKey => $resource]);
61
    }
62
63
    /**
64
     * Set privilege string
65
     *
66
     * @param string $privilege privilege to require
67
     *
68
     * @return $this
69
     *
70
     * @access public
71
     */
72 2
    public function privilege($privilege)
73
    {
74 2
        return $this->extras([$this->privilegeKey => $privilege]);
75
    }
76
77
    /**
78
     * Provided by BaseRoute classes
79
     *
80
     * @param array $extras array of extras
81
     *
82
     * @return $this
83
     *
84
     * @access public
85
     */
86
    abstract public function extras(array $extras);
87
}
88