-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Kz faker random wrong output from getCenturyByYear #2026
base: master
Are you sure you want to change the base?
Conversation
Use current year to search for century instead of random year.
Codecov Report
@@ Coverage Diff @@
## master #2026 +/- ##
============================================
- Coverage 56.56% 55.86% -0.71%
Complexity 2068 2068
============================================
Files 306 306
Lines 4849 4849
============================================
- Hits 2743 2709 -34
- Misses 2106 2140 +34
Continue to review full report at Codecov.
|
@@ -183,7 +183,7 @@ class Person extends \Faker\Provider\Person | |||
*/ | |||
private static function getCenturyByYear($year) | |||
{ | |||
if ($year >= 2000 && $year <= DateTime::year()) { | |||
if ($year >= 2000 && $year <= date('Y')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why dont delete && $year <= date('Y')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To not run into a future I believe. We don't know why this statement exists, but I believe author know what is it for.
The only thing @maris-liepins-ermac did is switching from "Faker" DateTime with random year output to real DateTime year output
If $year is set to 2001, there is a chance that DateTime::year() will return value less than 2000, which will cause a bug and instead of 21st century will return 20th century. DateTime::year() returns random value.
#2025