Code cleanup from inspection results

This commit is contained in:
Nabeel Shahzad
2018-08-26 13:50:08 -05:00
parent 0f3424f41e
commit e95b3eb366
76 changed files with 226 additions and 268 deletions

View File

@@ -70,6 +70,7 @@ class DatabaseService extends Service
// see if this table uses a UUID as the PK
// if no ID is specified
if (\in_array($table, $this->uuid_tables, true)) {
/** @noinspection NestedPositiveIfStatementsInspection */
if (!array_key_exists('id', $row)) {
$row['id'] = Uuid::generate()->string;
}

View File

@@ -165,7 +165,7 @@ class FareService extends Service
$subfleet->fares()->syncWithoutDetaching([$fare->id]);
// modify any pivot values?
if (count($override) > 0) {
if (\count($override) > 0) {
$subfleet->fares()->updateExistingPivot($fare->id, $override);
}

View File

@@ -24,7 +24,6 @@ class PirepFinanceService extends Service
private $expenseRepo;
private $fareSvc;
private $journalRepo;
private $pirepSvc;
/**
* FinanceService constructor.
@@ -32,18 +31,15 @@ class PirepFinanceService extends Service
* @param ExpenseRepository $expenseRepo
* @param FareService $fareSvc
* @param JournalRepository $journalRepo
* @param PirepService $pirepSvc
*/
public function __construct(
ExpenseRepository $expenseRepo,
FareService $fareSvc,
JournalRepository $journalRepo,
PirepService $pirepSvc
JournalRepository $journalRepo
) {
$this->expenseRepo = $expenseRepo;
$this->fareSvc = $fareSvc;
$this->journalRepo = $journalRepo;
$this->pirepSvc = $pirepSvc;
}
/**
@@ -288,6 +284,7 @@ class PirepFinanceService extends Service
.$expense->name.'", A='.$expense->amount);
// If an airline_id is filled, then see if it matches
/** @noinspection NotOptimalIfConditionsInspection */
if (filled($expense->airline_id) && $expense->airline_id !== $pirep->airline_id) {
Log::info('Finance: Expense has an airline ID and it doesn\'t match, skipping');
continue;

View File

@@ -17,7 +17,6 @@ use Log;
*/
class FlightService extends Service
{
private $fareSvc;
private $flightRepo;
private $navDataRepo;
private $userSvc;
@@ -25,18 +24,15 @@ class FlightService extends Service
/**
* FlightService constructor.
*
* @param FareService $fareSvc
* @param FlightRepository $flightRepo
* @param NavdataRepository $navdataRepo
* @param UserService $userSvc
*/
public function __construct(
FareService $fareSvc,
FlightRepository $flightRepo,
NavdataRepository $navdataRepo,
UserService $userSvc
) {
$this->fareSvc = $fareSvc;
$this->flightRepo = $flightRepo;
$this->navDataRepo = $navdataRepo;
$this->userSvc = $userSvc;
@@ -128,19 +124,11 @@ class FlightService extends Service
// Return any flights that have the same route code and leg
// If this list is > 0, then this has a duplicate
$found_flights = $found_flights->filter(function ($value, $key) use ($flight) {
if ($flight->route_code === $value->route_code
&& $flight->route_leg === $value->route_leg) {
return true;
}
return false;
return $flight->route_code === $value->route_code
&& $flight->route_leg === $value->route_leg;
});
if ($found_flights->count() === 0) {
return false;
}
return true;
return !($found_flights->count() === 0);
}
/**
@@ -191,9 +179,7 @@ class FlightService extends Service
return collect();
}
$route_points = array_map(function ($point) {
return strtoupper($point);
}, explode(' ', $flight->route));
$route_points = array_map('strtoupper', explode(' ', $flight->route));
$route = $this->navDataRepo->findWhereIn('id', $route_points);
@@ -251,6 +237,7 @@ class FlightService extends Service
throw new BidExists('A bid already exists for this flight');
}
} else {
/** @noinspection NestedPositiveIfStatementsInspection */
if ($flight->has_bid === true) {
Log::info('Bid exists, flight='.$flight->id.'; no entry in bids table, cleaning up');
}

View File

@@ -253,6 +253,9 @@ class GeoService extends Service
* Return a single feature point for the
*
* @param mixed $pireps
*
* @return mixed
* @return \GeoJson\Feature\FeatureCollection
*/
public function getFeatureForLiveFlights($pireps)
{

View File

@@ -4,7 +4,6 @@ namespace App\Services\ImportExport;
use App\Interfaces\ImportExport;
use App\Models\Aircraft;
use App\Models\Flight;
/**
* The flight importer can be imported or export. Operates on rows

View File

@@ -54,6 +54,7 @@ class AircraftImporter extends ImportExport
* @param int $index
*
* @return bool
* @throws \Exception
*/
public function import(array $row, $index): bool
{

View File

@@ -34,7 +34,7 @@ class AviationWeather extends Metar
try {
$res = Http::get($url, []);
$xml = simplexml_load_string($res);
if (count($xml->data->METAR->raw_text) == 0) {
if (\count($xml->data->METAR->raw_text) === 0) {
return '';
}
return $xml->data->METAR->raw_text->__toString();

View File

@@ -31,23 +31,19 @@ class PirepService extends Service
{
private $geoSvc;
private $pilotSvc;
private $pirepRepo;
/**
* PirepService constructor.
*
* @param GeoService $geoSvc
* @param PirepRepository $pirepRepo
* @param UserService $pilotSvc
*/
public function __construct(
GeoService $geoSvc,
PirepRepository $pirepRepo,
UserService $pilotSvc
) {
$this->geoSvc = $geoSvc;
$this->pilotSvc = $pilotSvc;
$this->pirepRepo = $pirepRepo;
}
/**
@@ -200,6 +196,7 @@ class PirepService extends Service
* Submit the PIREP. Figure out its default state
*
* @param Pirep $pirep
* @throws \Exception
*/
public function submit(Pirep $pirep)
{
@@ -306,6 +303,7 @@ class PirepService extends Service
* @param Pirep $pirep
*
* @return Pirep
* @throws \Exception
*/
public function accept(Pirep $pirep): Pirep
{