Skip to content

Commit a136842

Browse files
authored
PHP 8.4 Support (#904)
1 parent 5c89067 commit a136842

26 files changed

+45
-41
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- "8.1"
2424
- "8.2"
2525
- "8.3"
26+
- "8.4"
2627

2728
runs-on: "ubuntu-latest"
2829

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
'no_whitespace_in_blank_line' => true,
127127
'non_printable_character' => true,
128128
'normalize_index_brace' => true,
129+
'nullable_type_declaration_for_default_null_value' => true,
129130
'operator_linebreak' => [
130131
'only_booleans' => true,
131132
'position' => 'beginning',

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

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

5+
- Added support for PHP 8.4 (#904)
6+
57
## [2023-09-29, v1.23.1](https://github.com/FakerPHP/Faker/compare/v1.23.0..v1.23.1)
68

79
- Fixed double `а` female lastName in `ru_RU/Person::name()` (#832)

psalm.baseline.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
<file src="src/Faker/ORM/Spot/Populator.php">
126126
<UndefinedClass>
127127
<code><![CDATA[$this->locator]]></code>
128-
<code>Locator</code>
128+
<code>?Locator</code>
129129
</UndefinedClass>
130130
<UndefinedDocblockClass>
131131
<code>Locator</code>

src/Faker/Core/Barcode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class Barcode implements Extension\BarcodeExtension
1414
{
1515
private Extension\NumberExtension $numberExtension;
1616

17-
public function __construct(Extension\NumberExtension $numberExtension = null)
17+
public function __construct(?Extension\NumberExtension $numberExtension = null)
1818
{
1919
$this->numberExtension = $numberExtension ?: new Number();
2020
}

src/Faker/Core/Color.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ final class Color implements Extension\ColorExtension
5454
'Turquoise', 'Violet', 'Wheat', 'White', 'WhiteSmoke', 'Yellow', 'YellowGreen',
5555
];
5656

57-
public function __construct(Extension\NumberExtension $numberExtension = null)
57+
public function __construct(?Extension\NumberExtension $numberExtension = null)
5858
{
5959
$this->numberExtension = $numberExtension ?: new Number();
6060
}

src/Faker/Core/Coordinates.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class Coordinates implements Extension\Extension
1313
{
1414
private Extension\NumberExtension $numberExtension;
1515

16-
public function __construct(Extension\NumberExtension $numberExtension = null)
16+
public function __construct(?Extension\NumberExtension $numberExtension = null)
1717
{
1818
$this->numberExtension = $numberExtension ?: new Number();
1919
}

src/Faker/Core/DateTime.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ private function setTimezone(\DateTime $dateTime, ?string $timezone): \DateTime
7272
return $dateTime->setTimezone(new \DateTimeZone($timezone));
7373
}
7474

75-
public function dateTime($until = 'now', string $timezone = null): \DateTime
75+
public function dateTime($until = 'now', ?string $timezone = null): \DateTime
7676
{
7777
return $this->setTimezone(
7878
$this->getTimestampDateTime($this->unixTime($until)),
7979
$timezone,
8080
);
8181
}
8282

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

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

93-
public function dateTimeBetween($from = '-30 years', $until = 'now', string $timezone = null): \DateTime
93+
public function dateTimeBetween($from = '-30 years', $until = 'now', ?string $timezone = null): \DateTime
9494
{
9595
$start = $this->getTimestamp($from);
9696
$end = $this->getTimestamp($until);
@@ -107,7 +107,7 @@ public function dateTimeBetween($from = '-30 years', $until = 'now', string $tim
107107
);
108108
}
109109

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

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

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

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

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

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

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

@@ -204,7 +204,7 @@ public function century(): string
204204
return Helper::randomElement($this->centuries);
205205
}
206206

207-
public function timezone(string $countryCode = null): string
207+
public function timezone(?string $countryCode = null): string
208208
{
209209
if ($countryCode) {
210210
$timezones = \DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, $countryCode);

src/Faker/Core/Number.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function randomFloat(?int $nbMaxDecimals = null, float $min = 0, ?float $
6363
return round($min + $this->numberBetween() / mt_getrandmax() * ($max - $min), $nbMaxDecimals);
6464
}
6565

66-
public function randomNumber(int $nbDigits = null, bool $strict = false): int
66+
public function randomNumber(?int $nbDigits = null, bool $strict = false): int
6767
{
6868
if (null === $nbDigits) {
6969
$nbDigits = $this->randomDigitNotZero();

src/Faker/Core/Uuid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ final class Uuid implements Extension\UuidExtension
1111
{
1212
private Extension\NumberExtension $numberExtension;
1313

14-
public function __construct(Extension\NumberExtension $numberExtension = null)
14+
public function __construct(?Extension\NumberExtension $numberExtension = null)
1515
{
1616

1717
$this->numberExtension = $numberExtension ?: new Number();

src/Faker/Core/Version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class Version implements Extension\VersionExtension
1818
*/
1919
private array $semverCommonPreReleaseIdentifiers = ['alpha', 'beta', 'rc'];
2020

21-
public function __construct(Extension\NumberExtension $numberExtension = null)
21+
public function __construct(?Extension\NumberExtension $numberExtension = null)
2222
{
2323

2424
$this->numberExtension = $numberExtension ?: new Number();

src/Faker/Extension/DateTimeExtension.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface DateTimeExtension
2525
*
2626
* @example DateTime('2005-08-16 20:39:21')
2727
*/
28-
public function dateTime($until = 'now', string $timezone = null): \DateTime;
28+
public function dateTime($until = 'now', ?string $timezone = null): \DateTime;
2929

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

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

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

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

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

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

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

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

131131
/**
132132
* Get a date string between January 1, 1970, and `$until`.
@@ -238,5 +238,5 @@ public function century(): string;
238238
*
239239
* @example 'Europe/Rome'
240240
*/
241-
public function timezone(string $countryCode = null): string;
241+
public function timezone(?string $countryCode = null): string;
242242
}

src/Faker/Generator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ class Generator
565565
*/
566566
private $uniqueGenerator;
567567

568-
public function __construct(ContainerInterface $container = null)
568+
public function __construct(?ContainerInterface $container = null)
569569
{
570570
$this->container = $container ?: Container\ContainerBuilder::withDefaultExtensions()->build();
571571
}

src/Faker/ORM/Doctrine/Populator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Populator
4848
*
4949
* @param int $batchSize
5050
*/
51-
public function __construct(Generator $generator, ObjectManager $manager = null, $batchSize = 1000)
51+
public function __construct(Generator $generator, ?ObjectManager $manager = null, $batchSize = 1000)
5252
{
5353
$this->generator = $generator;
5454
$this->manager = $manager;

src/Faker/ORM/Spot/Populator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Populator
1717
/**
1818
* Populator constructor.
1919
*/
20-
public function __construct(\Faker\Generator $generator, Locator $locator = null)
20+
public function __construct(\Faker\Generator $generator, ?Locator $locator = null)
2121
{
2222
$this->generator = $generator;
2323
$this->locator = $locator;

src/Faker/Provider/DateTime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public static function century()
334334
*
335335
* @example 'Europe/Paris'
336336
*/
337-
public static function timezone(string $countryCode = null)
337+
public static function timezone(?string $countryCode = null)
338338
{
339339
if ($countryCode) {
340340
$timezones = \DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, $countryCode);

src/Faker/Provider/de_AT/Person.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static function suffix()
127127
*
128128
* @return string
129129
*/
130-
public static function ssn(\DateTime $birthdate = null)
130+
public static function ssn(?\DateTime $birthdate = null)
131131
{
132132
$birthdate = $birthdate ?? DateTime::dateTimeThisCentury();
133133

src/Faker/Provider/en_GB/Company.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Company extends \Faker\Provider\Company
1818
*
1919
* @see https://en.wikipedia.org/wiki/VAT_identification_number#VAT_numbers_by_country
2020
*/
21-
public static function vat(string $type = null): string
21+
public static function vat(?string $type = null): string
2222
{
2323
switch ($type) {
2424
case static::VAT_TYPE_BRANCH:

src/Faker/Provider/en_ZA/Person.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class Person extends \Faker\Provider\Person
140140
*
141141
* @return string
142142
*/
143-
public function idNumber(\DateTime $birthdate = null, $citizen = true, $gender = null)
143+
public function idNumber(?\DateTime $birthdate = null, $citizen = true, $gender = null)
144144
{
145145
if (!$birthdate) {
146146
$birthdate = $this->generator->dateTimeThisCentury();

src/Faker/Provider/fi_FI/Person.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class Person extends \Faker\Provider\Person
9595
*
9696
* @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)
9797
*/
98-
public function personalIdentityNumber(\DateTime $birthdate = null, $gender = null)
98+
public function personalIdentityNumber(?\DateTime $birthdate = null, $gender = null)
9999
{
100100
$checksumCharacters = '0123456789ABCDEFHJKLMNPRSTUVWXY';
101101

src/Faker/Provider/kk_KZ/Company.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function companyNameSuffix()
5656
*
5757
* @return string 12 digits, like 150140000019
5858
*/
59-
public static function businessIdentificationNumber(\DateTime $registrationDate = null)
59+
public static function businessIdentificationNumber(?\DateTime $registrationDate = null)
6060
{
6161
if (!$registrationDate) {
6262
$registrationDate = \Faker\Provider\DateTime::dateTimeThisYear();

src/Faker/Provider/kk_KZ/Person.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private static function getCenturyByYear($year)
211211
*
212212
* @return string 12 digits, like 780322300455
213213
*/
214-
public static function individualIdentificationNumber(\DateTime $birthDate = null, $gender = self::GENDER_MALE)
214+
public static function individualIdentificationNumber(?\DateTime $birthDate = null, $gender = self::GENDER_MALE)
215215
{
216216
if (!$birthDate) {
217217
$birthDate = DateTime::dateTimeBetween();

src/Faker/Provider/lt_LT/Person.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public function passportNumber()
330330
*
331331
* @return string on format XXXXXXXXXXX
332332
*/
333-
public function personalIdentityNumber($gender = 'male', \DateTime $birthdate = null, $randomNumber = '')
333+
public function personalIdentityNumber($gender = 'male', ?\DateTime $birthdate = null, $randomNumber = '')
334334
{
335335
if (!$birthdate) {
336336
$birthdate = \Faker\Provider\DateTime::dateTimeThisCentury();

src/Faker/Provider/lv_LV/Person.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function passportNumber()
136136
*
137137
* @return string on format XXXXXX-XXXXX
138138
*/
139-
public function personalIdentityNumber(\DateTime $birthdate = null)
139+
public function personalIdentityNumber(?\DateTime $birthdate = null)
140140
{
141141
if (!$birthdate) {
142142
$birthdate = DateTime::dateTimeThisCentury();

src/Faker/Provider/nb_NO/Person.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class Person extends \Faker\Provider\Person
292292
*
293293
* @return string on format DDMMYY#####
294294
*/
295-
public function personalIdentityNumber(\DateTime $birthdate = null, $gender = null)
295+
public function personalIdentityNumber(?\DateTime $birthdate = null, $gender = null)
296296
{
297297
if (!$birthdate) {
298298
$birthdate = \Faker\Provider\DateTime::dateTimeThisCentury();

src/Faker/Provider/sv_SE/Person.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class Person extends \Faker\Provider\Person
125125
*
126126
* @return string on format XXXXXX-XXXX
127127
*/
128-
public function personalIdentityNumber(\DateTime $birthdate = null, $gender = null)
128+
public function personalIdentityNumber(?\DateTime $birthdate = null, $gender = null)
129129
{
130130
if (!$birthdate) {
131131
$birthdate = \Faker\Provider\DateTime::dateTimeThisCentury();

0 commit comments

Comments
 (0)