getEvidenceActions()   B
last analyzed

Complexity

Conditions 8
Paths 8

Size

Total Lines 59
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 59
c 0
b 0
f 0
rs 7.9119
cc 8
nc 8
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 6 and the first side effect is on line 12.

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