Skip to content

Commit

Permalink
PHP 8.4 Support (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jubeki authored Nov 7, 2024
1 parent 5c89067 commit a136842
Show file tree
Hide file tree
Showing 26 changed files with 45 additions and 41 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
- "8.4"

runs-on: "ubuntu-latest"

Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
'no_whitespace_in_blank_line' => true,
'non_printable_character' => true,
'normalize_index_brace' => true,
'nullable_type_declaration_for_default_null_value' => true,
'operator_linebreak' => [
'only_booleans' => true,
'position' => 'beginning',
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased](https://github.com/FakerPHP/Faker/compare/v1.23.1...1.23)

- Added support for PHP 8.4 (#904)

## [2023-09-29, v1.23.1](https://github.com/FakerPHP/Faker/compare/v1.23.0..v1.23.1)

- Fixed double `а` female lastName in `ru_RU/Person::name()` (#832)
Expand Down
2 changes: 1 addition & 1 deletion psalm.baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
<file src="src/Faker/ORM/Spot/Populator.php">
<UndefinedClass>
<code><![CDATA[$this->locator]]></code>
<code>Locator</code>
<code>?Locator</code>
</UndefinedClass>
<UndefinedDocblockClass>
<code>Locator</code>
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Core/Barcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class Barcode implements Extension\BarcodeExtension
{
private Extension\NumberExtension $numberExtension;

public function __construct(Extension\NumberExtension $numberExtension = null)
public function __construct(?Extension\NumberExtension $numberExtension = null)
{
$this->numberExtension = $numberExtension ?: new Number();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Core/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final class Color implements Extension\ColorExtension
'Turquoise', 'Violet', 'Wheat', 'White', 'WhiteSmoke', 'Yellow', 'YellowGreen',
];

public function __construct(Extension\NumberExtension $numberExtension = null)
public function __construct(?Extension\NumberExtension $numberExtension = null)
{
$this->numberExtension = $numberExtension ?: new Number();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Core/Coordinates.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class Coordinates implements Extension\Extension
{
private Extension\NumberExtension $numberExtension;

public function __construct(Extension\NumberExtension $numberExtension = null)
public function __construct(?Extension\NumberExtension $numberExtension = null)
{
$this->numberExtension = $numberExtension ?: new Number();
}
Expand Down
20 changes: 10 additions & 10 deletions src/Faker/Core/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ private function setTimezone(\DateTime $dateTime, ?string $timezone): \DateTime
return $dateTime->setTimezone(new \DateTimeZone($timezone));
}

public function dateTime($until = 'now', string $timezone = null): \DateTime
public function dateTime($until = 'now', ?string $timezone = null): \DateTime
{
return $this->setTimezone(
$this->getTimestampDateTime($this->unixTime($until)),
$timezone,
);
}

public function dateTimeAD($until = 'now', string $timezone = null): \DateTime
public function dateTimeAD($until = 'now', ?string $timezone = null): \DateTime
{
$min = (PHP_INT_SIZE > 4) ? -62135597361 : -PHP_INT_MAX;

Expand All @@ -90,7 +90,7 @@ public function dateTimeAD($until = 'now', string $timezone = null): \DateTime
);
}

public function dateTimeBetween($from = '-30 years', $until = 'now', string $timezone = null): \DateTime
public function dateTimeBetween($from = '-30 years', $until = 'now', ?string $timezone = null): \DateTime
{
$start = $this->getTimestamp($from);
$end = $this->getTimestamp($until);
Expand All @@ -107,7 +107,7 @@ public function dateTimeBetween($from = '-30 years', $until = 'now', string $tim
);
}

public function dateTimeInInterval($from = '-30 years', string $interval = '+5 days', string $timezone = null): \DateTime
public function dateTimeInInterval($from = '-30 years', string $interval = '+5 days', ?string $timezone = null): \DateTime
{
$intervalObject = \DateInterval::createFromDateString($interval);
$datetime = $from instanceof \DateTime ? $from : new \DateTime($from);
Expand All @@ -120,29 +120,29 @@ public function dateTimeInInterval($from = '-30 years', string $interval = '+5 d
return $this->dateTimeBetween($begin, $end, $timezone);
}

public function dateTimeThisWeek($until = 'sunday this week', string $timezone = null): \DateTime
public function dateTimeThisWeek($until = 'sunday this week', ?string $timezone = null): \DateTime
{
return $this->dateTimeBetween('monday this week', $until, $timezone);
}

public function dateTimeThisMonth($until = 'last day of this month', string $timezone = null): \DateTime
public function dateTimeThisMonth($until = 'last day of this month', ?string $timezone = null): \DateTime
{
return $this->dateTimeBetween('first day of this month', $until, $timezone);
}

public function dateTimeThisYear($until = 'last day of december', string $timezone = null): \DateTime
public function dateTimeThisYear($until = 'last day of december', ?string $timezone = null): \DateTime
{
return $this->dateTimeBetween('first day of january', $until, $timezone);
}

public function dateTimeThisDecade($until = 'now', string $timezone = null): \DateTime
public function dateTimeThisDecade($until = 'now', ?string $timezone = null): \DateTime
{
$year = floor(date('Y') / 10) * 10;

return $this->dateTimeBetween("first day of january $year", $until, $timezone);
}

public function dateTimeThisCentury($until = 'now', string $timezone = null): \DateTime
public function dateTimeThisCentury($until = 'now', ?string $timezone = null): \DateTime
{
$year = floor(date('Y') / 100) * 100;

Expand Down Expand Up @@ -204,7 +204,7 @@ public function century(): string
return Helper::randomElement($this->centuries);
}

public function timezone(string $countryCode = null): string
public function timezone(?string $countryCode = null): string
{
if ($countryCode) {
$timezones = \DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, $countryCode);
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Core/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function randomFloat(?int $nbMaxDecimals = null, float $min = 0, ?float $
return round($min + $this->numberBetween() / mt_getrandmax() * ($max - $min), $nbMaxDecimals);
}

public function randomNumber(int $nbDigits = null, bool $strict = false): int
public function randomNumber(?int $nbDigits = null, bool $strict = false): int
{
if (null === $nbDigits) {
$nbDigits = $this->randomDigitNotZero();
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Core/Uuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class Uuid implements Extension\UuidExtension
{
private Extension\NumberExtension $numberExtension;

public function __construct(Extension\NumberExtension $numberExtension = null)
public function __construct(?Extension\NumberExtension $numberExtension = null)
{

$this->numberExtension = $numberExtension ?: new Number();
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Core/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class Version implements Extension\VersionExtension
*/
private array $semverCommonPreReleaseIdentifiers = ['alpha', 'beta', 'rc'];

public function __construct(Extension\NumberExtension $numberExtension = null)
public function __construct(?Extension\NumberExtension $numberExtension = null)
{

$this->numberExtension = $numberExtension ?: new Number();
Expand Down
20 changes: 10 additions & 10 deletions src/Faker/Extension/DateTimeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface DateTimeExtension
*
* @example DateTime('2005-08-16 20:39:21')
*/
public function dateTime($until = 'now', string $timezone = null): \DateTime;
public function dateTime($until = 'now', ?string $timezone = null): \DateTime;

/**
* Get a DateTime object for a date between January 1, 0001, and now.
Expand All @@ -38,7 +38,7 @@ public function dateTime($until = 'now', string $timezone = null): \DateTime;
* @see http://php.net/manual/en/timezones.php
* @see http://php.net/manual/en/function.date-default-timezone-get.php
*/
public function dateTimeAD($until = 'now', string $timezone = null): \DateTime;
public function dateTimeAD($until = 'now', ?string $timezone = null): \DateTime;

/**
* Get a DateTime object a random date between `$from` and `$until`.
Expand All @@ -52,7 +52,7 @@ public function dateTimeAD($until = 'now', string $timezone = null): \DateTime;
* @see http://php.net/manual/en/timezones.php
* @see http://php.net/manual/en/function.date-default-timezone-get.php
*/
public function dateTimeBetween($from = '-30 years', $until = 'now', string $timezone = null): \DateTime;
public function dateTimeBetween($from = '-30 years', $until = 'now', ?string $timezone = null): \DateTime;

/**
* Get a DateTime object based on a random date between `$from` and an interval.
Expand All @@ -66,7 +66,7 @@ public function dateTimeBetween($from = '-30 years', $until = 'now', string $tim
* @see http://php.net/manual/en/timezones.php
* @see http://php.net/manual/en/function.date-default-timezone-get.php
*/
public function dateTimeInInterval($from = '-30 years', string $interval = '+5 days', string $timezone = null): \DateTime;
public function dateTimeInInterval($from = '-30 years', string $interval = '+5 days', ?string $timezone = null): \DateTime;

/**
* Get a date time object somewhere inside the current week.
Expand All @@ -78,7 +78,7 @@ public function dateTimeInInterval($from = '-30 years', string $interval = '+5 d
* @see http://php.net/manual/en/timezones.php
* @see http://php.net/manual/en/function.date-default-timezone-get.php
*/
public function dateTimeThisWeek($until = 'now', string $timezone = null): \DateTime;
public function dateTimeThisWeek($until = 'now', ?string $timezone = null): \DateTime;

/**
* Get a date time object somewhere inside the current month.
Expand All @@ -90,7 +90,7 @@ public function dateTimeThisWeek($until = 'now', string $timezone = null): \Date
* @see http://php.net/manual/en/timezones.php
* @see http://php.net/manual/en/function.date-default-timezone-get.php
*/
public function dateTimeThisMonth($until = 'now', string $timezone = null): \DateTime;
public function dateTimeThisMonth($until = 'now', ?string $timezone = null): \DateTime;

/**
* Get a date time object somewhere inside the current year.
Expand All @@ -102,7 +102,7 @@ public function dateTimeThisMonth($until = 'now', string $timezone = null): \Dat
* @see http://php.net/manual/en/timezones.php
* @see http://php.net/manual/en/function.date-default-timezone-get.php
*/
public function dateTimeThisYear($until = 'now', string $timezone = null): \DateTime;
public function dateTimeThisYear($until = 'now', ?string $timezone = null): \DateTime;

/**
* Get a date time object somewhere inside the current decade.
Expand All @@ -114,7 +114,7 @@ public function dateTimeThisYear($until = 'now', string $timezone = null): \Date
* @see http://php.net/manual/en/timezones.php
* @see http://php.net/manual/en/function.date-default-timezone-get.php
*/
public function dateTimeThisDecade($until = 'now', string $timezone = null): \DateTime;
public function dateTimeThisDecade($until = 'now', ?string $timezone = null): \DateTime;

/**
* Get a date time object somewhere inside the current century.
Expand All @@ -126,7 +126,7 @@ public function dateTimeThisDecade($until = 'now', string $timezone = null): \Da
* @see http://php.net/manual/en/timezones.php
* @see http://php.net/manual/en/function.date-default-timezone-get.php
*/
public function dateTimeThisCentury($until = 'now', string $timezone = null): \DateTime;
public function dateTimeThisCentury($until = 'now', ?string $timezone = null): \DateTime;

/**
* Get a date string between January 1, 1970, and `$until`.
Expand Down Expand Up @@ -238,5 +238,5 @@ public function century(): string;
*
* @example 'Europe/Rome'
*/
public function timezone(string $countryCode = null): string;
public function timezone(?string $countryCode = null): string;
}
2 changes: 1 addition & 1 deletion src/Faker/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ class Generator
*/
private $uniqueGenerator;

public function __construct(ContainerInterface $container = null)
public function __construct(?ContainerInterface $container = null)
{
$this->container = $container ?: Container\ContainerBuilder::withDefaultExtensions()->build();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/ORM/Doctrine/Populator.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Populator
*
* @param int $batchSize
*/
public function __construct(Generator $generator, ObjectManager $manager = null, $batchSize = 1000)
public function __construct(Generator $generator, ?ObjectManager $manager = null, $batchSize = 1000)
{
$this->generator = $generator;
$this->manager = $manager;
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/ORM/Spot/Populator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Populator
/**
* Populator constructor.
*/
public function __construct(\Faker\Generator $generator, Locator $locator = null)
public function __construct(\Faker\Generator $generator, ?Locator $locator = null)
{
$this->generator = $generator;
$this->locator = $locator;
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Provider/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public static function century()
*
* @example 'Europe/Paris'
*/
public static function timezone(string $countryCode = null)
public static function timezone(?string $countryCode = null)
{
if ($countryCode) {
$timezones = \DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, $countryCode);
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Provider/de_AT/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static function suffix()
*
* @return string
*/
public static function ssn(\DateTime $birthdate = null)
public static function ssn(?\DateTime $birthdate = null)
{
$birthdate = $birthdate ?? DateTime::dateTimeThisCentury();

Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Provider/en_GB/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Company extends \Faker\Provider\Company
*
* @see https://en.wikipedia.org/wiki/VAT_identification_number#VAT_numbers_by_country
*/
public static function vat(string $type = null): string
public static function vat(?string $type = null): string
{
switch ($type) {
case static::VAT_TYPE_BRANCH:
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Provider/en_ZA/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class Person extends \Faker\Provider\Person
*
* @return string
*/
public function idNumber(\DateTime $birthdate = null, $citizen = true, $gender = null)
public function idNumber(?\DateTime $birthdate = null, $citizen = true, $gender = null)
{
if (!$birthdate) {
$birthdate = $this->generator->dateTimeThisCentury();
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Provider/fi_FI/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Person extends \Faker\Provider\Person
*
* @return string on format DDMMYYCZZZQ, where DDMMYY is the date of birth, C the century sign, ZZZ the individual number and Q the control character (checksum)
*/
public function personalIdentityNumber(\DateTime $birthdate = null, $gender = null)
public function personalIdentityNumber(?\DateTime $birthdate = null, $gender = null)
{
$checksumCharacters = '0123456789ABCDEFHJKLMNPRSTUVWXY';

Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Provider/kk_KZ/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function companyNameSuffix()
*
* @return string 12 digits, like 150140000019
*/
public static function businessIdentificationNumber(\DateTime $registrationDate = null)
public static function businessIdentificationNumber(?\DateTime $registrationDate = null)
{
if (!$registrationDate) {
$registrationDate = \Faker\Provider\DateTime::dateTimeThisYear();
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Provider/kk_KZ/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private static function getCenturyByYear($year)
*
* @return string 12 digits, like 780322300455
*/
public static function individualIdentificationNumber(\DateTime $birthDate = null, $gender = self::GENDER_MALE)
public static function individualIdentificationNumber(?\DateTime $birthDate = null, $gender = self::GENDER_MALE)
{
if (!$birthDate) {
$birthDate = DateTime::dateTimeBetween();
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Provider/lt_LT/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public function passportNumber()
*
* @return string on format XXXXXXXXXXX
*/
public function personalIdentityNumber($gender = 'male', \DateTime $birthdate = null, $randomNumber = '')
public function personalIdentityNumber($gender = 'male', ?\DateTime $birthdate = null, $randomNumber = '')
{
if (!$birthdate) {
$birthdate = \Faker\Provider\DateTime::dateTimeThisCentury();
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Provider/lv_LV/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function passportNumber()
*
* @return string on format XXXXXX-XXXXX
*/
public function personalIdentityNumber(\DateTime $birthdate = null)
public function personalIdentityNumber(?\DateTime $birthdate = null)
{
if (!$birthdate) {
$birthdate = DateTime::dateTimeThisCentury();
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Provider/nb_NO/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class Person extends \Faker\Provider\Person
*
* @return string on format DDMMYY#####
*/
public function personalIdentityNumber(\DateTime $birthdate = null, $gender = null)
public function personalIdentityNumber(?\DateTime $birthdate = null, $gender = null)
{
if (!$birthdate) {
$birthdate = \Faker\Provider\DateTime::dateTimeThisCentury();
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Provider/sv_SE/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class Person extends \Faker\Provider\Person
*
* @return string on format XXXXXX-XXXX
*/
public function personalIdentityNumber(\DateTime $birthdate = null, $gender = null)
public function personalIdentityNumber(?\DateTime $birthdate = null, $gender = null)
{
if (!$birthdate) {
$birthdate = \Faker\Provider\DateTime::dateTimeThisCentury();
Expand Down

0 comments on commit a136842

Please sign in to comment.