Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPMD complains about itself #77

Closed
morganestes opened this issue Mar 26, 2013 · 8 comments
Closed

PHPMD complains about itself #77

morganestes opened this issue Mar 26, 2013 · 8 comments

Comments

@morganestes
Copy link

I just installed PHPMD in PhpStorm 6.0 and ran it for the first time in my project. The very first warning was about itself and not my code; I can't figure out how to to keep it from checking its own files and checking mine instead.

phpmd: PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CDT/-5.0/DST' instead in /usr/lib/share/pear/PHP/PMD/Renderer/XMLRenderer.php on line 97

@ooxi
Copy link

ooxi commented Apr 4, 2013

Take a look at PHP_PMD::$ignorePatterns

@morganestes
Copy link
Author

@ooxi I'm looking at it, but don't see how it fits here. The error I'm getting is from PHPMD checking itself and reporting errors. Shouldn't it only be checking my project for errors?

@GodsBoss
Copy link

PHPMD does not check itself, this message appears if PHP's date/time functions, but not default timezone is set. You can configure it, the setting is date.timezone.

@michaelhogg
Copy link
Contributor

The problem is that XMLRenderer::renderReport() is calling date() without a default timezone being set. So date_default_timezone_set() needs to be called first.

@jazbek
Copy link

jazbek commented Jun 16, 2014

I'm having this issue as well. Any chance for a fix?

@hbandura
Copy link

hbandura commented Nov 1, 2014

I have the same issue with version 2.1.3, which has the fix made by @manuelpichler . the call to date_default_timezone_get() still triggers the php warning, but returns UTC by default by PHP, so it never enters the if clause, and then the date() call also prints a warning due to date_default_timezone_set never being called.

date_default_timezone_set(@date_default_timezone_get()) would fix the issue (though it's not exactly beautiful, but well).

@bgaillard
Copy link

Hi, we also have this issue using PHP 5.6.

PHP Warning:  date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/ec2-user/.jenkins/jobs/fatcap-php-services-testing/workspace/vendor/phpmd/phpmd/src/bin/phpmd on line 24
PHP Stack trace:
PHP   1. {main}() /home/ec2-user/.jenkins/jobs/fatcap-php-services-testing/workspace/vendor/phpmd/phpmd/src/bin/phpmd:0
PHP   2. date_default_timezone_get() /home/ec2-user/.jenkins/jobs/fatcap-php-services-testing/workspace/vendor/phpmd/phpmd/src/bin/phpmd:24

The fix applied is not valid for PHP 5.6, the warning is explicit, even if the system timezone is set we should set a timezone explicitly in the source code.

So (at least for PHP 5.6) we should replace ...

if (!ini_get('date.timezone') && !date_default_timezone_get()) {
    date_default_timezone_set('UTC');
}

by ...

if (version_compare(phpversion(), '5.6.0', '>=') ||  (!ini_get('date.timezone') && !date_default_timezone_get())) {
    date_default_timezone_set('UTC');
}

michaelhogg added a commit to michaelhogg/phpmd that referenced this issue Jul 30, 2015
@michaelhogg
Copy link
Contributor

@hbandura: Yes, even after @manuelpichler's fix, a timezone warning is still raised.

I've just created PR #297 which completely fixes the issue (@bgaillard: even on PHP 5.6).

ravage84 added a commit that referenced this issue Sep 9, 2015
@ravage84 ravage84 added this to the 2.x (unspecific) milestone May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

8 participants