Faker\Provider\ro_RO\Person::cnp PHP Method

cnp() public method

Personal Numerical Code (CNP)
public cnp ( null | string $gender = null, null | string $dateOfBirth = null, null | string $county = null, null | boolean $isResident = true ) : string
$gender null | string Person::GENDER_MALE or Person::GENDER_FEMALE
$dateOfBirth null | string (1800-2099) 'Y-m-d', 'Y-m', 'Y' I.E. '1981-06-16', '2085-03', '1900'
$county null | string county code where the CNP was issued
$isResident null | boolean flag if the person resides in Romania
return string 13 digits CNP code
    public function cnp($gender = null, $dateOfBirth = null, $county = null, $isResident = true)
    {
        $genders = array(Person::GENDER_MALE, Person::GENDER_FEMALE);
        if (empty($gender)) {
            $gender = static::randomElement($genders);
        } elseif (!in_array($gender, $genders)) {
            throw new \InvalidArgumentException("Gender must be '{Person::GENDER_MALE}' or '{Person::GENDER_FEMALE}'");
        }
        $date = $this->getDateOfBirth($dateOfBirth);
        if (is_null($county)) {
            $countyCode = static::randomElement(array_values(static::$cnpCountyCodes));
        } elseif (!array_key_exists($county, static::$cnpCountyCodes)) {
            throw new \InvalidArgumentException("Invalid county code '{$county}' received");
        } else {
            $countyCode = static::$cnpCountyCodes[$county];
        }
        $cnp = (string) $this->getGenderDigit($date, $gender, $isResident) . $date->format('ymd') . $countyCode . static::numerify('##%');
        $checksum = $this->getChecksumDigit($cnp);
        return $cnp . $checksum;
    }