BaseClass::getVariables()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Sunnysideup\UpgradeToSilverstripe4\UpgradeRecipes;
4
5
abstract class BaseClass
6
{
7
    protected $varsToProvide = [
8
        'nameOfUpgradeStarterBranch',
9
        'nameOfTempBranch',
10
        'defaultNamespaceForTasks',
11
        'taskSteps',
12
        'listOfTasks',
13
        'frameworkComposerRestraint',
14
    ];
15
16
    /**
17
     * A list of task groups
18
     *
19
     * @var array
20
     */
21
    protected $taskSteps = [
22
        's00' => 'Generic',
23
        's10' => 'Prepare Codebase',
24
        's20' => 'Upgrade Structure',
25
        's30' => 'Prepare Code',
26
        's40' => 'Upgrade Code',
27
        's50' => 'Upgrade Fixes',
28
        's60' => 'Check',
29
        's70' => 'Finalise',
30
        's99' => 'ERROR!',
31
    ];
32
33
    public function getVariables(): array
34
    {
35
        $returnArray = [];
36
        foreach ($this->varsToProvide as $var) {
37
            $returnArray[$var] = $this->returnValidValue($var);
38
        }
39
40
        return $returnArray;
41
    }
42
43
    protected function returnValidValue($nameOfVar)
44
    {
45
        if (empty($this->{$nameOfVar}) === true) {
46
            return user_error('You have not defined a variable "' . $nameOfVar . '" in your recipe: ' . self::class);
47
        }
48
        return $this->{$nameOfVar};
49
    }
50
}
51