Issues (152)

tools/find_undocumented_columns.php (1 issue)

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 structure for given evidence
9
 *
10
 * @param string     $evidence
11
 * @param FlexiBeeRO $syncer Class to read from FlexiBee
12
 * @return array     Evidence structure
13
 */
14
function getColumnsInfo($evidence, FlexiBeeRO $syncer)
15
{
16
    $useKeywords = [];
17
    $flexinfo    = $syncer->performRequest($evidence.'/properties.json');
18
    if (count($flexinfo) && array_key_exists('properties', $flexinfo)) {
19
        foreach ($flexinfo['properties']['property'] as $evidenceProperty) {
20
            $key                       = $evidenceProperty['propertyName'];
21
            $useKeywords[$key]         = $evidenceProperty;
22
            $useKeywords[$key]['name'] = $evidenceProperty['name'];
23
            $useKeywords[$key]['type'] = $evidenceProperty['type'];
24
        }
25
    }
26
    return $useKeywords;
27
}
28
29
function controlData($data, $fbColumns, $fbRelations)
30
{
31
    $controlResult = [];
32
    if (count($fbColumns)) {
33
        foreach ($data as $key => $value) {
34
            if ($key == 'external-ids') {
35
                continue;
36
            }
37
38
            if (strstr($key, '@')) {
39
                $baseKey = substr($key, 0, strrpos($key, '@'));
40
                if (!array_key_exists($baseKey, $fbColumns)) {
41
                    $controlResult[$key][] = sprintf('unknown column property %s',
42
                        $key);
43
                }
44
                continue;
45
            }
46
47
            if (!array_key_exists($key, $fbColumns)) {
48
                if (is_array($fbRelations) && !array_key_exists($key,
49
                        $fbRelations)) {
50
                    $controlResult[$key][] = sprintf('unknown column %s', $key);
51
                }
52
            }
53
        }
54
    }
55
    return $controlResult;
56
}
57
$syncer = new EvidenceList();
58
59
$evidencies = $syncer->getColumnsFromFlexibee(['evidencePath', 'evidenceName']);
60
61
62
$controlResult = [];
63
foreach ($evidencies['evidences']['evidence'] as $evidenceID => $evidence) {
64
    $evlist[$evidence['evidencePath']] = $evidence['evidenceName'];
65
66
    $syncer->setEvidence($evidence['evidencePath']);
67
    $firstRecord = $syncer->getFlexiData(null, ['limit' => 1]);
68
    if (count($firstRecord) && isset($firstRecord[0]) && count($firstRecord[0])) {
69
        $controlled = controlData($firstRecord[0], $syncer->getColumnsInfo(),
70
            $syncer->getRelationsInfo());
71
        if (count($controlled)) {
72
            $controlResult[$evidence['evidencePath']] = $controlled;
73
        }
74
    }
75
}
76
77
echo json_encode($controlResult, JSON_PRETTY_PRINT);
78
79
80