Fix formatting and interfaces in nearly every file

This commit is contained in:
Nabeel Shahzad
2018-03-19 20:50:40 -05:00
parent 04c5b9e7bf
commit ccf56ddec1
331 changed files with 3282 additions and 2492 deletions

View File

@@ -2,12 +2,16 @@
namespace App\Console\Commands;
use App\Console\BaseCommand;
use App\Console\Command;
use App\Facades\Utils;
use GuzzleHttp\Client;
use Illuminate\Database\Eloquent\Collection;
class AcarsReplay extends BaseCommand
/**
* Class AcarsReplay
* @package App\Console\Commands
*/
class AcarsReplay extends Command
{
protected $signature = 'phpvms:replay {files} {--manual} {--write-all} {--no-submit}';
protected $description = 'Replay an ACARS file';
@@ -35,7 +39,6 @@ class AcarsReplay extends BaseCommand
*/
protected $httpClient;
/**
* Return an instance of an HTTP client all ready to post
*/
@@ -45,46 +48,43 @@ class AcarsReplay extends BaseCommand
$this->httpClient = new Client([
'base_uri' => config('app.url'),
'headers' => [
'headers' => [
'Authorization' => $this->apiKey,
]
]);
}
/*protected function getArguments()
{
return [
['--files', InputOption::VALUE_OPTIONAL]
];
}*/
/**
* Make a request to start a PIREP
* @param \stdClass $flight
* @return string
* @throws \RuntimeException
*/
protected function startPirep($flight): string
{
# convert the planned flight time to be completely in minutes
$pft = Utils::hoursToMinutes($flight->planned_hrsenroute,
$flight->planned_minenroute);
$pft = Utils::hoursToMinutes(
$flight->planned_hrsenroute,
$flight->planned_minenroute
);
$flight_number = substr($flight->callsign, 3);
$response = $this->httpClient->post('/api/pireps/prefile', [
'json' => [
'airline_id' => 1,
'flight_number' => $flight_number,
'aircraft_id' => 1,
'dpt_airport_id' => $flight->planned_depairport,
'arr_airport_id' => $flight->planned_destairport,
'level' => $flight->planned_altitude,
'planned_flight_time' => $pft,
'route' => $flight->planned_route,
'airline_id' => 1,
'flight_number' => $flight_number,
'aircraft_id' => 1,
'dpt_airport_id' => $flight->planned_depairport,
'arr_airport_id' => $flight->planned_destairport,
'level' => $flight->planned_altitude,
'planned_flight_time' => $pft,
'route' => $flight->planned_route,
]
]);
$body = \json_decode($response->getBody()->getContents());
return $body->id;
}
@@ -92,14 +92,16 @@ class AcarsReplay extends BaseCommand
* Mark the PIREP as filed
* @param $pirep_id
* @return mixed
* @throws \RuntimeException
*/
protected function filePirep($pirep_id)
{
$response = $this->httpClient->post('/api/pireps/'.$pirep_id.'/file', [
'json'=> []
'json' => []
]);
$body = \json_decode($response->getBody()->getContents());
return $body;
}
@@ -107,18 +109,19 @@ class AcarsReplay extends BaseCommand
* @param $pirep_id
* @param $data
* @return array
* @throws \RuntimeException
*/
protected function postUpdate($pirep_id, $data)
{
$uri = '/api/pireps/' . $pirep_id . '/acars/position';
$uri = '/api/pireps/'.$pirep_id.'/acars/position';
$position = [
'log' => '',
'lat' => $data->latitude,
'lon' => $data->longitude,
'heading' => $data->heading,
'altitude' => $data->altitude,
'gs' => $data->groundspeed,
'log' => '',
'lat' => $data->latitude,
'lon' => $data->longitude,
'heading' => $data->heading,
'altitude' => $data->altitude,
'gs' => $data->groundspeed,
'transponder' => $data->transponder,
];
@@ -129,13 +132,14 @@ class AcarsReplay extends BaseCommand
];
$this->info("Update: $data->callsign, $position[lat] x $position[lon] \t\t"
. "hdg: $position[heading]\t\talt: $position[altitude]\t\tgs: $position[gs]");
."hdg: $position[heading]\t\talt: $position[altitude]\t\tgs: $position[gs]");
$response = $this->httpClient->post($uri, [
'json' => $upd
]);
$body = \json_decode($response->getBody()->getContents());
return [
$data->callsign,
$position['lat'],
@@ -149,22 +153,24 @@ class AcarsReplay extends BaseCommand
/**
* Parse this file and run the updates
* @param array $files
* @throws \RuntimeException
*/
protected function updatesFromFile(array $files)
{
/**
* @var $flights Collection
*/
$flights = collect($files)->transform(function ($f)
{
$file = storage_path('/replay/' . $f . '.json');
$flights = collect($files)->transform(function ($f) {
$file = storage_path('/replay/'.$f.'.json');
if (file_exists($file)) {
$this->info('Loading ' . $file);
$this->info('Loading '.$file);
$contents = file_get_contents($file);
$contents = \json_decode($contents);
return collect($contents->updates);
} else {
$this->error($file . ' not found, skipping');
$this->error($file.' not found, skipping');
return false;
}
})
@@ -178,12 +184,11 @@ class AcarsReplay extends BaseCommand
/**
* File the initial pirep to get a "preflight" status
*/
$flights->each(function ($updates, $idx)
{
$flights->each(function ($updates, $idx) {
$update = $updates->first();
$pirep_id = $this->startPirep($update);
$this->pirepList[$update->callsign] = $pirep_id;
$this->info('Prefiled ' . $update->callsign . ', ID: ' . $pirep_id);
$this->info('Prefiled '.$update->callsign.', ID: '.$pirep_id);
});
/**
@@ -202,14 +207,14 @@ class AcarsReplay extends BaseCommand
$this->postUpdate($pirep_id, $update);
# we're done and don't put the "no-submit" option
if($updates->count() === 0 && !$this->option('no-submit')) {
if ($updates->count() === 0 && !$this->option('no-submit')) {
$this->filePirep($pirep_id);
}
})->filter(function ($updates, $idx) {
return $updates->count() > 0;
});
if(!$this->option('write-all')) {
if (!$this->option('write-all')) {
if (!$this->option('manual')) {
sleep($this->sleepTime);
} else {
@@ -221,8 +226,8 @@ class AcarsReplay extends BaseCommand
/**
* Execute the console command.
*
* @return mixed
* @throws \RuntimeException
*/
public function handle()
{

View File

@@ -2,15 +2,22 @@
namespace App\Console\Commands;
use App\Console\BaseCommand;
use App\Console\Command;
use Log;
class CreateDatabase extends BaseCommand
/**
* Class CreateDatabase
* @package App\Console\Commands
*/
class CreateDatabase extends Command
{
protected $signature = 'database:create {--reset} {--conn=?}';
protected $description = 'Create a database';
protected $os;
/**
* CreateDatabase constructor.
*/
public function __construct()
{
parent::__construct();
@@ -24,21 +31,22 @@ class CreateDatabase extends BaseCommand
*/
protected function create_mysql($dbkey)
{
$host = config($dbkey . 'host');
$port = config($dbkey . 'port');
$name = config($dbkey . 'database');
$user = config($dbkey . 'username');
$pass = config($dbkey . 'password');
$host = config($dbkey.'host');
$port = config($dbkey.'port');
$name = config($dbkey.'database');
$user = config($dbkey.'username');
$pass = config($dbkey.'password');
$dbSvc = new \App\Console\Services\Database();
$dsn = $dbSvc->createDsn($host, $port);
Log::info('Connection string: ' . $dsn);
Log::info('Connection string: '.$dsn);
try {
$conn = $dbSvc->createPDO($dsn, $user, $pass);
} catch (\PDOException $e) {
Log::error($e);
return false;
}
@@ -59,6 +67,7 @@ class CreateDatabase extends BaseCommand
$conn->exec($sql);
} catch (\PDOException $e) {
Log::error($e);
return false;
}
}
@@ -75,14 +84,14 @@ class CreateDatabase extends BaseCommand
}
if ($this->option('reset') === true) {
$cmd = ['rm', '-rf', config($dbkey . 'database')];
$cmd = ['rm', '-rf', config($dbkey.'database')];
$this->runCommand($cmd);
}
if (!file_exists(config($dbkey . 'database'))) {
if (!file_exists(config($dbkey.'database'))) {
$cmd = [
$exec,
config($dbkey . 'database'),
config($dbkey.'database'),
'""',
];
@@ -108,21 +117,17 @@ class CreateDatabase extends BaseCommand
}
}*/
$this->info('Using connection "' . config('database.default') . '"');
$this->info('Using connection "'.config('database.default').'"');
$conn = config('database.default');
$dbkey = 'database.connections.' . $conn . '.';
$dbkey = 'database.connections.'.$conn.'.';
if (config($dbkey . 'driver') === 'mysql') {
if (config($dbkey.'driver') === 'mysql') {
$this->create_mysql($dbkey);
}
elseif (config($dbkey . 'driver') === 'sqlite') {
} elseif (config($dbkey.'driver') === 'sqlite') {
$this->create_sqlite($dbkey);
}
// TODO: Eventually
elseif (config($dbkey . 'driver') === 'postgres') {
} // TODO: Eventually
elseif (config($dbkey.'driver') === 'postgres') {
$this->create_postgres($dbkey);
}
}

View File

@@ -2,7 +2,7 @@
namespace App\Console\Commands;
use App\Console\BaseCommand;
use App\Console\Command;
use App\Models\Acars;
use App\Models\Airline;
use App\Models\Pirep;
@@ -12,7 +12,11 @@ use DB;
use PDO;
use Symfony\Component\Yaml\Yaml;
class DevCommands extends BaseCommand
/**
* Class DevCommands
* @package App\Console\Commands
*/
class DevCommands extends Command
{
protected $signature = 'phpvms {cmd} {param?}';
protected $description = 'Developer commands';
@@ -30,15 +34,15 @@ class DevCommands extends BaseCommand
}
$commands = [
'list-awards' => 'listAwardClasses',
'clear-acars' => 'clearAcars',
'clear-users' => 'clearUsers',
'compile-assets' => 'compileAssets',
'db-attrs' => 'dbAttrs',
'xml-to-yaml' => 'xmlToYaml',
'list-awards' => 'listAwardClasses',
'clear-acars' => 'clearAcars',
'clear-users' => 'clearUsers',
'compile-assets' => 'compileAssets',
'db-attrs' => 'dbAttrs',
'xml-to-yaml' => 'xmlToYaml',
];
if(!array_key_exists($command, $commands)) {
if (!array_key_exists($command, $commands)) {
$this->error('Command not found!');
exit();
}
@@ -56,7 +60,7 @@ class DevCommands extends BaseCommand
$headers = ['Award Name', 'Class'];
$formatted_awards = [];
foreach($awards as $award) {
foreach ($awards as $award) {
$formatted_awards[] = [$award->name, \get_class($award)];
}
@@ -68,7 +72,7 @@ class DevCommands extends BaseCommand
*/
protected function clearAcars()
{
if(config('database.default') === 'mysql') {
if (config('database.default') === 'mysql') {
DB::statement('SET foreign_key_checks=0');
}
@@ -122,7 +126,7 @@ class DevCommands extends BaseCommand
$server_version = $pdo->getAttribute(PDO::ATTR_SERVER_VERSION);
$emulate_prepares = version_compare($server_version, $emulate_prepares_below_version, '<');
$this->info('Server Version: '. $server_version);
$this->info('Server Version: '.$server_version);
$this->info('Emulate Prepares: '.$emulate_prepares);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $emulate_prepares);
@@ -134,7 +138,7 @@ class DevCommands extends BaseCommand
protected function xmlToYaml()
{
$file = $this->argument('param');
$this->info('Reading '. $file);
$this->info('Reading '.$file);
$xml_str = file_get_contents($file);
$xml = new \SimpleXMLElement($xml_str);
@@ -148,7 +152,7 @@ class DevCommands extends BaseCommand
foreach ($xml->database->table_data->row as $row) {
$yaml_row = [];
foreach($row->field as $field) {
foreach ($row->field as $field) {
$fname = (string) $field['name'];
$fvalue = (string) $field;
@@ -163,6 +167,6 @@ class DevCommands extends BaseCommand
$file_name = $table_name.'.yml';
file_put_contents(storage_path($file_name), Yaml::dump($yaml, 4, 2));
$this->info('Writing yaml to storage: '. $file_name);
$this->info('Writing yaml to storage: '.$file_name);
}
}

View File

@@ -2,14 +2,14 @@
namespace App\Console\Commands;
use App\Console\BaseCommand;
use App\Console\Command;
use Modules\Installer\Services\ConfigService;
/**
* Create a fresh development install
* @package App\Console\Commands
*/
class DevInstall extends BaseCommand
class DevInstall extends Command
{
protected $signature = 'phpvms:dev-install {--reset-db}';
protected $description = 'Run a developer install and run the sample migration';
@@ -20,7 +20,7 @@ class DevInstall extends BaseCommand
*/
public function handle()
{
if(!$this->option('reset-db')) {
if (!$this->option('reset-db')) {
$this->rewriteConfigs();
}
@@ -69,26 +69,26 @@ class DevInstall extends BaseCommand
# Remove the old files
$config_file = base_path('config.php');
if(file_exists($config_file)) {
if (file_exists($config_file)) {
unlink($config_file);
}
$env_file = base_path('env.php');
if(file_exists($env_file)) {
if (file_exists($env_file)) {
unlink($env_file);
}
$this->info('Removing the sqlite db');
$db_file = storage_path('db.sqlite');
if(file_exists($db_file)) {
if (file_exists($db_file)) {
unlink($db_file);
}
$this->info('Regenerating the config files');
$cfgSvc->createConfigFiles([
'APP_ENV' => 'dev',
'APP_ENV' => 'dev',
'SITE_NAME' => 'phpvms test',
'DB_CONN' => 'sqlite',
'DB_CONN' => 'sqlite',
]);
$this->info('Config files generated!');

View File

@@ -2,9 +2,9 @@
namespace App\Console\Commands;
use App\Console\BaseCommand;
use App\Console\Command;
class ImportFromClassic extends BaseCommand
class ImportFromClassic extends Command
{
protected $signature = 'phpvms:importer {db_host} {db_name} {db_user} {db_pass?} {table_prefix=phpvms_}';
protected $description = 'Import from an older version of phpVMS';
@@ -15,10 +15,10 @@ class ImportFromClassic extends BaseCommand
public function handle()
{
$db_creds = [
'host' => $this->argument('db_host'),
'name' => $this->argument('db_name'),
'user' => $this->argument('db_user'),
'pass' => $this->argument('db_pass'),
'host' => $this->argument('db_host'),
'name' => $this->argument('db_name'),
'user' => $this->argument('db_user'),
'pass' => $this->argument('db_pass'),
'table_prefix' => $this->argument('table_prefix')
];

View File

@@ -2,9 +2,13 @@
namespace App\Console\Commands;
use App\Console\BaseCommand;
use App\Console\Command;
class Install extends BaseCommand
/**
* Class Install
* @package App\Console\Commands
*/
class Install extends Command
{
protected $signature = 'phpvms:install
{--update}
@@ -13,11 +17,17 @@ class Install extends BaseCommand
protected $description = 'Install or update phpVMS';
/**
* Install constructor.
*/
public function __construct()
{
parent::__construct();
}
/**
* @return mixed|void
*/
public function handle()
{
$this->info('Installing phpVMS...');
@@ -25,7 +35,7 @@ class Install extends BaseCommand
$this->setupDatabase();
# Only run these if we're doing an initial install
if(!$this->option('update')) {
if (!$this->option('update')) {
$this->writeLocalConfig();
$this->initialData();
}
@@ -38,22 +48,20 @@ class Install extends BaseCommand
*/
protected function setupDatabase()
{
if(!$this->option('update')) {
if (!$this->option('update')) {
$this->call('database:create');
}
$this->info('Running database migrations...');
$this->call('migrate');
# TODO: Call initial seed data, for the groups and other supporting data
}
/**
* Write a local config file
*/
protected function writeLocalConfig()
protected function writeLocalConfig(): void
{
}
/**
@@ -63,15 +71,14 @@ class Install extends BaseCommand
{
# TODO: Prompt for initial airline info
$airline_name = $this->option('airline-name');
if(!$airline_name) {
if (!$airline_name) {
$airline_name = $this->ask('Enter your airline name');
}
$airline_code = $this->option('airline-code');
if(!$airline_code) {
if (!$airline_code) {
$airline_code = $this->ask('Enter your airline code');
}
# TODO: Prompt for admin user/password
}
}

View File

@@ -2,15 +2,33 @@
namespace App\Console\Commands;
use App\Console\BaseCommand;
use App\Console\Command;
use App\Models\Enums\NavaidType;
use App\Models\Navdata;
class NavdataImport extends BaseCommand
/**
* Class NavdataImport
* @package App\Console\Commands
*/
class NavdataImport extends Command
{
protected $signature = 'phpvms:navdata';
protected $description = '';
/**
* @return mixed|void
* @throws \League\Geotools\Exception\InvalidArgumentException
*/
public function handle()
{
$this->info('Emptying the current navdata...');
Navdata::query()->truncate();
$this->info('Looking for nav files...');
$this->read_wp_nav_aid();
$this->read_wp_nav_fix();
}
/**
* Read and parse in the navaid file
* @throws \League\Geotools\Exception\InvalidArgumentException
@@ -49,6 +67,7 @@ class NavdataImport extends BaseCommand
$file_path = storage_path('/navdata/WPNAVAID.txt');
if (!file_exists($file_path)) {
$this->error('WPNAVAID.txt not found in storage/navdata');
return false;
}
@@ -57,10 +76,9 @@ class NavdataImport extends BaseCommand
$imported = 0;
foreach($generator as $line) {
foreach ($generator as $line) {
$navaid = [
'id' => trim(substr($line, 24, 4)), // ident column
'id' => trim(substr($line, 24, 4)), // ident column
'name' => trim(substr($line, 0, 24)),
'type' => trim(substr($line, 29, 4)),
'lat' => trim(substr($line, 33, 9)),
@@ -70,8 +88,7 @@ class NavdataImport extends BaseCommand
];
# Map to the Navaid enum
switch($navaid['type'])
{
switch ($navaid['type']) {
case 'ILS':
$navaid['type'] = NavaidType::LOC;
break;
@@ -104,12 +121,12 @@ class NavdataImport extends BaseCommand
], $navaid);
$imported++;
if($imported % 100 === 0) {
$this->info('Imported ' . $imported . ' entries...');
if ($imported % 100 === 0) {
$this->info('Imported '.$imported.' entries...');
}
}
$this->info('Imported a total of ' . $imported . ' nav aids');
$this->info('Imported a total of '.$imported.' nav aids');
}
/**
@@ -137,8 +154,9 @@ class NavdataImport extends BaseCommand
*/
$file_path = storage_path('/navdata/WPNAVFIX.txt');
if(!file_exists($file_path)) {
if (!file_exists($file_path)) {
$this->error('WPNAVFIX.txt not found in storage/navdata');
return false;
}
@@ -148,11 +166,11 @@ class NavdataImport extends BaseCommand
$imported = 0;
foreach ($generator as $line) {
$navfix = [
'id' => trim(substr($line, 0, 4)), // ident column
'id' => trim(substr($line, 0, 4)), // ident column
'name' => trim(substr($line, 24, 6)),
'type' => NavaidType::FIX,
'lat' => trim(substr($line, 30, 10)),
'lon' => trim(substr($line, 40, 11)),
'lat' => trim(substr($line, 30, 10)),
'lon' => trim(substr($line, 40, 11)),
];
switch ($navfix['type']) {
@@ -165,20 +183,10 @@ class NavdataImport extends BaseCommand
$imported++;
if ($imported % 100 === 0) {
$this->info('Imported ' . $imported . ' entries...');
$this->info('Imported '.$imported.' entries...');
}
}
$this->info('Imported a total of ' . $imported . ' nav fixes');
}
public function handle()
{
$this->info('Emptying the current navdata...');
Navdata::query()->truncate();
$this->info('Looking for nav files...');
$this->read_wp_nav_aid();
$this->read_wp_nav_fix();
$this->info('Imported a total of '.$imported.' nav fixes');
}
}

View File

@@ -2,13 +2,16 @@
namespace App\Console\Commands;
use App\Console\BaseCommand;
use App\Console\Command;
use GuzzleHttp\Client;
class TestApi extends BaseCommand
/**
* Class TestApi
* @package App\Console\Commands
*/
class TestApi extends Command
{
protected $signature = 'phpvms:test-api {apikey} {url}';
protected $httpClient;
/**
@@ -17,11 +20,11 @@ class TestApi extends BaseCommand
public function handle()
{
$this->httpClient = new Client([
'headers' => [
'Authorization' => $this->argument('apikey'),
'Content-type' => 'application/json',
'X-API-Key' => $this->argument('apikey'),
]
'headers' => [
'Authorization' => $this->argument('apikey'),
'Content-type' => 'application/json',
'X-API-Key' => $this->argument('apikey'),
]
]);
$result = $this->httpClient->get($this->argument('url'));

View File

@@ -2,10 +2,14 @@
namespace App\Console\Commands;
use App\Console\BaseCommand;
use App\Console\Command;
use Symfony\Component\Yaml\Yaml;
class Version extends BaseCommand
/**
* Class Version
* @package App\Console\Commands
*/
class Version extends Command
{
protected $signature = 'phpvms:version {--write} {--base-only}';
@@ -19,7 +23,7 @@ class Version extends BaseCommand
# prefix with the date in YYMMDD format
$date = date('ymd');
$version = $date . '-' . $version;
$version = $date.'-'.$version;
return $version;
}
@@ -46,11 +50,11 @@ class Version extends BaseCommand
# Only show the major.minor.patch version
if ($this->option('base-only')) {
$version = 'v' . $cfg['current']['major'] . '.'
. $cfg['current']['minor'] . '.'
. $cfg['current']['patch'];
$version = 'v'.$cfg['current']['major'].'.'
.$cfg['current']['minor'].'.'
.$cfg['current']['patch'];
}
print $version . "\n";
print $version."\n";
}
}

View File

@@ -2,16 +2,24 @@
namespace App\Console\Commands;
use App\Console\BaseCommand;
use App\Console\Command;
use App\Services\DatabaseService;
use DB;
use Symfony\Component\Yaml\Yaml;
class YamlExport extends BaseCommand
/**
* Class YamlExport
* @package App\Console\Commands
*/
class YamlExport extends Command
{
protected $signature = 'phpvms:export {tables*}';
protected $description = 'YAML table export';
/**
* YamlExport constructor.
* @param DatabaseService $dbSvc
*/
public function __construct(DatabaseService $dbSvc)
{
parent::__construct();
@@ -23,17 +31,17 @@ class YamlExport extends BaseCommand
public function handle()
{
$tables = $this->argument('tables');
if(empty($tables)) {
if (empty($tables)) {
$this->error('No tables specified');
exit();
}
$export_tables = [];
foreach($tables as $table) {
foreach ($tables as $table) {
$export_tables[$table] = [];
$rows = DB::table($table)->get();
foreach($rows as $row) {
foreach ($rows as $row) {
$export_tables[$table][] = (array) $row;
}
}

View File

@@ -2,16 +2,23 @@
namespace App\Console\Commands;
use App\Console\BaseCommand;
use App\Console\Command;
use App\Services\DatabaseService;
class YamlImport extends BaseCommand
/**
* Class YamlImport
* @package App\Console\Commands
*/
class YamlImport extends Command
{
protected $signature = 'phpvms:import {files*}';
protected $description = 'Developer commands';
protected $dbSvc;
/**
* YamlImport constructor.
* @param DatabaseService $dbSvc
*/
public function __construct(DatabaseService $dbSvc)
{
parent::__construct();
@@ -20,31 +27,28 @@ class YamlImport extends BaseCommand
/**
* Run dev related commands
* @throws \Exception
*/
public function handle()
{
$files = $this->argument('files');
if(empty($files)) {
if (empty($files)) {
$this->error('No files to import specified!');
exit();
}
$ignore_errors = true;
/*$ignore_errors = $this->option('ignore_errors');
if(!$ignore_errors) {
$ignore_errors = false;
}*/
foreach($files as $file) {
if(!file_exists($file)) {
$this->error('File ' . $file .' doesn\'t exist');
foreach ($files as $file) {
if (!file_exists($file)) {
$this->error('File '.$file.' doesn\'t exist');
exit;
}
$this->info('Importing ' . $file);
$this->info('Importing '.$file);
$imported = $this->dbSvc->seed_from_yaml_file($file, $ignore_errors);
foreach($imported as $table => $count) {
foreach ($imported as $table => $count) {
$this->info('Imported '.$count.' records from "'.$table.'"');
}
}