From e95b3eb366ccc786e9109fdfb5a8971431bd11da Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Sun, 26 Aug 2018 13:50:08 -0500 Subject: [PATCH] Code cleanup from inspection results --- app/Console/Commands/AcarsReplay.php | 3 +- app/Console/Commands/ComposerCommand.php | 1 + app/Console/Commands/Version.php | 1 + app/Console/Kernel.php | 10 ----- app/Console/Services/Importer.php | 9 +++-- app/Exceptions/Handler.php | 15 -------- app/Facades/Utils.php | 27 +++++++++----- .../Controllers/Admin/AircraftController.php | 16 +++++--- .../Controllers/Admin/DashboardController.php | 7 +++- .../Controllers/Admin/FlightController.php | 5 ++- .../Admin/PirepFieldController.php | 1 + .../Controllers/Admin/SubfleetController.php | 2 + app/Http/Controllers/Api/AcarsController.php | 7 +--- app/Http/Controllers/Api/PirepController.php | 2 + app/Http/Controllers/Api/UserController.php | 4 -- .../Frontend/AirportController.php | 3 ++ .../Frontend/DownloadController.php | 5 ++- .../Controllers/Frontend/PirepController.php | 3 +- app/Http/Middleware/EncryptCookies.php | 4 +- app/Http/Middleware/MeasureExecutionTime.php | 2 +- app/Http/Middleware/VerifyCsrfToken.php | 3 +- app/Http/Requests/Acars/CommentRequest.php | 9 +---- app/Http/Requests/Acars/PositionRequest.php | 1 - app/Http/Requests/Acars/PrefileRequest.php | 1 - app/Http/Resources/AcarsLog.php | 12 +----- app/Http/Resources/AcarsRoute.php | 13 +------ app/Http/Resources/Aircraft.php | 5 +-- app/Http/Resources/Airport.php | 5 +-- app/Http/Resources/Response.php | 12 +----- app/Interfaces/Award.php | 2 +- app/Interfaces/Controller.php | 1 + app/Interfaces/Enum.php | 4 +- app/Interfaces/ImportExport.php | 2 +- app/Interfaces/Repository.php | 2 +- app/Models/Acars.php | 4 +- app/Models/Award.php | 4 +- app/Models/Flight.php | 3 +- app/Models/Observers/AircraftObserver.php | 1 + app/Models/Pirep.php | 37 +++++++++++-------- app/Providers/AppServiceProvider.php | 1 + app/Providers/RouteServiceProvider.php | 12 ------ app/Repositories/SettingRepository.php | 13 +------ app/Services/DatabaseService.php | 1 + app/Services/FareService.php | 2 +- app/Services/Finance/PirepFinanceService.php | 7 +--- app/Services/FlightService.php | 23 +++--------- app/Services/GeoService.php | 3 ++ .../ImportExport/AircraftExporter.php | 1 - .../ImportExport/AircraftImporter.php | 1 + app/Services/Metar/AviationWeather.php | 2 +- app/Services/PirepService.php | 6 +-- app/Support/ICAO.php | 1 + app/Support/Metar.php | 23 +++++++----- app/Support/TimezonelistExtended.php | 20 +++++----- app/helpers.php | 6 +-- bootstrap/application.php | 4 +- composer.json | 4 ++ .../Http/Controllers/InstallerController.php | 1 + .../Providers/InstallerServiceProvider.php | 19 ++++++---- .../Services/RequirementsService.php | 2 +- .../Providers/SampleServiceProvider.php | 19 ++++++---- .../Providers/AppServiceProvider.php | 7 +--- .../Providers/EventServiceProvider.php | 9 ----- resources/lang/en/errors.php | 6 +-- resources/lang/es/errors.php | 6 +-- resources/lang/it/errors.php | 6 +-- tests/AcarsTest.php | 5 ++- tests/ApiTest.php | 4 ++ tests/FlightTest.php | 5 ++- tests/GeoTest.php | 1 + tests/ImporterTest.php | 1 + tests/PIREPTest.php | 9 ++++- tests/RegistrationTest.php | 1 + tests/TestCase.php | 11 +++--- tests/TestData.php | 1 + tests/UtilsTest.php | 3 ++ 76 files changed, 226 insertions(+), 268 deletions(-) diff --git a/app/Console/Commands/AcarsReplay.php b/app/Console/Commands/AcarsReplay.php index f52671d2..efb3f545 100644 --- a/app/Console/Commands/AcarsReplay.php +++ b/app/Console/Commands/AcarsReplay.php @@ -241,7 +241,7 @@ class AcarsReplay extends Command * * @return mixed */ - public function handle() + public function handle(): void { $files = $this->argument('files'); $manual_mode = $this->option('manual'); @@ -249,6 +249,7 @@ class AcarsReplay extends Command if ($this->option('write-all')) { $this->info('In "dump-all" mode, just writing it all in'); } else { + /** @noinspection NestedPositiveIfStatementsInspection */ if (!$manual_mode) { $this->info('Going to send updates every 10s'); } else { diff --git a/app/Console/Commands/ComposerCommand.php b/app/Console/Commands/ComposerCommand.php index 086cb311..8b238f6a 100644 --- a/app/Console/Commands/ComposerCommand.php +++ b/app/Console/Commands/ComposerCommand.php @@ -33,6 +33,7 @@ class ComposerCommand extends Command protected function postUpdate(): void { if (config('app.env') === 'dev') { + /** @noinspection NestedPositiveIfStatementsInspection */ if (class_exists(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class)) { Artisan::call('ide-helper:generate'); Artisan::call('ide-helper:meta'); diff --git a/app/Console/Commands/Version.php b/app/Console/Commands/Version.php index cd153de6..6742b97d 100644 --- a/app/Console/Commands/Version.php +++ b/app/Console/Commands/Version.php @@ -16,6 +16,7 @@ class Version extends Command * Create the version number that gets written out * * @param mixed $cfg + * @return bool|string */ protected function createVersionNumber($cfg) { diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 76008907..a7a88416 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -14,16 +14,6 @@ use Illuminate\Foundation\Console\Kernel as ConsoleKernel; */ class Kernel extends ConsoleKernel { - protected $commands = [ - /*Commands\AcarsReplay::class, - Commands\CreateDatabase::class, - Commands\DevCommands::class, - Commands\YamlImport::class, - Commands\ImportFromClassic::class, - Commands\NavdataImport::class, - Commands\TestApi::class,*/ - ]; - /** * Define the application's command schedule. * diff --git a/app/Console/Services/Importer.php b/app/Console/Services/Importer.php index 305868be..09975504 100644 --- a/app/Console/Services/Importer.php +++ b/app/Console/Services/Importer.php @@ -43,7 +43,7 @@ class Importer /** * @var array */ - private $creds = []; + private $creds; /** * Hold the instance of the console logger @@ -55,8 +55,8 @@ class Importer /** * CONSTANTS */ - const BATCH_READ_ROWS = 300; - const SUBFLEET_NAME = 'Imported Aircraft'; + public const BATCH_READ_ROWS = 300; + public const SUBFLEET_NAME = 'Imported Aircraft'; /** * Importer constructor. @@ -140,11 +140,12 @@ class Importer } /** - * @param string $message + * @param string|array $message */ protected function info($message) { if (\is_array($message)) { + /** @noinspection ForgottenDebugOutputInspection */ print_r($message); } else { $this->log->writeln(''.$message.''); diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 4d0ea56b..0f620ecd 100755 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -28,21 +28,6 @@ class Handler extends ExceptionHandler \Illuminate\Validation\ValidationException::class, ]; - /** - * Report or log an exception. - * This is a great spot to send exceptions to Sentry, Bugsnag, etc. - * - * @param \Exception $exception - * - * @throws Exception - * - * @return void - */ - public function report(Exception $exception) - { - parent::report($exception); - } - /** * Create an error message * diff --git a/app/Facades/Utils.php b/app/Facades/Utils.php index 6a17e0bd..67bba325 100644 --- a/app/Facades/Utils.php +++ b/app/Facades/Utils.php @@ -13,7 +13,7 @@ class Utils extends Facade /** * @return string */ - protected static function getFacadeAccessor() + protected static function getFacadeAccessor(): string { return 'utils'; } @@ -25,7 +25,7 @@ class Utils extends Facade * * @return bool */ - public static function isObject($obj) + public static function isObject($obj): bool { if (!$obj) { return false; @@ -42,14 +42,15 @@ class Utils extends Facade * Download a URI. If a file is given, it will save the downloaded * content into that file * - * @param $uri - * @param null $file + * @param string $uri + * @param null $file * * @throws \RuntimeException + * @throws \GuzzleHttp\Exception\GuzzleException * * @return string */ - public static function downloadUrl($uri, $file = null) + public static function downloadUrl($uri, $file = null): string { $opts = []; if ($file !== null) { @@ -72,12 +73,16 @@ class Utils extends Facade * * @return string */ - public static function generateApiKey() + public static function generateApiKey(): string { $key = substr(sha1(time().mt_rand()), 0, 20); return $key; } + /** + * @param string $minutes + * @return array + */ public static function minutesToTimeParts($minutes): array { $hours = floor($minutes / 60); @@ -95,9 +100,10 @@ class Utils extends Facade /** * Convert seconds to an array of hours, minutes, seconds * - * @param $seconds + * @param int $seconds * * @return array['h', 'm', 's'] + * @throws \Exception */ public static function secondsToTimeParts($seconds): array { @@ -117,10 +123,11 @@ class Utils extends Facade /** * Convert seconds to HH MM format * - * @param $seconds + * @param int $seconds * @param bool $incl_sec * * @return string + * @throws \Exception */ public static function secondsToTimeString($seconds, $incl_sec = false): string { @@ -191,7 +198,7 @@ class Utils extends Facade * * @return int */ - public static function setDays(int $datefield, array $day_enums) + public static function setDays(int $datefield, array $day_enums): int { foreach ($day_enums as $day) { $datefield |= $day; @@ -208,7 +215,7 @@ class Utils extends Facade * * @return bool */ - public static function hasDay(int $datefield, int $day_enum) + public static function hasDay(int $datefield, int $day_enum): bool { return ($datefield & $day_enum) === $datefield; } diff --git a/app/Http/Controllers/Admin/AircraftController.php b/app/Http/Controllers/Admin/AircraftController.php index 817debf3..eccee88a 100644 --- a/app/Http/Controllers/Admin/AircraftController.php +++ b/app/Http/Controllers/Admin/AircraftController.php @@ -45,8 +45,6 @@ class AircraftController extends Controller * * @param Request $request * - * @throws \Prettus\Repository\Exceptions\RepositoryException - * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function index(Request $request) @@ -101,6 +99,8 @@ class AircraftController extends Controller * Display the specified Aircraft. * * @param mixed $id + * + * @return mixed */ public function show($id) { @@ -120,6 +120,8 @@ class AircraftController extends Controller * Show the form for editing the specified Aircraft. * * @param mixed $id + * + * @return mixed */ public function edit($id) { @@ -143,6 +145,8 @@ class AircraftController extends Controller * @param mixed $id * * @throws \Prettus\Validator\Exceptions\ValidatorException + * + * @return mixed */ public function update($id, UpdateAircraftRequest $request) { @@ -164,6 +168,8 @@ class AircraftController extends Controller * Remove the specified Aircraft from storage. * * @param mixed $id + * + * @return mixed */ public function destroy($id) { @@ -187,7 +193,7 @@ class AircraftController extends Controller * * @throws \League\Csv\Exception * - * @return \Symfony\Component\HttpFoundation\BinaryFileResponse + * @return mixed */ public function export(Request $request) { @@ -207,7 +213,7 @@ class AircraftController extends Controller * * @throws \Illuminate\Validation\ValidationException * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return mixed */ public function import(Request $request) { @@ -254,7 +260,7 @@ class AircraftController extends Controller * * @throws \Exception * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return mixed */ public function expenses($id, Request $request) { diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index be9cba0b..5edd4805 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -45,7 +45,7 @@ class DashboardController extends Controller * S3 and then using the semver library to do the comparison. Just show * a session flash file on this page that'll get cleared right away * - * @throws \RuntimeException + * @throws \GuzzleHttp\Exception\GuzzleException */ protected function checkNewVersion() { @@ -65,7 +65,10 @@ class DashboardController extends Controller /** * Show the admin dashboard * - * @throws \RuntimeException + * @param Request $request + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @throws \GuzzleHttp\Exception\GuzzleException + * @throws \GuzzleHttp\Exception\GuzzleException */ public function index(Request $request) { diff --git a/app/Http/Controllers/Admin/FlightController.php b/app/Http/Controllers/Admin/FlightController.php index b0299713..3f970486 100644 --- a/app/Http/Controllers/Admin/FlightController.php +++ b/app/Http/Controllers/Admin/FlightController.php @@ -100,7 +100,7 @@ class FlightController extends Controller } Log::info('PIREP Custom Fields', $custom_fields); - $this->flightSvc->updateCustomFields($flight->id, $custom_fields); + $this->flightSvc->updateCustomFields($flight, $custom_fields); } /** @@ -483,6 +483,9 @@ class FlightController extends Controller * Get all the fares that haven't been assigned to a given subfleet * * @param mixed $flight + * + * @return mixed + * @return array */ protected function getAvailFares($flight) { diff --git a/app/Http/Controllers/Admin/PirepFieldController.php b/app/Http/Controllers/Admin/PirepFieldController.php index 7325b6e5..c67d6f29 100644 --- a/app/Http/Controllers/Admin/PirepFieldController.php +++ b/app/Http/Controllers/Admin/PirepFieldController.php @@ -129,6 +129,7 @@ class PirepFieldController extends Controller * * @param mixed $id * + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function update($id, UpdatePirepFieldRequest $request) diff --git a/app/Http/Controllers/Admin/SubfleetController.php b/app/Http/Controllers/Admin/SubfleetController.php index c0702b36..1809f9da 100644 --- a/app/Http/Controllers/Admin/SubfleetController.php +++ b/app/Http/Controllers/Admin/SubfleetController.php @@ -90,6 +90,7 @@ class SubfleetController extends Controller * Get all the fares that haven't been assigned to a given subfleet * * @param mixed $subfleet + * @return array */ protected function getAvailFares($subfleet) { @@ -268,6 +269,7 @@ class SubfleetController extends Controller * @param Request $request * * @return \Symfony\Component\HttpFoundation\BinaryFileResponse + * @throws \League\Csv\CannotInsertRecord */ public function export(Request $request) { diff --git a/app/Http/Controllers/Api/AcarsController.php b/app/Http/Controllers/Api/AcarsController.php index ff2b2ea1..56280f97 100644 --- a/app/Http/Controllers/Api/AcarsController.php +++ b/app/Http/Controllers/Api/AcarsController.php @@ -15,7 +15,6 @@ use App\Models\Pirep; use App\Repositories\AcarsRepository; use App\Repositories\PirepRepository; use App\Services\GeoService; -use App\Services\PirepService; use Auth; use Carbon\Carbon; use Illuminate\Http\Request; @@ -29,7 +28,6 @@ class AcarsController extends Controller private $acarsRepo; private $geoSvc; private $pirepRepo; - private $pirepSvc; /** * AcarsController constructor. @@ -37,18 +35,15 @@ class AcarsController extends Controller * @param AcarsRepository $acarsRepo * @param GeoService $geoSvc * @param PirepRepository $pirepRepo - * @param PirepService $pirepSvc */ public function __construct( AcarsRepository $acarsRepo, GeoService $geoSvc, - PirepRepository $pirepRepo, - PirepService $pirepSvc + PirepRepository $pirepRepo ) { $this->geoSvc = $geoSvc; $this->acarsRepo = $acarsRepo; $this->pirepRepo = $pirepRepo; - $this->pirepSvc = $pirepSvc; } /** diff --git a/app/Http/Controllers/Api/PirepController.php b/app/Http/Controllers/Api/PirepController.php index d47e7911..4db7ffd0 100644 --- a/app/Http/Controllers/Api/PirepController.php +++ b/app/Http/Controllers/Api/PirepController.php @@ -222,6 +222,7 @@ class PirepController extends Controller $pirep = new Pirep($attrs); // See if this user is at the current airport + /** @noinspection NotOptimalIfConditionsInspection */ if (setting('pilots.only_flights_from_current') && $user->curr_airport_id !== $pirep->dpt_airport_id) { throw new UserNotAtAirport(); @@ -234,6 +235,7 @@ class PirepController extends Controller } // See if this aircraft is at the departure airport + /** @noinspection NotOptimalIfConditionsInspection */ if (setting('pireps.only_aircraft_at_dpt_airport') && $pirep->aircraft_id !== $pirep->dpt_airport_id) { throw new AircraftNotAtAirport(); diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index b86392a6..5b833993 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -29,7 +29,6 @@ class UserController extends Controller private $flightRepo; private $flightSvc; private $pirepRepo; - private $subfleetRepo; private $userRepo; private $userSvc; @@ -39,7 +38,6 @@ class UserController extends Controller * @param FlightRepository $flightRepo * @param FlightService $flightSvc * @param PirepRepository $pirepRepo - * @param SubfleetRepository $subfleetRepo * @param UserRepository $userRepo * @param UserService $userSvc */ @@ -47,14 +45,12 @@ class UserController extends Controller FlightRepository $flightRepo, FlightService $flightSvc, PirepRepository $pirepRepo, - SubfleetRepository $subfleetRepo, UserRepository $userRepo, UserService $userSvc ) { $this->flightRepo = $flightRepo; $this->flightSvc = $flightSvc; $this->pirepRepo = $pirepRepo; - $this->subfleetRepo = $subfleetRepo; $this->userRepo = $userRepo; $this->userSvc = $userSvc; } diff --git a/app/Http/Controllers/Frontend/AirportController.php b/app/Http/Controllers/Frontend/AirportController.php index cfc34388..f9039252 100644 --- a/app/Http/Controllers/Frontend/AirportController.php +++ b/app/Http/Controllers/Frontend/AirportController.php @@ -28,6 +28,9 @@ class AirportController extends Controller * Show the airport * * @param mixed $id + * + * @return mixed + * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View */ public function show($id, Request $request) { diff --git a/app/Http/Controllers/Frontend/DownloadController.php b/app/Http/Controllers/Frontend/DownloadController.php index 28aa0e38..3d1972e9 100644 --- a/app/Http/Controllers/Frontend/DownloadController.php +++ b/app/Http/Controllers/Frontend/DownloadController.php @@ -54,7 +54,10 @@ class DownloadController extends Controller /** * Show the application dashboard. * - * @param mixed $id + * @param string $id + * + * @return mixed + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Symfony\Component\HttpFoundation\StreamedResponse */ public function show($id) { diff --git a/app/Http/Controllers/Frontend/PirepController.php b/app/Http/Controllers/Frontend/PirepController.php index a494af7b..a9538837 100644 --- a/app/Http/Controllers/Frontend/PirepController.php +++ b/app/Http/Controllers/Frontend/PirepController.php @@ -284,6 +284,7 @@ class PirepController extends Controller } // is the aircraft in the right place? + /** @noinspection NotOptimalIfConditionsInspection */ if (setting('pireps.only_aircraft_at_dpt_airport') && $pirep->aircraft_id !== $pirep->dpt_airport_id) { return $this->flashError( @@ -356,7 +357,7 @@ class PirepController extends Controller // set the custom fields foreach ($pirep->fields as $field) { - if ($field->slug == null) { + if ($field->slug === null) { $field->slug = str_slug($field->name); } diff --git a/app/Http/Middleware/EncryptCookies.php b/app/Http/Middleware/EncryptCookies.php index 3aa15f8d..15a20c00 100755 --- a/app/Http/Middleware/EncryptCookies.php +++ b/app/Http/Middleware/EncryptCookies.php @@ -11,7 +11,5 @@ class EncryptCookies extends BaseEncrypter * * @var array */ - protected $except = [ - // - ]; + protected $except = []; } diff --git a/app/Http/Middleware/MeasureExecutionTime.php b/app/Http/Middleware/MeasureExecutionTime.php index b83329d6..59139ce0 100644 --- a/app/Http/Middleware/MeasureExecutionTime.php +++ b/app/Http/Middleware/MeasureExecutionTime.php @@ -21,7 +21,7 @@ class MeasureExecutionTime { // Get the response $response = $next($request); - if (!defined('LUMEN_START')) { + if (!\defined('LUMEN_START')) { return $response; } diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index 0faba9ee..9c26fd50 100755 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -11,6 +11,5 @@ class VerifyCsrfToken extends BaseVerifier * * @var array */ - protected $except = [ - ]; + protected $except = []; } diff --git a/app/Http/Requests/Acars/CommentRequest.php b/app/Http/Requests/Acars/CommentRequest.php index 83feded9..1493c185 100644 --- a/app/Http/Requests/Acars/CommentRequest.php +++ b/app/Http/Requests/Acars/CommentRequest.php @@ -5,16 +5,11 @@ namespace App\Http\Requests\Acars; use App\Interfaces\FormRequest; /** - * Class FileRequest + * Class CommentRequest */ class CommentRequest extends FormRequest { - public function authorize() - { - return true; // Anyone can comment - } - - public function rules() + public function rules(): array { $rules = [ 'comment' => 'required', diff --git a/app/Http/Requests/Acars/PositionRequest.php b/app/Http/Requests/Acars/PositionRequest.php index 5aef5163..d637ca4d 100644 --- a/app/Http/Requests/Acars/PositionRequest.php +++ b/app/Http/Requests/Acars/PositionRequest.php @@ -3,7 +3,6 @@ namespace App\Http\Requests\Acars; use App\Interfaces\FormRequest; -use App\Models\Acars; use App\Models\Pirep; use Auth; diff --git a/app/Http/Requests/Acars/PrefileRequest.php b/app/Http/Requests/Acars/PrefileRequest.php index 14d7c989..8344bbb2 100644 --- a/app/Http/Requests/Acars/PrefileRequest.php +++ b/app/Http/Requests/Acars/PrefileRequest.php @@ -3,7 +3,6 @@ namespace App\Http\Requests\Acars; use App\Interfaces\FormRequest; -use App\Models\Pirep; /** * Class PrefileRequest diff --git a/app/Http/Resources/AcarsLog.php b/app/Http/Resources/AcarsLog.php index 3d86cf23..3c2bfb02 100644 --- a/app/Http/Resources/AcarsLog.php +++ b/app/Http/Resources/AcarsLog.php @@ -10,15 +10,5 @@ use Illuminate\Http\Resources\Json\Resource; */ class AcarsLog extends Resource { - public function toArray($request) - { - return parent::toArray($request); - /*return [ - 'id' => $this->id, - 'name' => $this->name, - 'log' => $this->log, - 'lat' => $this->lat, - 'lon' => $this->lon, - ];*/ - } + } diff --git a/app/Http/Resources/AcarsRoute.php b/app/Http/Resources/AcarsRoute.php index 9e756683..89cc09f2 100644 --- a/app/Http/Resources/AcarsRoute.php +++ b/app/Http/Resources/AcarsRoute.php @@ -10,16 +10,5 @@ use Illuminate\Http\Resources\Json\Resource; */ class AcarsRoute extends Resource { - public function toArray($request) - { - return parent::toArray($request); - /*return [ - 'id' => $this->id, - 'name' => $this->name, - 'order' => $this->order, - 'nav_type' => $this->nav_type, - 'lat' => $this->lat, - 'lon' => $this->lon, - ];*/ - } + } diff --git a/app/Http/Resources/Aircraft.php b/app/Http/Resources/Aircraft.php index aa410fca..aa62694b 100644 --- a/app/Http/Resources/Aircraft.php +++ b/app/Http/Resources/Aircraft.php @@ -6,8 +6,5 @@ use Illuminate\Http\Resources\Json\Resource; class Aircraft extends Resource { - public function toArray($request) - { - return parent::toArray($request); - } + } diff --git a/app/Http/Resources/Airport.php b/app/Http/Resources/Airport.php index 53b95ef9..0a255653 100644 --- a/app/Http/Resources/Airport.php +++ b/app/Http/Resources/Airport.php @@ -6,8 +6,5 @@ use Illuminate\Http\Resources\Json\Resource; class Airport extends Resource { - public function toArray($request) - { - return parent::toArray($request); - } + } diff --git a/app/Http/Resources/Response.php b/app/Http/Resources/Response.php index bbf0cc65..0c285709 100644 --- a/app/Http/Resources/Response.php +++ b/app/Http/Resources/Response.php @@ -9,15 +9,5 @@ use Illuminate\Http\Resources\Json\Resource; */ class Response extends Resource { - /** - * Transform the resource into an array. - * - * @param \Illuminate\Http\Request $request - * - * @return array - */ - public function toArray($request) - { - return parent::toArray($request); - } + } diff --git a/app/Interfaces/Award.php b/app/Interfaces/Award.php index 389cc4aa..2301e126 100644 --- a/app/Interfaces/Award.php +++ b/app/Interfaces/Award.php @@ -96,7 +96,7 @@ abstract class Award $e->getTrace() ); - return; + return false; } return $award; diff --git a/app/Interfaces/Controller.php b/app/Interfaces/Controller.php index 4cd35885..ee539c25 100755 --- a/app/Interfaces/Controller.php +++ b/app/Interfaces/Controller.php @@ -62,6 +62,7 @@ abstract class Controller extends \Illuminate\Routing\Controller $fields[$field] = $request->input($field); } } else { + /** @noinspection NestedPositiveIfStatementsInspection */ if (array_key_exists($field, $request)) { $fields[$field] = $request[$field]; } diff --git a/app/Interfaces/Enum.php b/app/Interfaces/Enum.php index 72778b30..2db997c2 100644 --- a/app/Interfaces/Enum.php +++ b/app/Interfaces/Enum.php @@ -138,7 +138,7 @@ abstract class Enum */ final public function equals(self $enum): bool { - return $this->getValue() === $enum->getValue() && get_called_class() == get_class($enum); + return $this->getValue() === $enum->getValue() && static::class === \get_class($enum); } /** @@ -161,7 +161,7 @@ abstract class Enum } throw new \BadMethodCallException( - "No static method or enum constant '$name' in class ".get_called_class() + "No static method or enum constant '$name' in class ".static::class ); } } diff --git a/app/Interfaces/ImportExport.php b/app/Interfaces/ImportExport.php index 0b25a15b..72c584ef 100644 --- a/app/Interfaces/ImportExport.php +++ b/app/Interfaces/ImportExport.php @@ -51,7 +51,7 @@ class ImportExport * * @param $code * - * @return Airline + * @return \Illuminate\Database\Eloquent\Model */ public function getAirline($code) { diff --git a/app/Interfaces/Repository.php b/app/Interfaces/Repository.php index 89e5cabf..26aa6236 100644 --- a/app/Interfaces/Repository.php +++ b/app/Interfaces/Repository.php @@ -15,7 +15,7 @@ abstract class Repository extends \Prettus\Repository\Eloquent\BaseRepository * * @return mixed|null */ - public function findWithoutFail($id, $columns = ['*']) + public function findWithoutFail($id, array $columns = ['*']) { try { return $this->find($id, $columns); diff --git a/app/Models/Acars.php b/app/Models/Acars.php index dffba7b7..f3bcdfe8 100644 --- a/app/Models/Acars.php +++ b/app/Models/Acars.php @@ -87,7 +87,7 @@ class Acars extends Model public function getDistanceAttribute() { if (!array_key_exists('distance', $this->attributes)) { - return; + return 0; } try { @@ -127,7 +127,7 @@ class Acars extends Model public function getFuelAttribute() { if (!array_key_exists('fuel', $this->attributes)) { - return; + return 0; } try { diff --git a/app/Models/Award.php b/app/Models/Award.php index 4a3dce33..9f624759 100755 --- a/app/Models/Award.php +++ b/app/Models/Award.php @@ -34,8 +34,8 @@ class Award extends Model /** * Get the referring object * - * @param Award|null $award - * @param User|null $user + * @param self $award + * @param User|null $user * * @return null */ diff --git a/app/Models/Flight.php b/app/Models/Flight.php index f5e65d34..9dd9dce2 100644 --- a/app/Models/Flight.php +++ b/app/Models/Flight.php @@ -104,6 +104,7 @@ class Flight extends Model */ public static function findByDays(array $days) { + /** @noinspection DynamicInvocationViaScopeResolutionInspection */ $flights = self::where('active', true); foreach ($days as $day) { $flights = $flights->where('days', '&', $day); @@ -139,7 +140,7 @@ class Flight extends Model public function getDistanceAttribute() { if (!array_key_exists('distance', $this->attributes)) { - return; + return 0; } try { diff --git a/app/Models/Observers/AircraftObserver.php b/app/Models/Observers/AircraftObserver.php index 05b3138e..0c9d8f14 100644 --- a/app/Models/Observers/AircraftObserver.php +++ b/app/Models/Observers/AircraftObserver.php @@ -12,6 +12,7 @@ class AircraftObserver { /** * @param Aircraft $aircraft + * @throws \Exception */ public function creating(Aircraft $aircraft): void { diff --git a/app/Models/Pirep.php b/app/Models/Pirep.php index e908169b..493524cd 100644 --- a/app/Models/Pirep.php +++ b/app/Models/Pirep.php @@ -21,9 +21,9 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName; * @property string flight_number * @property string route_code * @property string route_leg - * @property int airline_id - * @property int user_id - * @property int aircraft_id + * @property int airline_id + * @property int user_id + * @property int aircraft_id * @property Aircraft aircraft * @property Airline airline * @property Airport arr_airport @@ -32,13 +32,13 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName; * @property string dpt_airport_id * @property Carbon block_off_time * @property Carbon block_on_time - * @property int block_time - * @property int flight_time In minutes - * @property int planned_flight_time - * @property float distance - * @property float planned_distance + * @property int block_time + * @property int flight_time In minutes + * @property int planned_flight_time + * @property float distance + * @property float planned_distance * @property string route - * @property int score + * @property int score * @property User user * @property Flight|null flight * @property Collection fields @@ -50,6 +50,7 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName; * @property bool read_only * @property Acars position * @property Acars[] acars + * @property mixed cancelled */ class Pirep extends Model { @@ -160,25 +161,29 @@ class Pirep extends Model /** * Return the block off time in carbon format * - * @return Carbon + * @return Carbon|null */ public function getBlockOffTimeAttribute() { if (array_key_exists('block_off_time', $this->attributes)) { return new Carbon($this->attributes['block_off_time']); } + + return null; } /** * Return the block on time * - * @return Carbon + * @return Carbon|null */ public function getBlockOnTimeAttribute() { if (array_key_exists('block_on_time', $this->attributes)) { return new Carbon($this->attributes['block_on_time']); } + + return null; } /** @@ -191,6 +196,8 @@ class Pirep extends Model if (array_key_exists('submitted_at', $this->attributes)) { return new Carbon($this->attributes['submitted_at']); } + + return null; } /** @@ -201,7 +208,7 @@ class Pirep extends Model public function getDistanceAttribute() { if (!array_key_exists('distance', $this->attributes)) { - return; + return 0; } try { @@ -249,7 +256,7 @@ class Pirep extends Model public function getFuelUsedAttribute() { if (!array_key_exists('fuel_used', $this->attributes)) { - return; + return 0; } try { @@ -271,7 +278,7 @@ class Pirep extends Model public function getPlannedDistanceAttribute() { if (!array_key_exists('planned_distance', $this->attributes)) { - return; + return 0; } try { @@ -401,7 +408,7 @@ class Pirep extends Model /** * Return if this is cancelled or not */ - public function getCancelledAttribute() + public function getCancelledAttribute(): bool { return $this->state === PirepState::CANCELLED; } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 165f6ad3..77bc4f50 100755 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -64,6 +64,7 @@ class AppServiceProvider extends ServiceProvider if ($this->app->environment() === 'dev') { // Only load the IDE helper if it's included. This lets use distribute the // package without any dev dependencies + /** @noinspection NestedPositiveIfStatementsInspection */ if (class_exists(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class)) { $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class); } diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 12e9f337..6f0382f9 100755 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -16,18 +16,6 @@ class RouteServiceProvider extends ServiceProvider */ protected $namespace = 'App\Http\Controllers'; - /** - * Define your route model bindings, pattern filters, etc. - * - * @return void - */ - public function boot() - { - // - - parent::boot(); - } - /** * Define the routes for the application. * diff --git a/app/Repositories/SettingRepository.php b/app/Repositories/SettingRepository.php index bfa60142..0f542c25 100644 --- a/app/Repositories/SettingRepository.php +++ b/app/Repositories/SettingRepository.php @@ -51,25 +51,15 @@ class SettingRepository extends Repository implements CacheableInterface case 'bool': case 'boolean': $value = $setting->value; - if ($value === 'true' || $value === '1') { - $value = true; - } elseif ($value === 'false' || $value === '0') { - $value = false; - } - - return (bool) $value; - break; + return $value === 'true' || $value === '1' || $value === 1; case 'date': return Carbon::parse($setting->value); - break; case 'int': case 'integer': case 'number': return (int) $setting->value; - break; case 'float': return (float) $setting->value; - break; default: return $setting->value; } @@ -80,6 +70,7 @@ class SettingRepository extends Repository implements CacheableInterface * * @param mixed $key * @param mixed $value + * @return null */ public function save($key, $value) { diff --git a/app/Services/DatabaseService.php b/app/Services/DatabaseService.php index f3f43104..70b492ba 100644 --- a/app/Services/DatabaseService.php +++ b/app/Services/DatabaseService.php @@ -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; } diff --git a/app/Services/FareService.php b/app/Services/FareService.php index 5bdc1cd7..bb8a0abd 100644 --- a/app/Services/FareService.php +++ b/app/Services/FareService.php @@ -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); } diff --git a/app/Services/Finance/PirepFinanceService.php b/app/Services/Finance/PirepFinanceService.php index e4169e92..2dc07134 100644 --- a/app/Services/Finance/PirepFinanceService.php +++ b/app/Services/Finance/PirepFinanceService.php @@ -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; diff --git a/app/Services/FlightService.php b/app/Services/FlightService.php index 89f75faf..a5d409bf 100644 --- a/app/Services/FlightService.php +++ b/app/Services/FlightService.php @@ -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'); } diff --git a/app/Services/GeoService.php b/app/Services/GeoService.php index cb8cca6b..8500c367 100644 --- a/app/Services/GeoService.php +++ b/app/Services/GeoService.php @@ -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) { diff --git a/app/Services/ImportExport/AircraftExporter.php b/app/Services/ImportExport/AircraftExporter.php index 554e7d4e..b5f92483 100644 --- a/app/Services/ImportExport/AircraftExporter.php +++ b/app/Services/ImportExport/AircraftExporter.php @@ -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 diff --git a/app/Services/ImportExport/AircraftImporter.php b/app/Services/ImportExport/AircraftImporter.php index 24d66b55..eac8e9d5 100644 --- a/app/Services/ImportExport/AircraftImporter.php +++ b/app/Services/ImportExport/AircraftImporter.php @@ -54,6 +54,7 @@ class AircraftImporter extends ImportExport * @param int $index * * @return bool + * @throws \Exception */ public function import(array $row, $index): bool { diff --git a/app/Services/Metar/AviationWeather.php b/app/Services/Metar/AviationWeather.php index 092a70a5..91b38e71 100644 --- a/app/Services/Metar/AviationWeather.php +++ b/app/Services/Metar/AviationWeather.php @@ -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(); diff --git a/app/Services/PirepService.php b/app/Services/PirepService.php index 7e094469..53389684 100644 --- a/app/Services/PirepService.php +++ b/app/Services/PirepService.php @@ -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 { diff --git a/app/Support/ICAO.php b/app/Support/ICAO.php index 2c20f294..affdf22d 100644 --- a/app/Support/ICAO.php +++ b/app/Support/ICAO.php @@ -14,6 +14,7 @@ class ICAO * @param null $country * * @return string + * @throws \Exception */ public static function createHexCode($country = null) { diff --git a/app/Support/Metar.php b/app/Support/Metar.php index 0a98a928..37fe7e10 100644 --- a/app/Support/Metar.php +++ b/app/Support/Metar.php @@ -438,6 +438,7 @@ class Metar implements \ArrayAccess 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 ($this->result['cloud_height']['ft'] > 3000 && $this->result['visibility']['nmi'] > 5) { $this->result['category'] = 'VFR'; @@ -566,6 +567,7 @@ class Metar implements \ArrayAccess * Decodes TAF code if present. * * @param mixed $part + * @return bool */ private function get_taf($part) { @@ -770,6 +772,7 @@ class Metar implements \ArrayAccess if ($found[1] === 'CAVOK' || $found[1] === '9999') { $this->set_result_value('visibility', new Distance(10000, 'm')); $this->set_result_value('visibility_report', 'Greater than 10 km'); + /** @noinspection NotOptimalIfConditionsInspection */ if ($found[1] === 'CAVOK') { $this->set_result_value('cavok', true); $this->method += 4; // can skip the next 4 methods: visibility_min, runway_vr, present_weather, clouds @@ -887,7 +890,7 @@ class Metar implements \ArrayAccess ]; // Runway past tendency - if (isset($found[8]) && isset(static::$rvr_tendency_codes[$found[8]])) { + if (isset($found[8], static::$rvr_tendency_codes[$found[8]])) { $observed['tendency'] = $found[8]; } @@ -1002,7 +1005,7 @@ class Metar implements \ArrayAccess } } // Type - if (isset($found[6]) && !empty($found[6]) && isset(static::$cloud_type_codes[$found[6]]) && $found[4] != 'VV') { + if (isset($found[6], static::$cloud_type_codes[$found[6]]) && !empty($found[6]) && $found[4] !== 'VV') { $observed['type'] = $found[6]; } @@ -1204,13 +1207,13 @@ class Metar implements \ArrayAccess // Build runways report $report = []; - if (null !== $observed['deposits']) { + if ($observed['deposits'] !== null) { $report[] = static::$runway_deposits_codes[$observed['deposits']]; if (null !== $observed['deposits_extent']) { $report[] = 'contamination '.static::$runway_deposits_extent_codes[$observed['deposits_extent']]; } - if (null !== $observed['deposits_depth']) { + if ($observed['deposits_depth'] !== null) { if ($observed['deposits_depth'] === '99') { $report[] = 'runway closed'; } elseif (isset(static::$runway_deposits_depth_codes[$observed['deposits_depth']])) { @@ -1221,7 +1224,7 @@ class Metar implements \ArrayAccess } } - if (null !== $observed['friction']) { + if ($observed['friction'] !== null) { if (isset(static::$runway_friction_codes[$observed['friction']])) { $report[] = 'a braking action is '.static::$runway_friction_codes[$observed['friction']]; } else { @@ -1385,7 +1388,7 @@ class Metar implements \ArrayAccess while ($this->part < \count($this->raw_parts)) { if (preg_match($r, $this->raw_parts[$this->part], $found)) { // Get trend flag - if (isset($found[2]) && isset(static::$trends_flag_codes[$found[2]])) { + if (isset($found[2], static::$trends_flag_codes[$found[2]])) { $trend['flag'] = $found[2]; } // Get PROBpp formatted period @@ -1393,7 +1396,7 @@ class Metar implements \ArrayAccess $trend['probability'] = $found[4]; } // Get AT, FM, TL formatted period - elseif (isset($found[8]) && isset(static::$trends_time_codes[$found[5]])) { + elseif (isset($found[8], static::$trends_time_codes[$found[5]])) { $trend['period']['flag'] = $found[5]; if (!empty($found[6])) { $trend['period']['day'] = (int) $found[6]; @@ -1512,7 +1515,7 @@ class Metar implements \ArrayAccess $remarks = []; // Get all parts after - while ($this->part < count($this->raw_parts)) { + while ($this->part < \count($this->raw_parts)) { if (isset($this->raw_parts[$this->part])) { $remarks[] = $this->raw_parts[$this->part]; } @@ -1582,11 +1585,11 @@ class Metar implements \ArrayAccess } } - if (null !== $observed['characteristics']) { + if ($observed['characteristics'] !== null) { $report[] = static::$weather_char_codes[$observed['characteristics']]; } - if (null !== $observed['types']) { + if ($observed['types'] !== null) { foreach ($observed['types'] as $code) { $report[] = static::$weather_type_codes[$code]; } diff --git a/app/Support/TimezonelistExtended.php b/app/Support/TimezonelistExtended.php index a3554385..57b3b69c 100644 --- a/app/Support/TimezonelistExtended.php +++ b/app/Support/TimezonelistExtended.php @@ -15,20 +15,20 @@ class TimezonelistExtended extends Timezonelist * @param bool $htmlencode * * @return string + * @throws \Exception + * @throws \Exception */ protected function formatTimezone($timezone, $continent, $htmlencode = true) { $time = new \DateTimeImmutable(null, new DateTimeZone($timezone)); $offset = $time->format('P'); if ($htmlencode) { - $offset = str_replace('-', ' − ', $offset); - $offset = str_replace('+', ' + ', $offset); + $offset = str_replace(['-', '+'], array(' − ', ' + '), $offset); } - $timezone = substr($timezone, strlen($continent) + 1); - $timezone = str_replace('St_', 'St. ', $timezone); - $timezone = str_replace('_', ' ', $timezone); - $formatted = '(GMT/UTC'.$offset.')'.self::WHITESPACE_SEP.$timezone; - return $formatted; + $timezone = substr($timezone, \strlen($continent) + 1); + $timezone = str_replace(['St_', '_'], array('St. ', ' '), $timezone); + + return '(GMT/UTC'.$offset.')'.self::WHITESPACE_SEP.$timezone; } /** @@ -46,7 +46,7 @@ class TimezonelistExtended extends Timezonelist // Attributes for select element $attrSet = ''; if (!empty($attr)) { - if (is_array($attr)) { + if (\is_array($attr)) { foreach ($attr as $attr_name => $attr_value) { $attrSet .= ' '.$attr_name.'="'.$attr_value.'"'; } @@ -59,7 +59,7 @@ class TimezonelistExtended extends Timezonelist // Add popular timezones $listbox .= ''; foreach ($this->popularTimezones as $key => $value) { - $selected_attr = ($selected == $key) ? ' selected="selected"' : ''; + $selected_attr = ($selected === $key) ? ' selected="selected"' : ''; $listbox .= ''; } $listbox .= ''; @@ -70,7 +70,7 @@ class TimezonelistExtended extends Timezonelist $listbox .= ''; // create option tags foreach ($timezones as $timezone) { - $selected_attr = ($selected == $timezone) ? ' selected="selected"' : ''; + $selected_attr = ($selected === $timezone) ? ' selected="selected"' : ''; $listbox .= ''; diff --git a/app/helpers.php b/app/helpers.php index 20a254ee..c1e5e11b 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -111,7 +111,7 @@ if (!function_exists('skin_view')) { * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - function skin_view($template, array $vars = [], $merge_data = []) + function skin_view($template, array $vars = [], array $merge_data = []) { // Add the current skin name so we don't need to hardcode it in the templates // Makes it a bit easier to create a new skin by modifying an existing one @@ -149,7 +149,7 @@ if (!function_exists('setting')) { * set */ if (!function_exists('public_asset')) { - function public_asset($path, $parameters = [], $secure = null) + function public_asset($path, array $parameters = [], $secure = null) { $publicBaseUrl = app()->publicUrlPath(); $path = $publicBaseUrl.$path; @@ -174,7 +174,7 @@ if (!function_exists('show_datetime')) { */ function show_datetime(\Carbon\Carbon $date = null) { - if (empty($date)) { + if ($date === null) { return '-'; } diff --git a/bootstrap/application.php b/bootstrap/application.php index 1015571a..57d696ab 100644 --- a/bootstrap/application.php +++ b/bootstrap/application.php @@ -103,10 +103,10 @@ class application extends Illuminate\Foundation\Application return $this->basePath.DS.'config'.($path ? DS.$path : $path); } - public function environmentPath() + /*public function environmentPath() { return $this->environmentPath ?: $this->basePath; - } + }*/ public function langPath() { diff --git a/composer.json b/composer.json index d6d23de8..5517c54a 100755 --- a/composer.json +++ b/composer.json @@ -8,6 +8,10 @@ "homepage": "http://www.phpvms.net", "require": { "php": ">=7.1", + "ext-calendar": "*", + "ext-json": "*", + "ext-mbstring": "*", + "ext-pdo": "*", "laravel/framework": "^5.6", "laravelcollective/html": "5.6.x", "prettus/l5-repository": "2.6.x", diff --git a/modules/Installer/Http/Controllers/InstallerController.php b/modules/Installer/Http/Controllers/InstallerController.php index 6d1f35d9..a696ad76 100644 --- a/modules/Installer/Http/Controllers/InstallerController.php +++ b/modules/Installer/Http/Controllers/InstallerController.php @@ -259,6 +259,7 @@ class InstallerController extends Controller * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @throws \RuntimeException * @throws \Prettus\Validator\Exceptions\ValidatorException + * @throws \Exception */ public function usersetup(Request $request) { diff --git a/modules/Installer/Providers/InstallerServiceProvider.php b/modules/Installer/Providers/InstallerServiceProvider.php index ad6f1805..b584a218 100644 --- a/modules/Installer/Providers/InstallerServiceProvider.php +++ b/modules/Installer/Providers/InstallerServiceProvider.php @@ -2,14 +2,13 @@ namespace Modules\Installer\Providers; +use App\Services\ModuleService; use Illuminate\Database\Eloquent\Factory; use Illuminate\Support\ServiceProvider; use Route; - class InstallerServiceProvider extends ServiceProvider { - protected $defer = false; protected $moduleSvc; /** @@ -17,7 +16,7 @@ class InstallerServiceProvider extends ServiceProvider */ public function boot() { - $this->moduleSvc = app('App\Services\ModuleService'); + $this->moduleSvc = app(ModuleService::class); $this->registerRoutes(); $this->registerTranslations(); @@ -78,9 +77,15 @@ class InstallerServiceProvider extends ServiceProvider $sourcePath => $viewPath ],'views'); - $this->loadViewsFrom(array_merge(array_map(function ($path) { - return $path . '/modules/installer'; - }, \Config::get('view.paths')), [$sourcePath]), 'installer'); + $paths = array_map( + function ($path) { + return $path.'/modules/installer'; + }, + \Config::get('view.paths') + ); + + $paths[] = $sourcePath; + $this->loadViewsFrom($paths, 'installer'); } /** @@ -111,7 +116,7 @@ class InstallerServiceProvider extends ServiceProvider /** * Get the services provided by the provider. */ - public function provides() + public function provides(): array { return []; } diff --git a/modules/Installer/Services/RequirementsService.php b/modules/Installer/Services/RequirementsService.php index f3bba76b..09e92fd8 100644 --- a/modules/Installer/Services/RequirementsService.php +++ b/modules/Installer/Services/RequirementsService.php @@ -31,7 +31,7 @@ class RequirementsService extends Service $extensions = []; foreach(config('installer.extensions') as $ext) { $pass = true; - if(!extension_loaded($ext)) { + if(!\extension_loaded($ext)) { $pass = false; } diff --git a/modules/Sample/Providers/SampleServiceProvider.php b/modules/Sample/Providers/SampleServiceProvider.php index 2852a0d5..29956fe4 100644 --- a/modules/Sample/Providers/SampleServiceProvider.php +++ b/modules/Sample/Providers/SampleServiceProvider.php @@ -2,14 +2,13 @@ namespace Modules\Sample\Providers; +use App\Services\ModuleService; use Illuminate\Support\ServiceProvider; use Illuminate\Database\Eloquent\Factory; use Route; - class SampleServiceProvider extends ServiceProvider { - protected $defer = false; protected $moduleSvc; /** @@ -17,7 +16,7 @@ class SampleServiceProvider extends ServiceProvider */ public function boot() { - $this->moduleSvc = app('App\Services\ModuleService'); + $this->moduleSvc = app(ModuleService::class); $this->registerRoutes(); $this->registerTranslations(); @@ -121,9 +120,15 @@ class SampleServiceProvider extends ServiceProvider $sourcePath => $viewPath ],'views'); - $this->loadViewsFrom(array_merge(array_map(function ($path) { - return $path . '/modules/sample'; - }, \Config::get('view.paths')), [$sourcePath]), 'sample'); + $paths = array_map( + function ($path) { + return $path.'/modules/sample'; + }, + \Config::get('view.paths') + ); + + $paths[] = $sourcePath; + $this->loadViewsFrom($paths, 'sample'); } /** @@ -154,7 +159,7 @@ class SampleServiceProvider extends ServiceProvider /** * Get the services provided by the provider. */ - public function provides() + public function provides(): array { return []; } diff --git a/modules/Vacentral/Providers/AppServiceProvider.php b/modules/Vacentral/Providers/AppServiceProvider.php index 488e4e55..38af2731 100644 --- a/modules/Vacentral/Providers/AppServiceProvider.php +++ b/modules/Vacentral/Providers/AppServiceProvider.php @@ -3,13 +3,10 @@ namespace Modules\Vacentral\Providers; use Illuminate\Support\ServiceProvider; -use Illuminate\Database\Eloquent\Factory; -use Route; - +use App\Services\ModuleService; class AppServiceProvider extends ServiceProvider { - protected $defer = false; protected $moduleSvc; /** @@ -17,7 +14,7 @@ class AppServiceProvider extends ServiceProvider */ public function boot() { - $this->moduleSvc = app('App\Services\ModuleService'); + $this->moduleSvc = app(ModuleService::class); $this->registerConfig(); } diff --git a/modules/Vacentral/Providers/EventServiceProvider.php b/modules/Vacentral/Providers/EventServiceProvider.php index 4cddc53b..bea6449f 100644 --- a/modules/Vacentral/Providers/EventServiceProvider.php +++ b/modules/Vacentral/Providers/EventServiceProvider.php @@ -3,7 +3,6 @@ namespace Modules\Vacentral\Providers; use App\Events\PirepAccepted; -use App\Events\TestEvent; use Modules\Vacentral\Listeners\PirepAcceptedEventListener; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; @@ -15,12 +14,4 @@ class EventServiceProvider extends ServiceProvider protected $listen = [ PirepAccepted::class => [PirepAcceptedEventListener::class], ]; - - /** - * Register any events for your application. - */ - public function boot() - { - parent::boot(); - } } diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php index e3a88167..7806f398 100644 --- a/resources/lang/en/errors.php +++ b/resources/lang/en/errors.php @@ -2,17 +2,17 @@ return [ - '401' => [ + 401 => [ 'title' => 'Unauthorized Access', 'message' => 'Well, this is embarrassing, you are not authorized to access or perform this function. '. 'Click here to go back to the home page.', ], - '404' => [ + 404 => [ 'title' => 'Page Not Found', 'message' => 'Well, this is embarrassing, the page you requested does not exist.'. 'Click here to go back to the home page.', ], - '503' => [ + 503 => [ 'title' => 'Internal Error', 'message' => 'An Error Occured', ], diff --git a/resources/lang/es/errors.php b/resources/lang/es/errors.php index 85dd9cc9..5d85eabe 100644 --- a/resources/lang/es/errors.php +++ b/resources/lang/es/errors.php @@ -2,17 +2,17 @@ return [ - '401' => [ + 401 => [ 'title' => 'Acceso no autorizado', 'message' => 'Bueno, esto es embarazoso, no estás autorizado a acceder o realizar esta acción. '. 'Clic aquí para retroceder a la página de inicio.', ], - '404' => [ + 404 => [ 'title' => 'Página no encontrada', 'message' => 'Bueno, esto es embarazoso, la página solicitada no existe.'. 'Clic aquí para retroceder a la página de inicio.', ], - '503' => [ + 503 => [ 'title' => 'Error interno', 'message' => 'Ocurrió un error', ], diff --git a/resources/lang/it/errors.php b/resources/lang/it/errors.php index c2309709..516609a5 100644 --- a/resources/lang/it/errors.php +++ b/resources/lang/it/errors.php @@ -2,17 +2,17 @@ return [ - '401' => [ + 401 => [ 'title' => 'Non Autorizzato', 'message' => 'Beh, è imbarazzante, non sei autorizzato ad accedere o ad eseguire questa funzionalità. '. 'Clicca qui per tornare alla home page.', ], - '404' => [ + 404 => [ 'title' => 'Page Not Found', 'message' => 'Beh, è imbarazzante, la pagina che hai richiesto non esiste.'. 'Clicca qui per tornare alla home page.', ], - '503' => [ + 503 => [ 'title' => 'Internal Error', 'message' => 'Torniamo subito.', ], diff --git a/tests/AcarsTest.php b/tests/AcarsTest.php index 848e191a..4b54f36e 100644 --- a/tests/AcarsTest.php +++ b/tests/AcarsTest.php @@ -24,7 +24,7 @@ class AcarsTest extends TestCase * @param $points * @param array $addtl_fields */ - protected function allPointsInRoute($route, $points, $addtl_fields = []) + protected function allPointsInRoute($route, $points, array $addtl_fields = []) { if (empty($addtl_fields)) { $addtl_fields = []; @@ -40,7 +40,7 @@ class AcarsTest extends TestCase $addtl_fields ); - $this->assertEquals(\count($route), \count($points)); + $this->assertCount(\count($route), $points); foreach ($route as $idx => $point) { $this->assertHasKeys($points[$idx], $fields); foreach ($fields as $f) { @@ -556,6 +556,7 @@ class AcarsTest extends TestCase /** * Test publishing multiple, batched updates + * @throws Exception */ public function testMultipleAcarsPositionUpdates() { diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 47d0d754..bd963227 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -71,6 +71,9 @@ class ApiTest extends TestCase $this->assertTrue(array_key_exists('user', $response['data'][0])); } + /** + * @throws Exception + */ public function testGetAirlines() { $size = \random_int(5, 10); @@ -134,6 +137,7 @@ class ApiTest extends TestCase /** * Test getting the subfleets + * @throws Exception */ public function testGetSubfleets() { diff --git a/tests/FlightTest.php b/tests/FlightTest.php index f8a2d6d8..f887d428 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -123,6 +123,7 @@ class FlightTest extends TestCase /** * Get the flight's route + * @throws Exception */ public function testFlightRoute() { @@ -398,7 +399,7 @@ class FlightTest extends TestCase $req->assertStatus(200); $body = $req->json()['data']; - $this->assertEquals(1, count($body['bids'])); + $this->assertCount(1, $body['bids']); $this->assertEquals($flight->id, $body['bids'][0]['flight_id']); $req = $this->get('/api/users/'.$user->id.'/bids', $headers); @@ -435,7 +436,7 @@ class FlightTest extends TestCase $body = $req->json()['data']; $this->assertEquals($user->id, $body['id']); - $this->assertEquals(0, count($body['bids'])); + $this->assertCount(0, $body['bids']); $req = $this->get('/api/users/'.$user->id.'/bids', $headers); $req->assertStatus(200); diff --git a/tests/GeoTest.php b/tests/GeoTest.php index 2a54f546..bad765c2 100644 --- a/tests/GeoTest.php +++ b/tests/GeoTest.php @@ -35,6 +35,7 @@ class GeoTest extends TestCase /** * Make sure the departure airports/sid/star are all filtered out + * @throws Exception */ public function testGetCoords() { diff --git a/tests/ImporterTest.php b/tests/ImporterTest.php index df42cb9a..f2b9e001 100644 --- a/tests/ImporterTest.php +++ b/tests/ImporterTest.php @@ -228,6 +228,7 @@ class ImporterTest extends TestCase /** * Test exporting all the flights to a file + * @throws \Illuminate\Validation\ValidationException */ public function testAircraftExporter(): void { diff --git a/tests/PIREPTest.php b/tests/PIREPTest.php index ba01c565..aec1687c 100644 --- a/tests/PIREPTest.php +++ b/tests/PIREPTest.php @@ -49,6 +49,9 @@ class PIREPTest extends TestCase return $saved_route; } + /** + * @throws Exception + */ public function testAddPirep() { $user = factory(App\Models\User::class)->create(); @@ -59,7 +62,11 @@ class PIREPTest extends TestCase ]); $pirep = $this->pirepSvc->create($pirep, []); - $this->pirepSvc->saveRoute($pirep); + try { + $this->pirepSvc->saveRoute($pirep); + } catch (Exception $e) { + throw $e; + } /* * Check the initial state info diff --git a/tests/RegistrationTest.php b/tests/RegistrationTest.php index 5a8e4ccc..38ffb630 100644 --- a/tests/RegistrationTest.php +++ b/tests/RegistrationTest.php @@ -9,6 +9,7 @@ class RegistrationTest extends TestCase * A basic test example. * * @return void + * @throws Exception */ public function testRegistration() { diff --git a/tests/TestCase.php b/tests/TestCase.php index 3ebb9f9d..7927b169 100755 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -59,10 +59,11 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase { if ($user !== null) { $headers['x-api-key'] = $user->api_key; - } else { - if ($this->user !== null) { - $headers['x-api-key'] = $this->user->api_key; - } + return $headers; + } + + if ($this->user !== null) { + $headers['x-api-key'] = $this->user->api_key; } return $headers; @@ -90,7 +91,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase * @param $obj * @param array $keys */ - public function assertHasKeys($obj, $keys = []) + public function assertHasKeys($obj, array $keys = []): void { foreach ($keys as $key) { $this->assertArrayHasKey($key, $obj); diff --git a/tests/TestData.php b/tests/TestData.php index 49af97ff..246d0131 100644 --- a/tests/TestData.php +++ b/tests/TestData.php @@ -57,6 +57,7 @@ trait TestData * @param null $airport_id * * @return mixed + * @throws \Exception */ public function createSubfleetWithAircraft($aircraft_count = null, $airport_id = null) { diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index f80bec7e..24145391 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -14,6 +14,9 @@ class UtilsTest extends TestCase $this->assertNotNull($carbon); } + /** + * @throws Exception + */ public function testSecondsToTimeParts() { $t = Utils::secondsToTimeParts(3600);