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