GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 0c3dc8...b46d2a )
by Hong
03:03
created

NameGlobbingTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 60
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A globEventNames() 0 12 3
A matchEventName() 0 13 4
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Event
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\Event\Traits;
16
17
/**
18
 * Matching event name
19
 *
20
 * Returns matched names with $eventName. e.g.
21
 *
22
 * ```php
23
 * $names = ['*', 'u*.*', 'user.*', 'blog.*'];
24
 *
25
 * // returns ['*', 'u*.*', 'user.*']
26
 * $matched = $this->globEventNames('user.login', $names);
27
 * ```
28
 *
29
 * @package Phossa2\Event
30
 * @author  Hong Zhang <[email protected]>
31
 * @version 2.0.0
32
 * @since   2.0.0 added
33
 */
34
trait NameGlobbingTrait
35
{
36
    /**
37
     * Returns all names matches with $eventName
38
     *
39
     * e.g.
40
     * 'user.login' matches '*', 'u*.*', 'user.*', 'user.l*', 'user.login' etc.
41
     *
42
     * @param  string $eventName
43
     * @param  array $names
44
     * @return array
45
     * @access protected
46
     */
47
    protected function globEventNames(
48
        /*# string */ $eventName,
49
        array $names
50
    )/*# : array */ {
51
        $result = [];
52
        foreach ($names as $name) {
53
            if ($this->matchEventName($name, $eventName)) {
54
                $result[] = $name;
55
            }
56
        }
57
        return $result;
58
    }
59
60
    /**
61
     * Check to see if $name matches with $eventName
62
     *
63
     *  e.g.
64
     *  ```php
65
     *  // true
66
     *  $this->matchEventName('user.*', 'user.login');
67
     *
68
     *  // true
69
     *  $this->matchEventName('*', 'user.login');
70
     *
71
     *  // false
72
     *  $this->matchEventName('blog.*', 'user.login');
73
     *  ```
74
     *
75
     * @param  string $name
76
     * @param  string $eventName
77
     * @return bool
78
     * @access protected
79
     */
80
    protected function matchEventName(
81
        /*# string */ $name,
82
        /*# string */ $eventName
83
    )/*# : bool */ {
84
        if ('*' === $name || $name === $eventName) {
85
            return true;
86
        } elseif (false !== strpos($name, '*')) {
87
            $pat = str_replace(array('.', '*'), array('[.]', '[^.]*+'), $name);
88
            return (bool) preg_match('~^' . $pat . '$~', $eventName);
89
        } else {
90
            return false;
91
        }
92
    }
93
}
94