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
This commit is contained in:
Nabeel S
2019-12-11 12:57:18 -05:00
committed by GitHub
parent 1f65b744a0
commit e6d38f9338
18 changed files with 256 additions and 211 deletions

View File

@@ -8,7 +8,7 @@ use Symfony\Component\Yaml\Yaml;
class Version extends Command
{
protected $signature = 'phpvms:version {--write} {--base-only}';
protected $signature = 'phpvms:version {--write} {--base-only} {--write-full-version} {version?}';
private $versionSvc;
@@ -26,11 +26,32 @@ class Version extends Command
*/
public function handle()
{
// Write the updated build number out to the file
if ($this->option('write')) {
// Write the updated build number out to the file
$version_file = config_path('version.yml');
$cfg = Yaml::parse(file_get_contents($version_file));
// If a version is being passed in, the update the build, etc data against this
if ($this->argument('version')) {
$version = \SemVer\SemVer\Version::fromString($this->argument('version'));
if ($this->option('write_full_version')) {
$cfg['current']['major'] = $version->getMajor();
$cfg['current']['minor'] = $version->getMinor();
$cfg['current']['patch'] = $version->getPatch();
}
$prerelease = $version->getPreRelease();
if (strpos($prerelease, '.') !== false) {
$prerelease = explode('.', $prerelease);
$cfg['current']['prerelease'] = $prerelease[0];
$cfg['current']['buildmetadata'] = $prerelease[1];
} else {
$cfg['current']['prerelease'] = $prerelease;
}
}
$build_number = $this->versionSvc->getBuildId($cfg);
$cfg['current']['commit'] = $build_number;
$cfg['build']['number'] = $build_number;
file_put_contents($version_file, Yaml::dump($cfg, 4, 2));

View File

@@ -3,13 +3,10 @@
namespace App\Contracts;
use ArrayAccess;
use PhpUnitsOfMeasure\Exception\UnknownUnitOfMeasure;
/**
* Class Unit
*
* @property mixed $instance
* @property string $unit
* @property array $units
* Abstract unit wrapper
*/
class Unit implements ArrayAccess
{
@@ -25,6 +22,8 @@ class Unit implements ArrayAccess
/**
* Holds an instance of the PhpUnit type
*
* @var \PhpUnitsOfMeasure\AbstractPhysicalQuantity
*/
protected $instance;
@@ -75,7 +74,7 @@ class Unit implements ArrayAccess
*/
public function offsetExists($offset)
{
return array_key_exists($offset, $this->units);
return $this->offsetGet($offset) !== null;
}
/**
@@ -87,7 +86,16 @@ class Unit implements ArrayAccess
*/
public function offsetGet($offset)
{
return round($this->instance->toUnit($offset), 2);
try {
$value = $this->instance->toUnit($offset);
if (!$value) {
return;
}
} catch (UnknownUnitOfMeasure $e) {
return;
}
return round($value, 2);
}
/**
@@ -116,6 +124,6 @@ class Unit implements ArrayAccess
*/
public function __toString()
{
return (string) $this->units[$this->unit];
return (string) $this->offsetGet($this->unit);
}
}

View File

@@ -8,7 +8,7 @@ use Faker\Generator as Faker;
if (!function_exists('createFactoryICAO')) {
function createFactoryICAO(): string
{
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$max = strlen($characters) - 1;
$string = '';
for ($i = 0; $i < 4; $i++) {
@@ -26,14 +26,15 @@ if (!function_exists('createFactoryICAO')) {
* Add any number of airports. Don't really care if they're real or not
*/
$factory->define(App\Models\Airport::class, function (Faker $faker) {
$used = [];
return [
'id' => function () use ($used) {
do {
$string = createFactoryICAO();
} while (in_array($string, $used, true));
$usedIcaos = [];
return $string;
return [
'id' => function () use ($usedIcaos) {
do {
$airport = createFactoryICAO();
} while (in_array($airport, $usedIcaos, true));
return $airport;
},
'icao' => function (array $apt) {
return $apt['id'];

View File

@@ -307,10 +307,10 @@ flights:
dpt_airport_id: MKJP
arr_airport_id: MWCR
flight_time: 70
flight_type: J
dpt_time: 0800
arr_time: 0900
route: MLY5 KEMBO UG442 SIA UG633 OTEKO UR640 NALRO GUBEL3
flight_type: 'J'
dpt_time: '0800'
arr_time: '0900'
route: 'MLY5 KEMBO UG442 SIA UG633 OTEKO UR640 NALRO GUBEL3'
created_at: NOW
updated_at: NOW

View File

@@ -74,6 +74,12 @@ class AppServiceProvider extends ServiceProvider
/* @noinspection PhpFullyQualifiedNameUsageInspection */
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
if (config('app.debug_toolbar') === true) {
app('debugbar')->enable();
} else {
app('debugbar')->disable();
}
}
}
}

View File

@@ -153,6 +153,12 @@ class VersionService extends Service
$c = $cfg['current'];
$version = "{$c['major']}.{$c['minor']}.{$c['patch']}";
if ($c['prerelease'] !== '') {
$version .= "-{$c['prerelease']}";
if ($c['buildmetadata'] !== '') {
$version .= ".{$c['buildmetadata']}";
}
}
if ($include_build) {
// Get the current build id

View File

@@ -520,13 +520,16 @@ class Metar implements \ArrayAccess
}
}
}
// Finally determine if it's VFR or IFR conditions
// https://www.aviationweather.gov/cva/help
$this->result['category'] = 'VFR';
if (array_key_exists('cavok', $this->result) && $this->result['cavok']) {
$this->result['category'] = 'VFR';
} else {
/* @noinspection NestedPositiveIfStatementsInspection */
if (array_key_exists('cloud_height', $this->result) && array_key_exists('visibility', $this->result)) {
if (array_key_exists('cloud_height', $this->result) && $this->result['cloud_height'] !== null) {
if ($this->result['cloud_height']['ft'] > 3000 && $this->result['visibility']['nmi'] > 5) {
$this->result['category'] = 'VFR';
} else {
@@ -902,7 +905,7 @@ class Metar implements \ArrayAccess
}
$this->set_result_value('visibility', $visibility);
$this->set_result_value('visibility_report', $prefix.$visibility.$unit);
$this->set_result_value('visibility_report', $prefix.$visibility['m'].$unit);
}
return true;
@@ -1086,7 +1089,7 @@ class Metar implements \ArrayAccess
$observed['height'] = $this->createAltitude($found[5] * 100, 'feet');
// Cloud height
if (null === $this->result['cloud_height']['m'] || $observed['height']['m'] < $this->result['cloud_height']['m']) {
if (null === $this->result['cloud_height'] || $observed['height']['m'] < $this->result['cloud_height']['m']) {
$this->set_result_value('cloud_height', $observed['height']);
}

View File

@@ -8,6 +8,7 @@ use PhpUnitsOfMeasure\PhysicalQuantity\Length;
class Distance extends Unit
{
public $responseUnits = [
'm',
'km',
'mi',
'nmi',