Passed
Push — master ( 270305...ffbaef )
by Vítězslav
02:03
created

getPropertiesInfo()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 2
nop 2
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 5 and the first side effect is on line 8.

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
define('EASE_APPNAME', 'FlexiPeehUP');
6
define('EASE_LOGGER', 'console|syslog');
7
8
require_once '../testing/bootstrap.php';
9
10
$outFile = 'Properties.php';
11
$ok      = 0;
12
13
/**
14
 * Obtain structure for given evidence
15
 *
16
 * @param string     $evidence
17
 * @param FlexiBeeRO $syncer Class to read from FlexiBee
18
 * @return array     Evidence structure
19
 */
20
function getPropertiesInfo($evidence, FlexiBeeRO $syncer)
21
{
22
    $properties = [];
23
    $flexinfo   = $syncer->performRequest($evidence.'/properties.json');
24
    if (count($flexinfo) && array_key_exists('properties', $flexinfo)) {
25
        foreach ($flexinfo['properties']['property'] as $evidenceProperty) {
26
            $key                      = $evidenceProperty['propertyName'];
27
            $properties[$key]         = $evidenceProperty;
28
            $properties[$key]['name'] = $evidenceProperty['name'];
29
            $properties[$key]['type'] = $evidenceProperty['type'];
30
            if(array_key_exists('url', $evidenceProperty)){
31
               $properties[$key]['url'] = str_replace('?limit=0', '', $evidenceProperty['url']);
32
            }
33
        }
34
    }
35
    return $properties;
36
}
37
$evidenceProps = '<?php
38
/**
39
 * FlexiPeeHP - Evidence Properties.
40
 *
41
 * @author     Vítězslav Dvořák <[email protected]>
42
 * @copyright  (C) 2015-2017 Spoje.Net
43
 */
44
45
namespace FlexiPeeHP;
46
47
/**
48
 * Evidence Properties
49
 *
50
 * @link https://demo.flexibee.eu/c/demo/evidence-list.json vlastnosti evidence
51
 */
52
53
class Properties
54
{
55
';
56
57
$statuser = new Status();
58
59
60
$syncer = new FlexiBeeRO();
61
$syncer->setObjectName('FlexiBee Evidence Properties');
62
$syncer->addStatusMessage('Updating Evidences Properties');
63
64
$pos = 0;
65
foreach (EvidenceList::$name as $evidencePath => $evidenceName) {
66
    $pos++;
67
    if ($evidencePath == 'nastaveni') {
68
        $info      = json_decode(file_get_contents('nastaveni-properties.json'),
69
            true);
70
        $structure = $info['properties']['property'];
71
    } else {
72
        $structure = getPropertiesInfo($evidencePath, $syncer);
73
    }
74
75
    if (count($structure)) {
76
        $syncer->addStatusMessage($pos.' of '.count(EvidenceList::$name).' '.$evidencePath.': structure obtained',
77
            'success');
78
        $ok++;
79
    } else {
80
        $syncer->addStatusMessage($pos.' of '.count(EvidenceList::$name).' '.$evidencePath.': structure problem',
81
            'error');
82
    }
83
    file_put_contents('Properties.'.$evidencePath.'.json',
84
        json_encode($structure));
85
}
86
87
$syncer->addStatusMessage('Updating of '.$ok.' Evidences Properties done',
88
    'success');
89