PrefixAwareTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setPathPrefix() 0 5 1
A matchPathPrefix() 0 10 4
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Route
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Route\Traits;
16
17
use Phossa2\Route\Interfaces\PrefixAwareInterface;
18
19
/**
20
 * PrefixAwareTrait
21
 *
22
 * Implementation of PrefixAwareInterface
23
 *
24
 * @package Phossa2\Route
25
 * @author  Hong Zhang <[email protected]>
26
 * @see     PrefixAwareInterface
27
 * @version 2.0.1
28
 * @since   2.0.1 added
29
 */
30
trait PrefixAwareTrait
31
{
32
    /**
33
     * prefix to match
34
     *
35
     * @var    string
36
     * @access protected
37
     */
38
    protected $path_prefix;
39
40
    /**
41
     * {@inheritDoc}
42
     */
43
    public function setPathPrefix(/*# string */ $pathPrefix = null)
44
    {
45
        $this->path_prefix = $pathPrefix;
46
        return $this;
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52
    public function matchPathPrefix(/*# string */ $uriPath)/*# : bool */
53
    {
54
        if (!is_string($this->path_prefix) ||
55
            empty($this->path_prefix) ||
56
            0 === strpos($uriPath, $this->path_prefix)
57
        ) {
58
            return true;
59
        }
60
        return false;
61
    }
62
}
63