Passed
Pull Request — master (#13)
by Kris
19:43
created

Program::inArguments()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 2
nc 2
nop 3
1
<?php
2
3
/* 
4
 *   __  __  _       _            _  _
5
 *  |  \/  |(_) ___ | |__    ___ | || |
6
 *  | |\/| || |/ __|| '_ \  / _ \| || |
7
 *  | |  | || |\__ \| | | ||  __/| || |
8
 *  |_|  |_||_||___/|_| |_| \___||_||_|
9
 *
10
 * This file is part of Kristuff\Mishell.
11
 * (c) Kristuff <[email protected]>
12
 *
13
 * For the full copyright and license information, please view the LICENSE
14
 * file that was distributed with this source code.
15
 *
16
 * @version    1.2.0 
17
 * @copyright  2017-2020 Kristuff
18
 */
19
20
namespace Kristuff\Mishell;
21
 
22
class Program 
23
{
24
    /**
25
     * Exit with given exit code 
26
     *
27
     * @access public
28
     * @static 
29
     * @param bool   $code      The exit code. Default is 0. 1 is generaly set for error.  
30
     *
31
     * @return void         
32
     */
33
    public static function exit(int $code = 0) {
34
        exit($code);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
35
    }
36
37
    /**
38
     * helper function to check if a argument is given
39
     * 
40
     * @access protected
41
     * @static
42
     * @param array     $arguments      The list of arguments     
43
     * @param string    $shortArg       The short argument to check
44
     * @param string    $longArg        The long argument to check
45
     * 
46
     * @return bool     True if the short or long argument exist in the arguments array, otherwise false
47
     */
48
    protected static function inArguments(array $arguments, string $shortArg, string $longArg)
49
    {
50
          return array_key_exists($shortArg, $arguments) || array_key_exists($longArg, $arguments);
51
    }
52
53
    /**
54
     * helper function to get the value of an argument
55
     * 
56
     *  
57
     * @access protected
58
     * @static
59
     * @param array         $arguments      The list of arguments     
60
     * @param string        $shortArg       The short argument name to check
61
     * @param string        $longArg        The long argument name to check
62
     * 
63
     * @return string|null   
64
     * 
65
     */
66
    protected static function getArgumentValue(array $arguments, string $shortArg, string $longArg)
67
    {
68
          $val = array_key_exists($shortArg, $arguments) ? $arguments[$shortArg] : 
69
                 (array_key_exists($longArg, $arguments) ? $arguments[$longArg]  : null);
70
          
71
          
72
          return $val;
73
74
    }
75
76
}