These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | require 'vendor/autoload.php'; |
||
4 | |||
5 | use frictionlessdata\datapackage\Registry; |
||
6 | |||
7 | function update() |
||
8 | { |
||
9 | $base_filename = realpath(dirname(__FILE__)) |
||
10 | .DIRECTORY_SEPARATOR.'src' |
||
11 | .DIRECTORY_SEPARATOR.'Validators' |
||
12 | .DIRECTORY_SEPARATOR.'schemas' |
||
13 | .DIRECTORY_SEPARATOR; |
||
14 | $numUpdated = 0; |
||
15 | foreach (Registry::getAllSchemas() as $schema) { |
||
16 | $filename = $base_filename.$schema->schema_path; |
||
17 | $old_schema = file_exists($filename) ? file_get_contents($filename) : 'FORCE UPDATE'; |
||
18 | echo "downloading schema from {$schema->schema}\n"; |
||
19 | $new_schema = file_get_contents($schema->schema); |
||
20 | if ($old_schema == $new_schema) { |
||
21 | echo "no update needed\n"; |
||
22 | } else { |
||
23 | echo "schema changed - updating local file\n"; |
||
24 | file_put_contents($filename, $new_schema); |
||
25 | file_put_contents($base_filename.'CHANGELOG', "\n\nChanges to {$schema->id} schema\n".date('c')."\n* check the git diff and summarize the spec changes here\n* \n\n", FILE_APPEND); |
||
26 | if ($schema->id == 'registry') { |
||
27 | echo "registry was updated, re-running update to fetch latest files from registry\n\n"; |
||
28 | |||
29 | return update(); |
||
30 | } |
||
31 | ++$numUpdated; |
||
32 | } |
||
33 | } |
||
34 | echo "\n{$numUpdated} schemas updated\n"; |
||
35 | |||
36 | return 0; |
||
37 | } |
||
38 | |||
39 | exit(update()); |
||
40 |
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.