This commit is contained in:
2025-05-12 14:25:25 +02:00
parent ab2db755ef
commit 9e378ca2b7
2719 changed files with 46505 additions and 60181 deletions

View File

@@ -1,6 +1,16 @@
# CHANGELOG
## [Unreleased](https://github.com/FakerPHP/Faker/compare/v1.23.1...1.23)
## [Unreleased](https://github.com/FakerPHP/Faker/compare/v1.24.0...1.24.1)
- Removed domain `gmail.com.au` from `Provider\en_AU\Internet` (#886)
## [2024-11-09, v1.24.0](https://github.com/FakerPHP/Faker/compare/v1.23.1..v1.24.0)
- Fix internal deprecations in Doctrine's populator by @gnutix in (#889)
- Fix mobile phone number pattern for France by @ker0x in (#859)
- PHP 8.4 Support by @Jubeki in (#904)
- 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)

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -72,7 +72,7 @@ final class DateTime implements DateTimeExtension, GeneratorAwareExtension
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)),
@@ -80,7 +80,7 @@ final class DateTime implements DateTimeExtension, GeneratorAwareExtension
);
}
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;
@@ -90,7 +90,7 @@ final class DateTime implements DateTimeExtension, GeneratorAwareExtension
);
}
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);
@@ -107,7 +107,7 @@ final class DateTime implements DateTimeExtension, GeneratorAwareExtension
);
}
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);
@@ -120,29 +120,29 @@ final class DateTime implements DateTimeExtension, GeneratorAwareExtension
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;
@@ -204,7 +204,7 @@ final class DateTime implements DateTimeExtension, GeneratorAwareExtension
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);

View File

@@ -63,7 +63,7 @@ final class Number implements Extension\NumberExtension
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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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.
@@ -38,7 +38,7 @@ interface DateTimeExtension
* @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`.
@@ -52,7 +52,7 @@ interface DateTimeExtension
* @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.
@@ -66,7 +66,7 @@ interface DateTimeExtension
* @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.
@@ -78,7 +78,7 @@ interface DateTimeExtension
* @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.
@@ -90,7 +90,7 @@ interface DateTimeExtension
* @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.
@@ -102,7 +102,7 @@ interface DateTimeExtension
* @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.
@@ -114,7 +114,7 @@ interface DateTimeExtension
* @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.
@@ -126,7 +126,7 @@ interface DateTimeExtension
* @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`.
@@ -238,5 +238,5 @@ interface DateTimeExtension
*
* @example 'Europe/Rome'
*/
public function timezone(string $countryCode = null): string;
public function timezone(?string $countryCode = null): string;
}

View File

@@ -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();
}

View File

@@ -26,37 +26,37 @@ class Name
if (preg_match('/^is[_A-Z]/', $name)) {
return static function () use ($generator) {
return $generator->boolean;
return $generator->boolean();
};
}
if (preg_match('/(_a|A)t$/', $name)) {
return static function () use ($generator) {
return $generator->dateTime;
return $generator->dateTime();
};
}
switch (str_replace('_', '', $name)) {
case 'firstname':
return static function () use ($generator) {
return $generator->firstName;
return $generator->firstName();
};
case 'lastname':
return static function () use ($generator) {
return $generator->lastName;
return $generator->lastName();
};
case 'username':
case 'login':
return static function () use ($generator) {
return $generator->userName;
return $generator->userName();
};
case 'email':
case 'emailaddress':
return static function () use ($generator) {
return $generator->email;
return $generator->email();
};
case 'phonenumber':
@@ -64,68 +64,68 @@ class Name
case 'telephone':
case 'telnumber':
return static function () use ($generator) {
return $generator->phoneNumber;
return $generator->phoneNumber();
};
case 'address':
return static function () use ($generator) {
return $generator->address;
return $generator->address();
};
case 'city':
case 'town':
return static function () use ($generator) {
return $generator->city;
return $generator->city();
};
case 'streetaddress':
return static function () use ($generator) {
return $generator->streetAddress;
return $generator->streetAddress();
};
case 'postcode':
case 'zipcode':
return static function () use ($generator) {
return $generator->postcode;
return $generator->postcode();
};
case 'state':
return static function () use ($generator) {
return $generator->state;
return $generator->state();
};
case 'county':
if ($this->generator->locale == 'en_US') {
return static function () use ($generator) {
return sprintf('%s County', $generator->city);
return sprintf('%s County', $generator->city());
};
}
return static function () use ($generator) {
return $generator->state;
return $generator->state();
};
case 'country':
switch ($size) {
case 2:
return static function () use ($generator) {
return $generator->countryCode;
return $generator->countryCode();
};
case 3:
return static function () use ($generator) {
return $generator->countryISOAlpha3;
return $generator->countryISOAlpha3();
};
case 5:
case 6:
return static function () use ($generator) {
return $generator->locale;
return $generator->locale();
};
default:
return static function () use ($generator) {
return $generator->country;
return $generator->country();
};
}
@@ -133,37 +133,37 @@ class Name
case 'locale':
return static function () use ($generator) {
return $generator->locale;
return $generator->locale();
};
case 'currency':
case 'currencycode':
return static function () use ($generator) {
return $generator->currencyCode;
return $generator->currencyCode();
};
case 'url':
case 'website':
return static function () use ($generator) {
return $generator->url;
return $generator->url();
};
case 'company':
case 'companyname':
case 'employer':
return static function () use ($generator) {
return $generator->company;
return $generator->company();
};
case 'title':
if ($size !== null && $size <= 10) {
return static function () use ($generator) {
return $generator->title;
return $generator->title();
};
}
return static function () use ($generator) {
return $generator->sentence;
return $generator->sentence();
};
case 'body':
@@ -171,7 +171,7 @@ class Name
case 'article':
case 'description':
return static function () use ($generator) {
return $generator->text;
return $generator->text();
};
}

View File

@@ -27,7 +27,7 @@ class ColumnTypeGuesser
switch ($type) {
case 'boolean':
return static function () use ($generator) {
return $generator->boolean;
return $generator->boolean();
};
case 'decimal':
@@ -66,14 +66,14 @@ class ColumnTypeGuesser
case 'text':
return static function () use ($generator) {
return $generator->text;
return $generator->text();
};
case 'datetime':
case 'date':
case 'time':
return static function () use ($generator) {
return $generator->datetime;
return $generator->datetime();
};
case 'datetime_immutable':

View File

@@ -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;

View File

@@ -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;

View File

@@ -334,7 +334,7 @@ class DateTime extends Base
*
* @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);

View File

@@ -127,7 +127,7 @@ class Person extends \Faker\Provider\Person
*
* @return string
*/
public static function ssn(\DateTime $birthdate = null)
public static function ssn(?\DateTime $birthdate = null)
{
$birthdate = $birthdate ?? DateTime::dateTimeThisCentury();

View File

@@ -4,6 +4,6 @@ namespace Faker\Provider\en_AU;
class Internet extends \Faker\Provider\Internet
{
protected static $freeEmailDomain = ['gmail.com', 'yahoo.com', 'hotmail.com', 'gmail.com.au', 'yahoo.com.au', 'hotmail.com.au'];
protected static $freeEmailDomain = ['gmail.com', 'yahoo.com', 'hotmail.com', 'yahoo.com.au', 'hotmail.com.au'];
protected static $tld = ['com', 'com.au', 'org', 'org.au', 'net', 'net.au', 'biz', 'info', 'edu', 'edu.au'];
}

View File

@@ -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:

View File

@@ -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();

View File

@@ -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';

View File

@@ -13,7 +13,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'+33 (0)3 ## ## ## ##',
'+33 (0)4 ## ## ## ##',
'+33 (0)5 ## ## ## ##',
'+33 (0)6 ## ## ## ##',
'+33 (0)6 {{phoneNumber06WithSeparator}}',
'+33 (0)7 {{phoneNumber07WithSeparator}}',
'+33 (0)8 {{phoneNumber08WithSeparator}}',
'+33 (0)9 ## ## ## ##',
@@ -23,7 +23,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'+33 3 ## ## ## ##',
'+33 4 ## ## ## ##',
'+33 5 ## ## ## ##',
'+33 6 ## ## ## ##',
'+33 6 {{phoneNumber06WithSeparator}}',
'+33 7 {{phoneNumber07WithSeparator}}',
'+33 8 {{phoneNumber08WithSeparator}}',
'+33 9 ## ## ## ##',
@@ -33,7 +33,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'03########',
'04########',
'05########',
'06########',
'06{{phoneNumber06}}',
'07{{phoneNumber07}}',
'08{{phoneNumber08}}',
'09########',
@@ -43,7 +43,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'03 ## ## ## ##',
'04 ## ## ## ##',
'05 ## ## ## ##',
'06 ## ## ## ##',
'06 {{phoneNumber06WithSeparator}}',
'07 {{phoneNumber07WithSeparator}}',
'08 {{phoneNumber08WithSeparator}}',
'09 ## ## ## ##',
@@ -52,13 +52,13 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
// Mobile phone numbers start by 06 and 07
// 06 is the most common prefix
protected static $mobileFormats = [
'+33 (0)6 ## ## ## ##',
'+33 6 ## ## ## ##',
'+33 (0)6 {{phoneNumber06WithSeparator}}',
'+33 6 {{phoneNumber06WithSeparator}}',
'+33 (0)7 {{phoneNumber07WithSeparator}}',
'+33 7 {{phoneNumber07WithSeparator}}',
'06########',
'06{{phoneNumber06}}',
'07{{phoneNumber07}}',
'06 ## ## ## ##',
'06 {{phoneNumber06WithSeparator}}',
'07 {{phoneNumber07WithSeparator}}',
];
@@ -73,6 +73,26 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'+33#########',
];
public function phoneNumber06()
{
$phoneNumber = $this->phoneNumber06WithSeparator();
return str_replace(' ', '', $phoneNumber);
}
/**
* Only 0601 to 0638, 0640 to 0689, 0695 and 0698 to 0699 are acceptable prefixes with 06
*
* @see https://www.arcep.fr/la-regulation/grands-dossiers-thematiques-transverses/la-numerotation.html#c8961
* @see https://www.itu.int/itu-t/nnp/#/numbering-plans?country=France%C2%A0&code=33
*/
public function phoneNumber06WithSeparator()
{
$regex = '([0-24-8]\d|3[0-8]|9[589])( \d{2}){3}';
return static::regexify($regex);
}
public function phoneNumber07()
{
$phoneNumber = $this->phoneNumber07WithSeparator();
@@ -81,16 +101,16 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
}
/**
* Only 073 to 079 are acceptable prefixes with 07
* Only 0730 to 0789 are acceptable prefixes with 07
*
* @see http://www.arcep.fr/index.php?id=8146
* @see https://www.arcep.fr/la-regulation/grands-dossiers-thematiques-transverses/la-numerotation.html#c8961
* @see https://www.itu.int/itu-t/nnp/#/numbering-plans?country=France%C2%A0&code=33
*/
public function phoneNumber07WithSeparator()
{
$phoneNumber = $this->generator->numberBetween(3, 9);
$phoneNumber .= $this->numerify('# ## ## ##');
$regex = '([3-8]\d)( \d{2}){3}';
return $phoneNumber;
return static::regexify($regex);
}
public function phoneNumber08()
@@ -121,9 +141,9 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
*/
public function phoneNumber08WithSeparator()
{
$regex = '([012]{1}\d{1}|(9[1-357-9])( \d{2}){3}';
$regex = '([012]\d|(9[1-357-9])( \d{2}){3}';
return $this->regexify($regex);
return static::regexify($regex);
}
/**

View File

@@ -56,7 +56,7 @@ class Company extends \Faker\Provider\Company
*
* @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();

View File

@@ -211,7 +211,7 @@ class Person extends \Faker\Provider\Person
*
* @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();

View File

@@ -330,7 +330,7 @@ class Person extends \Faker\Provider\Person
*
* @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();

View File

@@ -136,7 +136,7 @@ class Person extends \Faker\Provider\Person
*
* @return string on format XXXXXX-XXXXX
*/
public function personalIdentityNumber(\DateTime $birthdate = null)
public function personalIdentityNumber(?\DateTime $birthdate = null)
{
if (!$birthdate) {
$birthdate = DateTime::dateTimeThisCentury();

View File

@@ -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();

View File

@@ -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();