Completed
Push — master ( 77c4c6...fbe049 )
by Ori
04:20
created

update-schema.php ➔ update()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 17
nc 4
nop 0
dl 0
loc 21
rs 9.3142
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 3 and the first side effect is on line 25.

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
function update()
4
{
5
    $schemaUrl = 'http://specs.frictionlessdata.io/schemas/table-schema.json';
6
    $base_filename = realpath(dirname(__FILE__))
7
        .DIRECTORY_SEPARATOR.'src'
8
        .DIRECTORY_SEPARATOR.'schemas'
9
        .DIRECTORY_SEPARATOR;
10
    $filename = $base_filename.'table-schema.json';
11
    $old_schema = file_exists($filename) ? file_get_contents($filename) : 'FORCE UPDATE';
12
    echo "downloading schema from {$schemaUrl}\n";
13
    $new_schema = file_get_contents($schemaUrl);
14
    if ($old_schema == $new_schema) {
15
        echo "no update needed\n";
16
    } else {
17
        echo "schema changed - updating local file\n";
18
        file_put_contents($filename, $new_schema);
19
        file_put_contents($base_filename.'LAST_UPDATE', date('c'));
20
    }
21
22
    return 0;
23
}
24
25
exit(update());
26