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.

Std   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 95
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A value() 0 4 1
A __destruct() 0 4 1
A read() 0 19 3
A valid() 0 4 2
A view() 0 4 1
1
<?php
2
/**
3
 * Cli
4
 *
5
 * @copyright Copyright (c)  Gjero Krsteski (http://krsteski.de)
6
 * @license   http://opensource.org/licenses/MIT MIT License
7
 */
8
9
namespace Pimf\Cli;
10
11
/**
12
 * Responsible for accessing I/O streams that allow access to PHP's own input and output streams.
13
 *
14
 * @package Cli
15
 * @author  Gjero Krsteski <[email protected]>
16
 */
17
class Std
18
{
19
    /**
20
     * @var resource
21
     */
22
    private $handle;
23
24
    /**
25
     * @param string $stream
26
     */
27
    public function __construct($stream = 'php://stdin')
28
    {
29
        $this->handle = fopen($stream, 'r');
30
    }
31
32
    /**
33
     * @return string
34
     */
35
    public function value()
36
    {
37
        return substr(fgets($this->handle, 1024), 0, -1);
38
    }
39
40
    public function __destruct()
41
    {
42
        fclose($this->handle);
43
    }
44
45
    /**
46
     * Allow direct access to the corresponding input stream of the PHP process.
47
     *
48
     * @param string $prompt
49
     * @param string $validation A regex pattern
50
     *
51
     * <code>
52
     *
53
     *  Have a look at the examples for $validation:
54
     *
55
     *  Regular Expression  | Will match...
56
     *  -------------------------------------------------------------
57
     *  .*                  | Not empty
58
     *  foo                 | The string "foo"
59
     *  ^foo                | "foo" at the start of a string
60
     *  foo$                | "foo" at the end of a string
61
     *  ^foo$               | "foo" when it is alone on a string
62
     *  [abc]               | a, b, or c
63
     *  [a-z]               | Any lowercase letter
64
     *  [^A-Z]              | Any character that is not a uppercase letter
65
     *  (gif|jpg)           | Matches either "gif" or "jpeg"
66
     *  [a-z]+              | One or more lowercase letters
67
     *  [0-9\.\-]           | Аny number, dot, or minus sign
68
     *
69
     * </code>
70
     *
71
     * @return string
72
     */
73
    public function read($prompt, $validation = "/.*/")
74
    {
75
        $value = '';
76
77
        while (true) {
78
79
            $this->view("Please enter a " . $prompt . ":");
80
81
            $value = $this->value();
82
83
            if ($this->valid($validation, $value)) {
84
                break;
85
            }
86
87
            $this->view("[ Value format for " . $prompt . " is invalid! ]");
88
        }
89
90
        return $value;
91
    }
92
93
    /**
94
     * @param string $validation A regex pattern
95
     * @param string $value
96
     *
97
     * @return bool
98
     */
99
    public function valid($validation, $value)
100
    {
101
        return strlen($value) > 0 && preg_match($validation, $value);
102
    }
103
104
    /**
105
     * @param string $prompt
106
     */
107
    public function view($prompt)
108
    {
109
        echo $prompt . "\n";
110
    }
111
}
112