Global variable or function should never be used 10

  • Major
  • Architecture

More information: https://insight.symfony.com/what-we-analyse/php.use_global_variable_or_function

  1. echo export_locales($availableLocales);
  2. /**
  3. * Converts the provided data into json and writes it to the disk.
  4. */
  5. function file_put_json($filename, $data)

    file_put_json() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  6. {
  7. $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
  8. // Indenting with tabs instead of 4 spaces gives us 20% smaller files.
  9. $data = str_replace(' ', "\t", $data);
  10. file_put_contents($filename, $data);
  1. }
  2. /**
  3. * Exports locales.
  4. */
  5. function export_locales($data)

    export_locales() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  6. {
  7. // Wrap the values in single quotes.
  8. $data = array_map(function ($value) {
  9. return "'" . $value . "'";
  10. }, $data);
  1. }
  2. /**
  3. * Prepares the currencies for a specific country.
  4. */
  5. function prepare_currencies($currencies)

    prepare_currencies() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  6. {
  7. if (empty($currencies)) {
  8. return [];
  9. }
  10. // Rekey the array by currency code.
  1. }
  2. /**
  3. * uasort callback for comparing arrays using their "_from" dates.
  4. */
  5. function compare_from_dates($a, $b)

    compare_from_dates() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  6. {
  7. $a = new DateTime($a['_from']);
  8. $b = new DateTime($b['_from']);
  9. // DateTime overloads the comparison providers.
  10. if ($a == $b) {
  1. echo export_locales($availableLocales);
  2. /**
  3. * Converts the provided data into json and writes it to the disk.
  4. */
  5. function file_put_json($filename, $data)

    file_put_json() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  6. {
  7. $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
  8. // Indenting with tabs instead of 4 spaces gives us 20% smaller files.
  9. $data = str_replace(' ', "\t", $data);
  10. file_put_contents($filename, $data);
  1. }
  2. /**
  3. * Exports locales.
  4. */
  5. function export_locales($data)

    export_locales() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  6. {
  7. // Wrap the values in single quotes.
  8. $data = array_map(function ($value) {
  9. return "'" . $value . "'";
  10. }, $data);
  1. echo export_locales($availableLocales);
  2. /**
  3. * Converts the provided data into json and writes it to the disk.
  4. */
  5. function file_put_json($filename, $data)

    file_put_json() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  6. {
  7. $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
  8. // Indenting with tabs instead of 4 spaces gives us 20% smaller files.
  9. $data = str_replace(' ', "\t", $data);
  10. file_put_contents($filename, $data);
  1. }
  2. /**
  3. * Exports locales.
  4. */
  5. function export_locales($data)

    export_locales() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  6. {
  7. // Wrap the values in single quotes.
  8. $data = array_map(function ($value) {
  9. return "'" . $value . "'";
  10. }, $data);
  1. echo export_locales($availableLocales);
  2. /**
  3. * Converts the provided data into json and writes it to the disk.
  4. */
  5. function file_put_json($filename, $data)

    file_put_json() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  6. {
  7. $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
  8. // Indenting with tabs instead of 4 spaces gives us 20% smaller files.
  9. $data = str_replace(' ', "\t", $data);
  10. file_put_contents($filename, $data);
  1. }
  2. /**
  3. * Exports locales.
  4. */
  5. function export_locales($data)

    export_locales() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  6. {
  7. // Wrap the values in single quotes.
  8. $data = array_map(function ($value) {
  9. return "'" . $value . "'";
  10. }, $data);

exit() and die() functions should be avoided 17

  • Major
  • Bugrisk

More information: https://insight.symfony.com/what-we-analyse/php.use_exit_function

  1. $enCountries = $localeDirectory . 'en/territories.json';
  2. // Downloaded from https://github.com/unicode-cldr/cldr-core.git
  3. $codeMappings = '../assets/cldr-core/supplemental/codeMappings.json';
  4. $currencyData = '../assets/cldr-core/supplemental/currencyData.json';
  5. if (!file_exists($enCountries)) {
  6. die("The $enCountries file was not found");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  7. }
  8. if (!file_exists($codeMappings)) {
  9. die("The $codeMappings file was not found");
  10. }
  11. if (!file_exists($currencyData)) {
  1. $currencyData = '../assets/cldr-core/supplemental/currencyData.json';
  2. if (!file_exists($enCountries)) {
  3. die("The $enCountries file was not found");
  4. }
  5. if (!file_exists($codeMappings)) {
  6. die("The $codeMappings file was not found");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  7. }
  8. if (!file_exists($currencyData)) {
  9. die("The $currencyData file was not found");
  10. }
  11. if (!function_exists('collator_create')) {
  1. }
  2. if (!file_exists($codeMappings)) {
  3. die("The $codeMappings file was not found");
  4. }
  5. if (!file_exists($currencyData)) {
  6. die("The $currencyData file was not found");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Jimmy Henderickx
  7. }
  8. if (!function_exists('collator_create')) {
  9. // Reimplementing intl's collator would be a huge undertaking, so we
  10. // use it instead to presort the generated locale specific data.
  11. die('The intl extension was not found.');
  1. die("The $currencyData file was not found");
  2. }
  3. if (!function_exists('collator_create')) {
  4. // Reimplementing intl's collator would be a huge undertaking, so we
  5. // use it instead to presort the generated locale specific data.
  6. die('The intl extension was not found.');

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  7. }
  8. if (!is_dir($localeDirectory)) {
  9. die("The $localeDirectory directory was not found");
  10. }
  1. // Reimplementing intl's collator would be a huge undertaking, so we
  2. // use it instead to presort the generated locale specific data.
  3. die('The intl extension was not found.');
  4. }
  5. if (!is_dir($localeDirectory)) {
  6. die("The $localeDirectory directory was not found");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  7. }
  8. $ignoredCountries = [
  9. 'AN', // Netherlands Antilles, no longer exists.
  10. 'BV', 'HM', 'CP', // Uninhabited islands.
  1. // Downloaded from https://github.com/unicode-cldr/cldr-core.git
  2. $currencyData = '../assets/cldr-core/supplemental/currencyData.json';
  3. // Downloaded from https://github.com/unicode-cldr/cldr-localenames-full.git
  4. $localeDirectory = '../assets/cldr-localenames-full/main/';
  5. if (!file_exists($isoCurrencies)) {
  6. die("The $isoCurrencies file was not found");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  7. }
  8. if (!file_exists($cldrCurrencies)) {
  9. die("The $cldrCurrencies file was not found");
  10. }
  11. if (!file_exists($currencyData)) {
  1. $localeDirectory = '../assets/cldr-localenames-full/main/';
  2. if (!file_exists($isoCurrencies)) {
  3. die("The $isoCurrencies file was not found");
  4. }
  5. if (!file_exists($cldrCurrencies)) {
  6. die("The $cldrCurrencies file was not found");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  7. }
  8. if (!file_exists($currencyData)) {
  9. die("The $currencyData file was not found");
  10. }
  11. if (!function_exists('collator_create')) {
  1. }
  2. if (!file_exists($cldrCurrencies)) {
  3. die("The $cldrCurrencies file was not found");
  4. }
  5. if (!file_exists($currencyData)) {
  6. die("The $currencyData file was not found");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  7. }
  8. if (!function_exists('collator_create')) {
  9. // Reimplementing intl's collator would be a huge undertaking, so we
  10. // use it instead to presort the generated locale specific data.
  11. die('The intl extension was not found.');
  1. die("The $currencyData file was not found");
  2. }
  3. if (!function_exists('collator_create')) {
  4. // Reimplementing intl's collator would be a huge undertaking, so we
  5. // use it instead to presort the generated locale specific data.
  6. die('The intl extension was not found.');

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  7. }
  8. if (!is_dir($localeDirectory)) {
  9. die("The $localeDirectory directory was not found");
  10. }
  11. if (!is_dir($numbersDirectory)) {
  1. // Reimplementing intl's collator would be a huge undertaking, so we
  2. // use it instead to presort the generated locale specific data.
  3. die('The intl extension was not found.');
  4. }
  5. if (!is_dir($localeDirectory)) {
  6. die("The $localeDirectory directory was not found");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  7. }
  8. if (!is_dir($numbersDirectory)) {
  9. die("The $numbersDirectory directory was not found");
  10. }
  1. }
  2. if (!is_dir($localeDirectory)) {
  3. die("The $localeDirectory directory was not found");
  4. }
  5. if (!is_dir($numbersDirectory)) {
  6. die("The $numbersDirectory directory was not found");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  7. }
  8. // Locales listed without a "-" match all variants.
  9. // Locales listed with a "-" match only those exact ones.
  10. $ignoredLocales = [
  1. // Downloaded from https://github.com/unicode-cldr/cldr-localenames-full.git
  2. $localeDirectory = '../assets/cldr-localenames-full/main/';
  3. $enLanguages = $localeDirectory . 'en/languages.json';
  4. if (!is_dir($localeDirectory)) {
  5. die("The $localeDirectory directory was not found");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  6. }
  7. if (!file_exists($enLanguages)) {
  8. die("The $enLanguages file was not found");
  9. }
  10. if (!function_exists('collator_create')) {
  1. if (!is_dir($localeDirectory)) {
  2. die("The $localeDirectory directory was not found");
  3. }
  4. if (!file_exists($enLanguages)) {
  5. die("The $enLanguages file was not found");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  6. }
  7. if (!function_exists('collator_create')) {
  8. // Reimplementing intl's collator would be a huge undertaking, so we
  9. // use it instead to presort the generated locale specific data.
  10. die('The intl extension was not found.');
  1. die("The $enLanguages file was not found");
  2. }
  3. if (!function_exists('collator_create')) {
  4. // Reimplementing intl's collator would be a huge undertaking, so we
  5. // use it instead to presort the generated locale specific data.
  6. die('The intl extension was not found.');

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  7. }
  8. // Locales listed without a "-" match all variants.
  9. // Locales listed with a "-" match only those exact ones.
  10. $ignoredLocales = [
  1. $enLanguages = $localeDirectory . 'en/languages.json';
  2. // Downloaded from https://github.com/unicode-cldr/cldr-numbers-full.git
  3. $numbersDirectory = '../assets/cldr-numbers-full/main/';
  4. if (!is_dir($localeDirectory)) {
  5. die("The $localeDirectory directory was not found");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Jimmy Henderickx
  6. }
  7. if (!is_dir($numbersDirectory)) {
  8. die("The $numbersDirectory directory was not found");
  9. }
  10. if (!file_exists($enLanguages)) {
  1. if (!is_dir($localeDirectory)) {
  2. die("The $localeDirectory directory was not found");
  3. }
  4. if (!is_dir($numbersDirectory)) {
  5. die("The $numbersDirectory directory was not found");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Jimmy Henderickx
  6. }
  7. if (!file_exists($enLanguages)) {
  8. die("The $enLanguages file was not found");
  9. }
  1. }
  2. if (!is_dir($numbersDirectory)) {
  3. die("The $numbersDirectory directory was not found");
  4. }
  5. if (!file_exists($enLanguages)) {
  6. die("The $enLanguages file was not found");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  7. }
  8. // Locales listed without a "-" match all variants.
  9. // Locales listed with a "-" match only those exact ones.
  10. $ignoredLocales = [

Booleans and null should be compared strictly

  • Minor
  • Bugrisk

More information: https://insight.symfony.com/what-we-analyse/php.strict_boolean_comparison_should_be_used

in src/Calculator.php, line 221
  1. *
  2. * @return string The trimmed number.
  3. */
  4. public static function trim($number)
  5. {
  6. if (strpos($number, '.') != false) {

    With booleans and null, only strict comparison (with !== operator) should be used to lower bug risks and to improve performances.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Bojan Zivanovic
  7. // The number is decimal, strip trailing zeroes.
  8. // If no digits remain after the decimal point, strip it as well.
  9. $number = rtrim($number, '0');
  10. $number = rtrim($number, '.');
  11. }