phpvms/app/Database/factories/AirportFactory.php
Nabeel S e6d38f9338
Add PHP 7.4 support (#464)
* Add PHP 7.4 to build matrix

* DB fix

* YAML parser fix in test data

* Show versions

* Package updates

* Track used ICAOs

* 7.4 METAR parsing fix

* METAR parser fix

* Formatting

* Add meters to response units

* Call instance for unit conversion

* Return value

* Catch exception for unknown quantity

* Comment fix

* Formatting

* METAR parsing fixes on PHP 7.4

* Package updates

* More random airport ID

* More random airport ID

* Properly disable toolbar

* Semver written out to version file

* Use dev as default identifier
2019-12-11 12:57:18 -05:00

57 lines
1.6 KiB
PHP

<?php
use Faker\Generator as Faker;
/*
* Create an ICAO for use in the factory.
*/
if (!function_exists('createFactoryICAO')) {
function createFactoryICAO(): string
{
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$max = strlen($characters) - 1;
$string = '';
for ($i = 0; $i < 4; $i++) {
try {
$string .= $characters[random_int(0, $max)];
} catch (Exception $e) {
}
}
return $string;
}
}
/*
* Add any number of airports. Don't really care if they're real or not
*/
$factory->define(App\Models\Airport::class, function (Faker $faker) {
$usedIcaos = [];
return [
'id' => function () use ($usedIcaos) {
do {
$airport = createFactoryICAO();
} while (in_array($airport, $usedIcaos, true));
return $airport;
},
'icao' => function (array $apt) {
return $apt['id'];
},
'iata' => function (array $apt) {
return $apt['id'];
},
'name' => $faker->sentence(3),
'country' => $faker->country,
'timezone' => $faker->timezone,
'lat' => $faker->latitude,
'lon' => $faker->longitude,
'hub' => false,
'ground_handling_cost' => $faker->randomFloat(2, 0, 500),
'fuel_100ll_cost' => $faker->randomFloat(2, 1, 10),
'fuel_jeta_cost' => $faker->randomFloat(2, 1, 10),
'fuel_mogas_cost' => $faker->randomFloat(2, 1, 10),
];
});