ATask::getParams()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace kalanis\kw_clipr\Tasks;
4
5
6
use kalanis\kw_clipr\Interfaces;
7
use kalanis\kw_clipr\Output;
8
use kalanis\kw_input\Interfaces\IFiltered;
9
10
11
/**
12
 * Class ATask
13
 * @package kalanis\kw_clipr\Tasks
14
 * @property bool $verbose
15
 * @property bool $noHeaders
16
 * @property bool $noColor
17
 * @property string $outputFile
18
 * @property bool $webOutput
19
 * @property bool $noAppend
20
 * @property bool $quiet
21
 * @property bool $help
22
 */
23
abstract class ATask implements Interfaces\IStatuses
24
{
25
    use Output\TWrite;
26
27
    protected ?Interfaces\ILoader $loader = null;
28
    protected Output\AOutput $translator;
29
    protected Params $params;
30
    protected IFiltered $inputs;
31
32
    /**
33
     * @param Output\AOutput $translator
34
     * @param IFiltered $inputs
35
     * @param Interfaces\ILoader|null $loader
36
     */
37 19
    public final function initTask(Output\AOutput $translator, IFiltered $inputs, ?Interfaces\ILoader $loader): void
38
    {
39 19
        $this->loader = $loader;
40 19
        $this->translator = $translator;
41 19
        $inputArray = $inputs->getInArray();
42 19
        $this->params = new Params($inputArray);
43 19
        $this->inputs = $inputs;
44 19
        $this->startup();
45 18
    }
46
47 19
    protected function startup(): void
48
    {
49
        // you can set your variables here
50 19
        $this->params->addParam('verbose', 'verbose', null, false, 'v', 'Verbose output');
51 19
        $this->params->addParam('noHeaders', 'no-headers', null, true, null, 'No headers from core');
52 19
        $this->params->addParam('noColor', 'no-color', null, false, 'c', 'Use no colors in output');
53 19
        $this->params->addParam('outputFile', 'output-file', null, Interfaces\ISources::OUTPUT_STD, null, 'Output into...');
54 19
        $this->params->addParam('webOutput', 'web-output', null, false, 'w', 'Output is into web');
55 19
        $this->params->addParam('noAppend', 'no-append', null, false, null, 'Overwrite whole output');
56 19
        $this->params->addParam('quiet', 'quiet', null, false, 'q', 'Silence output');
57 19
        $this->params->addParam('help', 'help', null, false, 'h', 'Help with task');
58 19
    }
59
60
    /**
61
     * @param string $name
62
     * @return mixed|null
63
     */
64 19
    public function __get($name)
65
    {
66 19
        return $this->params->__get($name);
67
    }
68
69
    /**
70
     * @param string $name
71
     * @return bool
72
     */
73 14
    public function __isset($name): bool
74
    {
75 14
        return $this->params->__isset($name);
76
    }
77
78 14
    protected function getTranslator(): Output\AOutput
79
    {
80 14
        return $this->translator;
81
    }
82
83 2
    protected function getParams(): Params
84
    {
85 2
        return $this->params;
86
    }
87
88
    /**
89
     * Description of script
90
     * @return string
91
     */
92
    abstract public function desc(): string;
93
94
    /**
95
     * Process script itself
96
     * @return int status of process
97
     * @see Interfaces\IStatuses
98
     */
99
    abstract public function process(): int;
100
}
101