Apply fixes from StyleCI

This commit is contained in:
Nabeel Shahzad
2018-08-26 16:40:04 +00:00
committed by StyleCI Bot
parent 20f46adbc4
commit 9596d88b48
407 changed files with 4032 additions and 3286 deletions

View File

@@ -4,13 +4,10 @@ namespace App\Services\ImportExport;
use App\Interfaces\ImportExport;
use App\Models\Aircraft;
use App\Models\Enums\AircraftStatus;
use App\Models\Flight;
/**
* The flight importer can be imported or export. Operates on rows
*
* @package App\Services\Import
*/
class AircraftExporter extends ImportExport
{
@@ -26,17 +23,19 @@ class AircraftExporter extends ImportExport
/**
* Import a flight, parse out the different rows
*
* @param Aircraft $aircraft
*
* @return array
*/
public function export($aircraft): array
{
$ret = [];
foreach(self::$columns as $column) {
foreach (self::$columns as $column) {
$ret[$column] = $aircraft->{$column};
}
# Modify special fields
// Modify special fields
$ret['subfleet'] = $aircraft->subfleet->type;
return $ret;

View File

@@ -11,7 +11,6 @@ use App\Support\ICAO;
/**
* Import aircraft
* @package App\Services\Import
*/
class AircraftImporter extends ImportExport
{
@@ -34,7 +33,9 @@ class AircraftImporter extends ImportExport
/**
* Find the subfleet specified, or just create it on the fly
*
* @param $type
*
* @return Subfleet|\Illuminate\Database\Eloquent\Model|null|object|static
*/
protected function getSubfleet($type)
@@ -48,8 +49,10 @@ class AircraftImporter extends ImportExport
/**
* Import a flight, parse out the different rows
*
* @param array $row
* @param int $index
*
* @return bool
*/
public function import(array $row, $index): bool
@@ -57,28 +60,28 @@ class AircraftImporter extends ImportExport
$subfleet = $this->getSubfleet($row['subfleet']);
$row['subfleet_id'] = $subfleet->id;
# Generate a hex code
if(!$row['hex_code']) {
// Generate a hex code
if (!$row['hex_code']) {
$row['hex_code'] = ICAO::createHexCode();
}
# Set a default status
// Set a default status
$row['status'] = trim($row['status']);
if($row['status'] === null || $row['status'] === '') {
if ($row['status'] === null || $row['status'] === '') {
$row['status'] = AircraftStatus::ACTIVE;
}
# Just set its state right now as parked
// Just set its state right now as parked
$row['state'] = AircraftState::PARKED;
# Try to add or update
// Try to add or update
$aircraft = Aircraft::firstOrNew([
'registration' => $row['registration'],
], $row);
try {
$aircraft->save();
} catch(\Exception $e) {
} catch (\Exception $e) {
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
return false;
}

View File

@@ -7,8 +7,6 @@ use App\Models\Airport;
/**
* The flight importer can be imported or export. Operates on rows
*
* @package App\Services\Import
*/
class AirportExporter extends ImportExport
{
@@ -24,13 +22,15 @@ class AirportExporter extends ImportExport
/**
* Import a flight, parse out the different rows
*
* @param Airport $airport
*
* @return array
*/
public function export($airport): array
{
$ret = [];
foreach(self::$columns as $column) {
foreach (self::$columns as $column) {
$ret[$column] = $airport->{$column};
}

View File

@@ -7,7 +7,6 @@ use App\Models\Airport;
/**
* Import airports
* @package App\Services\Import
*/
class AirportImporter extends ImportExport
{
@@ -35,8 +34,10 @@ class AirportImporter extends ImportExport
/**
* Import a flight, parse out the different rows
*
* @param array $row
* @param int $index
*
* @return bool
*/
public function import(array $row, $index): bool
@@ -45,7 +46,7 @@ class AirportImporter extends ImportExport
$row['hub'] = get_truth_state($row['hub']);
$airport = Airport::firstOrNew([
'id' => $row['icao']
'id' => $row['icao'],
], $row);
try {

View File

@@ -5,13 +5,11 @@ namespace App\Services\ImportExport;
use App\Interfaces\ImportExport;
use App\Models\Aircraft;
use App\Models\Airport;
use App\Models\Enums\ExpenseType;
use App\Models\Expense;
use App\Models\Subfleet;
/**
* Import expenses
* @package App\Services\Import
*/
class ExpenseExporter extends ImportExport
{
@@ -27,20 +25,22 @@ class ExpenseExporter extends ImportExport
/**
* Import a flight, parse out the different rows
*
* @param Expense $expense
*
* @return array
*/
public function export($expense): array
{
$ret = [];
foreach(self::$columns as $col) {
foreach (self::$columns as $col) {
$ret[$col] = $expense->{$col};
}
// Special fields
if($ret['airline']) {
if ($ret['airline']) {
$ret['airline'] = $expense->airline->icao;
}
@@ -51,7 +51,7 @@ class ExpenseExporter extends ImportExport
$ret['ref_model_id'] = '';
} else {
$obj = $expense->getReferencedObject();
if(!$obj) { // bail out
if (!$obj) { // bail out
return $ret;
}

View File

@@ -5,14 +5,12 @@ namespace App\Services\ImportExport;
use App\Interfaces\ImportExport;
use App\Models\Aircraft;
use App\Models\Airport;
use App\Models\Enums\ExpenseType;
use App\Models\Expense;
use App\Models\Subfleet;
use Log;
/**
* Import expenses
* @package App\Services\Import
*/
class ExpenseImporter extends ImportExport
{
@@ -36,20 +34,22 @@ class ExpenseImporter extends ImportExport
/**
* Import a flight, parse out the different rows
*
* @param array $row
* @param int $index
*
* @return bool
*/
public function import(array $row, $index): bool
{
if($row['airline']) {
if ($row['airline']) {
$row['airline_id'] = $this->getAirline($row['airline'])->id;
}
# Figure out what this is referring to
// Figure out what this is referring to
$row = $this->getRefClassInfo($row);
if(!$row['active']) {
if (!$row['active']) {
$row['active'] = true;
}
@@ -70,7 +70,9 @@ class ExpenseImporter extends ImportExport
/**
* See if this expense refers to a ref_model
*
* @param array $row
*
* @return array
*/
protected function getRefClassInfo(array $row)
@@ -93,19 +95,19 @@ class ExpenseImporter extends ImportExport
$obj = null;
if ($class === Aircraft::class) {
Log::info('Trying to import expense on aircraft, registration: ' . $id);
Log::info('Trying to import expense on aircraft, registration: '.$id);
$obj = Aircraft::where('registration', $id)->first();
} elseif ($class === Airport::class) {
Log::info('Trying to import expense on airport, icao: ' . $id);
Log::info('Trying to import expense on airport, icao: '.$id);
$obj = Airport::where('icao', $id)->first();
} elseif ($class === Subfleet::class) {
Log::info('Trying to import expense on subfleet, type: ' . $id);
Log::info('Trying to import expense on subfleet, type: '.$id);
$obj = Subfleet::where('type', $id)->first();
} else {
$this->errorLog('Unknown/unsupported Expense class: '.$class);
}
if(!$obj) {
if (!$obj) {
return $row;
}

View File

@@ -7,8 +7,6 @@ use App\Models\Fare;
/**
* The flight importer can be imported or export. Operates on rows
*
* @package App\Services\Import
*/
class FareExporter extends ImportExport
{
@@ -24,13 +22,15 @@ class FareExporter extends ImportExport
/**
* Import a flight, parse out the different rows
*
* @param Fare $fare
*
* @return array
*/
public function export($fare): array
{
$ret = [];
foreach(self::$columns as $column) {
foreach (self::$columns as $column) {
$ret[$column] = $fare->{$column};
}

View File

@@ -7,7 +7,6 @@ use App\Models\Fare;
/**
* Import aircraft
* @package App\Services\Import
*/
class FareImporter extends ImportExport
{
@@ -29,20 +28,22 @@ class FareImporter extends ImportExport
/**
* Import a flight, parse out the different rows
*
* @param array $row
* @param int $index
*
* @return bool
*/
public function import(array $row, $index): bool
{
# Try to add or update
// Try to add or update
$fare = Fare::firstOrNew([
'code' => $row['code'],
], $row);
try {
$fare->save();
} catch(\Exception $e) {
} catch (\Exception $e) {
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
return false;
}

View File

@@ -8,8 +8,6 @@ use App\Models\Flight;
/**
* The flight importer can be imported or export. Operates on rows
*
* @package App\Services\Import
*/
class FlightExporter extends ImportExport
{
@@ -25,23 +23,25 @@ class FlightExporter extends ImportExport
/**
* Import a flight, parse out the different rows
*
* @param Flight $flight
*
* @return array
*/
public function export($flight): array
{
$ret = [];
foreach(self::$columns as $column) {
foreach (self::$columns as $column) {
$ret[$column] = $flight->{$column};
}
# Modify special fields
// Modify special fields
$ret['airline'] = $ret['airline']->icao;
$ret['distance'] = $ret['distance'][config('phpvms.internal_units.distance')];
$ret['dpt_airport'] = $flight->dpt_airport_id;
$ret['arr_airport'] = $flight->arr_airport_id;
if($flight->alt_airport) {
if ($flight->alt_airport) {
$ret['alt_airport'] = $flight->alt_airport_id;
}
@@ -56,14 +56,16 @@ class FlightExporter extends ImportExport
/**
* Return the days string
*
* @param Flight $flight
*
* @return string
*/
protected function getDays(Flight &$flight)
{
$days_str = '';
if($flight->on_day(Days::MONDAY)) {
if ($flight->on_day(Days::MONDAY)) {
$days_str .= '1';
}
@@ -96,15 +98,17 @@ class FlightExporter extends ImportExport
/**
* Return any custom fares that have been made to this flight
*
* @param Flight $flight
*
* @return string
*/
protected function getFares(Flight &$flight): string
{
$fares = [];
foreach($flight->fares as $fare) {
foreach ($flight->fares as $fare) {
$fare_export = [];
if($fare->pivot->price) {
if ($fare->pivot->price) {
$fare_export['price'] = $fare->pivot->price;
}
@@ -124,7 +128,9 @@ class FlightExporter extends ImportExport
/**
* Parse all of the subfields
*
* @param Flight $flight
*
* @return string
*/
protected function getFields(Flight &$flight): string
@@ -139,13 +145,15 @@ class FlightExporter extends ImportExport
/**
* Create the list of subfleets that are associated here
*
* @param Flight $flight
*
* @return string
*/
protected function getSubfleets(Flight &$flight): string
{
$subfleets = [];
foreach($flight->subfleets as $subfleet) {
foreach ($flight->subfleets as $subfleet) {
$subfleets[] = $subfleet->type;
}

View File

@@ -15,8 +15,6 @@ use Log;
/**
* The flight importer can be imported or export. Operates on rows
*
* @package App\Services\Import
*/
class FlightImporter extends ImportExport
{
@@ -49,11 +47,9 @@ class FlightImporter extends ImportExport
'fields' => 'nullable',
];
/**
*
*/
private $fareSvc,
$flightSvc;
private $fareSvc;
private $flightSvc;
/**
* FlightImportExporter constructor.
@@ -66,8 +62,10 @@ class FlightImporter extends ImportExport
/**
* Import a flight, parse out the different rows
*
* @param array $row
* @param int $index
*
* @return bool
*/
public function import(array $row, $index): bool
@@ -108,7 +106,7 @@ class FlightImporter extends ImportExport
// Check for a valid value
$flight_type = $row['flight_type'];
if(!array_key_exists($flight_type, FlightType::labels())) {
if (!array_key_exists($flight_type, FlightType::labels())) {
$flight_type = 'J';
}
@@ -139,17 +137,19 @@ class FlightImporter extends ImportExport
/**
* Return the mask of the days
*
* @param $day_str
*
* @return int|mixed
*/
protected function setDays($day_str)
{
if(!$day_str) {
if (!$day_str) {
return 0;
}
$days = [];
if(strpos($day_str, '1') !== false) {
if (strpos($day_str, '1') !== false) {
$days[] = Days::MONDAY;
}
@@ -182,7 +182,9 @@ class FlightImporter extends ImportExport
/**
* Process the airport
*
* @param $airport
*
* @return \Illuminate\Database\Eloquent\Model
*/
protected function processAirport($airport)
@@ -195,6 +197,7 @@ class FlightImporter extends ImportExport
/**
* Parse out all of the subfleets and associate them to the flight
* The subfleet is created if it doesn't exist
*
* @param Flight $flight
* @param $col
*/
@@ -202,7 +205,7 @@ class FlightImporter extends ImportExport
{
$count = 0;
$subfleets = $this->parseMultiColumnValues($col);
foreach($subfleets as $subfleet_type) {
foreach ($subfleets as $subfleet_type) {
$subfleet = Subfleet::firstOrCreate(
['type' => $subfleet_type],
['name' => $subfleet_type]
@@ -210,9 +213,9 @@ class FlightImporter extends ImportExport
$subfleet->save();
# sync
// sync
$flight->subfleets()->syncWithoutDetaching([$subfleet->id]);
$count ++;
$count++;
}
Log::info('Subfleets added/processed: '.$count);
@@ -220,6 +223,7 @@ class FlightImporter extends ImportExport
/**
* Parse all of the fares in the multi-format
*
* @param Flight $flight
* @param $col
*/
@@ -239,6 +243,7 @@ class FlightImporter extends ImportExport
/**
* Parse all of the subfields
*
* @param Flight $flight
* @param $col
*/
@@ -246,9 +251,9 @@ class FlightImporter extends ImportExport
{
$pass_fields = [];
$fields = $this->parseMultiColumnValues($col);
foreach($fields as $field_name => $field_value) {
foreach ($fields as $field_name => $field_value) {
$pass_fields[] = [
'name' => $field_name,
'name' => $field_name,
'value' => $field_value,
];
}

View File

@@ -3,14 +3,11 @@
namespace App\Services\ImportExport;
use App\Interfaces\ImportExport;
use App\Models\Enums\FlightType;
use App\Models\Flight;
use App\Models\Subfleet;
/**
* The flight importer can be imported or export. Operates on rows
*
* @package App\Services\Import
*/
class SubfleetExporter extends ImportExport
{
@@ -26,17 +23,19 @@ class SubfleetExporter extends ImportExport
/**
* Import a flight, parse out the different rows
*
* @param Subfleet $subfleet
*
* @return array
*/
public function export($subfleet): array
{
$ret = [];
foreach(self::$columns as $column) {
foreach (self::$columns as $column) {
$ret[$column] = $subfleet->{$column};
}
# Modify special fields
// Modify special fields
$ret['airline'] = $subfleet->airline->icao;
$ret['fares'] = $this->getFares($subfleet);
@@ -45,15 +44,17 @@ class SubfleetExporter extends ImportExport
/**
* Return any custom fares that have been made to this flight
*
* @param Subfleet $subfleet
*
* @return string
*/
protected function getFares(Subfleet &$subfleet): string
{
$fares = [];
foreach($subfleet->fares as $fare) {
foreach ($subfleet->fares as $fare) {
$fare_export = [];
if($fare->pivot->price) {
if ($fare->pivot->price) {
$fare_export['price'] = $fare->pivot->price;
}
@@ -73,7 +74,9 @@ class SubfleetExporter extends ImportExport
/**
* Parse all of the subfields
*
* @param Flight $flight
*
* @return string
*/
protected function getFields(Flight &$flight): string
@@ -88,13 +91,15 @@ class SubfleetExporter extends ImportExport
/**
* Create the list of subfleets that are associated here
*
* @param Flight $flight
*
* @return string
*/
protected function getSubfleets(Flight &$flight): string
{
$subfleets = [];
foreach($flight->subfleets as $subfleet) {
foreach ($flight->subfleets as $subfleet) {
$subfleets[] = $subfleet->type;
}

View File

@@ -9,7 +9,6 @@ use App\Services\FareService;
/**
* Import subfleets
* @package App\Services\Import
*/
class SubfleetImporter extends ImportExport
{
@@ -38,8 +37,10 @@ class SubfleetImporter extends ImportExport
/**
* Import a flight, parse out the different rows
*
* @param array $row
* @param int $index
*
* @return bool
*/
public function import(array $row, $index): bool
@@ -48,12 +49,12 @@ class SubfleetImporter extends ImportExport
$row['airline_id'] = $airline->id;
$subfleet = Subfleet::firstOrNew([
'type' => $row['type']
'type' => $row['type'],
], $row);
try {
$subfleet->save();
} catch(\Exception $e) {
} catch (\Exception $e) {
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
return false;
}
@@ -66,8 +67,9 @@ class SubfleetImporter extends ImportExport
/**
* Parse all of the fares in the multi-format
*
* @param Subfleet $subfleet
* @param $col
* @param $col
*/
protected function processFares(Subfleet &$subfleet, $col): void
{