timw4mail /
HummingBirdAnimeClient
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 | $animeclient_file_patterns = [ |
||
| 4 | 'app/config/*.php', |
||
| 5 | 'app/booststrap.php', |
||
| 6 | 'src/functions.php', |
||
| 7 | 'src/Aviat/AnimeClient/*.php' |
||
| 8 | ]; |
||
| 9 | |||
| 10 | $ion_file_patterns = [ |
||
| 11 | 'src/Aviat/Ion/*.php' |
||
| 12 | ]; |
||
| 13 | |||
| 14 | if ( ! function_exists('glob_recursive')) |
||
| 15 | { |
||
| 16 | // Does not support flag GLOB_BRACE |
||
| 17 | |||
| 18 | function glob_recursive($pattern, $flags = 0) |
||
| 19 | { |
||
| 20 | $files = glob($pattern, $flags); |
||
| 21 | |||
| 22 | foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) |
||
| 23 | { |
||
| 24 | $files = array_merge($files, glob_recursive($dir . '/' . basename($pattern), $flags)); |
||
| 25 | } |
||
| 26 | |||
| 27 | return $files; |
||
| 28 | } |
||
| 29 | } |
||
| 30 | |||
| 31 | function get_text_to_replace($tokens) |
||
| 32 | { |
||
| 33 | if ($tokens[0][0] !== T_OPEN_TAG) |
||
| 34 | { |
||
| 35 | return NULL; |
||
| 36 | } |
||
| 37 | |||
| 38 | // If there is already a docblock, as the second token after the |
||
| 39 | // open tag, get the contents of that token to replace |
||
| 40 | if ($tokens[1][0] === T_DOC_COMMENT) |
||
| 41 | { |
||
| 42 | return "<?php\n" . $tokens[1][1]; |
||
| 43 | } |
||
| 44 | else if ($tokens[1][0] !== T_DOC_COMMENT) |
||
| 45 | { |
||
| 46 | return "<?php"; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | function get_tokens($source) |
||
| 51 | { |
||
| 52 | return token_get_all($source); |
||
| 53 | } |
||
| 54 | |||
| 55 | function replace_files(array $files, $template) |
||
| 56 | { |
||
| 57 | foreach ($files as $file) |
||
| 58 | { |
||
| 59 | $source = file_get_contents($file); |
||
| 60 | $tokens = get_tokens($source); |
||
| 61 | $text_to_replace = get_text_to_replace($tokens); |
||
| 62 | |||
| 63 | $header = file_get_contents(__DIR__ . $template); |
||
| 64 | $new_text = "<?php\n{$header}"; |
||
| 65 | |||
| 66 | $new_source = str_replace($text_to_replace, $new_text, $source); |
||
| 67 | file_put_contents($file, $new_source); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | foreach ($animeclient_file_patterns as $glob) |
||
| 72 | { |
||
| 73 | $files = glob_recursive($glob); |
||
| 74 | replace_files($files, '/animeclient_header_comment.txt'); |
||
| 75 | } |
||
| 76 | $loose_files = [ |
||
| 77 | __DIR__ . '/../index.php', |
||
| 78 | __DIR__ . '/../public/css.php', |
||
| 79 | __DIR__ . '/../public/js.php' |
||
| 80 | ]; |
||
| 81 | replace_files($loose_files, '/animeclient_header_comment.txt'); |
||
| 82 | |||
| 83 | foreach ($ion_file_patterns as $glob) |
||
| 84 | { |
||
| 85 | $files = glob_recursive($glob); |
||
| 86 | replace_files($files, '/ion_header_comment.txt'); |
||
| 87 | } |
||
| 88 | |||
| 89 | echo "Successfully updated headers \n"; |
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.