Skip to content

Commit

Permalink
Apply Pint auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pelmered committed Sep 25, 2024
1 parent 104dff2 commit 04e30e5
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 307 deletions.
76 changes: 22 additions & 54 deletions src/FakeCar.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@

class FakeCar extends \Faker\Provider\Base
{
protected const EBCDIC = "0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ";
protected const MODEL_YEAR = "ABCDEFGHJKLMNPRSTVWXY123456789";
protected const EBCDIC = '0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ';

protected const MODEL_YEAR = 'ABCDEFGHJKLMNPRSTVWXY123456789';

protected FakeCarDataProviderInterface $dataProvider;

/**
* @param Generator $generator
*/
public function __construct(Generator $generator)
{
parent::__construct($generator);
$this->setDataProvider(new FakeCarDataProvider());
$this->setDataProvider(new FakeCarDataProvider);
}

public function setDataProvider(FakeCarDataProviderInterface $dataProvider): void
Expand All @@ -28,8 +26,6 @@ public function setDataProvider(FakeCarDataProviderInterface $dataProvider): voi

/**
* Get vehicle string with brand and model
*
* @return string
*/
public function vehicle(): string
{
Expand All @@ -40,23 +36,19 @@ public function vehicle(): string

/**
* Get vehicle with brand and model as an array
*
* @return array
*/
public function vehicleArray(): array
{
$vehicleBrand = $this->vehicleBrand();

return [
'brand' => $vehicleBrand,
'model' => $this->vehicleModel($vehicleBrand)
'model' => $this->vehicleModel($vehicleBrand),
];
}

/**
* Get random vehicle brand
*
* @return string
*/
public function vehicleBrand(): string
{
Expand All @@ -66,37 +58,32 @@ public function vehicleBrand(): string
/**
* Get random vehicle model
*
* @param string $brand Get random model from specific brand (optional)
*
* @param string $brand Get random model from specific brand (optional)
* @return mixed
*/
public function vehicleModel(string $brand = null): string
public function vehicleModel(?string $brand = null): string
{
return (string) $this->dataProvider->getVehicleModel($brand);
}

/**
* Generate VIN
* @link https://en.wikipedia.org/wiki/Vehicle_identification_number
*
* @param int $year
* @link https://en.wikipedia.org/wiki/Vehicle_identification_number
*
* @return mixed
*/
public function vin(int $year = 1980): string
{
$modelYear = static::modelYear($year);
$regex = "([a-hj-npr-z0-9]{8})_{$modelYear}([a-hj-npr-z0-9]{7})";
$vin = static::regexify($regex);
$regex = "([a-hj-npr-z0-9]{8})_{$modelYear}([a-hj-npr-z0-9]{7})";
$vin = static::regexify($regex);

return str_replace('_', self::checkDigit($vin), $vin);
}

/**
* Get vehicle registration number
*
* @param string $regex
*
* @return string
*/
public function vehicleRegistration(string $regex = '[A-Z]{3}-[0-9]{3}'): string
{
Expand All @@ -107,7 +94,6 @@ public function vehicleRegistration(string $regex = '[A-Z]{3}-[0-9]{3}'): string
/**
* Get vehicle type
*
* @return string
* @throws Exception
*/
public function vehicleType(): string
Expand All @@ -117,10 +103,6 @@ public function vehicleType(): string

/**
* Get vehicle fuel type
*
* @param int $count
*
* @return string
*/
public function vehicleFuelType(int $count = 1): string
{
Expand All @@ -130,7 +112,6 @@ public function vehicleFuelType(int $count = 1): string
/**
* Get vehicle door count
*
* @return int
* @throws Exception
*/
public function vehicleDoorCount(): int
Expand All @@ -141,7 +122,6 @@ public function vehicleDoorCount(): int
/**
* Get vehicle door count
*
* @return int
* @throws Exception
*/
public function vehicleSeatCount(): int
Expand All @@ -152,9 +132,7 @@ public function vehicleSeatCount(): int
/**
* Get an array of random vehicle properties
*
* @param int $count
*
* @return array
* @throws Exception
*/
public function vehicleProperties(int $count = 0): array
Expand All @@ -166,6 +144,7 @@ public function vehicleProperties(int $count = 0): array
* Get random vehicle gearbox type
*
* @return mixed
*
* @throws Exception
*/
public function vehicleGearBoxType(): string
Expand All @@ -177,18 +156,19 @@ public function vehicleGearBoxType(): string
* Get random vehicle gearbox type without unit
*
* @return mixed
*
* @throws Exception
*/
public function vehicleGearBoxTypeValue(): string
{
return $this->dataProvider->getVehicleGearBoxType();
}


/**
* Get engine torque
*
* @return mixed
*
* @throws Exception
*/
public function vehicleEngineTorque(): string
Expand All @@ -200,6 +180,7 @@ public function vehicleEngineTorque(): string
* Get engine torque without unit
*
* @return mixed
*
* @throws Exception
*/
public function vehicleEngineTorqueValue(): string
Expand All @@ -211,6 +192,7 @@ public function vehicleEngineTorqueValue(): string
* Get engine power (horsepower or kilowatts)
*
* @return mixed
*
* @throws Exception
*/
public function vehicleEnginePower(): string
Expand All @@ -222,6 +204,7 @@ public function vehicleEnginePower(): string
* Get engine power without unit
*
* @return mixed
*
* @throws Exception
*/
public function vehicleEnginePowerValue(): string
Expand All @@ -240,22 +223,11 @@ public function isSupported($method): bool
throw new \RuntimeException('Method not supported be data provider. Please implement '.$method.'() in your data provider.');
}


/**
* @param int $year
*
* @return string
*/
public static function modelYear(int $year = 1980): string
{
return substr(self::MODEL_YEAR, ($year - 1980) % 30, 1);
}

/**
* @param string $character
*
* @return string
*/
private static function transliterate(string $character): string
{
return stripos(self::EBCDIC, $character) % 10;
Expand All @@ -268,21 +240,17 @@ private static function transliterate(string $character): string
*/
private static function checkDigit(string $vin): string
{
$map = "0123456789X";
$weights = "8765432X098765432";
$sum = 0;
for ($i=0; $i < 17; $i++) {
$map = '0123456789X';
$weights = '8765432X098765432';
$sum = 0;
for ($i = 0; $i < 17; $i++) {
$sum += self::transliterate(substr($vin, $i, 1))
* stripos($map, $weights[$i]);
}

return $map[$sum % 11];
}

/**
* @param $vin
*
* @return bool
*/
public static function validateVin(string $vin): bool
{
if (strlen($vin) !== 17) {
Expand Down
Loading

0 comments on commit 04e30e5

Please sign in to comment.