Global variable or function should never be used 6

  • Major
  • Architecture

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

  1. define('LINE_WIDTH', 75);
  2. define('LINE', str_repeat('-', LINE_WIDTH)."\n");
  3. function bailout($message)

    bailout() 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 Bernhard Schussek
  4. {
  5. echo wordwrap($message, LINE_WIDTH)." Aborting.\n";
  6. exit(1);
  7. }
  • fabpot

    Ignored on Tue, 02 Feb 2016 14:02:08 GMT
  1. echo wordwrap($message, LINE_WIDTH)." Aborting.\n";
  2. exit(1);
  3. }
  4. function strip_minor_versions($version)

    strip_minor_versions() 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 Bernhard Schussek
  5. {
  6. preg_match('/^(?P<version>[0-9]\.[0-9]|[0-9]{2,})/', $version, $matches);
  7. return $matches['version'];
  8. }
  • fabpot

    Ignored on Tue, 02 Feb 2016 14:02:24 GMT
  1. preg_match('/^(?P<version>[0-9]\.[0-9]|[0-9]{2,})/', $version, $matches);
  2. return $matches['version'];
  3. }
  4. function centered($text)

    centered() 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 Bernhard Schussek
  5. {
  6. $padding = (int) ((LINE_WIDTH - strlen($text)) / 2);
  7. return str_repeat(' ', $padding).$text;
  8. }
  • fabpot

    Ignored on Tue, 02 Feb 2016 14:02:28 GMT
  1. $padding = (int) ((LINE_WIDTH - strlen($text)) / 2);
  2. return str_repeat(' ', $padding).$text;
  3. }
  4. function cd($dir)

    cd() 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 Bernhard Schussek
  5. {
  6. if (false === chdir($dir)) {
  7. bailout("Could not switch to directory $dir.");
  8. }
  9. }
  • fabpot

    Ignored on Tue, 02 Feb 2016 14:02:31 GMT
  1. if (false === chdir($dir)) {
  2. bailout("Could not switch to directory $dir.");
  3. }
  4. }
  5. function run($command)

    run() 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 Bernhard Schussek
  6. {
  7. exec($command, $output, $status);
  8. if (0 !== $status) {
  9. $output = implode("\n", $output);
  • fabpot

    Ignored on Tue, 02 Feb 2016 14:02:36 GMT
  1. bailout("\"$command\" failed.");
  2. }
  3. }
  4. function get_icu_version_from_genrb($genrb)

    get_icu_version_from_genrb() 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 Bernhard Schussek
  5. {
  6. exec($genrb.' --version 2>&1', $output, $status);
  7. if (0 !== $status) {
  8. bailout($genrb.' failed.');
  • fabpot

    Ignored on Tue, 02 Feb 2016 14:02:41 GMT

sleep() should not be used

  • Major
  • Performance

More information: https://insight.sensiolabs.com/what-we-analyse/php.use_php_sleep_function

  1. }
  2. public static function sleep($s)
  3. {
  4. if (null === self::$now) {
  5. return \sleep($s);

    sleep() may create timeouts without even protecting your application.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Nicolas Grekas
  6. }
  7. self::$now += (int) $s;
  8. return 0;
  • fabpot

    mock

Interfaces names should end with "Interface"

  • Info
  • Codestyle

More information: https://insight.sensiolabs.com/what-we-analyse/php.interface_has_no_interface_suffix

  1. * Contains resolved option values.
  2. *
  3. * @author Bernhard Schussek <bschussek@gmail.com>
  4. * @author Tobias Schultze <http://tobion.de>
  5. */
  6. interface Options extends \ArrayAccess, \Countable

    Interface Options should be named OptionsInterface for better clarity.

    Time to fix: about 1 hour
    Open Issue Permalink
    Last edited by Bernhard Schussek
  7. {
  8. }
  • fabpot

    Ignored on Sun, 27 Sep 2015 14:52:50 GMT

PHP code should follow PSR-1 basic coding standard

  • Info
  • Codestyle

More information: https://insight.sensiolabs.com/what-we-analyse/php.psr1

  1. }
  2. return $ips;
  3. }
  4. public static function dns_get_record($hostname, $type = DNS_ANY, &$authns = null, &$addtl = null, $raw = false)

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Nicolas Grekas
  5. {
  6. if (!self::$hosts) {
  7. return \dns_get_record($hostname, $type, $authns, $addtl, $raw);
  8. }
  • fabpot

    That's a mock