Passed
Push — master ( 5e712b...61b36a )
by Tom
02:52
created

FileOptions::shower()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Utility;
6
7
use Ktomk\Pipelines\Cli\Args;
8
use Ktomk\Pipelines\Cli\Streams;
9
use Ktomk\Pipelines\File;
10
11
class FileOptions
12
{
13
    /**
14
     * @var Args
15
     */
16
    private $args;
17
18
    /**
19
     * @var callable
20
     */
21
    private $output;
22
23
    /**
24
     * @var File
25
     */
26
    private $file;
27
28
    /**
29
     * bind options
30
     *
31
     * @param Args $args
32
     * @param Streams $streams
33
     * @param File $file
34
     * @return FileOptions
35
     */
36 1
    public static function bind(Args $args, Streams $streams, File $file)
37
    {
38 1
        return new self($args, $streams, $file);
39
    }
40
41
    /**
42
     * FileOptions constructor.
43
     * @param Args $args
44
     * @param callable $output
45
     * @param File $file
46
     */
47 7
    public function __construct(Args $args, $output, File $file)
48
    {
49 7
        $this->args = $args;
50 7
        $this->output = $output;
51 7
        $this->file = $file;
52 7
    }
53
54
    /**
55
     * run options
56
     *
57
     * @return int|null exit status or null if run was not applicable
58
     */
59 4
    public function run()
60
    {
61 4
        $args = $this->args;
62
63 4
        $images = $args->hasOption('images');
64 4
        $show = $args->hasOption('show');
65 4
        $list = $args->hasOption('list');
66
67 4
        if ($images) {
68 1
            return $this->shower()->showImages();
69
        }
70
71 3
        if ($show) {
72 1
            return $this->shower()->showPipelines();
73
        }
74
75 2
        if ($list) {
76 1
            return $this->shower()->showPipelineIds();
77
        }
78
79 1
        return null;
80
    }
81
82
    /**
83
     * @param $pipelines
84
     * @return int
85
     */
86 1
    public function showPipelines(File $pipelines)
87
    {
88 1
        return $this->shower($pipelines)->showPipelines();
89
    }
90
91
    /**
92
     * @param File|null $file [optional]
93
     * @return FileShower
94
     */
95 4
    private function shower(File $file = null)
96
    {
97 4
        if (null === $file) {
98 3
            $file = $this->file;
99
        }
100
101 4
        return new FileShower($this->output, $file);
102
    }
103
}
104