Completed
Push — master ( 7a2611...ea972e )
by Vítězslav
03:21
created

update_actions_class.php ➔ getEvidenceActions()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 3
nop 2
dl 0
loc 17
rs 8.8571
c 0
b 0
f 0
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 14 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
/**
8
 * Obtain Actions for given evidence
9
 *
10
 * @param string     $evidence
11
 * @param FlexiBeeRO $syncer Class to read from FlexiBee
12
 * @return array Actions structure
13
 */
14
function getEvidenceActions($evidence, FlexiBeeRO $syncer)
15
{
16
    $actions  = [];
17
    $flexinfo = $syncer->performRequest($evidence.'/actions.json');
18
    if (count($flexinfo) && array_key_exists('actions', $flexinfo)) {
19
        if (isset($flexinfo['actions']['action'])) {
20
            foreach ($flexinfo['actions']['action'] as $evidenceActions) {
21
                $key           = $evidenceActions['actionId'];
22
                $actions[$key] = $evidenceActions;
23
            }
24
        } else {
25
            $syncer->addStatusMessage(sprintf('Missing actions for %s',
26
                    $evidence), 'warning');
27
        }
28
    }
29
    return $actions;
30
}
31
echo '<?php
32
/**
33
 * FlexiPeeHP - Evidence Actions.
34
 *
35
 * @author     Vítězslav Dvořák <[email protected]>
36
 * @copyright  (C) 2015,2016 Spoje.Net
37
 */
38
39
namespace FlexiPeeHP;
40
41
/**
42
 * EvidenceActions
43
 *
44
 * @link https://demo.flexibee.eu/devdoc/actions Provádění akcí
45
 */
46
47
class Actions
48
{
49
';
50
51
52
$syncer = new FlexiBeeRO();
53
54
$pos = 0;
55 View Code Duplication
foreach (EvidenceList::$name as $evidencePath => $evidenceName) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    $pos++;
57
    $structure = getEvidenceActions($evidencePath, $syncer);
58
    if (count($structure)) {
59
        echo '    /**
60
     * Evidence '.$evidencePath.' ('.$evidenceName.') Actions.
61
     *
62
     * @var array
63
     */
64
';
65
        echo ' static public $'.lcfirst(FlexiBeeRO::evidenceToClassName($evidencePath)).' = '.var_export($structure,
66
            true).';
67
';
68
69
        $syncer->addStatusMessage($pos.' of '.count(EvidenceList::$name).' '.$evidencePath.': actions obtained',
70
            'success');
71
    } else {
72
        $syncer->addStatusMessage($pos.' of '.count(EvidenceList::$name).' '.$evidencePath.': obtaining actions problem',
73
            'error');
74
    }
75
}
76
77
echo '}
78
';
79