Passed
Push — master ( 6d8a3f...ef71b6 )
by Vítězslav
03:10
created

getEvidenceActions()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 54
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 54
c 0
b 0
f 0
rs 7.8331
cc 7
eloc 43
nc 6
nop 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 7 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace FlexiPeeHP;
4
5
require_once '../testing/bootstrap.php';
6
7
define('EASE_APPNAME', 'FlexiPeehUP');
8
define('EASE_LOGGER', 'console|syslog');
9
10
$outFile = 'Actions.php';
11
$outJson = 'Actions.json';
12
$ok      = 0;
13
14
/**
15
 * Obtain Actions for given evidence
16
 *
17
 * @param string     $evidence
18
 * @param FlexiBeeRO $syncer Class to read from FlexiBee
19
 * @return array Actions structure
20
 */
21
function getEvidenceActions($evidence, FlexiBeeRO $syncer)
22
{
23
    $columns = $syncer->getColumnsInfo($evidence);
24
    if (array_key_exists('zamekK', $columns)) {
25
        $syncer->addStatusMessage('Adding LOCK actions to evidence '.$evidence,
26
            'debug');
27
        $actions = [
28
            'lock' => [
29
                'actionId' => 'lock',
30
                'actionName' => 'Zamknout',
31
                'needInstance' => 'true',
32
                'actionMakesSense' => 'ONLY_WITH_INSTANCE_AND_NOT_IN_CREATE',
33
                'isRealAction' => 'true',
34
                'isService' => 'YES',
35
            ],
36
            'lock-for-ucetni' => [
37
                'actionId' => 'lock-for-ucetni',
38
                'actionName' => 'Zamknout pro učetní',
39
                'needInstance' => 'true',
40
                'actionMakesSense' => 'ONLY_WITH_INSTANCE_AND_NOT_IN_CREATE',
41
                'isRealAction' => 'true',
42
                'isService' => 'YES',
43
            ],
44
            'unlock' => [
45
                'actionId' => 'unlock',
46
                'actionName' => 'Odemknout',
47
                'needInstance' => 'true',
48
                'actionMakesSense' => 'ONLY_WITH_INSTANCE_AND_NOT_IN_CREATE',
49
                'isRealAction' => 'true',
50
                'isService' => 'YES',
51
            ]
52
        ];
53
    } else {
54
        $actions = [];
55
    }
56
    $flexinfo = $syncer->performRequest($evidence.'/actions.json');
57
    if (count($flexinfo) && array_key_exists('actions', $flexinfo)) {
58
        if (isset($flexinfo['actions']['action'])) {
59
            foreach ($flexinfo['actions']['action'] as $evidenceActions) {
60
                if (array_key_exists('actionId', $evidenceActions)) {
61
                    $key           = $evidenceActions['actionId'];
62
                    $actions[$key] = $evidenceActions;
63
                } else {
64
                    $syncer->addStatusMessage(sprintf('actionId not set for %s',
65
                            $evidence.' / '.$evidenceActions['actionName']),
66
                        'warning');
67
                }
68
            }
69
        } else {
70
            $syncer->addStatusMessage(sprintf('Missing actions for %s',
71
                    $evidence), 'warning');
72
        }
73
    }
74
    return $actions;
75
}
76
$evidenceActions = '<?php
77
/**
78
 * FlexiPeeHP - Evidence Actions.
79
 *
80
 * @author     Vítězslav Dvořák <[email protected]>
81
 * @copyright  (C) 2015-2017 Spoje.Net
82
 */
83
84
namespace FlexiPeeHP;
85
86
/**
87
 * EvidenceActions
88
 *
89
 * @link https://demo.flexibee.eu/devdoc/actions Provádění akcí
90
 */
91
92
class Actions
93
{
94
';
95
96
$statuser        = new Status();
97
$evidenceActions .= '    /**
98
     * Source FlexiBee server version.
99
     *
100
     * @var string
101
     */
102
';
103
$evidenceActions .= ' static public $version = \''.$statuser->getDataValue('version').'\';
104
105
';
106
107
$syncer = new FlexiBeeRO();
108
$syncer->setObjectName('FlexiBee Evidence Actions');
109
$syncer->addStatusMessage('Updating Evidences Actions');
110
111
$structures = [];
112
113
$pos = 0;
114
foreach (EvidenceList::$name as $evidencePath => $evidenceName) {
115
    $pos++;
116
    $structure                 = getEvidenceActions($evidencePath, $syncer);
117
    $structures[$evidencePath] = $structure;
118
    if (count($structure)) {
119
        $evidenceActions .= '    /**
120
     * Evidence '.$evidencePath.' ('.$evidenceName.') Actions.
121
     *
122
     * @var array
123
     */
124
';
125
        $evidenceActions .= ' static public $'.lcfirst(FlexiBeeRO::evidenceToClassName($evidencePath)).' = '.var_export($structure,
126
                true).';
127
';
128
129
        $syncer->addStatusMessage($pos.' of '.count(EvidenceList::$name).' '.$evidencePath.': actions obtained',
130
            'success');
131
        $ok++;
132
    } else {
133
        $syncer->addStatusMessage($pos.' of '.count(EvidenceList::$name).' '.$evidencePath.': obtaining actions problem',
134
            'error');
135
    }
136
}
137
138
$evidenceActions .= '}
139
';
140
141
$syncer->addStatusMessage('Updating of '.$ok.' Evidences Actions done',
142
    'success');
143
file_put_contents($outFile, $evidenceActions);
144
145
file_put_contents($outJson, json_encode($structures));
146