Guided::isPHPActionOptionValid()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
 * This file is part of CaptainHook
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Runner\Config\Setup;
13
14
use CaptainHook\App\Console\IO;
15
use Exception;
16
17
/**
18
 * Class Guided
19
 *
20
 * @package CaptainHook
21
 * @author  Sebastian Feldmann <[email protected]>
22
 * @link    https://github.com/captainhook-git/captainhook
23
 * @since   Class available since Release 2.2.0
24
 */
25
abstract class Guided
26
{
27
    /**
28
     * @var \CaptainHook\App\Console\IO
29
     */
30
    protected $io;
31
32
    /**
33
     * Guided constructor
34
     *
35
     * @param \CaptainHook\App\Console\IO $io
36
     */
37 8
    public function __construct(IO $io)
38
    {
39 8
        $this->io = $io;
40
    }
41
42
    /**
43
     * PHP action option validation
44
     *
45
     * @param  string $option
46
     * @return string
47
     * @throws \Exception
48
     */
49 2
    public static function isPHPActionOptionValid(string $option): string
50
    {
51 2
        if (count(explode(':', $option)) !== 2) {
52 1
            throw new Exception('Invalid option, use "key:value"');
53
        }
54 1
        return $option;
55
    }
56
}
57