From ccf56ddec17c69f006df0ac18089ca9f18a860b1 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Mon, 19 Mar 2018 20:50:40 -0500 Subject: [PATCH] Fix formatting and interfaces in nearly every file --- .travis/Formatting.xml | 27 +++ app/Awards/PilotFlightAwards.php | 6 +- app/Bootstrap/LoadConfiguration.php | 3 +- app/Console/{BaseCommand.php => Command.php} | 29 ++- app/Console/Commands/AcarsReplay.php | 87 ++++---- app/Console/Commands/CreateDatabase.php | 47 ++-- app/Console/Commands/DevCommands.php | 34 +-- app/Console/Commands/DevInstall.php | 16 +- app/Console/Commands/ImportFromClassic.php | 12 +- app/Console/Commands/Install.php | 27 ++- app/Console/Commands/NavdataImport.php | 60 ++--- app/Console/Commands/TestApi.php | 19 +- app/Console/Commands/Version.php | 18 +- app/Console/Commands/YamlExport.php | 18 +- app/Console/Commands/YamlImport.php | 30 +-- app/Console/Cron/Monthly.php | 7 +- app/Console/Cron/Nightly.php | 7 +- app/Console/Cron/Weekly.php | 7 +- app/Console/Kernel.php | 15 +- app/Console/Services/Database.php | 10 +- app/Console/Services/Importer.php | 210 +++++++++--------- app/Database/factories/AcarsFactory.php | 24 +- app/Database/factories/AircraftFactory.php | 20 +- app/Database/factories/AirlineFactory.php | 13 +- app/Database/factories/AirportFactory.php | 27 ++- app/Database/factories/AwardsFactory.php | 8 +- app/Database/factories/ExpenseFactory.php | 16 +- app/Database/factories/FareFactory.php | 10 +- app/Database/factories/FlightFactory.php | 30 +-- app/Database/factories/JournalFactory.php | 2 +- .../factories/JournalTransactionsFactory.php | 12 +- app/Database/factories/NavdataFactory.php | 6 +- app/Database/factories/PirepFactory.php | 49 ++-- app/Database/factories/RankFactory.php | 14 +- app/Database/factories/SubfleetFactory.php | 8 +- app/Database/factories/UserFactory.php | 25 +-- ...017_06_07_014930_create_settings_table.php | 184 +++++++-------- ...17_06_08_0001_roles_permissions_tables.php | 9 +- ...017_06_08_191703_create_airlines_table.php | 1 - ...17_06_09_010621_create_aircrafts_table.php | 1 - .../2017_06_10_040335_create_fares_table.php | 1 - ...2017_06_17_214650_create_flight_tables.php | 1 - .../2017_06_21_165410_create_ranks_table.php | 9 +- ...17_06_23_011011_create_subfleet_tables.php | 4 +- .../2017_06_28_195426_create_pirep_tables.php | 1 - .../2018_01_03_014930_create_stats_table.php | 1 - .../2018_01_28_180522_create_awards_table.php | 5 +- ...018_02_26_185121_create_expenses_table.php | 1 - app/Database/seeds/DatabaseSeeder.php | 10 +- app/Events/CronMonthly.php | 3 + app/Events/CronNightly.php | 3 + app/Events/CronWeekly.php | 3 + app/Events/Expenses.php | 3 +- app/Events/PirepAccepted.php | 8 + app/Events/PirepFiled.php | 1 - app/Events/PirepRejected.php | 8 + app/Events/TestEvent.php | 5 + app/Events/UserAccepted.php | 8 + app/Events/UserRegistered.php | 8 + app/Events/UserStateChanged.php | 5 + app/Events/UserStatsChanged.php | 4 + app/Exceptions/AircraftPermissionDenied.php | 15 +- app/Exceptions/BidExists.php | 15 +- app/Exceptions/Handler.php | 26 +-- app/Exceptions/PirepCancelled.php | 15 +- app/Exceptions/SettingNotFound.php | 8 +- app/Facades/Utils.php | 52 +++-- .../Controllers/Admin/AircraftController.php | 24 +- .../Controllers/Admin/AirlinesController.php | 18 +- .../Controllers/Admin/AirportController.php | 31 ++- .../Controllers/Admin/AwardController.php | 30 ++- app/Http/Controllers/Admin/BaseController.php | 12 - .../Controllers/Admin/DashboardController.php | 23 +- .../Controllers/Admin/ExpenseController.php | 20 +- app/Http/Controllers/Admin/FareController.php | 14 +- .../Controllers/Admin/FinanceController.php | 35 +-- .../Controllers/Admin/FlightController.php | 86 ++++--- .../Controllers/Admin/PirepController.php | 83 ++++--- .../Admin/PirepFieldController.php | 17 +- app/Http/Controllers/Admin/RankController.php | 37 +-- .../Controllers/Admin/SettingsController.php | 14 +- .../Controllers/Admin/SubfleetController.php | 69 +++--- app/Http/Controllers/Admin/UserController.php | 76 ++++--- app/Http/Controllers/Api/AcarsController.php | 19 +- .../Controllers/Api/AirlineController.php | 10 +- .../Controllers/Api/AirportController.php | 13 +- app/Http/Controllers/Api/FleetController.php | 24 +- app/Http/Controllers/Api/FlightController.php | 22 +- app/Http/Controllers/Api/PirepController.php | 104 +++++---- .../Controllers/Api/SettingsController.php | 9 +- app/Http/Controllers/Api/StatusController.php | 9 +- app/Http/Controllers/Api/UserController.php | 39 ++-- .../Auth/ForgotPasswordController.php | 6 +- app/Http/Controllers/Auth/LoginController.php | 15 +- .../Controllers/Auth/RegisterController.php | 51 +++-- .../Auth/ResetPasswordController.php | 12 +- app/Http/Controllers/Controller.php | 25 --- .../Controllers/Frontend/AcarsController.php | 15 +- .../Frontend/DashboardController.php | 17 +- .../Controllers/Frontend/FlightController.php | 32 +-- .../Controllers/Frontend/HomeController.php | 6 +- .../Controllers/Frontend/PirepController.php | 85 +++---- .../Frontend/ProfileController.php | 24 +- .../Controllers/Frontend/UserController.php | 10 +- app/Http/Kernel.php | 16 +- app/Http/Middleware/ApiAuth.php | 14 +- app/Http/Middleware/JsonResponse.php | 1 + app/Http/Middleware/MeasureExecutionTime.php | 6 +- .../Middleware/RedirectIfAuthenticated.php | 6 +- app/Http/Requests/Acars/CommentRequest.php | 2 +- app/Http/Requests/Acars/EventRequest.php | 13 +- app/Http/Requests/Acars/FileRequest.php | 49 ++-- app/Http/Requests/Acars/LogRequest.php | 9 +- app/Http/Requests/Acars/PositionRequest.php | 23 +- app/Http/Requests/Acars/PrefileRequest.php | 44 ++-- app/Http/Requests/Acars/RouteRequest.php | 11 +- app/Http/Requests/Acars/UpdateRequest.php | 49 ++-- app/Http/Requests/CreateAircraftRequest.php | 1 - app/Http/Requests/CreateAirlineRequest.php | 1 + app/Http/Requests/CreateAirportRequest.php | 1 + app/Http/Requests/CreateAwardRequest.php | 3 +- app/Http/Requests/CreateFareRequest.php | 1 - app/Http/Requests/CreateFlightRequest.php | 1 - app/Http/Requests/CreatePirepFieldRequest.php | 2 - app/Http/Requests/CreateRankRequest.php | 1 - app/Http/Requests/CreateSubfleetRequest.php | 1 - app/Http/Requests/CreateUserRequest.php | 2 +- app/Http/Requests/UpdateAircraftRequest.php | 3 +- app/Http/Requests/UpdateAirlineRequest.php | 1 - app/Http/Requests/UpdateAirportRequest.php | 1 - app/Http/Requests/UpdateAwardRequest.php | 3 +- app/Http/Requests/UpdateFareRequest.php | 1 - app/Http/Requests/UpdateFlightRequest.php | 1 - app/Http/Requests/UpdatePirepFieldRequest.php | 1 - app/Http/Requests/UpdatePirepRequest.php | 1 - app/Http/Requests/UpdateRankRequest.php | 1 - app/Http/Requests/UpdateSubfleetRequest.php | 1 - app/Http/Requests/UpdateUserRequest.php | 1 - app/Http/Resources/Acars.php | 2 +- app/Http/Resources/Airline.php | 10 +- app/Http/Resources/Award.php | 6 +- app/Http/Resources/Flight.php | 2 +- app/Http/Resources/JournalTransaction.php | 1 + app/Http/Resources/Pirep.php | 6 +- app/Http/Resources/PirepComment.php | 16 +- app/Http/Resources/Rank.php | 2 +- app/Http/Resources/Response.php | 2 +- app/Http/Resources/Setting.php | 12 +- app/Http/Resources/User.php | 32 +-- app/Http/Resources/UserBid.php | 6 +- .../{AwardInterface.php => Award.php} | 53 +++-- .../Controller.php} | 43 ++-- app/Interfaces/Enum.php | 48 +++- app/Interfaces/Listener.php | 12 + app/Interfaces/Migration.php | 7 + app/Interfaces/Model.php | 8 + .../Repository.php} | 24 +- app/Interfaces/Service.php | 8 + app/Interfaces/Widget.php | 25 +++ app/Listeners/AwardListener.php | 13 +- app/Listeners/Cron/Monthly/ApplyExpenses.php | 17 +- app/Listeners/Cron/Nightly/ApplyExpenses.php | 15 +- .../Cron/Nightly/RecalculateBalances.php | 11 +- app/Listeners/ExpenseListener.php | 9 +- app/Listeners/FinanceEvents.php | 17 +- app/Listeners/NotificationEvents.php | 40 ++-- app/Mail/Admin/UserRegistered.php | 13 +- app/Mail/NewLoginDetails.php | 7 +- app/Mail/UserPending.php | 7 +- app/Mail/UserRegistered.php | 10 +- app/Mail/UserRejected.php | 10 +- app/Models/Acars.php | 32 +-- app/Models/Aircraft.php | 30 +-- app/Models/Airline.php | 30 +-- app/Models/Airport.php | 33 +-- app/Models/Award.php | 21 +- app/Models/BaseModel.php | 8 - app/Models/Bid.php | 4 +- app/Models/Enums/AcarsType.php | 4 +- app/Models/Enums/ActiveState.php | 6 +- app/Models/Enums/AircraftState.php | 6 +- app/Models/Enums/AircraftStatus.php | 16 +- app/Models/Enums/AnalyticsDimensions.php | 4 +- app/Models/Enums/AnalyticsMetrics.php | 1 + app/Models/Enums/Days.php | 18 +- app/Models/Enums/ExpenseType.php | 16 +- app/Models/Enums/FlightType.php | 16 +- app/Models/Enums/FuelType.php | 16 +- app/Models/Enums/JournalType.php | 4 +- app/Models/Enums/NavaidType.php | 27 +-- app/Models/Enums/PirepSource.php | 2 +- app/Models/Enums/PirepState.php | 28 +-- app/Models/Enums/PirepStatus.php | 16 +- app/Models/Enums/UserState.php | 10 +- app/Models/Expense.php | 22 +- app/Models/Fare.php | 17 +- app/Models/Flight.php | 19 +- app/Models/FlightFields.php | 4 +- app/Models/GeoJson.php | 10 +- app/Models/Journal.php | 24 +- app/Models/JournalTransaction.php | 12 +- app/Models/Ledger.php | 5 +- app/Models/Migrations/Migration.php | 59 ++--- app/Models/Navdata.php | 16 +- app/Models/News.php | 6 +- app/Models/Observers/AircraftObserver.php | 3 + .../Observers/JournalTransactionObserver.php | 5 +- app/Models/Observers/SettingObserver.php | 4 + app/Models/Observers/SubfleetObserver.php | 22 ++ app/Models/Permission.php | 1 + app/Models/Pirep.php | 111 ++++----- app/Models/PirepComment.php | 4 +- app/Models/PirepFare.php | 4 +- app/Models/PirepField.php | 4 +- app/Models/PirepFieldValues.php | 4 +- app/Models/Rank.php | 20 +- app/Models/Role.php | 2 +- app/Models/Setting.php | 4 +- app/Models/Subfleet.php | 64 ++---- app/Models/Traits/ExpensableTrait.php | 1 - app/Models/Traits/HashIdTrait.php | 2 + app/Models/Traits/JournalTrait.php | 2 +- app/Models/User.php | 49 ++-- app/Models/UserAward.php | 4 +- app/Providers/AppServiceProvider.php | 4 +- app/Providers/AuthServiceProvider.php | 1 - app/Providers/EventServiceProvider.php | 4 +- app/Providers/RouteServiceProvider.php | 8 +- app/Providers/vaCentralServiceProvider.php | 3 +- app/Repositories/AcarsRepository.php | 20 +- app/Repositories/AircraftRepository.php | 11 +- app/Repositories/AirlineRepository.php | 12 +- app/Repositories/AirportRepository.php | 14 +- app/Repositories/AwardRepository.php | 10 +- app/Repositories/Criteria/WhereCriteria.php | 5 +- app/Repositories/ExpenseRepository.php | 14 +- app/Repositories/FareRepository.php | 14 +- app/Repositories/FlightRepository.php | 38 ++-- app/Repositories/JournalRepository.php | 80 +++---- app/Repositories/NavdataRepository.php | 7 +- app/Repositories/NewsRepository.php | 13 +- app/Repositories/PirepFieldRepository.php | 7 +- app/Repositories/PirepRepository.php | 20 +- app/Repositories/RankRepository.php | 11 +- app/Repositories/SettingRepository.php | 22 +- app/Repositories/SubfleetRepository.php | 10 +- app/Repositories/UserRepository.php | 22 +- app/Routes/admin.php | 10 +- app/Routes/api.php | 7 +- app/Routes/web.php | 5 +- app/Services/AnalyticsService.php | 10 +- app/Services/AwardService.php | 11 +- app/Services/BaseService.php | 8 - app/Services/DatabaseService.php | 37 +-- app/Services/FareService.php | 29 ++- app/Services/Finance/PirepFinanceService.php | 56 +++-- .../Finance/RecurringFinanceService.php | 33 +-- app/Services/FleetService.php | 17 +- app/Services/FlightService.php | 35 +-- app/Services/GeoService.php | 95 ++++---- app/Services/ImporterService.php | 25 ++- app/Services/ModuleService.php | 26 ++- app/Services/PirepService.php | 59 ++--- app/Services/UserService.php | 47 ++-- app/Support/ClassLoader.php | 6 +- app/Support/Dates.php | 7 +- app/Support/ICAO.php | 3 +- app/Support/Math.php | 6 +- app/Support/Money.php | 18 +- app/Support/Units/Altitude.php | 5 +- app/Support/Units/Distance.php | 1 + app/Support/Units/Fuel.php | 3 +- app/Support/Units/Mass.php | 3 +- app/Support/Units/Time.php | 8 +- app/Support/Units/Velocity.php | 3 +- app/Support/Units/Volume.php | 5 +- app/Widgets/BaseWidget.php | 16 -- app/Widgets/LatestNews.php | 5 +- app/Widgets/LatestPilots.php | 5 +- app/Widgets/LatestPireps.php | 3 +- app/Widgets/LiveMap.php | 9 +- app/helpers.php | 29 +-- config/auth.php | 14 +- config/database.php | 50 ++--- config/datatables.php | 86 ------- config/gamp.php | 10 +- config/gravatar.php | 2 +- config/laravel-widgets.php | 15 +- config/modules.php | 126 +++++------ .../Http/Controllers/InstallerController.php | 53 +++-- .../Http/Controllers/UpdaterController.php | 16 +- modules/Installer/Services/ConfigService.php | 3 +- .../Installer/Services/DatabaseService.php | 5 +- .../Installer/Services/MigrationService.php | 3 +- .../Services/RequirementsService.php | 5 +- modules/Sample/Awards/SampleAward.php | 4 +- .../Controllers/Admin/AdminController.php | 7 +- .../Http/Controllers/Api/SampleController.php | 10 +- .../Http/Controllers/SampleController.php | 7 +- modules/Sample/Models/SampleTable.php | 9 +- resources/stubs/modules/controller-admin.stub | 7 +- resources/stubs/modules/controller-api.stub | 6 +- resources/stubs/modules/controller-plain.stub | 7 +- resources/stubs/modules/controller.stub | 7 +- resources/stubs/modules/event.stub | 4 + resources/stubs/modules/job-queued.stub | 4 + resources/stubs/modules/job.stub | 4 + resources/stubs/modules/listener-duck.stub | 7 +- .../stubs/modules/listener-queued-duck.stub | 7 +- resources/stubs/modules/listener-queued.stub | 7 +- resources/stubs/modules/listener.stub | 7 +- resources/stubs/modules/mail.stub | 4 + resources/stubs/modules/middleware.stub | 4 + resources/stubs/modules/migration/add.stub | 9 +- resources/stubs/modules/migration/create.stub | 7 +- resources/stubs/modules/migration/delete.stub | 9 +- resources/stubs/modules/migration/drop.stub | 7 +- resources/stubs/modules/migration/plain.stub | 5 +- resources/stubs/modules/model.stub | 16 +- resources/stubs/modules/notification.stub | 10 +- resources/stubs/modules/policy.plain.stub | 4 + resources/stubs/modules/provider.stub | 4 + resources/stubs/modules/request.stub | 4 + .../stubs/modules/resource-collection.stub | 4 + resources/stubs/modules/resource.stub | 4 + resources/stubs/modules/route-provider.stub | 4 + resources/stubs/modules/rule.stub | 4 + resources/stubs/modules/scaffold/config.stub | 3 + .../stubs/modules/scaffold/provider.stub | 8 +- resources/stubs/widgets/widget.stub | 31 +++ resources/stubs/widgets/widget_plain.stub | 21 ++ 331 files changed, 3282 insertions(+), 2492 deletions(-) create mode 100644 .travis/Formatting.xml rename app/Console/{BaseCommand.php => Command.php} (79%) delete mode 100644 app/Http/Controllers/Admin/BaseController.php delete mode 100755 app/Http/Controllers/Controller.php rename app/Interfaces/{AwardInterface.php => Award.php} (55%) rename app/{Http/Controllers/Api/RestController.php => Interfaces/Controller.php} (64%) mode change 100644 => 100755 create mode 100644 app/Interfaces/Listener.php create mode 100644 app/Interfaces/Migration.php create mode 100644 app/Interfaces/Model.php rename app/{Repositories/BaseRepository.php => Interfaces/Repository.php} (72%) create mode 100644 app/Interfaces/Service.php create mode 100644 app/Interfaces/Widget.php delete mode 100644 app/Models/BaseModel.php create mode 100644 app/Models/Observers/SubfleetObserver.php delete mode 100644 app/Services/BaseService.php delete mode 100644 app/Widgets/BaseWidget.php delete mode 100644 config/datatables.php create mode 100644 resources/stubs/widgets/widget.stub create mode 100644 resources/stubs/widgets/widget_plain.stub diff --git a/.travis/Formatting.xml b/.travis/Formatting.xml new file mode 100644 index 00000000..41cf2013 --- /dev/null +++ b/.travis/Formatting.xml @@ -0,0 +1,27 @@ + + diff --git a/app/Awards/PilotFlightAwards.php b/app/Awards/PilotFlightAwards.php index 183aefbe..43190cc5 100644 --- a/app/Awards/PilotFlightAwards.php +++ b/app/Awards/PilotFlightAwards.php @@ -2,14 +2,14 @@ namespace App\Awards; -use App\Interfaces\AwardInterface; +use App\Interfaces\Award; /** * Simple example of an awards class, where you can apply an award when a user * has 100 flights. All award classes need to extend the AwardInterface * @package App\Awards */ -class PilotFlightAwards extends AwardInterface +class PilotFlightAwards extends Award { /** * Set the name of this award class to make it easier to see when @@ -38,7 +38,7 @@ class PilotFlightAwards extends AwardInterface */ public function check($number_of_flights = null): bool { - if(!$number_of_flights) { + if (!$number_of_flights) { $number_of_flights = 100; } diff --git a/app/Bootstrap/LoadConfiguration.php b/app/Bootstrap/LoadConfiguration.php index 4f135e32..bd1d2cc9 100644 --- a/app/Bootstrap/LoadConfiguration.php +++ b/app/Bootstrap/LoadConfiguration.php @@ -23,8 +23,7 @@ class LoadConfiguration extends \Illuminate\Foundation\Bootstrap\LoadConfigurati * Load the configuration items from all of the files. * * @param \Illuminate\Contracts\Foundation\Application $app - * @param \Illuminate\Contracts\Config\Repository $repository - * @return void + * @param \Illuminate\Contracts\Config\Repository $repository * @throws \Exception */ protected function loadConfigurationFiles(Application $app, RepositoryContract $repository) diff --git a/app/Console/BaseCommand.php b/app/Console/Command.php similarity index 79% rename from app/Console/BaseCommand.php rename to app/Console/Command.php index 4a4682c7..6be4a2f6 100644 --- a/app/Console/BaseCommand.php +++ b/app/Console/Command.php @@ -2,12 +2,20 @@ namespace App\Console; -use Illuminate\Console\Command; -use Symfony\Component\Process\Process; use Log; +use Symfony\Component\Process\Process; -class BaseCommand extends Command +/** + * Class BaseCommand + * @package App\Console + */ +abstract class Command extends \Illuminate\Console\Command { + /** + * @return mixed + */ + abstract public function handle(); + /** * Splice the logger and replace the active handlers with * the handlers from the "cron" stack in config/logging.php @@ -17,7 +25,7 @@ class BaseCommand extends Command * * @param string $channel_name Channel name to grab the handlers from */ - public function redirectLoggingToStdout($channel_name) + public function redirectLoggingToStdout($channel_name): void { $logger = app(\Illuminate\Log\Logger::class); @@ -28,7 +36,7 @@ class BaseCommand extends Command $handler->close(); } } catch (\Exception $e) { - $this->error('Error closing handlers: ' . $e->getMessage()); + $this->error('Error closing handlers: '.$e->getMessage()); } // Open the handlers for the channel name, @@ -38,7 +46,7 @@ class BaseCommand extends Command Log::channel($channel_name)->getHandlers() ); } catch (\Exception $e) { - $this->error('Couldn\'t splice the logger: ' . $e->getMessage()); + $this->error('Couldn\'t splice the logger: '.$e->getMessage()); } } @@ -47,10 +55,9 @@ class BaseCommand extends Command * @param $filename * @return \Generator */ - public function readFile($filename) + public function readFile($filename): ?\Generator { $fp = fopen($filename, 'rb'); - while (($line = fgets($fp)) !== false) { $line = rtrim($line, "\r\n"); if ($line[0] === ';') { @@ -64,20 +71,20 @@ class BaseCommand extends Command } /** - * @param $cmd + * @param $cmd * @param bool $return * @return string * @throws \Symfony\Component\Process\Exception\RuntimeException * @throws \Symfony\Component\Process\Exception\LogicException */ - public function runCommand($cmd, $return = false, $verbose = true) + public function runCommand($cmd, $return = false, $verbose = true): string { if (\is_array($cmd)) { $cmd = join(' ', $cmd); } if ($verbose) { - $this->info('Running "' . $cmd . '"'); + $this->info('Running "'.$cmd.'"'); } $val = ''; diff --git a/app/Console/Commands/AcarsReplay.php b/app/Console/Commands/AcarsReplay.php index 17435de9..69e83d29 100644 --- a/app/Console/Commands/AcarsReplay.php +++ b/app/Console/Commands/AcarsReplay.php @@ -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() { diff --git a/app/Console/Commands/CreateDatabase.php b/app/Console/Commands/CreateDatabase.php index 7d29a875..e4e626e8 100644 --- a/app/Console/Commands/CreateDatabase.php +++ b/app/Console/Commands/CreateDatabase.php @@ -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); } } diff --git a/app/Console/Commands/DevCommands.php b/app/Console/Commands/DevCommands.php index c302d5af..4eb6a048 100644 --- a/app/Console/Commands/DevCommands.php +++ b/app/Console/Commands/DevCommands.php @@ -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); } } diff --git a/app/Console/Commands/DevInstall.php b/app/Console/Commands/DevInstall.php index 87e81284..6fc7e852 100644 --- a/app/Console/Commands/DevInstall.php +++ b/app/Console/Commands/DevInstall.php @@ -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!'); diff --git a/app/Console/Commands/ImportFromClassic.php b/app/Console/Commands/ImportFromClassic.php index 4f2f2369..a5380f99 100644 --- a/app/Console/Commands/ImportFromClassic.php +++ b/app/Console/Commands/ImportFromClassic.php @@ -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') ]; diff --git a/app/Console/Commands/Install.php b/app/Console/Commands/Install.php index f31755d9..cef22473 100644 --- a/app/Console/Commands/Install.php +++ b/app/Console/Commands/Install.php @@ -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 } } diff --git a/app/Console/Commands/NavdataImport.php b/app/Console/Commands/NavdataImport.php index be3337f6..e5460710 100644 --- a/app/Console/Commands/NavdataImport.php +++ b/app/Console/Commands/NavdataImport.php @@ -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'); } } diff --git a/app/Console/Commands/TestApi.php b/app/Console/Commands/TestApi.php index 019722a9..a4d01723 100644 --- a/app/Console/Commands/TestApi.php +++ b/app/Console/Commands/TestApi.php @@ -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')); diff --git a/app/Console/Commands/Version.php b/app/Console/Commands/Version.php index 9a7bc5be..5e2bd52f 100644 --- a/app/Console/Commands/Version.php +++ b/app/Console/Commands/Version.php @@ -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"; } } diff --git a/app/Console/Commands/YamlExport.php b/app/Console/Commands/YamlExport.php index a6e46736..6021fa58 100644 --- a/app/Console/Commands/YamlExport.php +++ b/app/Console/Commands/YamlExport.php @@ -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; } } diff --git a/app/Console/Commands/YamlImport.php b/app/Console/Commands/YamlImport.php index 8792e8ee..f7a3f3a3 100644 --- a/app/Console/Commands/YamlImport.php +++ b/app/Console/Commands/YamlImport.php @@ -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.'"'); } } diff --git a/app/Console/Cron/Monthly.php b/app/Console/Cron/Monthly.php index 00208ab6..c3d17557 100644 --- a/app/Console/Cron/Monthly.php +++ b/app/Console/Cron/Monthly.php @@ -2,7 +2,7 @@ namespace App\Console\Cron; -use App\Console\BaseCommand; +use App\Console\Command; use App\Events\CronMonthly; /** @@ -10,12 +10,15 @@ use App\Events\CronMonthly; * listeners, etc can just be called to run those tasks * @package App\Console\Cron */ -class Monthly extends BaseCommand +class Monthly extends Command { protected $signature = 'cron:monthly'; protected $description = 'Run the monthly cron tasks'; protected $schedule; + /** + * + */ public function handle(): void { $this->redirectLoggingToStdout('cron'); diff --git a/app/Console/Cron/Nightly.php b/app/Console/Cron/Nightly.php index 2d81d323..18437df7 100644 --- a/app/Console/Cron/Nightly.php +++ b/app/Console/Cron/Nightly.php @@ -2,7 +2,7 @@ namespace App\Console\Cron; -use App\Console\BaseCommand; +use App\Console\Command; use App\Events\CronNightly; /** @@ -10,12 +10,15 @@ use App\Events\CronNightly; * listeners, etc can just be called to run those tasks * @package App\Console\Cron */ -class Nightly extends BaseCommand +class Nightly extends Command { protected $signature = 'cron:nightly'; protected $description = 'Run the nightly cron tasks'; protected $schedule; + /** + * + */ public function handle(): void { $this->redirectLoggingToStdout('cron'); diff --git a/app/Console/Cron/Weekly.php b/app/Console/Cron/Weekly.php index 4cb2b61e..b5f9e652 100644 --- a/app/Console/Cron/Weekly.php +++ b/app/Console/Cron/Weekly.php @@ -2,7 +2,7 @@ namespace App\Console\Cron; -use App\Console\BaseCommand; +use App\Console\Command; use App\Events\CronMonthly; /** @@ -10,12 +10,15 @@ use App\Events\CronMonthly; * listeners, etc can just be called to run those tasks * @package App\Console\Cron */ -class Weekly extends BaseCommand +class Weekly extends Command { protected $signature = 'cron:monthly'; protected $description = 'Run the monthly cron tasks'; protected $schedule; + /** + * + */ public function handle(): void { $this->redirectLoggingToStdout('cron'); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index a397987e..96b082a8 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -8,13 +8,12 @@ use App\Console\Cron\Weekly; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; +/** + * Class Kernel + * @package App\Console + */ class Kernel extends ConsoleKernel { - /** - * The Artisan commands provided by your application. - * - * @var array - */ protected $commands = [ Commands\AcarsReplay::class, Commands\CreateDatabase::class, @@ -28,7 +27,7 @@ class Kernel extends ConsoleKernel /** * Define the application's command schedule. - * @param \Illuminate\Console\Scheduling\Schedule $schedule + * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule): void @@ -45,7 +44,7 @@ class Kernel extends ConsoleKernel protected function commands(): void { require app_path('Routes/console.php'); - $this->load(__DIR__ . '/Commands'); - $this->load(__DIR__ . '/Cron'); + $this->load(__DIR__.'/Commands'); + $this->load(__DIR__.'/Cron'); } } diff --git a/app/Console/Services/Database.php b/app/Console/Services/Database.php index 86da3d27..222787d4 100644 --- a/app/Console/Services/Database.php +++ b/app/Console/Services/Database.php @@ -2,7 +2,7 @@ namespace App\Console\Services; -use Doctrine\DBAL\Driver\PDOException; +use PDOException; use PDO; /** @@ -13,16 +13,16 @@ class Database { /** * Create the base connection DSN, optionally include the DB name - * @param $host - * @param $port + * @param $host + * @param $port * @param null $name * @return string */ - public function createDsn($host, $port, $name=null) + public function createDsn($host, $port, $name = null) { $conn = config('database.default'); $dsn = "$conn:host=$host;port=$port"; - if(filled($name)) { + if (filled($name)) { $dsn .= ';dbname='.$name; } diff --git a/app/Console/Services/Importer.php b/app/Console/Services/Importer.php index 25b24f2e..17800b10 100644 --- a/app/Console/Services/Importer.php +++ b/app/Console/Services/Importer.php @@ -15,7 +15,7 @@ use App\Models\Rank; use App\Models\Subfleet; use App\Models\User; use Carbon\Carbon; -use Doctrine\DBAL\Driver\PDOException; +use PDOException; use Illuminate\Database\QueryException; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; @@ -56,7 +56,7 @@ class Importer */ const BATCH_READ_ROWS = 300; - const SUBFLEET_NAME = 'Imported Aircraft'; + const SUBFLEET_NAME = 'Imported Aircraft'; /** * Importer constructor. @@ -69,11 +69,11 @@ class Importer # The db credentials $this->creds = array_merge([ - 'host' => '127.0.0.1', - 'port' => 3306, - 'name' => '', - 'user' => '', - 'pass' => '', + 'host' => '127.0.0.1', + 'port' => 3306, + 'name' => '', + 'user' => '', + 'pass' => '', 'table_prefix' => 'phpvms_' ], $db_creds); } @@ -105,13 +105,13 @@ class Importer */ protected function reconnect() { - $dsn = 'mysql:' . implode(';', [ - 'host=' . $this->creds['host'], - 'port=' . $this->creds['port'], - 'dbname=' . $this->creds['name'] + $dsn = 'mysql:'.implode(';', [ + 'host='.$this->creds['host'], + 'port='.$this->creds['port'], + 'dbname='.$this->creds['name'] ]); - $this->info('Connection string: ' . $dsn); + $this->info('Connection string: '.$dsn); try { $this->conn = new PDO($dsn, $this->creds['user'], $this->creds['pass']); @@ -127,14 +127,15 @@ class Importer */ protected function comment($message) { - $this->log->writeln('' . $message . ''); + $this->log->writeln(''.$message.''); } /** * @param $message */ - protected function error($message) { - $this->log->writeln('' . $message . ''); + protected function error($message) + { + $this->log->writeln(''.$message.''); } /** @@ -142,10 +143,9 @@ class Importer */ protected function info($message) { - if(\is_array($message)) { + if (\is_array($message)) { print_r($message); - } - else { + } else { $this->log->writeln(''.$message.''); } } @@ -157,7 +157,7 @@ class Importer */ protected function tableName($table) { - if($this->creds['table_prefix'] !== false) { + if ($this->creds['table_prefix'] !== false) { return $this->creds['table_prefix'].$table; } @@ -173,9 +173,10 @@ class Importer { try { $model->save(); + return true; } catch (QueryException $e) { - if($e->getCode() !== '23000') { + if ($e->getCode() !== '23000') { $this->error($e); } @@ -191,7 +192,7 @@ class Importer */ protected function addMapping($entity, $old_id, $new_id) { - if(!array_key_exists($entity, $this->mappedEntities)) { + if (!array_key_exists($entity, $this->mappedEntities)) { $this->mappedEntities[$entity] = []; } @@ -206,12 +207,12 @@ class Importer */ protected function getMapping($entity, $old_id) { - if(!array_key_exists($entity, $this->mappedEntities)) { + if (!array_key_exists($entity, $this->mappedEntities)) { return 0; } $entity = $this->mappedEntities[$entity]; - if(array_key_exists($old_id, $entity)) { + if (array_key_exists($old_id, $entity)) { return $entity[$old_id]; } @@ -225,6 +226,7 @@ class Importer protected function parseDate($date) { $carbon = Carbon::parse($date); + return $carbon; } @@ -235,9 +237,9 @@ class Importer */ protected function convertDuration($duration) { - if(strpos($duration, '.') !== false) { + if (strpos($duration, '.') !== false) { $delim = '.'; - } elseif(strpos($duration, ':')) { + } elseif (strpos($duration, ':')) { $delim = ':'; } else { # no delimiter, assume it's just a straight hour @@ -259,52 +261,52 @@ class Importer { $table = $this->tableName($table); - $sql = 'SELECT COUNT(*) FROM ' . $table; + $sql = 'SELECT COUNT(*) FROM '.$table; $rows = $this->conn->query($sql)->fetchColumn(); $this->info('Found '.$rows.' rows in '.$table); + return (int) $rows; } /** * Read all the rows in a table, but read them in a batched manner - * @param string $table The name of the table - * @param null $read_rows Number of rows to read + * @param string $table The name of the table + * @param null $read_rows Number of rows to read * @return \Generator */ - protected function readRows($table, $read_rows=null) + protected function readRows($table, $read_rows = null) { // Set the table prefix if it has been entered $this->tableName($table); $offset = 0; - if($read_rows === null) { + if ($read_rows === null) { $read_rows = self::BATCH_READ_ROWS; } $total_rows = $this->getTotalRows($table); - while($offset < $total_rows) - { + while ($offset < $total_rows) { $rows_to_read = $offset + $read_rows; - if($rows_to_read > $total_rows) { + if ($rows_to_read > $total_rows) { $rows_to_read = $total_rows; } $this->info('Reading '.$offset.' to '.$rows_to_read.' of '.$total_rows); - $sql = 'SELECT * FROM ' . $this->tableName($table) - . ' LIMIT ' . self::BATCH_READ_ROWS . ' OFFSET ' . $offset; + $sql = 'SELECT * FROM '.$this->tableName($table) + .' LIMIT '.self::BATCH_READ_ROWS.' OFFSET '.$offset; try { foreach ($this->conn->query($sql) as $row) { yield $row; } - } catch(PDOException $e) { + } catch (PDOException $e) { // Without incrementing the offset, it should re-run the same query $this->error($e); - if(strpos($e->getMessage(), 'server has gone away') !== false) { + if (strpos($e->getMessage(), 'server has gone away') !== false) { $this->reconnect(); continue; } @@ -344,22 +346,21 @@ class Importer $this->comment('--- RANK IMPORT ---'); $count = 0; - foreach ($this->readRows('ranks') as $row) - { + foreach ($this->readRows('ranks') as $row) { $rank = Rank::firstOrCreate( ['name' => $row->rank], - ['image_url' => $row->rankimage, 'hours'=>$row->minhours] + ['image_url' => $row->rankimage, 'hours' => $row->minhours] ); $this->addMapping('ranks', $row->rankid, $rank->id); $this->addMapping('ranks', $row->rank, $rank->id); - if($rank->wasRecentlyCreated) { + if ($rank->wasRecentlyCreated) { ++$count; } } - $this->info('Imported ' . $count . ' ranks'); + $this->info('Imported '.$count.' ranks'); } /** @@ -371,8 +372,7 @@ class Importer $this->comment('--- AIRLINE IMPORT ---'); $count = 0; - foreach ($this->readRows('airlines') as $row) - { + foreach ($this->readRows('airlines') as $row) { $airline = Airline::firstOrCreate( ['icao' => $row->code], ['iata' => $row->code, 'name' => $row->name, 'active' => $row->enabled] @@ -386,7 +386,7 @@ class Importer } } - $this->info('Imported '. $count.' airlines'); + $this->info('Imported '.$count.' airlines'); } /** @@ -401,23 +401,22 @@ class Importer $this->info('Subfleet ID is '.$subfleet->id); $count = 0; - foreach($this->readRows('aircraft') as $row) - { + foreach ($this->readRows('aircraft') as $row) { $aircraft = Aircraft::firstOrCreate( ['name' => $row->fullname, 'registration' => $row->registration], - ['icao' => $row->icao, + ['icao' => $row->icao, 'subfleet_id' => $subfleet->id, - 'active' => $row->enabled + 'active' => $row->enabled ]); $this->addMapping('aircraft', $row->id, $aircraft->id); - if($aircraft->wasRecentlyCreated) { + if ($aircraft->wasRecentlyCreated) { ++$count; } } - $this->info('Imported ' . $count . ' aircraft'); + $this->info('Imported '.$count.' aircraft'); } /** @@ -428,16 +427,15 @@ class Importer $this->comment('--- AIRPORT IMPORT ---'); $count = 0; - foreach ($this->readRows('airports') as $row) - { + foreach ($this->readRows('airports') as $row) { $attrs = [ - 'id' => trim($row->icao), - 'icao' => trim($row->icao), - 'name' => $row->name, + 'id' => trim($row->icao), + 'icao' => trim($row->icao), + 'name' => $row->name, 'country' => $row->country, - 'lat' => $row->lat, - 'lon' => $row->lng, - 'hub' => $row->hub, + 'lat' => $row->lat, + 'lon' => $row->lng, + 'hub' => $row->hub, ]; $airport = Airport::updateOrCreate( @@ -445,12 +443,12 @@ class Importer $attrs ); - if($airport->wasRecentlyCreated) { + if ($airport->wasRecentlyCreated) { ++$count; } } - $this->info('Imported ' . $count . ' airports'); + $this->info('Imported '.$count.' airports'); } /** @@ -461,8 +459,7 @@ class Importer $this->comment('--- FLIGHT SCHEDULE IMPORT ---'); $count = 0; - foreach ($this->readRows('schedules') as $row) - { + foreach ($this->readRows('schedules') as $row) { $airline_id = $this->getMapping('airlines', $row->code); $flight_num = trim($row->flightnum); @@ -470,14 +467,14 @@ class Importer $attrs = [ 'dpt_airport_id' => $row->depicao, 'arr_airport_id' => $row->arricao, - 'route' => $row->route ?: '', - 'distance' => round($row->distance ?: 0, 2), - 'level' => $row->flightlevel ?: 0, - 'dpt_time' => $row->deptime ?: '', - 'arr_time' => $row->arrtime ?: '', - 'flight_time' => $this->convertDuration($row->flighttime) ?: '', - 'notes' => $row->notes ?: '', - 'active' => $row->enabled ?: true, + 'route' => $row->route ?: '', + 'distance' => round($row->distance ?: 0, 2), + 'level' => $row->flightlevel ?: 0, + 'dpt_time' => $row->deptime ?: '', + 'arr_time' => $row->arrtime ?: '', + 'flight_time' => $this->convertDuration($row->flighttime) ?: '', + 'notes' => $row->notes ?: '', + 'active' => $row->enabled ?: true, ]; try { @@ -493,12 +490,12 @@ class Importer // TODO: deserialize route_details into ACARS table - if($flight->wasRecentlyCreated) { + if ($flight->wasRecentlyCreated) { ++$count; } } - $this->info('Imported ' . $count . ' flights'); + $this->info('Imported '.$count.' flights'); } /** @@ -509,8 +506,7 @@ class Importer $this->comment('--- PIREP IMPORT ---'); $count = 0; - foreach ($this->readRows('pireps') as $row) - { + foreach ($this->readRows('pireps') as $row) { $pirep_id = $row->pirepid; $user_id = $this->getMapping('users', $row->pilotid); $airline_id = $this->getMapping('airlines', $row->code); @@ -518,17 +514,17 @@ class Importer $attrs = [ #'id' => $pirep_id, - 'user_id' => $user_id, - 'airline_id' => $airline_id, - 'aircraft_id' => $aircraft_id, - 'flight_number' => $row->flightnum ?: '', + 'user_id' => $user_id, + 'airline_id' => $airline_id, + 'aircraft_id' => $aircraft_id, + 'flight_number' => $row->flightnum ?: '', 'dpt_airport_id' => $row->depicao, 'arr_airport_id' => $row->arricao, - 'block_fuel' => $row->fuelused, - 'route' => $row->route ?: '', - 'source_name' => $row->source, - 'created_at' => $this->parseDate($row->submitdate), - 'updated_at' => $this->parseDate($row->modifieddate), + 'block_fuel' => $row->fuelused, + 'route' => $row->route ?: '', + 'source_name' => $row->source, + 'created_at' => $this->parseDate($row->submitdate), + 'updated_at' => $this->parseDate($row->modifieddate), ]; # Set the distance @@ -542,7 +538,7 @@ class Importer $attrs['planned_flight_time'] = $duration; # Set how it was filed - if(strtoupper($row->source) === 'MANUAL') { + if (strtoupper($row->source) === 'MANUAL') { $attrs['source'] = PirepSource::MANUAL; } else { $attrs['source'] = PirepSource::ACARS; @@ -550,16 +546,16 @@ class Importer # Set the flight type $row->flighttype = strtoupper($row->flighttype); - if($row->flighttype === 'P') { + if ($row->flighttype === 'P') { $attrs['flight_type'] = FlightType::PASSENGER; - } elseif($row->flighttype === 'C') { + } elseif ($row->flighttype === 'C') { $attrs['flight_type'] = FlightType::CARGO; } else { $attrs['flight_type'] = FlightType::CHARTER; } # Set the flight level of the PIREP is set - if(property_exists($row, 'flightlevel')) { + if (property_exists($row, 'flightlevel')) { $attrs['level'] = $row->flightlevel; } else { $attrs['level'] = 0; @@ -571,11 +567,11 @@ class Importer ); $source = strtoupper($row->source); - if($source === 'SMARTCARS') { + if ($source === 'SMARTCARS') { # TODO: Parse smartcars log into the acars table - } elseif($source === 'KACARS') { + } elseif ($source === 'KACARS') { # TODO: Parse kACARS log into acars table - } elseif($source === 'XACARS') { + } elseif ($source === 'XACARS') { # TODO: Parse XACARS log into acars table } @@ -587,7 +583,7 @@ class Importer } } - $this->info('Imported ' . $count . ' pireps'); + $this->info('Imported '.$count.' pireps'); } protected function importUsers() @@ -596,10 +592,9 @@ class Importer $count = 0; foreach ($this->readRows('pilots', 50) as $row) { - # TODO: What to do about pilot ids - $name = $row->firstname . ' ' . $row->lastname; + $name = $row->firstname.' '.$row->lastname; $airline_id = $this->getMapping('airlines', $row->code); $rank_id = $this->getMapping('ranks', $row->rank); @@ -608,17 +603,17 @@ class Importer $new_password = Str::random(60); $attrs = [ - 'name' => $name, - 'password' => Hash::make($new_password), - 'api_key' => Utils::generateApiKey(), - 'airline_id' => $airline_id, - 'rank_id' => $rank_id, + 'name' => $name, + 'password' => Hash::make($new_password), + 'api_key' => Utils::generateApiKey(), + 'airline_id' => $airline_id, + 'rank_id' => $rank_id, 'home_airport_id' => $row->hub, 'curr_airport_id' => $row->hub, - 'flights' => (int)$row->totalflights, - 'flight_time' => Utils::hoursToMinutes($row->totalhours), - 'state' => $state, - 'created_at' => $this->parseDate($row->joindate), + 'flights' => (int) $row->totalflights, + 'flight_time' => Utils::hoursToMinutes($row->totalhours), + 'state' => $state, + 'created_at' => $this->parseDate($row->joindate), ]; $user = User::updateOrCreate( @@ -633,7 +628,7 @@ class Importer } } - $this->info('Imported ' . $count . ' users'); + $this->info('Imported '.$count.' users'); } /** @@ -641,7 +636,6 @@ class Importer */ protected function findLastPireps() { - } /** @@ -665,9 +659,9 @@ class Importer // Declare array of classic states $phpvms_classic_states = [ - 'ACTIVE' => 0, + 'ACTIVE' => 0, 'INACTIVE' => 1, - 'BANNED' => 2, + 'BANNED' => 2, 'ON_LEAVE' => 3 ]; @@ -682,7 +676,7 @@ class Importer } elseif ($state === $phpvms_classic_states['ON_LEAVE']) { return UserState::ON_LEAVE; } else { - $this->error('Unknown status: '. $state); + $this->error('Unknown status: '.$state); } } } diff --git a/app/Database/factories/AcarsFactory.php b/app/Database/factories/AcarsFactory.php index 651d450a..a10bfcd6 100644 --- a/app/Database/factories/AcarsFactory.php +++ b/app/Database/factories/AcarsFactory.php @@ -4,18 +4,18 @@ use Faker\Generator as Faker; $factory->define(App\Models\Acars::class, function (Faker $faker) { return [ - 'id' => null, - 'pirep_id' => null, - 'log' => $faker->text(100), - 'lat' => $faker->latitude, - 'lon' => $faker->longitude, - 'heading' => $faker->numberBetween(0, 359), - 'altitude' => $faker->numberBetween(20, 400), - 'vs' => $faker->numberBetween(-5000, 5000), - 'gs' => $faker->numberBetween(300, 500), + 'id' => null, + 'pirep_id' => null, + 'log' => $faker->text(100), + 'lat' => $faker->latitude, + 'lon' => $faker->longitude, + 'heading' => $faker->numberBetween(0, 359), + 'altitude' => $faker->numberBetween(20, 400), + 'vs' => $faker->numberBetween(-5000, 5000), + 'gs' => $faker->numberBetween(300, 500), 'transponder' => $faker->numberBetween(200, 9999), - 'autopilot' => $faker->text(10), - 'fuel_flow' => $faker->randomFloat(2, 100, 1000), - 'sim_time' => $faker->dateTime('now', 'UTC'), + 'autopilot' => $faker->text(10), + 'fuel_flow' => $faker->randomFloat(2, 100, 1000), + 'sim_time' => $faker->dateTime('now', 'UTC'), ]; }); diff --git a/app/Database/factories/AircraftFactory.php b/app/Database/factories/AircraftFactory.php index 85cc45d5..be5474a5 100644 --- a/app/Database/factories/AircraftFactory.php +++ b/app/Database/factories/AircraftFactory.php @@ -4,21 +4,21 @@ use Faker\Generator as Faker; $factory->define(App\Models\Aircraft::class, function (Faker $faker) { return [ - 'id' => null, - 'subfleet_id' => function() { + 'id' => null, + 'subfleet_id' => function () { return factory(App\Models\Subfleet::class)->create()->id; }, - 'airport_id' => function () { + 'airport_id' => function () { return factory(App\Models\Airport::class)->create()->id; }, - 'icao' => $faker->unique()->text(5), - 'name' => $faker->unique()->text(50), + 'icao' => $faker->unique()->text(5), + 'name' => $faker->unique()->text(50), 'registration' => $faker->unique()->text(10), - 'hex_code' => \App\Support\ICAO::createHexCode(), - 'status' => \App\Models\Enums\AircraftStatus::ACTIVE, - 'state' => \App\Models\Enums\AircraftState::PARKED, - 'created_at' => $faker->dateTimeBetween('-1 week', 'now'), - 'updated_at' => function (array $pirep) { + 'hex_code' => \App\Support\ICAO::createHexCode(), + 'status' => \App\Models\Enums\AircraftStatus::ACTIVE, + 'state' => \App\Models\Enums\AircraftState::PARKED, + 'created_at' => $faker->dateTimeBetween('-1 week', 'now'), + 'updated_at' => function (array $pirep) { return $pirep['created_at']; }, ]; diff --git a/app/Database/factories/AirlineFactory.php b/app/Database/factories/AirlineFactory.php index 20067eb4..143ccf81 100644 --- a/app/Database/factories/AirlineFactory.php +++ b/app/Database/factories/AirlineFactory.php @@ -8,15 +8,18 @@ use Hashids\Hashids; */ $factory->define(App\Models\Airline::class, function (Faker $faker) { return [ - 'id' => null, - 'icao' => function (array $apt) use ($faker) { + 'id' => null, + 'icao' => function (array $apt) use ($faker) { $hashids = new Hashids(microtime(), 5); $mt = str_replace('.', '', microtime(true)); + return $hashids->encode($mt); }, - 'iata' => function (array $apt) { return $apt['icao']; }, - 'name' => $faker->sentence(3), + 'iata' => function (array $apt) { + return $apt['icao']; + }, + 'name' => $faker->sentence(3), 'country' => $faker->country, - 'active' => 1 + 'active' => 1 ]; }); diff --git a/app/Database/factories/AirportFactory.php b/app/Database/factories/AirportFactory.php index 9c5c5d86..5ec4c1ef 100644 --- a/app/Database/factories/AirportFactory.php +++ b/app/Database/factories/AirportFactory.php @@ -6,9 +6,8 @@ use Faker\Generator as Faker; * Add any number of airports. Don't really care if they're real or not */ $factory->define(App\Models\Airport::class, function (Faker $faker) { - return [ - 'id' => function() { + 'id' => function () { $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $string = ''; $max = strlen($characters) - 1; @@ -18,16 +17,20 @@ $factory->define(App\Models\Airport::class, function (Faker $faker) { return $string; }, - 'icao' => function(array $apt) { return $apt['id']; }, - 'iata' => function (array $apt) { return $apt['id']; }, - 'name' => $faker->sentence(3), - 'country' => $faker->country, - 'timezone' => $faker->timezone, - 'lat' => $faker->latitude, - 'lon' => $faker->longitude, + 'icao' => function (array $apt) { + return $apt['id']; + }, + 'iata' => function (array $apt) { + return $apt['id']; + }, + 'name' => $faker->sentence(3), + 'country' => $faker->country, + 'timezone' => $faker->timezone, + 'lat' => $faker->latitude, + 'lon' => $faker->longitude, 'ground_handling_cost' => $faker->randomFloat(2, 0, 500), - 'fuel_100ll_cost' => $faker->randomFloat(2, 0, 100), - 'fuel_jeta_cost' => $faker->randomFloat(2, 0, 100), - 'fuel_mogas_cost' => $faker->randomFloat(2, 0, 100), + 'fuel_100ll_cost' => $faker->randomFloat(2, 0, 100), + 'fuel_jeta_cost' => $faker->randomFloat(2, 0, 100), + 'fuel_mogas_cost' => $faker->randomFloat(2, 0, 100), ]; }); diff --git a/app/Database/factories/AwardsFactory.php b/app/Database/factories/AwardsFactory.php index 48cbaba0..2bcbae05 100644 --- a/app/Database/factories/AwardsFactory.php +++ b/app/Database/factories/AwardsFactory.php @@ -4,10 +4,10 @@ use Faker\Generator as Faker; $factory->define(App\Models\Award::class, function (Faker $faker) { return [ - 'id' => null, - 'name' => $faker->name, - 'description' => $faker->text(10), - 'ref_class' => null, + 'id' => null, + 'name' => $faker->name, + 'description' => $faker->text(10), + 'ref_class' => null, 'ref_class_params' => null, ]; }); diff --git a/app/Database/factories/ExpenseFactory.php b/app/Database/factories/ExpenseFactory.php index 15ae4fe9..88779ec0 100644 --- a/app/Database/factories/ExpenseFactory.php +++ b/app/Database/factories/ExpenseFactory.php @@ -5,14 +5,14 @@ use Faker\Generator as Faker; $factory->define(App\Models\Expense::class, function (Faker $faker) { return [ - 'id' => null, - 'airline_id' => null, - 'name' => $faker->text(20), - 'amount' => $faker->randomFloat(2, 100, 1000), - 'type' => ExpenseType::FLIGHT, - 'multiplier' => false, - 'ref_class' => \App\Models\Expense::class, + 'id' => null, + 'airline_id' => null, + 'name' => $faker->text(20), + 'amount' => $faker->randomFloat(2, 100, 1000), + 'type' => ExpenseType::FLIGHT, + 'multiplier' => false, + 'ref_class' => \App\Models\Expense::class, 'ref_class_id' => null, - 'active' => true, + 'active' => true, ]; }); diff --git a/app/Database/factories/FareFactory.php b/app/Database/factories/FareFactory.php index 1721abb9..0289435b 100644 --- a/app/Database/factories/FareFactory.php +++ b/app/Database/factories/FareFactory.php @@ -4,11 +4,11 @@ use Faker\Generator as Faker; $factory->define(App\Models\Fare::class, function (Faker $faker) { return [ - 'id' => null, - 'code' => $faker->text(5), - 'name' => $faker->text(20), - 'price' => $faker->randomFloat(2, 100, 1000), - 'cost' => function (array $fare) { + 'id' => null, + 'code' => $faker->text(5), + 'name' => $faker->text(20), + 'price' => $faker->randomFloat(2, 100, 1000), + 'cost' => function (array $fare) { return round($fare['price'] / 2); }, 'capacity' => $faker->randomFloat(0, 20, 500), diff --git a/app/Database/factories/FlightFactory.php b/app/Database/factories/FlightFactory.php index ccdc5c03..83776e99 100644 --- a/app/Database/factories/FlightFactory.php +++ b/app/Database/factories/FlightFactory.php @@ -8,14 +8,14 @@ $airlinesAvailable = [1]; $factory->define(App\Models\Flight::class, function (Faker $faker) use ($airlinesAvailable) { return [ - 'id' => null, - 'airline_id' => function () { + 'id' => null, + 'airline_id' => function () { return factory(App\Models\Airline::class)->create()->id; }, - 'flight_number' => $faker->unique()->numberBetween(10, 1000000), - 'route_code' => $faker->randomElement(['', $faker->text(5)]), - 'route_leg' => $faker->randomElement(['', $faker->text(5)]), - 'dpt_airport_id' => function() { + 'flight_number' => $faker->unique()->numberBetween(10, 1000000), + 'route_code' => $faker->randomElement(['', $faker->text(5)]), + 'route_leg' => $faker->randomElement(['', $faker->text(5)]), + 'dpt_airport_id' => function () { return factory(App\Models\Airport::class)->create()->id; }, 'arr_airport_id' => function () { @@ -24,15 +24,15 @@ $factory->define(App\Models\Flight::class, function (Faker $faker) use ($airline 'alt_airport_id' => function () { return factory(App\Models\Airport::class)->create()->id; }, - 'distance' => $faker->numberBetween(0, 3000), - 'route' => null, - 'dpt_time' => $faker->time(), - 'arr_time' => $faker->time(), - 'flight_time' => $faker->numberBetween(60, 360), - 'has_bid' => false, - 'active' => true, - 'created_at' => $faker->dateTimeBetween('-1 week', 'now'), - 'updated_at' => function (array $flight) { + 'distance' => $faker->numberBetween(0, 3000), + 'route' => null, + 'dpt_time' => $faker->time(), + 'arr_time' => $faker->time(), + 'flight_time' => $faker->numberBetween(60, 360), + 'has_bid' => false, + 'active' => true, + 'created_at' => $faker->dateTimeBetween('-1 week', 'now'), + 'updated_at' => function (array $flight) { return $flight['created_at']; }, ]; diff --git a/app/Database/factories/JournalFactory.php b/app/Database/factories/JournalFactory.php index 497868f2..c4d4d6ee 100644 --- a/app/Database/factories/JournalFactory.php +++ b/app/Database/factories/JournalFactory.php @@ -4,6 +4,6 @@ use Faker\Generator as Faker; $factory->define(App\Models\Journal::class, function (Faker $faker) { return [ - 'currency' => 'USD', + 'currency' => 'USD', ]; }); diff --git a/app/Database/factories/JournalTransactionsFactory.php b/app/Database/factories/JournalTransactionsFactory.php index 81ba2a64..a46d2693 100644 --- a/app/Database/factories/JournalTransactionsFactory.php +++ b/app/Database/factories/JournalTransactionsFactory.php @@ -5,13 +5,13 @@ use Faker\Generator as Faker; $factory->define(App\Models\JournalTransactions::class, function (Faker $faker) { return [ 'transaction_group' => \Ramsey\Uuid\Uuid::uuid4()->toString(), - 'journal_id' => function () { + 'journal_id' => function () { return factory(App\Models\Journal::class)->create()->id; }, - 'credit' => $faker->numberBetween(100, 10000), - 'debit' => $faker->numberBetween(100, 10000), - 'currency' => 'USD', - 'memo' => $faker->sentence(6), - 'post_date' => \Carbon\Carbon::now(), + 'credit' => $faker->numberBetween(100, 10000), + 'debit' => $faker->numberBetween(100, 10000), + 'currency' => 'USD', + 'memo' => $faker->sentence(6), + 'post_date' => \Carbon\Carbon::now(), ]; }); diff --git a/app/Database/factories/NavdataFactory.php b/app/Database/factories/NavdataFactory.php index dedebbda..db3130ca 100644 --- a/app/Database/factories/NavdataFactory.php +++ b/app/Database/factories/NavdataFactory.php @@ -5,11 +5,11 @@ use Faker\Generator as Faker; $factory->define(App\Models\Navdata::class, function (Faker $faker) { return [ - 'id' => str_replace(' ', '', str_replace('.', '', $faker->unique()->text(5))), + 'id' => str_replace(' ', '', str_replace('.', '', $faker->unique()->text(5))), 'name' => str_replace('.', '', $faker->unique()->word), 'type' => $faker->randomElement([NavaidType::VOR, NavaidType::NDB]), - 'lat' => $faker->latitude, - 'lon' => $faker->longitude, + 'lat' => $faker->latitude, + 'lon' => $faker->longitude, 'freq' => $faker->randomFloat(2, 100, 1000), ]; }); diff --git a/app/Database/factories/PirepFactory.php b/app/Database/factories/PirepFactory.php index dfa1b34d..133d3f21 100644 --- a/app/Database/factories/PirepFactory.php +++ b/app/Database/factories/PirepFactory.php @@ -7,47 +7,46 @@ use Faker\Generator as Faker; * Create a new PIREP */ $factory->define(App\Models\Pirep::class, function (Faker $faker) { - return [ - 'id' => null, - 'airline_id' => function () { + 'id' => null, + 'airline_id' => function () { return factory(App\Models\Airline::class)->create()->id; }, - 'user_id' => function () { + 'user_id' => function () { return factory(App\Models\User::class)->create()->id; }, - 'aircraft_id' => function () { + 'aircraft_id' => function () { return factory(App\Models\Aircraft::class)->create()->id; }, - 'flight_number' => function (array $pirep) { + 'flight_number' => function (array $pirep) { return factory(App\Models\Flight::class)->create([ 'airline_id' => $pirep['airline_id'] ])->flight_number; }, - 'route_code' => null, - 'route_leg' => null, - 'dpt_airport_id' => function () { + 'route_code' => null, + 'route_leg' => null, + 'dpt_airport_id' => function () { return factory(App\Models\Airport::class)->create()->id; }, - 'arr_airport_id' => function () { + 'arr_airport_id' => function () { return factory(App\Models\Airport::class)->create()->id; }, - 'level' => $faker->numberBetween(20, 400), - 'distance' => $faker->randomFloat(2, 0, 6000), - 'planned_distance' => $faker->randomFloat(2, 0, 6000), - 'flight_time' => $faker->numberBetween(60, 360), + 'level' => $faker->numberBetween(20, 400), + 'distance' => $faker->randomFloat(2, 0, 6000), + 'planned_distance' => $faker->randomFloat(2, 0, 6000), + 'flight_time' => $faker->numberBetween(60, 360), 'planned_flight_time' => $faker->numberBetween(60, 360), - 'zfw' => $faker->randomFloat(2), - 'block_fuel' => $faker->randomFloat(2, 0, 30000), - 'fuel_used' => $faker->randomFloat(2, 0, 30000), - 'route' => $faker->text(200), - 'notes' => $faker->text(200), - 'source' => $faker->randomElement([PirepSource::MANUAL, PirepSource::ACARS]), - 'source_name' => 'Test Factory', - 'state' => PirepState::PENDING, - 'status' => PirepStatus::SCHEDULED, - 'created_at' => Carbon::now()->toDateTimeString(), - 'updated_at' => function(array $pirep) { + 'zfw' => $faker->randomFloat(2), + 'block_fuel' => $faker->randomFloat(2, 0, 30000), + 'fuel_used' => $faker->randomFloat(2, 0, 30000), + 'route' => $faker->text(200), + 'notes' => $faker->text(200), + 'source' => $faker->randomElement([PirepSource::MANUAL, PirepSource::ACARS]), + 'source_name' => 'Test Factory', + 'state' => PirepState::PENDING, + 'status' => PirepStatus::SCHEDULED, + 'created_at' => Carbon::now()->toDateTimeString(), + 'updated_at' => function (array $pirep) { return $pirep['created_at']; }, ]; diff --git a/app/Database/factories/RankFactory.php b/app/Database/factories/RankFactory.php index 39911df4..3ea3d9f4 100644 --- a/app/Database/factories/RankFactory.php +++ b/app/Database/factories/RankFactory.php @@ -11,13 +11,13 @@ use Faker\Generator as Faker; */ $factory->define(App\Models\Rank::class, function (Faker $faker) { return [ - 'id' => null, - 'name' => $faker->unique()->text(50), - 'hours' => $faker->numberBetween(10, 50), - 'acars_base_pay_rate' => $faker->numberBetween(10, 100), + 'id' => null, + 'name' => $faker->unique()->text(50), + 'hours' => $faker->numberBetween(10, 50), + 'acars_base_pay_rate' => $faker->numberBetween(10, 100), 'manual_base_pay_rate' => $faker->numberBetween(10, 100), - 'auto_approve_acars' => 0, - 'auto_approve_manual' => 0, - 'auto_promote' => 0, + 'auto_approve_acars' => 0, + 'auto_approve_manual' => 0, + 'auto_promote' => 0, ]; }); diff --git a/app/Database/factories/SubfleetFactory.php b/app/Database/factories/SubfleetFactory.php index 3790cf9c..3fa500e6 100644 --- a/app/Database/factories/SubfleetFactory.php +++ b/app/Database/factories/SubfleetFactory.php @@ -4,12 +4,12 @@ use Faker\Generator as Faker; $factory->define(App\Models\Subfleet::class, function (Faker $faker) { return [ - 'id' => null, - 'airline_id' => function () { + 'id' => null, + 'airline_id' => function () { return factory(App\Models\Airline::class)->create()->id; }, - 'name' => $faker->unique()->text(50), - 'type' => $faker->unique()->text(7), + 'name' => $faker->unique()->text(50), + 'type' => $faker->unique()->text(7), 'ground_handling_multiplier' => $faker->numberBetween(50, 200), ]; }); diff --git a/app/Database/factories/UserFactory.php b/app/Database/factories/UserFactory.php index 2ac82906..f8a5d206 100644 --- a/app/Database/factories/UserFactory.php +++ b/app/Database/factories/UserFactory.php @@ -3,24 +3,23 @@ use App\Models\Enums\UserState; use Faker\Generator as Faker; -$factory->define(App\Models\User::class, function (Faker $faker) -{ +$factory->define(App\Models\User::class, function (Faker $faker) { static $password; return [ - 'id' => null, - 'name' => $faker->name, - 'email' => $faker->safeEmail, - 'password' => $password ?: $password = Hash::make('secret'), - 'api_key' => $faker->sha1, - 'airline_id' => function () { + 'id' => null, + 'name' => $faker->name, + 'email' => $faker->safeEmail, + 'password' => $password ?: $password = Hash::make('secret'), + 'api_key' => $faker->sha1, + 'airline_id' => function () { return factory(App\Models\Airline::class)->create()->id; }, - 'rank_id' => 1, - 'flights' => $faker->numberBetween(0, 1000), - 'flight_time' => $faker->numberBetween(0, 10000), - 'transfer_time' => $faker->numberBetween(0, 10000), - 'state' => UserState::ACTIVE, + 'rank_id' => 1, + 'flights' => $faker->numberBetween(0, 1000), + 'flight_time' => $faker->numberBetween(0, 10000), + 'transfer_time' => $faker->numberBetween(0, 10000), + 'state' => UserState::ACTIVE, 'remember_token' => $faker->unique()->text(5), ]; }); diff --git a/app/Database/migrations/2017_06_07_014930_create_settings_table.php b/app/Database/migrations/2017_06_07_014930_create_settings_table.php index 80b17713..ec2ccef1 100644 --- a/app/Database/migrations/2017_06_07_014930_create_settings_table.php +++ b/app/Database/migrations/2017_06_07_014930_create_settings_table.php @@ -35,18 +35,18 @@ class CreateSettingsTable extends Migration */ $this->addSetting('general.start_date', [ - 'name' => 'Start Date', - 'group' => 'general', - 'value' => '', - 'type' => 'date', + 'name' => 'Start Date', + 'group' => 'general', + 'value' => '', + 'type' => 'date', 'description' => 'The date your VA started', ]); $this->addSetting('general.admin_email', [ - 'name' => 'Admin Email', - 'group' => 'general', - 'value' => '', - 'type' => 'text', + 'name' => 'Admin Email', + 'group' => 'general', + 'value' => '', + 'type' => 'text', 'description' => 'Email where notices, etc are sent', ]); @@ -60,56 +60,56 @@ class CreateSettingsTable extends Migration ]);*/ $this->addSetting('units.distance', [ - 'name' => 'Distance Units', - 'group' => 'units', - 'value' => 'NM', - 'type' => 'select', - 'options' => 'km=kilometers,mi=miles,NM=nautical miles', + 'name' => 'Distance Units', + 'group' => 'units', + 'value' => 'NM', + 'type' => 'select', + 'options' => 'km=kilometers,mi=miles,NM=nautical miles', 'description' => 'The distance unit for display', ]); $this->addSetting('units.weight', [ - 'name' => 'Weight Units', - 'group' => 'units', - 'value' => 'lbs', - 'type' => 'select', - 'options' => 'lbs,kg', + 'name' => 'Weight Units', + 'group' => 'units', + 'value' => 'lbs', + 'type' => 'select', + 'options' => 'lbs,kg', 'description' => 'The weight unit for display', ]); $this->addSetting('units.speed', [ - 'name' => 'Speed Units', - 'group' => 'units', - 'value' => 'knot', - 'type' => 'select', - 'options' => 'km/h,knot', + 'name' => 'Speed Units', + 'group' => 'units', + 'value' => 'knot', + 'type' => 'select', + 'options' => 'km/h,knot', 'description' => 'The speed unit for display', ]); $this->addSetting('units.altitude', [ - 'name' => 'Altitude Units', - 'group' => 'units', - 'value' => 'ft', - 'type' => 'select', - 'options' => 'ft=feet,m=meters', + 'name' => 'Altitude Units', + 'group' => 'units', + 'value' => 'ft', + 'type' => 'select', + 'options' => 'ft=feet,m=meters', 'description' => 'The altitude unit for display', ]); $this->addSetting('units.fuel', [ - 'name' => 'Fuel Units', - 'group' => 'units', - 'value' => 'lbs', - 'type' => 'select', - 'options' => 'lbs,kg', + 'name' => 'Fuel Units', + 'group' => 'units', + 'value' => 'lbs', + 'type' => 'select', + 'options' => 'lbs,kg', 'description' => 'The units for fuel for display', ]); $this->addSetting('units.volume', [ - 'name' => 'Volume Units', - 'group' => 'units', - 'value' => 'gallons', - 'type' => 'select', - 'options' => 'gallons,l=liters', + 'name' => 'Volume Units', + 'group' => 'units', + 'value' => 'gallons', + 'type' => 'select', + 'options' => 'gallons,l=liters', 'description' => 'The units for fuel for display', ]); @@ -118,26 +118,26 @@ class CreateSettingsTable extends Migration */ $this->addSetting('bids.disable_flight_on_bid', [ - 'name' => 'Disable flight on bid', - 'group' => 'bids', - 'value' => true, - 'type' => 'boolean', + 'name' => 'Disable flight on bid', + 'group' => 'bids', + 'value' => true, + 'type' => 'boolean', 'description' => 'When a flight is bid on, no one else can bid on it', ]); $this->addSetting('bids.allow_multiple_bids', [ - 'name' => 'Allow multiple bids', - 'group' => 'bids', - 'value' => true, - 'type' => 'boolean', + 'name' => 'Allow multiple bids', + 'group' => 'bids', + 'value' => true, + 'type' => 'boolean', 'description' => 'Whether or not someone can bid on multiple flights', ]); $this->addSetting('bids.expire_time', [ - 'name' => 'Expire Time', - 'group' => 'bids', - 'value' => 48, - 'type' => 'int', + 'name' => 'Expire Time', + 'group' => 'bids', + 'value' => 48, + 'type' => 'int', 'description' => 'Number of hours to expire bids after', ]); @@ -146,10 +146,10 @@ class CreateSettingsTable extends Migration */ $this->addSetting('pireps.duplicate_check_time', [ - 'name' => 'PIREP duplicate time check', - 'group' => 'pireps', - 'value' => 10, - 'type' => 'int', + 'name' => 'PIREP duplicate time check', + 'group' => 'pireps', + 'value' => 10, + 'type' => 'int', 'description' => 'The time in minutes to check for a duplicate PIREP', ]); @@ -162,26 +162,26 @@ class CreateSettingsTable extends Migration ]);*/ $this->addSetting('pireps.restrict_aircraft_to_rank', [ - 'name' => 'Restrict Aircraft to Ranks', - 'group' => 'pireps', - 'value' => true, - 'type' => 'boolean', + 'name' => 'Restrict Aircraft to Ranks', + 'group' => 'pireps', + 'value' => true, + 'type' => 'boolean', 'description' => 'Aircraft that can be flown are restricted to a user\'s rank', ]); $this->addSetting('pireps.only_aircraft_at_dep_airport', [ - 'name' => 'Restrict Aircraft At Departure', - 'group' => 'pireps', - 'value' => false, - 'type' => 'boolean', + 'name' => 'Restrict Aircraft At Departure', + 'group' => 'pireps', + 'value' => false, + 'type' => 'boolean', 'description' => 'Only allow aircraft that are at the departure airport', ]); $this->addSetting('pireps.remove_bid_on_accept', [ - 'name' => 'Remove bid on accept', - 'group' => 'pireps', - 'value' => false, - 'type' => 'boolean', + 'name' => 'Remove bid on accept', + 'group' => 'pireps', + 'value' => false, + 'type' => 'boolean', 'description' => 'When a PIREP is accepted, remove the bid, if it exists', ]); @@ -190,52 +190,52 @@ class CreateSettingsTable extends Migration */ $this->addSetting('pilots.id_length', [ - 'name' => 'Pilot ID Length', - 'group' => 'pilots', - 'value' => 4, - 'default' => 4, - 'type' => 'int', + 'name' => 'Pilot ID Length', + 'group' => 'pilots', + 'value' => 4, + 'default' => 4, + 'type' => 'int', 'description' => 'The length of a pilot\'s ID', ]); $this->addSetting('pilots.auto_accept', [ - 'name' => 'Auto Accept New Pilot', - 'group' => 'pilots', - 'value' => true, - 'type' => 'boolean', + 'name' => 'Auto Accept New Pilot', + 'group' => 'pilots', + 'value' => true, + 'type' => 'boolean', 'description' => 'Automatically accept a pilot when they register', ]); $this->addSetting('pilots.home_hubs_only', [ - 'name' => 'Hubs as home airport', - 'group' => 'pilots', - 'value' => false, - 'type' => 'boolean', + 'name' => 'Hubs as home airport', + 'group' => 'pilots', + 'value' => false, + 'type' => 'boolean', 'description' => 'Pilots can only select hubs as their home airport', ]); $this->addSetting('pilots.only_flights_from_current', [ - 'name' => 'Flights from Current', - 'group' => 'pilots', - 'value' => false, - 'type' => 'boolean', + 'name' => 'Flights from Current', + 'group' => 'pilots', + 'value' => false, + 'type' => 'boolean', 'description' => 'Only show/allow flights from their current location', ]); $this->addSetting('pilots.auto_leave_days', [ - 'name' => 'Pilot to ON LEAVE days', - 'group' => 'pilots', - 'value' => 30, - 'default' => 30, - 'type' => 'int', + 'name' => 'Pilot to ON LEAVE days', + 'group' => 'pilots', + 'value' => 30, + 'default' => 30, + 'type' => 'int', 'description' => 'Automatically set a pilot to ON LEAVE status after N days of no activity', ]); $this->addSetting('pilots.hide_inactive', [ - 'name' => 'Hide Inactive Pilots', - 'group' => 'pilots', - 'value' => true, - 'type' => 'boolean', + 'name' => 'Hide Inactive Pilots', + 'group' => 'pilots', + 'value' => true, + 'type' => 'boolean', 'description' => 'Don\'t show inactive pilots in the public view', ]); } diff --git a/app/Database/migrations/2017_06_08_0001_roles_permissions_tables.php b/app/Database/migrations/2017_06_08_0001_roles_permissions_tables.php index a8dd6179..134d2409 100644 --- a/app/Database/migrations/2017_06_08_0001_roles_permissions_tables.php +++ b/app/Database/migrations/2017_06_08_0001_roles_permissions_tables.php @@ -70,18 +70,17 @@ class RolesPermissionsTables extends Migration # create a default user/role $roles = [ [ - 'id' => 1, - 'name' => 'admin', + 'id' => 1, + 'name' => 'admin', 'display_name' => 'Administrators', ], [ - 'id' => 2, - 'name' => 'user', + 'id' => 2, + 'name' => 'user', 'display_name' => 'Pilot' ], ]; - $this->addData('roles', $roles); } diff --git a/app/Database/migrations/2017_06_08_191703_create_airlines_table.php b/app/Database/migrations/2017_06_08_191703_create_airlines_table.php index da8f85cf..d0ab5d60 100644 --- a/app/Database/migrations/2017_06_08_191703_create_airlines_table.php +++ b/app/Database/migrations/2017_06_08_191703_create_airlines_table.php @@ -5,7 +5,6 @@ use Illuminate\Database\Schema\Blueprint; class CreateAirlinesTable extends Migration { - /** * Run the migrations. * diff --git a/app/Database/migrations/2017_06_09_010621_create_aircrafts_table.php b/app/Database/migrations/2017_06_09_010621_create_aircrafts_table.php index 68cbc1f8..1ea1af36 100644 --- a/app/Database/migrations/2017_06_09_010621_create_aircrafts_table.php +++ b/app/Database/migrations/2017_06_09_010621_create_aircrafts_table.php @@ -27,7 +27,6 @@ class CreateAircraftsTable extends Migration $table->unique('registration'); $table->index('airport_id'); }); - } public function down() diff --git a/app/Database/migrations/2017_06_10_040335_create_fares_table.php b/app/Database/migrations/2017_06_10_040335_create_fares_table.php index 525925ce..e7ec7cac 100644 --- a/app/Database/migrations/2017_06_10_040335_create_fares_table.php +++ b/app/Database/migrations/2017_06_10_040335_create_fares_table.php @@ -5,7 +5,6 @@ use Illuminate\Database\Schema\Blueprint; class CreateFaresTable extends Migration { - /** * Run the migrations. * diff --git a/app/Database/migrations/2017_06_17_214650_create_flight_tables.php b/app/Database/migrations/2017_06_17_214650_create_flight_tables.php index 4b458c84..a7766987 100644 --- a/app/Database/migrations/2017_06_17_214650_create_flight_tables.php +++ b/app/Database/migrations/2017_06_17_214650_create_flight_tables.php @@ -6,7 +6,6 @@ use Illuminate\Database\Schema\Blueprint; class CreateFlightTables extends Migration { - /** * Run the migrations. * diff --git a/app/Database/migrations/2017_06_21_165410_create_ranks_table.php b/app/Database/migrations/2017_06_21_165410_create_ranks_table.php index 82a1d087..23cbb798 100644 --- a/app/Database/migrations/2017_06_21_165410_create_ranks_table.php +++ b/app/Database/migrations/2017_06_21_165410_create_ranks_table.php @@ -5,7 +5,6 @@ use Illuminate\Database\Schema\Blueprint; class CreateRanksTable extends Migration { - /** * Run the migrations. * @@ -33,10 +32,10 @@ class CreateRanksTable extends Migration */ $ranks = [ [ - 'id' => 1, - 'name' => 'New Pilot', - 'hours' => 0, - 'acars_base_pay_rate' => 50, + 'id' => 1, + 'name' => 'New Pilot', + 'hours' => 0, + 'acars_base_pay_rate' => 50, 'manual_base_pay_rate' => 25, ] ]; diff --git a/app/Database/migrations/2017_06_23_011011_create_subfleet_tables.php b/app/Database/migrations/2017_06_23_011011_create_subfleet_tables.php index beff35f0..d33cbd59 100644 --- a/app/Database/migrations/2017_06_23_011011_create_subfleet_tables.php +++ b/app/Database/migrations/2017_06_23_011011_create_subfleet_tables.php @@ -35,7 +35,7 @@ class CreateSubfleetTables extends Migration $table->index(['fare_id', 'subfleet_id']); }); - Schema::create('subfleet_flight', function(Blueprint $table) { + Schema::create('subfleet_flight', function (Blueprint $table) { $table->unsignedInteger('subfleet_id'); $table->string('flight_id', 12); @@ -43,7 +43,7 @@ class CreateSubfleetTables extends Migration $table->index(['flight_id', 'subfleet_id']); }); - Schema::create('subfleet_rank', function(Blueprint $table) { + Schema::create('subfleet_rank', function (Blueprint $table) { $table->unsignedInteger('rank_id'); $table->unsignedInteger('subfleet_id'); $table->string('acars_pay')->nullable(); diff --git a/app/Database/migrations/2017_06_28_195426_create_pirep_tables.php b/app/Database/migrations/2017_06_28_195426_create_pirep_tables.php index 1662ebf9..2fb620ed 100644 --- a/app/Database/migrations/2017_06_28_195426_create_pirep_tables.php +++ b/app/Database/migrations/2017_06_28_195426_create_pirep_tables.php @@ -8,7 +8,6 @@ use Illuminate\Database\Schema\Blueprint; class CreatePirepTables extends Migration { - /** * Run the migrations. * diff --git a/app/Database/migrations/2018_01_03_014930_create_stats_table.php b/app/Database/migrations/2018_01_03_014930_create_stats_table.php index dd22cb8b..aee7aa5d 100644 --- a/app/Database/migrations/2018_01_03_014930_create_stats_table.php +++ b/app/Database/migrations/2018_01_03_014930_create_stats_table.php @@ -22,7 +22,6 @@ class CreateStatsTable extends Migration $table->primary('id'); $table->timestamps(); }); - /*$this->addCounterGroups([ 'flights' => 1, ]); diff --git a/app/Database/migrations/2018_01_28_180522_create_awards_table.php b/app/Database/migrations/2018_01_28_180522_create_awards_table.php index 6d43d6e3..bdbb8da0 100644 --- a/app/Database/migrations/2018_01_28_180522_create_awards_table.php +++ b/app/Database/migrations/2018_01_28_180522_create_awards_table.php @@ -1,8 +1,8 @@ index(['ref_class']); }); - Schema::create('user_awards', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('user_id'); diff --git a/app/Database/migrations/2018_02_26_185121_create_expenses_table.php b/app/Database/migrations/2018_02_26_185121_create_expenses_table.php index 5a7024bd..d80816cf 100644 --- a/app/Database/migrations/2018_02_26_185121_create_expenses_table.php +++ b/app/Database/migrations/2018_02_26_185121_create_expenses_table.php @@ -9,7 +9,6 @@ class CreateExpensesTable extends Migration public function up() { Schema::create('expenses', function (Blueprint $table) { - $table->increments('id'); $table->unsignedInteger('airline_id')->nullable(); diff --git a/app/Database/seeds/DatabaseSeeder.php b/app/Database/seeds/DatabaseSeeder.php index f9d5c71b..bc319d9e 100755 --- a/app/Database/seeds/DatabaseSeeder.php +++ b/app/Database/seeds/DatabaseSeeder.php @@ -9,9 +9,9 @@ class DatabaseSeeder extends Seeder * @var array */ public static $seed_mapper = [ - 'local' => 'dev', - 'qa' => 'dev', - 'staging' => 'dev', + 'local' => 'dev', + 'qa' => 'dev', + 'staging' => 'dev', ]; /** @@ -20,13 +20,13 @@ class DatabaseSeeder extends Seeder public function run() { $env = App::environment(); - if(array_key_exists($env, self::$seed_mapper)) { + if (array_key_exists($env, self::$seed_mapper)) { $env = self::$seed_mapper[$env]; } $path = database_path('seeds/'.$env.'.yml'); - if(!file_exists($path)) { + if (!file_exists($path)) { $path = database_path('seeds/prod.yml'); } diff --git a/app/Events/CronMonthly.php b/app/Events/CronMonthly.php index d5a776d1..2ab176c7 100644 --- a/app/Events/CronMonthly.php +++ b/app/Events/CronMonthly.php @@ -14,6 +14,9 @@ class CronMonthly { use Dispatchable, SerializesModels; + /** + * CronMonthly constructor. + */ public function __construct() { diff --git a/app/Events/CronNightly.php b/app/Events/CronNightly.php index b92f228a..e511a932 100644 --- a/app/Events/CronNightly.php +++ b/app/Events/CronNightly.php @@ -14,6 +14,9 @@ class CronNightly { use Dispatchable, SerializesModels; + /** + * CronNightly constructor. + */ public function __construct() { diff --git a/app/Events/CronWeekly.php b/app/Events/CronWeekly.php index 4381bd73..a2242ddf 100644 --- a/app/Events/CronWeekly.php +++ b/app/Events/CronWeekly.php @@ -14,6 +14,9 @@ class CronWeekly { use Dispatchable, SerializesModels; + /** + * CronWeekly constructor. + */ public function __construct() { diff --git a/app/Events/Expenses.php b/app/Events/Expenses.php index 4f06d218..0359941d 100644 --- a/app/Events/Expenses.php +++ b/app/Events/Expenses.php @@ -32,13 +32,12 @@ use Illuminate\Queue\SerializesModels; class Expenses { use Dispatchable, SerializesModels; - public $pirep; /** * @param Pirep|null $pirep */ - public function __construct(Pirep $pirep=null) + public function __construct(Pirep $pirep = null) { $this->pirep = $pirep; } diff --git a/app/Events/PirepAccepted.php b/app/Events/PirepAccepted.php index 37942b23..e6fcd584 100644 --- a/app/Events/PirepAccepted.php +++ b/app/Events/PirepAccepted.php @@ -7,12 +7,20 @@ use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; +/** + * Class PirepAccepted + * @package App\Events + */ class PirepAccepted { use Dispatchable, InteractsWithSockets, SerializesModels; public $pirep; + /** + * PirepAccepted constructor. + * @param Pirep $pirep + */ public function __construct(Pirep $pirep) { $this->pirep = $pirep; diff --git a/app/Events/PirepFiled.php b/app/Events/PirepFiled.php index 6a7593ce..560b0ca6 100644 --- a/app/Events/PirepFiled.php +++ b/app/Events/PirepFiled.php @@ -10,7 +10,6 @@ use Illuminate\Queue\SerializesModels; class PirepFiled { use Dispatchable, InteractsWithSockets, SerializesModels; - public $pirep; public function __construct(Pirep $pirep) diff --git a/app/Events/PirepRejected.php b/app/Events/PirepRejected.php index 649d1c8d..f189cb1e 100644 --- a/app/Events/PirepRejected.php +++ b/app/Events/PirepRejected.php @@ -7,12 +7,20 @@ use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; +/** + * Class PirepRejected + * @package App\Events + */ class PirepRejected { use Dispatchable, InteractsWithSockets, SerializesModels; public $pirep; + /** + * PirepRejected constructor. + * @param Pirep $pirep + */ public function __construct(Pirep $pirep) { $this->pirep = $pirep; diff --git a/app/Events/TestEvent.php b/app/Events/TestEvent.php index fa9bb4de..8f5fc90d 100644 --- a/app/Events/TestEvent.php +++ b/app/Events/TestEvent.php @@ -7,6 +7,10 @@ use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; +/** + * Class TestEvent + * @package App\Events + */ class TestEvent { use Dispatchable, InteractsWithSockets, SerializesModels; @@ -15,6 +19,7 @@ class TestEvent /** * Create a new event instance. + * @param User $user */ public function __construct(User $user) { diff --git a/app/Events/UserAccepted.php b/app/Events/UserAccepted.php index e3ac3b42..1c58b52c 100644 --- a/app/Events/UserAccepted.php +++ b/app/Events/UserAccepted.php @@ -7,12 +7,20 @@ use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; +/** + * Class UserAccepted + * @package App\Events + */ class UserAccepted { use Dispatchable, InteractsWithSockets, SerializesModels; public $user; + /** + * UserAccepted constructor. + * @param User $user + */ public function __construct(User $user) { $this->user = $user; diff --git a/app/Events/UserRegistered.php b/app/Events/UserRegistered.php index 2d929fd2..57952cdb 100644 --- a/app/Events/UserRegistered.php +++ b/app/Events/UserRegistered.php @@ -7,12 +7,20 @@ use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; +/** + * Class UserRegistered + * @package App\Events + */ class UserRegistered { use Dispatchable, InteractsWithSockets, SerializesModels; public $user; + /** + * UserRegistered constructor. + * @param User $user + */ public function __construct(User $user) { $this->user = $user; diff --git a/app/Events/UserStateChanged.php b/app/Events/UserStateChanged.php index 15e3cf51..97823051 100644 --- a/app/Events/UserStateChanged.php +++ b/app/Events/UserStateChanged.php @@ -17,6 +17,11 @@ class UserStateChanged public $old_state, $user; + /** + * UserStateChanged constructor. + * @param User $user + * @param $old_state + */ public function __construct(User $user, $old_state) { $this->old_state = $old_state; diff --git a/app/Events/UserStatsChanged.php b/app/Events/UserStatsChanged.php index 0ffd6c37..ab89b174 100644 --- a/app/Events/UserStatsChanged.php +++ b/app/Events/UserStatsChanged.php @@ -7,6 +7,10 @@ use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; +/** + * Class UserStatsChanged + * @package App\Events + */ class UserStatsChanged { use Dispatchable, InteractsWithSockets, SerializesModels; diff --git a/app/Exceptions/AircraftPermissionDenied.php b/app/Exceptions/AircraftPermissionDenied.php index b0e83b43..3d722497 100644 --- a/app/Exceptions/AircraftPermissionDenied.php +++ b/app/Exceptions/AircraftPermissionDenied.php @@ -1,16 +1,21 @@ [ - 'status' => $status_code, + 'status' => $status_code, 'message' => $message, ] ]; @@ -60,19 +60,18 @@ class Handler extends ExceptionHandler /** * Render an exception into an HTTP response. * - * @param \Illuminate\Http\Request $request - * @param \Exception $exception + * @param \Illuminate\Http\Request $request + * @param \Exception $exception * @return mixed */ public function render($request, Exception $exception) { if ($request->is('api/*')) { - $headers = []; Log::error('API Error', $exception->getTrace()); - if($exception instanceof ModelNotFoundException || + if ($exception instanceof ModelNotFoundException || $exception instanceof NotFoundHttpException) { $error = $this->createError(404, $exception->getMessage()); } @@ -88,10 +87,10 @@ class Handler extends ExceptionHandler } # Create the detailed errors from the validation errors - elseif($exception instanceof ValidationException) { + elseif ($exception instanceof ValidationException) { $error_messages = []; $errors = $exception->errors(); - foreach($errors as $field => $error) { + foreach ($errors as $field => $error) { $error_messages[] = implode(', ', $error); } @@ -107,7 +106,7 @@ class Handler extends ExceptionHandler } # Only add trace if in dev - if(config('app.env') === 'dev') { + if (config('app.env') === 'dev') { $error['error']['trace'] = $exception->getTrace()[0]; } @@ -125,14 +124,15 @@ class Handler extends ExceptionHandler /** * Convert an authentication exception into an unauthenticated response. * - * @param \Illuminate\Http\Request $request - * @param \Illuminate\Auth\AuthenticationException $exception + * @param \Illuminate\Http\Request $request + * @param \Illuminate\Auth\AuthenticationException $exception * @return \Illuminate\Http\Response */ protected function unauthenticated($request, AuthenticationException $exception) { if ($request->expectsJson() || $request->is('api/*')) { $error = $this->createError(401, 'Unauthenticated'); + return response()->json($error, 401); } @@ -148,13 +148,13 @@ class Handler extends ExceptionHandler { $status = $e->getStatusCode(); view()->replaceNamespace('errors', [ - resource_path('views/layouts/' . config('phpvms.skin') . '/errors'), + resource_path('views/layouts/'.config('phpvms.skin').'/errors'), resource_path('views/errors'), - __DIR__ . '/views', + __DIR__.'/views', ]); if (view()->exists("errors::{$status}")) { - #if (view()->exists('layouts' . config('phpvms.skin') .'.errors.' .$status)) { + #if (view()->exists('layouts' . config('phpvms.skin') .'.errors.' .$status)) { return response()->view("errors::{$status}", [ 'exception' => $e, 'SKIN_NAME' => config('phpvms.skin'), diff --git a/app/Exceptions/PirepCancelled.php b/app/Exceptions/PirepCancelled.php index 7c1cd513..8db80e2a 100644 --- a/app/Exceptions/PirepCancelled.php +++ b/app/Exceptions/PirepCancelled.php @@ -1,16 +1,21 @@ request('GET', $uri, $opts); $body = $response->getBody()->getContents(); - if($response->getHeader('content-type') === 'application/json') { + if ($response->getHeader('content-type') === 'application/json') { $body = \GuzzleHttp\json_decode($body); } return $body; } - /** * Returns a 40 character API key that a user can use * @return string */ public static function generateApiKey() { - $key = substr(sha1(time() . mt_rand()), 0, 20); + $key = substr(sha1(time().mt_rand()), 0, 20); return $key; } @@ -78,7 +84,7 @@ class Utils extends Facade public static function minutesToTimeString($minutes): string { $hm = self::minutesToTimeParts($minutes); - return $hm['h']. 'h '. $hm['m'] . 'm'; + return $hm['h'].'h '.$hm['m'].'m'; } /** @@ -103,15 +109,15 @@ class Utils extends Facade /** * Convert seconds to HH MM format - * @param $seconds + * @param $seconds * @param bool $incl_sec * @return string */ - public static function secondsToTimeString($seconds, $incl_sec=false): string + public static function secondsToTimeString($seconds, $incl_sec = false): string { $hms = self::secondsToTimeParts($seconds); $format = $hms['h'].'h '.$hms['m'].'m'; - if($incl_sec) { + if ($incl_sec) { $format .= ' '.$hms['s'].'s'; } @@ -134,7 +140,7 @@ class Utils extends Facade */ public static function secondsToMinutes($seconds) { - return ceil($seconds/60); + return ceil($seconds / 60); } /** @@ -144,18 +150,18 @@ class Utils extends Facade */ public static function minutesToHours($minutes) { - return $minutes/60; + return $minutes / 60; } /** - * @param $hours + * @param $hours * @param null $minutes * @return float|int */ - public static function hoursToMinutes($hours, $minutes=null) + public static function hoursToMinutes($hours, $minutes = null) { $total = (int) $hours * 60; - if($minutes) { + if ($minutes) { $total += (int) $minutes; } @@ -164,12 +170,13 @@ class Utils extends Facade /** * Bitwise operator for setting days of week to integer field - * @param int $datefield initial datefield + * @param int $datefield initial datefield * @param array $day_enums Array of values from config("enum.days") * @return int */ - public static function setDays(int $datefield, array $day_enums) { - foreach($day_enums as $day) { + public static function setDays(int $datefield, array $day_enums) + { + foreach ($day_enums as $day) { $datefield |= $day; } @@ -179,10 +186,11 @@ class Utils extends Facade /** * Bit check if a day exists within a integer bitfield * @param int $datefield datefield from database - * @param int $day_enum Value from config("enum.days") + * @param int $day_enum Value from config("enum.days") * @return bool */ - public static function hasDay(int $datefield, int $day_enum) { + public static function hasDay(int $datefield, int $day_enum) + { return ($datefield & $day_enum) === $datefield; } } diff --git a/app/Http/Controllers/Admin/AircraftController.php b/app/Http/Controllers/Admin/AircraftController.php index dda98c9d..a9422211 100644 --- a/app/Http/Controllers/Admin/AircraftController.php +++ b/app/Http/Controllers/Admin/AircraftController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreateAircraftRequest; use App\Http\Requests\UpdateAircraftRequest; +use App\Interfaces\Controller; use App\Models\Aircraft; use App\Models\Enums\AircraftStatus; use App\Models\Expense; @@ -13,8 +14,11 @@ use Flash; use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; - -class AircraftController extends BaseController +/** + * Class AircraftController + * @package App\Http\Controllers\Admin + */ +class AircraftController extends Controller { private $aircraftRepo; @@ -49,7 +53,7 @@ class AircraftController extends BaseController { return view('admin.aircraft.create', [ 'subfleets' => Subfleet::all()->pluck('name', 'id'), - 'statuses' => AircraftStatus::select(true), + 'statuses' => AircraftStatus::select(true), ]); } @@ -63,6 +67,7 @@ class AircraftController extends BaseController $aircraft = $this->aircraftRepo->create($attrs); Flash::success('Aircraft saved successfully.'); + return redirect(route('admin.aircraft.edit', ['id' => $aircraft->id])); } @@ -75,11 +80,12 @@ class AircraftController extends BaseController if (empty($aircraft)) { Flash::error('Aircraft not found'); + return redirect(route('admin.aircraft.index')); } return view('admin.aircraft.show', [ - 'aircraft' => $aircraft, + 'aircraft' => $aircraft, ]); } @@ -92,12 +98,13 @@ class AircraftController extends BaseController if (empty($aircraft)) { Flash::error('Aircraft not found'); + return redirect(route('admin.aircraft.index')); } return view('admin.aircraft.edit', [ 'subfleets' => Subfleet::all()->pluck('name', 'id'), - 'statuses' => AircraftStatus::select(true), + 'statuses' => AircraftStatus::select(true), 'aircraft' => $aircraft, ]); } @@ -112,6 +119,7 @@ class AircraftController extends BaseController if (empty($aircraft)) { Flash::error('Aircraft not found'); + return redirect(route('admin.aircraft.index')); } @@ -119,6 +127,7 @@ class AircraftController extends BaseController $this->aircraftRepo->update($attrs, $id); Flash::success('Aircraft updated successfully.'); + return redirect(route('admin.aircraft.index')); } @@ -131,12 +140,14 @@ class AircraftController extends BaseController if (empty($aircraft)) { Flash::error('Aircraft not found'); + return redirect(route('admin.aircraft.index')); } $this->aircraftRepo->delete($id); Flash::success('Aircraft deleted successfully.'); + return redirect(route('admin.aircraft.index')); } @@ -147,6 +158,7 @@ class AircraftController extends BaseController protected function return_expenses_view(?Aircraft $aircraft) { $aircraft->refresh(); + return view('admin.aircraft.expenses', [ 'aircraft' => $aircraft, ]); @@ -154,7 +166,7 @@ class AircraftController extends BaseController /** * Operations for associating ranks to the subfleet - * @param $id + * @param $id * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * @throws \Exception diff --git a/app/Http/Controllers/Admin/AirlinesController.php b/app/Http/Controllers/Admin/AirlinesController.php index 6723cfeb..a9e8343a 100644 --- a/app/Http/Controllers/Admin/AirlinesController.php +++ b/app/Http/Controllers/Admin/AirlinesController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreateAirlineRequest; use App\Http\Requests\UpdateAirlineRequest; +use App\Interfaces\Controller; use App\Repositories\AirlineRepository; use App\Support\Countries; use Flash; @@ -11,9 +12,12 @@ use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; use Response; -class AirlinesController extends BaseController +/** + * Class AirlinesController + * @package App\Http\Controllers\Admin + */ +class AirlinesController extends Controller { - /** @var AirlineRepository */ private $airlineRepo; /** @@ -59,6 +63,7 @@ class AirlinesController extends BaseController $airlines = $this->airlineRepo->create($input); Flash::success('Airlines saved successfully.'); + return redirect(route('admin.airlines.index')); } @@ -73,6 +78,7 @@ class AirlinesController extends BaseController if (empty($airlines)) { Flash::error('Airlines not found'); + return redirect(route('admin.airlines.index')); } @@ -92,18 +98,19 @@ class AirlinesController extends BaseController if (empty($airline)) { Flash::error('Airline not found'); + return redirect(route('admin.airlines.index')); } return view('admin.airlines.edit', [ - 'airline' => $airline, + 'airline' => $airline, 'countries' => Countries::getSelectList(), ]); } /** * Update the specified Airlines in storage. - * @param int $id + * @param int $id * @param UpdateAirlineRequest $request * @return Response * @throws \Prettus\Validator\Exceptions\ValidatorException @@ -114,6 +121,7 @@ class AirlinesController extends BaseController if (empty($airlines)) { Flash::error('Airlines not found'); + return redirect(route('admin.airlines.index')); } @@ -135,12 +143,14 @@ class AirlinesController extends BaseController if (empty($airlines)) { Flash::error('Airlines not found'); + return redirect(route('admin.airlines.index')); } $this->airlineRepo->delete($id); Flash::success('Airlines deleted successfully.'); + return redirect(route('admin.airlines.index')); } } diff --git a/app/Http/Controllers/Admin/AirportController.php b/app/Http/Controllers/Admin/AirportController.php index fe413b34..68a320c7 100644 --- a/app/Http/Controllers/Admin/AirportController.php +++ b/app/Http/Controllers/Admin/AirportController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreateAirportRequest; use App\Http\Requests\UpdateAirportRequest; +use App\Interfaces\Controller; use App\Models\Airport; use App\Models\Expense; use App\Repositories\AirportRepository; @@ -13,14 +14,15 @@ use Illuminate\Http\Request; use Jackiedo\Timezonelist\Facades\Timezonelist; use Response; - -class AirportController extends BaseController +/** + * Class AirportController + * @package App\Http\Controllers\Admin + */ +class AirportController extends Controller { - /** @var AirportRepository */ private $airportRepo; /** - * AirportController constructor. * @param AirportRepository $airportRepo */ public function __construct( @@ -38,14 +40,14 @@ class AirportController extends BaseController public function index(Request $request) { $where = []; - if($request->has('icao')) { + if ($request->has('icao')) { $where['icao'] = $request->get('icao'); } $this->airportRepo->pushCriteria(new WhereCriteria($request, $where)); $airports = $this->airportRepo - ->orderBy('icao', 'asc') - ->paginate(); + ->orderBy('icao', 'asc') + ->paginate(); return view('admin.airports.index', [ 'airports' => $airports, @@ -77,6 +79,7 @@ class AirportController extends BaseController $this->airportRepo->create($input); Flash::success('Airport saved successfully.'); + return redirect(route('admin.airports.index')); } @@ -91,6 +94,7 @@ class AirportController extends BaseController if (empty($airport)) { Flash::error('Airport not found'); + return redirect(route('admin.airports.index')); } @@ -110,18 +114,19 @@ class AirportController extends BaseController if (empty($airport)) { Flash::error('Airport not found'); + return redirect(route('admin.airports.index')); } return view('admin.airports.edit', [ 'timezones' => Timezonelist::toArray(), - 'airport' => $airport, + 'airport' => $airport, ]); } /** * Update the specified Airport in storage. - * @param int $id + * @param int $id * @param UpdateAirportRequest $request * @return Response * @throws \Prettus\Validator\Exceptions\ValidatorException @@ -132,6 +137,7 @@ class AirportController extends BaseController if (empty($airport)) { Flash::error('Airport not found'); + return redirect(route('admin.airports.index')); } @@ -141,6 +147,7 @@ class AirportController extends BaseController $this->airportRepo->update($attrs, $id); Flash::success('Airport updated successfully.'); + return redirect(route('admin.airports.index')); } @@ -155,12 +162,14 @@ class AirportController extends BaseController if (empty($airport)) { Flash::error('Airport not found'); + return redirect(route('admin.airports.index')); } $this->airportRepo->delete($id); Flash::success('Airport deleted successfully.'); + return redirect(route('admin.airports.index')); } @@ -171,6 +180,7 @@ class AirportController extends BaseController protected function return_expenses_view(?Airport $airport) { $airport->refresh(); + return view('admin.airports.expenses', [ 'airport' => $airport, ]); @@ -178,7 +188,7 @@ class AirportController extends BaseController /** * Operations for associating ranks to the subfleet - * @param $id + * @param $id * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * @throws \Exception @@ -224,6 +234,7 @@ class AirportController extends BaseController $airport = $this->airportRepo->findWithoutFail($id); if (empty($airport)) { Flash::error('Flight not found'); + return redirect(route('admin.flights.index')); } diff --git a/app/Http/Controllers/Admin/AwardController.php b/app/Http/Controllers/Admin/AwardController.php index bfda770a..93d39be7 100755 --- a/app/Http/Controllers/Admin/AwardController.php +++ b/app/Http/Controllers/Admin/AwardController.php @@ -4,19 +4,25 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreateAwardRequest; use App\Http\Requests\UpdateAwardRequest; +use App\Interfaces\Controller; use App\Repositories\AwardRepository; use App\Services\AwardService; -use Illuminate\Http\Request; use Flash; +use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; use Response; -class AwardController extends BaseController +class AwardController extends Controller { /** @var AwardRepository */ private $awardRepository, - $awardSvc; + $awardSvc; + /** + * AwardController constructor. + * @param AwardRepository $awardRepo + * @param AwardService $awardSvc + */ public function __construct( AwardRepository $awardRepo, AwardService $awardSvc @@ -38,13 +44,13 @@ class AwardController extends BaseController $descriptions = []; $award_classes = $this->awardSvc->findAllAwardClasses(); - foreach($award_classes as $class_ref => $award) { + foreach ($award_classes as $class_ref => $award) { $awards[$class_ref] = $award->name; $descriptions[$class_ref] = $award->param_description; } return [ - 'awards' => $awards, + 'awards' => $awards, 'descriptions' => $descriptions, ]; } @@ -72,8 +78,9 @@ class AwardController extends BaseController public function create() { $class_refs = $this->getAwardClassesAndDescriptions(); + return view('admin.awards.create', [ - 'award_classes' => $class_refs['awards'], + 'award_classes' => $class_refs['awards'], 'award_descriptions' => $class_refs['descriptions'], ]); } @@ -103,6 +110,7 @@ class AwardController extends BaseController $award = $this->awardRepository->findWithoutFail($id); if (empty($award)) { Flash::error('Award not found'); + return redirect(route('admin.awards.index')); } @@ -121,20 +129,22 @@ class AwardController extends BaseController $award = $this->awardRepository->findWithoutFail($id); if (empty($award)) { Flash::error('Award not found'); + return redirect(route('admin.awards.index')); } $class_refs = $this->getAwardClassesAndDescriptions(); + return view('admin.awards.edit', [ - 'award' => $award, - 'award_classes' => $class_refs['awards'], + 'award' => $award, + 'award_classes' => $class_refs['awards'], 'award_descriptions' => $class_refs['descriptions'], ]); } /** * Update the specified award in storage. - * @param int $id + * @param int $id * @param UpdateAwardRequest $request * @return Response * @throws \Prettus\Validator\Exceptions\ValidatorException @@ -144,6 +154,7 @@ class AwardController extends BaseController $award = $this->awardRepository->findWithoutFail($id); if (empty($award)) { Flash::error('Award not found'); + return redirect(route('admin.awards.index')); } @@ -165,6 +176,7 @@ class AwardController extends BaseController $award = $this->awardRepository->findWithoutFail($id); if (empty($award)) { Flash::error('Fare not found'); + return redirect(route('admin.awards.index')); } diff --git a/app/Http/Controllers/Admin/BaseController.php b/app/Http/Controllers/Admin/BaseController.php deleted file mode 100644 index f84f0604..00000000 --- a/app/Http/Controllers/Admin/BaseController.php +++ /dev/null @@ -1,12 +0,0 @@ -getMessage()); @@ -63,9 +70,9 @@ class DashboardController extends BaseController $this->checkNewVersion(); return view('admin.dashboard.index', [ - 'news' => $this->newsRepo->getLatest(), + 'news' => $this->newsRepo->getLatest(), 'pending_pireps' => $this->pirepRepo->getPendingCount(), - 'pending_users' => $this->userRepo->getPendingCount(), + 'pending_users' => $this->userRepo->getPendingCount(), ]); } @@ -76,7 +83,7 @@ class DashboardController extends BaseController */ public function news(Request $request) { - if($request->isMethod('post')) { + if ($request->isMethod('post')) { $attrs = $request->post(); $attrs['user_id'] = Auth::user()->id; diff --git a/app/Http/Controllers/Admin/ExpenseController.php b/app/Http/Controllers/Admin/ExpenseController.php index dc085b8e..5a98a7d9 100644 --- a/app/Http/Controllers/Admin/ExpenseController.php +++ b/app/Http/Controllers/Admin/ExpenseController.php @@ -2,8 +2,7 @@ namespace App\Http\Controllers\Admin; -use App\Http\Requests\CreateAirlineRequest; -use App\Http\Requests\UpdateAirlineRequest; +use App\Interfaces\Controller; use App\Models\Enums\ExpenseType; use App\Models\Expense; use App\Repositories\AirlineRepository; @@ -13,7 +12,11 @@ use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; use Response; -class ExpenseController extends BaseController +/** + * Class ExpenseController + * @package App\Http\Controllers\Admin + */ +class ExpenseController extends Controller { private $airlineRepo, $expenseRepo; @@ -73,6 +76,7 @@ class ExpenseController extends BaseController $this->expenseRepo->create($input); Flash::success('Expense saved successfully.'); + return redirect(route('admin.expenses.index')); } @@ -87,6 +91,7 @@ class ExpenseController extends BaseController if (empty($expenses)) { Flash::error('expenses not found'); + return redirect(route('admin.expenses.index')); } @@ -106,11 +111,12 @@ class ExpenseController extends BaseController if (empty($expense)) { Flash::error('Expense not found'); + return redirect(route('admin.expenses.index')); } return view('admin.expenses.edit', [ - 'expense' => $expense, + 'expense' => $expense, 'airlines_list' => $this->airlineRepo->selectBoxList(true), 'expense_types' => ExpenseType::select(), ]); @@ -118,7 +124,7 @@ class ExpenseController extends BaseController /** * Update the specified expenses in storage. - * @param int $id + * @param int $id * @param Request $request * @return Response * @throws \Prettus\Validator\Exceptions\ValidatorException @@ -129,12 +135,14 @@ class ExpenseController extends BaseController if (empty($expenses)) { Flash::error('Expense not found'); + return redirect(route('admin.expenses.index')); } $this->expenseRepo->update($request->all(), $id); Flash::success('Expense updated successfully.'); + return redirect(route('admin.expenses.index')); } @@ -149,12 +157,14 @@ class ExpenseController extends BaseController if (empty($expenses)) { Flash::error('Expense not found'); + return redirect(route('admin.expenses.index')); } $this->expenseRepo->delete($id); Flash::success('Expense deleted successfully.'); + return redirect(route('admin.expenses.index')); } } diff --git a/app/Http/Controllers/Admin/FareController.php b/app/Http/Controllers/Admin/FareController.php index 1afd6320..ac952753 100644 --- a/app/Http/Controllers/Admin/FareController.php +++ b/app/Http/Controllers/Admin/FareController.php @@ -4,15 +4,19 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreateFareRequest; use App\Http\Requests\UpdateFareRequest; +use App\Interfaces\Controller; use App\Repositories\FareRepository; use Flash; use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; use Response; -class FareController extends BaseController +/** + * Class FareController + * @package App\Http\Controllers\Admin + */ +class FareController extends Controller { - /** @var FareRepository */ private $fareRepository; /** @@ -75,6 +79,7 @@ class FareController extends BaseController $fare = $this->fareRepository->findWithoutFail($id); if (empty($fare)) { Flash::error('Fare not found'); + return redirect(route('admin.fares.index')); } @@ -91,6 +96,7 @@ class FareController extends BaseController $fare = $this->fareRepository->findWithoutFail($id); if (empty($fare)) { Flash::error('Fare not found'); + return redirect(route('admin.fares.index')); } @@ -99,7 +105,7 @@ class FareController extends BaseController /** * Update the specified Fare in storage. - * @param int $id + * @param int $id * @param UpdateFareRequest $request * @return Response * @throws \Prettus\Validator\Exceptions\ValidatorException @@ -109,6 +115,7 @@ class FareController extends BaseController $fare = $this->fareRepository->findWithoutFail($id); if (empty($fare)) { Flash::error('Fare not found'); + return redirect(route('admin.fares.index')); } @@ -128,6 +135,7 @@ class FareController extends BaseController $fare = $this->fareRepository->findWithoutFail($id); if (empty($fare)) { Flash::error('Fare not found'); + return redirect(route('admin.fares.index')); } diff --git a/app/Http/Controllers/Admin/FinanceController.php b/app/Http/Controllers/Admin/FinanceController.php index 1628888e..92116e5f 100644 --- a/app/Http/Controllers/Admin/FinanceController.php +++ b/app/Http/Controllers/Admin/FinanceController.php @@ -2,12 +2,11 @@ namespace App\Http\Controllers\Admin; +use App\Interfaces\Controller; use App\Models\Enums\JournalType; use App\Models\Journal; use App\Models\JournalTransaction; use App\Repositories\AirlineRepository; -use App\Repositories\JournalRepository; -use App\Services\Finance\PirepFinanceService; use App\Support\Dates; use App\Support\Money; use Illuminate\Http\Request; @@ -16,25 +15,17 @@ use Illuminate\Http\Request; * Class FinanceController * @package App\Http\Controllers\Admin */ -class FinanceController extends BaseController +class FinanceController extends Controller { - private $airlineRepo, - $financeSvc, - $journalRepo; + private $airlineRepo; /** - * @param AirlineRepository $airlineRepo - * @param PirepFinanceService $financeSvc - * @param JournalRepository $journalRepo + * @param AirlineRepository $airlineRepo */ public function __construct( - AirlineRepository $airlineRepo, - PirepFinanceService $financeSvc, - JournalRepository $journalRepo + AirlineRepository $airlineRepo ) { $this->airlineRepo = $airlineRepo; - $this->financeSvc = $financeSvc; - $this->journalRepo = $journalRepo; } /** @@ -58,8 +49,7 @@ class FinanceController extends BaseController $airlines = $this->airlineRepo->orderBy('icao')->all(); # group by the airline - foreach($airlines as $airline) { - + foreach ($airlines as $airline) { # Return all the transactions, grouped by the transaction group $transactions = JournalTransaction::groupBy('transaction_group') ->selectRaw('transaction_group, currency, @@ -83,16 +73,16 @@ class FinanceController extends BaseController } $transaction_groups[] = [ - 'airline' => $airline, - 'credits' => new Money($sum_all_credits), - 'debits' => new Money($sum_all_debits), - 'transactions' => $transactions, + 'airline' => $airline, + 'credits' => new Money($sum_all_credits), + 'debits' => new Money($sum_all_debits), + 'transactions' => $transactions, ]; } return view('admin.finances.index', [ - 'current_month' => $month, - 'months_list' => Dates::getMonthsList($first_journal->created_at), + 'current_month' => $month, + 'months_list' => Dates::getMonthsList($first_journal->created_at), 'transaction_groups' => $transaction_groups, ]); } @@ -102,6 +92,5 @@ class FinanceController extends BaseController */ public function show($id) { - } } diff --git a/app/Http/Controllers/Admin/FlightController.php b/app/Http/Controllers/Admin/FlightController.php index c61d1d96..911a2fd5 100644 --- a/app/Http/Controllers/Admin/FlightController.php +++ b/app/Http/Controllers/Admin/FlightController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreateFlightRequest; use App\Http\Requests\UpdateFlightRequest; +use App\Interfaces\Controller; use App\Models\Enums\FlightType; use App\Models\Flight; use App\Models\FlightFields; @@ -19,7 +20,11 @@ use Flash; use Illuminate\Http\Request; use Response; -class FlightController extends BaseController +/** + * Class FlightController + * @package App\Http\Controllers\Admin + */ +class FlightController extends Controller { private $airlineRepo, $airportRepo, @@ -31,12 +36,12 @@ class FlightController extends BaseController /** * FlightController constructor. - * @param AirlineRepository $airlineRepo - * @param AirportRepository $airportRepo - * @param FareRepository $fareRepo - * @param FlightRepository $flightRepo - * @param FareService $fareSvc - * @param FlightService $flightSvc + * @param AirlineRepository $airlineRepo + * @param AirportRepository $airportRepo + * @param FareRepository $fareRepo + * @param FlightRepository $flightRepo + * @param FareService $fareSvc + * @param FlightService $flightSvc * @param SubfleetRepository $subfleetRepo */ public function __construct( @@ -84,8 +89,9 @@ class FlightController extends BaseController public function index(Request $request) { $flights = $this->flightRepo->searchCriteria($request, false)->paginate(); + return view('admin.flights.index', [ - 'flights' => $flights, + 'flights' => $flights, 'airlines' => $this->airlineRepo->selectBoxList(true), 'airports' => $this->airportRepo->selectBoxList(true), ]); @@ -98,9 +104,9 @@ class FlightController extends BaseController public function create() { return view('admin.flights.create', [ - 'flight' => null, - 'airlines' => $this->airlineRepo->selectBoxList(), - 'airports' => $this->airportRepo->selectBoxList(true, false), + 'flight' => null, + 'airlines' => $this->airlineRepo->selectBoxList(), + 'airports' => $this->airportRepo->selectBoxList(true, false), 'alt_airports' => $this->airportRepo->selectBoxList(true), 'flight_types' => FlightType::select(true), ]); @@ -120,17 +126,18 @@ class FlightController extends BaseController 'flight_number' => $input['flight_number'], ]; - if(filled($input['route_code'])) { + if (filled($input['route_code'])) { $where['route_code'] = $input['route_code']; } - if(filled($input['route_leg'])) { + if (filled($input['route_leg'])) { $where['route_leg'] = $input['route_leg']; } $flights = $this->flightRepo->findWhere($where); - if($flights->count() > 0) { + if ($flights->count() > 0) { Flash::error('Duplicate flight with same number/code/leg found, please change to proceed'); + return redirect()->back()->withInput($request->all()); } @@ -142,6 +149,7 @@ class FlightController extends BaseController $flight = $this->flightRepo->create($input); Flash::success('Flight saved successfully.'); + return redirect(route('admin.flights.edit', $flight->id)); } @@ -155,12 +163,14 @@ class FlightController extends BaseController if (empty($flight)) { Flash::error('Flight not found'); + return redirect(route('admin.flights.index')); } $avail_subfleets = $this->getAvailSubfleets($flight); + return view('admin.flights.show', [ - 'flight' => $flight, + 'flight' => $flight, 'avail_subfleets' => $avail_subfleets, ]); } @@ -174,6 +184,7 @@ class FlightController extends BaseController $flight = $this->flightRepo->findWithoutFail($id); if (empty($flight)) { Flash::error('Flight not found'); + return redirect(route('admin.flights.index')); } @@ -183,18 +194,18 @@ class FlightController extends BaseController $flight->minutes = $time->minutes; return view('admin.flights.edit', [ - 'flight' => $flight, - 'airlines' => $this->airlineRepo->selectBoxList(), - 'airports' => $this->airportRepo->selectBoxList(), - 'alt_airports' => $this->airportRepo->selectBoxList(true), - 'avail_fares' => $this->getAvailFares($flight), + 'flight' => $flight, + 'airlines' => $this->airlineRepo->selectBoxList(), + 'airports' => $this->airportRepo->selectBoxList(), + 'alt_airports' => $this->airportRepo->selectBoxList(true), + 'avail_fares' => $this->getAvailFares($flight), 'avail_subfleets' => $this->getAvailSubfleets($flight), - 'flight_types' => FlightType::select(true), + 'flight_types' => FlightType::select(true), ]); } /** - * @param $id + * @param $id * @param UpdateFlightRequest $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @throws \Prettus\Validator\Exceptions\ValidatorException @@ -205,6 +216,7 @@ class FlightController extends BaseController if (empty($flight)) { Flash::error('Flight not found'); + return redirect(route('admin.flights.index')); } @@ -227,6 +239,7 @@ class FlightController extends BaseController $flights = $this->flightRepo->findWhere($where); if ($flights->count() > 0) { Flash::error('Duplicate flight with same number/code/leg found, please change to proceed'); + return redirect()->back()->withInput($request->all()); } @@ -239,6 +252,7 @@ class FlightController extends BaseController $this->flightRepo->update($input, $id); Flash::success('Flight updated successfully.'); + return redirect(route('admin.flights.index')); } @@ -253,12 +267,14 @@ class FlightController extends BaseController if (empty($flight)) { Flash::error('Flight not found'); + return redirect(route('admin.flights.index')); } $this->flightSvc->deleteFlight($flight); Flash::success('Flight deleted successfully.'); + return redirect(route('admin.flights.index')); } @@ -269,6 +285,7 @@ class FlightController extends BaseController protected function return_fields_view($flight) { $flight->refresh(); + return view('admin.flights.flight_fields', [ 'flight' => $flight, ]); @@ -285,6 +302,7 @@ class FlightController extends BaseController $flight = $this->flightRepo->findWithoutFail($id); if (empty($flight)) { Flash::error('Flight not found'); + return redirect(route('admin.flights.index')); } @@ -295,16 +313,12 @@ class FlightController extends BaseController $field->name = $request->name; $field->value = $request->value; $field->save(); - } - - elseif ($request->isMethod('put')) { + } elseif ($request->isMethod('put')) { $field = FlightFields::where('id', $request->field_id)->first(); $field->value = $request->value; $field->save(); // update the field value - } - - // remove custom field from flight + } // remove custom field from flight elseif ($request->isMethod('delete')) { FlightFields::destroy($request->field_id); } @@ -319,14 +333,15 @@ class FlightController extends BaseController protected function return_subfleet_view($flight) { $avail_subfleets = $this->getAvailSubfleets($flight); + return view('admin.flights.subfleets', [ - 'flight' => $flight, + 'flight' => $flight, 'avail_subfleets' => $avail_subfleets, ]); } /** - * @param $id + * @param $id * @param Request $request * @return mixed */ @@ -335,15 +350,14 @@ class FlightController extends BaseController $flight = $this->flightRepo->findWithoutFail($id); if (empty($flight)) { Flash::error('Flight not found'); + return redirect(route('admin.flights.index')); } // add aircraft to flight if ($request->isMethod('post')) { $flight->subfleets()->syncWithoutDetaching([$request->subfleet_id]); - } - - // remove aircraft from flight + } // remove aircraft from flight elseif ($request->isMethod('delete')) { $flight->subfleets()->detach($request->subfleet_id); } @@ -360,7 +374,7 @@ class FlightController extends BaseController $all_fares = $this->fareRepo->all(); $avail_fares = $all_fares->except($flight->fares->modelKeys()); foreach ($avail_fares as $fare) { - $retval[$fare->id] = $fare->name . + $retval[$fare->id] = $fare->name. ' (base price: '.$fare->price.')'; } @@ -374,8 +388,9 @@ class FlightController extends BaseController protected function return_fares_view(Flight $flight) { $flight->refresh(); + return view('admin.flights.fares', [ - 'flight' => $flight, + 'flight' => $flight, 'avail_fares' => $this->getAvailFares($flight), ]); } @@ -400,6 +415,7 @@ class FlightController extends BaseController if ($request->isMethod('delete')) { $fare = $this->fareRepo->findWithoutFail($request->fare_id); $this->fareSvc->delFareFromFlight($flight, $fare); + return $this->return_fares_view($flight); } diff --git a/app/Http/Controllers/Admin/PirepController.php b/app/Http/Controllers/Admin/PirepController.php index fbfbcbe4..bfc28a62 100644 --- a/app/Http/Controllers/Admin/PirepController.php +++ b/app/Http/Controllers/Admin/PirepController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin; use App\Facades\Utils; use App\Http\Requests\CreatePirepRequest; use App\Http\Requests\UpdatePirepRequest; +use App\Interfaces\Controller; use App\Models\Enums\PirepSource; use App\Models\Enums\PirepState; use App\Models\Pirep; @@ -27,8 +28,11 @@ use Log; use Prettus\Repository\Criteria\RequestCriteria; use Response; - -class PirepController extends BaseController +/** + * Class PirepController + * @package App\Http\Controllers\Admin + */ +class PirepController extends Controller { private $airportRepo, $airlineRepo, @@ -43,16 +47,16 @@ class PirepController extends BaseController /** * PirepController constructor. - * @param AirportRepository $airportRepo - * @param AirlineRepository $airlineRepo - * @param AircraftRepository $aircraftRepo - * @param FareService $fareSvc - * @param JournalRepository $journalRepo - * @param PirepRepository $pirepRepo + * @param AirportRepository $airportRepo + * @param AirlineRepository $airlineRepo + * @param AircraftRepository $aircraftRepo + * @param FareService $fareSvc + * @param JournalRepository $journalRepo + * @param PirepRepository $pirepRepo * @param PirepFieldRepository $pirepFieldRepo - * @param PirepService $pirepSvc - * @param SubfleetRepository $subfleetRepo - * @param UserService $userSvc + * @param PirepService $pirepSvc + * @param SubfleetRepository $subfleetRepo + * @param UserService $userSvc */ public function __construct( AirportRepository $airportRepo, @@ -83,11 +87,11 @@ class PirepController extends BaseController * @param null $user * @return array */ - public function aircraftList($user=null) + public function aircraftList($user = null) { $aircraft = []; - if($user === null) { + if ($user === null) { $subfleets = $this->subfleetRepo->all(); } else { $subfleets = $this->userSvc->getAllowableSubfleets($user); @@ -96,7 +100,7 @@ class PirepController extends BaseController foreach ($subfleets as $subfleet) { $tmp = []; foreach ($subfleet->aircraft as $ac) { - $tmp[$ac->id] = $ac['name'] . ' - ' . $ac['registration']; + $tmp[$ac->id] = $ac['name'].' - '.$ac['registration']; } $aircraft[$subfleet->name] = $tmp; @@ -107,7 +111,7 @@ class PirepController extends BaseController /** * Save any custom fields found - * @param Pirep $pirep + * @param Pirep $pirep * @param Request $request */ protected function saveCustomFields(Pirep $pirep, Request $request) @@ -120,8 +124,8 @@ class PirepController extends BaseController } $custom_fields[] = [ - 'name' => $field->name, - 'value' => $request->input($field->slug), + 'name' => $field->name, + 'value' => $request->input($field->slug), 'source' => PirepSource::MANUAL ]; } @@ -132,7 +136,7 @@ class PirepController extends BaseController /** * Save the fares that have been specified/saved - * @param Pirep $pirep + * @param Pirep $pirep * @param Request $request * @throws \Exception */ @@ -140,8 +144,7 @@ class PirepController extends BaseController { $fares = []; foreach ($pirep->aircraft->subfleet->fares as $fare) { - - $field_name = 'fare_' . $fare->id; + $field_name = 'fare_'.$fare->id; if (!$request->filled($field_name)) { $count = 0; } else { @@ -150,7 +153,7 @@ class PirepController extends BaseController $fares[] = [ 'fare_id' => $fare->id, - 'count' => $count, + 'count' => $count, ]; } @@ -171,7 +174,7 @@ class PirepController extends BaseController Log::info('aircraft', $aircraft->toArray()); return view('admin.pireps.fares', [ - 'aircraft' => $aircraft, + 'aircraft' => $aircraft, 'read_only' => false, ]); } @@ -187,8 +190,8 @@ class PirepController extends BaseController $this->pirepRepo->pushCriteria($criterea); $pireps = $this->pirepRepo - ->orderBy('created_at', 'desc') - ->paginate(); + ->orderBy('created_at', 'desc') + ->paginate(); return view('admin.pireps.index', [ 'pireps' => $pireps @@ -247,6 +250,7 @@ class PirepController extends BaseController $this->saveFares($pirep, $request); Flash::success('Pirep saved successfully.'); + return redirect(route('admin.pireps.index')); } @@ -261,6 +265,7 @@ class PirepController extends BaseController if (empty($pirep)) { Flash::error('Pirep not found'); + return redirect(route('admin.pireps.index')); } @@ -280,6 +285,7 @@ class PirepController extends BaseController $pirep = $this->pirepRepo->findWithoutFail($id); if (empty($pirep)) { Flash::error('Pirep not found'); + return redirect(route('admin.pireps.index')); } @@ -297,25 +303,25 @@ class PirepController extends BaseController # set the fares foreach ($pirep->fares as $fare) { - $field_name = 'fare_' . $fare->fare_id; + $field_name = 'fare_'.$fare->fare_id; $pirep->{$field_name} = $fare->count; } $journal = $this->journalRepo->getAllForObject($pirep, $pirep->airline->journal); return view('admin.pireps.edit', [ - 'pirep' => $pirep, - 'read_only' => $read_only, - 'aircraft' => $pirep->aircraft, + 'pirep' => $pirep, + 'read_only' => $read_only, + 'aircraft' => $pirep->aircraft, 'aircraft_list' => $this->aircraftList(), 'airports_list' => $this->airportRepo->selectBoxList(), 'airlines_list' => $this->airlineRepo->selectBoxList(), - 'journal' => $journal, + 'journal' => $journal, ]); } /** - * @param $id + * @param $id * @param UpdatePirepRequest $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @throws \Prettus\Validator\Exceptions\ValidatorException @@ -327,6 +333,7 @@ class PirepController extends BaseController if (empty($pirep)) { Flash::error('Pirep not found'); + return redirect(route('admin.pireps.index')); } @@ -343,7 +350,7 @@ class PirepController extends BaseController $pirep = $this->pirepRepo->update($attrs, $id); // A route change in the PIREP, so update the saved points in the ACARS table - if($pirep->route !== $orig_route) { + if ($pirep->route !== $orig_route) { $this->pirepSvc->saveRoute($pirep); } @@ -351,6 +358,7 @@ class PirepController extends BaseController $this->saveFares($pirep, $request); Flash::success('Pirep updated successfully.'); + return redirect(route('admin.pireps.index')); } @@ -365,12 +373,14 @@ class PirepController extends BaseController if (empty($pirep)) { Flash::error('Pirep not found'); + return redirect(route('admin.pireps.index')); } $this->pirepRepo->delete($id); Flash::success('Pirep deleted successfully.'); + return redirect(route('admin.pireps.index')); } @@ -384,18 +394,19 @@ class PirepController extends BaseController Log::info('PIREP state update call', [$request->toArray()]); $pirep = $this->pirepRepo->findWithoutFail($request->id); - if($request->isMethod('post')) { + if ($request->isMethod('post')) { $new_status = (int) $request->post('new_status'); $pirep = $this->pirepSvc->changeState($pirep, $new_status); } $pirep->refresh(); + return view('admin.pireps.actions', ['pirep' => $pirep, 'on_edit_page' => false]); } /** * Add a comment to the Pirep - * @param $id + * @param $id * @param Request $request * @return mixed * @throws \Exception @@ -406,16 +417,16 @@ class PirepController extends BaseController $pirep = $this->pirepRepo->findWithoutFail($request->id); if ($request->isMethod('post')) { $comment = new PirepComment([ - 'user_id' => $user->id, + 'user_id' => $user->id, 'pirep_id' => $pirep->id, - 'comment' => $request->get('comment'), + 'comment' => $request->get('comment'), ]); $comment->save(); $pirep->refresh(); } - if($request->isMethod('delete')) { + if ($request->isMethod('delete')) { $comment = PirepComment::find($request->get('comment_id')); $comment->delete(); $pirep->refresh(); diff --git a/app/Http/Controllers/Admin/PirepFieldController.php b/app/Http/Controllers/Admin/PirepFieldController.php index b8da65d7..be1cc7ee 100644 --- a/app/Http/Controllers/Admin/PirepFieldController.php +++ b/app/Http/Controllers/Admin/PirepFieldController.php @@ -4,15 +4,19 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreatePirepFieldRequest; use App\Http\Requests\UpdatePirepFieldRequest; +use App\Interfaces\Controller; use App\Repositories\PirepFieldRepository; use Flash; use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; use Response; -class PirepFieldController extends BaseController +/** + * Class PirepFieldController + * @package App\Http\Controllers\Admin + */ +class PirepFieldController extends Controller { - /** @var PirepFieldRepository */ private $pirepFieldRepo; /** @@ -21,7 +25,7 @@ class PirepFieldController extends BaseController */ public function __construct( PirepFieldRepository $pirepFieldRepo - ){ + ) { $this->pirepFieldRepo = $pirepFieldRepo; } @@ -65,6 +69,7 @@ class PirepFieldController extends BaseController $this->pirepFieldRepo->create($attrs); Flash::success('Field added successfully.'); + return redirect(route('admin.pirepfields.index')); } @@ -79,6 +84,7 @@ class PirepFieldController extends BaseController if (empty($field)) { Flash::error('PirepField not found'); + return redirect(route('admin.pirepfields.index')); } @@ -98,6 +104,7 @@ class PirepFieldController extends BaseController if (empty($field)) { Flash::error('Field not found'); + return redirect(route('admin.pirepfields.index')); } @@ -116,6 +123,7 @@ class PirepFieldController extends BaseController if (empty($field)) { Flash::error('PirepField not found'); + return redirect(route('admin.pirepfields.index')); } @@ -125,6 +133,7 @@ class PirepFieldController extends BaseController $this->pirepFieldRepo->update($attrs, $id); Flash::success('Field updated successfully.'); + return redirect(route('admin.pirepfields.index')); } @@ -139,12 +148,14 @@ class PirepFieldController extends BaseController if (empty($field)) { Flash::error('Field not found'); + return redirect(route('admin.pirepfields.index')); } $this->pirepFieldRepo->delete($id); Flash::success('Field deleted successfully.'); + return redirect(route('admin.pirepfields.index')); } } diff --git a/app/Http/Controllers/Admin/RankController.php b/app/Http/Controllers/Admin/RankController.php index 2bca2ade..47189622 100644 --- a/app/Http/Controllers/Admin/RankController.php +++ b/app/Http/Controllers/Admin/RankController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreateRankRequest; use App\Http\Requests\UpdateRankRequest; +use App\Interfaces\Controller; use App\Repositories\RankRepository; use App\Repositories\SubfleetRepository; use App\Services\FleetService; @@ -13,17 +14,20 @@ use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; use Response; -class RankController extends BaseController +/** + * Class RankController + * @package App\Http\Controllers\Admin + */ +class RankController extends Controller { - /** @var RankRepository */ private $fleetSvc, $rankRepository, $subfleetRepo; /** * RankController constructor. - * @param FleetService $fleetSvc - * @param RankRepository $rankingRepo + * @param FleetService $fleetSvc + * @param RankRepository $rankingRepo * @param SubfleetRepository $subfleetRepo */ public function __construct( @@ -109,6 +113,7 @@ class RankController extends BaseController if (empty($rank)) { Flash::error('Ranking not found'); + return redirect(route('admin.ranks.index')); } @@ -128,19 +133,21 @@ class RankController extends BaseController if (empty($rank)) { Flash::error('Ranking not found'); + return redirect(route('admin.ranks.index')); } $avail_subfleets = $this->getAvailSubfleets($rank); + return view('admin.ranks.edit', [ - 'rank' => $rank, + 'rank' => $rank, 'avail_subfleets' => $avail_subfleets, ]); } /** * Update the specified Ranking in storage. - * @param int $id + * @param int $id * @param UpdateRankRequest $request * @return Response * @throws \Prettus\Validator\Exceptions\ValidatorException @@ -151,6 +158,7 @@ class RankController extends BaseController if (empty($rank)) { Flash::error('Ranking not found'); + return redirect(route('admin.ranks.index')); } @@ -158,6 +166,7 @@ class RankController extends BaseController Cache::forget(config('cache.keys.RANKS_PILOT_LIST.key')); Flash::success('Ranking updated successfully.'); + return redirect(route('admin.ranks.index')); } @@ -172,12 +181,14 @@ class RankController extends BaseController if (empty($rank)) { Flash::error('Ranking not found'); + return redirect(route('admin.ranks.index')); } $this->rankRepository->delete($id); Flash::success('Ranking deleted successfully.'); + return redirect(route('admin.ranks.index')); } @@ -188,15 +199,16 @@ class RankController extends BaseController protected function return_subfleet_view($rank) { $avail_subfleets = $this->getAvailSubfleets($rank); + return view('admin.ranks.subfleets', [ - 'rank' => $rank, + 'rank' => $rank, 'avail_subfleets' => $avail_subfleets, ]); } /** * Subfleet operations on a rank - * @param $id + * @param $id * @param Request $request * @return mixed */ @@ -205,6 +217,7 @@ class RankController extends BaseController $rank = $this->rankRepository->findWithoutFail($id); if (empty($rank)) { Flash::error('Rank not found!'); + return redirect(route('admin.ranks.index')); } @@ -212,17 +225,13 @@ class RankController extends BaseController if ($request->isMethod('post')) { $subfleet = $this->subfleetRepo->find($request->input('subfleet_id')); $this->fleetSvc->addSubfleetToRank($subfleet, $rank); - } - - elseif($request->isMethod('put')) { + } elseif ($request->isMethod('put')) { $override = []; $override[$request->name] = $request->value; $subfleet = $this->subfleetRepo->find($request->input('subfleet_id')); $this->fleetSvc->addSubfleetToRank($subfleet, $rank); - } - - // remove aircraft from flight + } // remove aircraft from flight elseif ($request->isMethod('delete')) { $subfleet = $this->subfleetRepo->find($request->input('subfleet_id')); $this->fleetSvc->removeSubfleetFromRank($subfleet, $rank); diff --git a/app/Http/Controllers/Admin/SettingsController.php b/app/Http/Controllers/Admin/SettingsController.php index 3f339db6..be20ec32 100644 --- a/app/Http/Controllers/Admin/SettingsController.php +++ b/app/Http/Controllers/Admin/SettingsController.php @@ -2,11 +2,16 @@ namespace App\Http\Controllers\Admin; +use App\Interfaces\Controller; use App\Models\Setting; use Illuminate\Http\Request; use Log; -class SettingsController extends BaseController +/** + * Class SettingsController + * @package App\Http\Controllers\Admin + */ +class SettingsController extends Controller { /** * Display the settings. Group them by the setting group @@ -16,7 +21,7 @@ class SettingsController extends BaseController $settings = Setting::orderBy('order', 'asc')->get(); $settings = $settings->groupBy('group'); - return view('admin.settings.index',[ + return view('admin.settings.index', [ 'grouped_settings' => $settings, ]); } @@ -28,9 +33,9 @@ class SettingsController extends BaseController */ public function update(Request $request) { - foreach($request->post() as $id => $value) { + foreach ($request->post() as $id => $value) { $setting = Setting::find($id); - if(!$setting) { + if (!$setting) { continue; } @@ -40,6 +45,7 @@ class SettingsController extends BaseController } flash('Settings saved!'); + return redirect('/admin/settings'); } } diff --git a/app/Http/Controllers/Admin/SubfleetController.php b/app/Http/Controllers/Admin/SubfleetController.php index 0003027a..db759f2f 100644 --- a/app/Http/Controllers/Admin/SubfleetController.php +++ b/app/Http/Controllers/Admin/SubfleetController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreateSubfleetRequest; use App\Http\Requests\UpdateSubfleetRequest; +use App\Interfaces\Controller; use App\Models\Airline; use App\Models\Enums\FuelType; use App\Models\Expense; @@ -19,9 +20,12 @@ use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; use Response; -class SubfleetController extends BaseController +/** + * Class SubfleetController + * @package App\Http\Controllers\Admin + */ +class SubfleetController extends Controller { - /** @var SubfleetRepository */ private $aircraftRepo, $fareRepo, $fareSvc, @@ -32,11 +36,11 @@ class SubfleetController extends BaseController /** * SubfleetController constructor. * @param AircraftRepository $aircraftRepo - * @param FleetService $fleetSvc - * @param RankRepository $rankRepo + * @param FleetService $fleetSvc + * @param RankRepository $rankRepo * @param SubfleetRepository $subfleetRepo - * @param FareRepository $fareRepo - * @param FareService $fareSvc + * @param FareRepository $fareRepo + * @param FareService $fareSvc */ public function __construct( AircraftRepository $aircraftRepo, @@ -112,7 +116,7 @@ class SubfleetController extends BaseController public function create() { return view('admin.subfleets.create', [ - 'airlines' => Airline::all()->pluck('name', 'id'), + 'airlines' => Airline::all()->pluck('name', 'id'), 'fuel_types' => FuelType::labels(), ]); } @@ -129,6 +133,7 @@ class SubfleetController extends BaseController $subfleet = $this->subfleetRepo->create($input); Flash::success('Subfleet saved successfully.'); + return redirect(route('admin.subfleets.edit', ['id' => $subfleet->id])); } @@ -143,12 +148,14 @@ class SubfleetController extends BaseController if (empty($subfleet)) { Flash::error('Subfleet not found'); + return redirect(route('admin.subfleets.index')); } $avail_fares = $this->getAvailFares($subfleet); + return view('admin.subfleets.show', [ - 'subfleet' => $subfleet, + 'subfleet' => $subfleet, 'avail_fares' => $avail_fares, ]); } @@ -164,6 +171,7 @@ class SubfleetController extends BaseController if (empty($subfleet)) { Flash::error('Subfleet not found'); + return redirect(route('admin.subfleets.index')); } @@ -171,17 +179,17 @@ class SubfleetController extends BaseController $avail_ranks = $this->getAvailRanks($subfleet); return view('admin.subfleets.edit', [ - 'airlines' => Airline::all()->pluck('name', 'id'), - 'fuel_types' => FuelType::labels(), - 'avail_fares' => $avail_fares, - 'avail_ranks' => $avail_ranks, - 'subfleet' => $subfleet, + 'airlines' => Airline::all()->pluck('name', 'id'), + 'fuel_types' => FuelType::labels(), + 'avail_fares' => $avail_fares, + 'avail_ranks' => $avail_ranks, + 'subfleet' => $subfleet, ]); } /** * Update the specified Subfleet in storage. - * @param int $id + * @param int $id * @param UpdateSubfleetRequest $request * @return Response * @throws \Prettus\Validator\Exceptions\ValidatorException @@ -192,12 +200,14 @@ class SubfleetController extends BaseController if (empty($subfleet)) { Flash::error('Subfleet not found'); + return redirect(route('admin.subfleets.index')); } $this->subfleetRepo->update($request->all(), $id); Flash::success('Subfleet updated successfully.'); + return redirect(route('admin.subfleets.index')); } @@ -212,20 +222,23 @@ class SubfleetController extends BaseController if (empty($subfleet)) { Flash::error('Subfleet not found'); + return redirect(route('admin.subfleets.index')); } # Make sure no aircraft are assigned to this subfleet # before trying to delete it, or else things might go boom $aircraft = $this->aircraftRepo->findWhere(['subfleet_id' => $id], ['id']); - if($aircraft->count() > 0) { + if ($aircraft->count() > 0) { Flash::error('There are aircraft still assigned to this subfleet, you can\'t delete it!')->important(); + return redirect(route('admin.subfleets.index')); } $this->subfleetRepo->delete($id); Flash::success('Subfleet deleted successfully.'); + return redirect(route('admin.subfleets.index')); } @@ -240,7 +253,7 @@ class SubfleetController extends BaseController $avail_ranks = $this->getAvailRanks($subfleet); return view('admin.subfleets.ranks', [ - 'subfleet' => $subfleet, + 'subfleet' => $subfleet, 'avail_ranks' => $avail_ranks, ]); } @@ -263,7 +276,7 @@ class SubfleetController extends BaseController /** * Operations for associating ranks to the subfleet - * @param $id + * @param $id * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ @@ -284,23 +297,20 @@ class SubfleetController extends BaseController if ($request->isMethod('post')) { $rank = $this->rankRepo->find($request->input('rank_id')); $this->fleetSvc->addSubfleetToRank($subfleet, $rank); - } - - elseif ($request->isMethod('put')) { + } elseif ($request->isMethod('put')) { $override = []; $rank = $this->rankRepo->find($request->input('rank_id')); $override[$request->name] = $request->value; $this->fleetSvc->addSubfleetToRank($subfleet, $rank, $override); - } - - // dissassociate fare from teh aircraft + } // dissassociate fare from teh aircraft elseif ($request->isMethod('delete')) { $rank = $this->rankRepo->find($request->input('rank_id')); $this->fleetSvc->removeSubfleetFromRank($subfleet, $rank); } $subfleet->save(); + return $this->return_ranks_view($subfleet); } @@ -311,6 +321,7 @@ class SubfleetController extends BaseController protected function return_expenses_view(?Subfleet $subfleet) { $subfleet->refresh(); + return view('admin.subfleets.expenses', [ 'subfleet' => $subfleet, ]); @@ -318,7 +329,7 @@ class SubfleetController extends BaseController /** * Operations for associating ranks to the subfleet - * @param $id + * @param $id * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * @throws \Exception @@ -357,7 +368,7 @@ class SubfleetController extends BaseController /** * Operations on fares to the subfleet - * @param $id + * @param $id * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ @@ -379,17 +390,13 @@ class SubfleetController extends BaseController if ($request->isMethod('post')) { $fare = $this->fareRepo->find($request->fare_id); $this->fareSvc->setForSubfleet($subfleet, $fare); - } - - // update the pivot table with overrides for the fares + } // update the pivot table with overrides for the fares elseif ($request->isMethod('put')) { $override = []; $fare = $this->fareRepo->find($request->fare_id); $override[$request->name] = $request->value; $this->fareSvc->setForSubfleet($subfleet, $fare, $override); - } - - // dissassociate fare from teh aircraft + } // dissassociate fare from teh aircraft elseif ($request->isMethod('delete')) { $fare = $this->fareRepo->find($request->fare_id); $this->fareSvc->delFareFromSubfleet($subfleet, $fare); diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 780d8941..30210dc9 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -5,7 +5,7 @@ namespace App\Http\Controllers\Admin; use App\Facades\Utils; use App\Http\Requests\CreateUserRequest; use App\Http\Requests\UpdateUserRequest; -use App\Models\Airline; +use App\Interfaces\Controller; use App\Models\Rank; use App\Models\Role; use App\Models\User; @@ -23,7 +23,11 @@ use Log; use Prettus\Repository\Exceptions\RepositoryException; use Response; -class UserController extends BaseController +/** + * Class UserController + * @package App\Http\Controllers\Admin + */ +class UserController extends Controller { private $airlineRepo, $airportRepo, @@ -35,9 +39,9 @@ class UserController extends BaseController * UserController constructor. * @param AirlineRepository $airlineRepo * @param AirportRepository $airportRepo - * @param PirepRepository $pirepRepo - * @param UserRepository $userRepo - * @param UserService $userSvc + * @param PirepRepository $pirepRepo + * @param UserRepository $userRepo + * @param UserService $userSvc */ public function __construct( AirlineRepository $airlineRepo, @@ -67,7 +71,7 @@ class UserController extends BaseController } return view('admin.users.index', [ - 'users' => $users, + 'users' => $users, 'country' => new \League\ISO3166\ISO3166(), ]); } @@ -82,14 +86,14 @@ class UserController extends BaseController $airports = $this->airportRepo->selectBoxList(false, setting('pilots.home_hubs_only')); return view('admin.users.create', [ - 'user' => null, - 'pireps' => null, - 'airlines' => $airlines, + 'user' => null, + 'pireps' => null, + 'airlines' => $airlines, 'timezones' => Timezonelist::toArray(), - 'country' => new \League\ISO3166\ISO3166(), - 'airports' => $airports, - 'ranks' => Rank::all()->pluck('name', 'id'), - 'roles' => Role::all()->pluck('name', 'id'), + 'country' => new \League\ISO3166\ISO3166(), + 'airports' => $airports, + 'ranks' => Rank::all()->pluck('name', 'id'), + 'roles' => Role::all()->pluck('name', 'id'), ]); } @@ -105,6 +109,7 @@ class UserController extends BaseController $user = $this->userRepo->create($input); Flash::success('User saved successfully.'); + return redirect(route('admin.users.index')); } @@ -119,6 +124,7 @@ class UserController extends BaseController if (empty($user)) { Flash::error('User not found'); + return redirect(route('admin.users.index')); } @@ -130,14 +136,14 @@ class UserController extends BaseController $airports = $this->airportRepo->selectBoxList(false, setting('pilots.home_hubs_only')); return view('admin.users.show', [ - 'user' => $user, - 'pireps' => $pireps, - 'airlines' => $airlines, + 'user' => $user, + 'pireps' => $pireps, + 'airlines' => $airlines, 'timezones' => Timezonelist::toArray(), - 'country' => new \League\ISO3166\ISO3166(), - 'airports' => $airports, - 'ranks' => Rank::all()->pluck('name', 'id'), - 'roles' => Role::all()->pluck('name', 'id'), + 'country' => new \League\ISO3166\ISO3166(), + 'airports' => $airports, + 'ranks' => Rank::all()->pluck('name', 'id'), + 'roles' => Role::all()->pluck('name', 'id'), ]); } @@ -152,6 +158,7 @@ class UserController extends BaseController if (empty($user)) { Flash::error('User not found'); + return redirect(route('admin.users.index')); } @@ -168,20 +175,20 @@ class UserController extends BaseController $airports = $this->airportRepo->selectBoxList(false, setting('pilots.home_hubs_only')); return view('admin.users.edit', [ - 'user' => $user, - 'pireps' => $pireps, + 'user' => $user, + 'pireps' => $pireps, 'countries' => $countries, 'timezones' => Timezonelist::toArray(), - 'airports' => $airports, - 'airlines' => $airlines, - 'ranks' => Rank::all()->pluck('name', 'id'), - 'roles' => Role::all()->pluck('name', 'id'), + 'airports' => $airports, + 'airlines' => $airlines, + 'ranks' => Rank::all()->pluck('name', 'id'), + 'roles' => Role::all()->pluck('name', 'id'), ]); } /** * Update the specified User in storage. - * @param int $id + * @param int $id * @param UpdateUserRequest $request * @return Response * @throws \Prettus\Validator\Exceptions\ValidatorException @@ -192,11 +199,12 @@ class UserController extends BaseController if (empty($user)) { Flash::error('User not found'); + return redirect(route('admin.users.index')); } $req_data = $request->all(); - if(!$request->filled('password')) { + if (!$request->filled('password')) { unset($req_data['password']); } else { $req_data['password'] = Hash::make($req_data['password']); @@ -206,17 +214,18 @@ class UserController extends BaseController $user = $this->userRepo->update($req_data, $id); - if($original_user_state !== $user->state) { + if ($original_user_state !== $user->state) { $this->userSvc->changeUserState($user, $original_user_state); } # Delete all of the roles and then re-attach the valid ones - DB::table('role_user')->where('user_id',$id)->delete(); + DB::table('role_user')->where('user_id', $id)->delete(); foreach ($request->input('roles') as $key => $value) { $user->attachRole($value); } Flash::success('User updated successfully.'); + return redirect(route('admin.users.index')); } @@ -231,30 +240,33 @@ class UserController extends BaseController if (empty($user)) { Flash::error('User not found'); + return redirect(route('admin.users.index')); } $this->userRepo->delete($id); Flash::success('User deleted successfully.'); + return redirect(route('admin.users.index')); } /** * Regenerate the user's API key - * @param $id + * @param $id * @param Request $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function regen_apikey($id, Request $request) { $user = User::find($id); - Log::info('Regenerating API key "' . $user->pilot_id . '"'); + Log::info('Regenerating API key "'.$user->pilot_id.'"'); $user->api_key = Utils::generateApiKey(); $user->save(); flash('New API key generated!')->success(); + return redirect(route('admin.users.edit', ['id' => $id])); } } diff --git a/app/Http/Controllers/Api/AcarsController.php b/app/Http/Controllers/Api/AcarsController.php index 935e9145..47529a6f 100644 --- a/app/Http/Controllers/Api/AcarsController.php +++ b/app/Http/Controllers/Api/AcarsController.php @@ -2,30 +2,31 @@ namespace App\Http\Controllers\Api; +use App\Interfaces\Controller; use App\Repositories\AcarsRepository; -use App\Repositories\PirepRepository; use App\Services\GeoService; use Illuminate\Http\Request; - -class AcarsController extends RestController +/** + * Class AcarsController + * @package App\Http\Controllers\Api + */ +class AcarsController extends Controller { - protected $acarsRepo, $geoSvc, $pirepRepo; + private $acarsRepo, + $geoSvc; /** * AcarsController constructor. - * @param GeoService $geoSvc + * @param GeoService $geoSvc * @param AcarsRepository $acarsRepo - * @param PirepRepository $pirepRepo */ public function __construct( GeoService $geoSvc, - AcarsRepository $acarsRepo, - PirepRepository $pirepRepo + AcarsRepository $acarsRepo ) { $this->geoSvc = $geoSvc; $this->acarsRepo = $acarsRepo; - $this->pirepRepo = $pirepRepo; } /** diff --git a/app/Http/Controllers/Api/AirlineController.php b/app/Http/Controllers/Api/AirlineController.php index 3d956331..73a7a618 100644 --- a/app/Http/Controllers/Api/AirlineController.php +++ b/app/Http/Controllers/Api/AirlineController.php @@ -3,12 +3,17 @@ namespace App\Http\Controllers\Api; use App\Http\Resources\Airline as AirlineResource; +use App\Interfaces\Controller; use App\Repositories\AirlineRepository; use Illuminate\Http\Request; -class AirlineController extends RestController +/** + * Class AirlineController + * @package App\Http\Controllers\Api + */ +class AirlineController extends Controller { - protected $airlineRepo; + private $airlineRepo; /** * AirlineController constructor. @@ -43,6 +48,7 @@ class AirlineController extends RestController public function get($id) { $id = strtoupper($id); + return new AirlineResource($this->airlineRepo->find($id)); } } diff --git a/app/Http/Controllers/Api/AirportController.php b/app/Http/Controllers/Api/AirportController.php index a4faee74..06f39642 100644 --- a/app/Http/Controllers/Api/AirportController.php +++ b/app/Http/Controllers/Api/AirportController.php @@ -3,15 +3,20 @@ namespace App\Http\Controllers\Api; use App\Http\Resources\Airport as AirportResource; +use App\Interfaces\Controller; use App\Repositories\AirportRepository; use Illuminate\Http\Request; use Illuminate\Support\Facades\Cache; use Log; use VaCentral\Airport as AirportLookup; -class AirportController extends RestController +/** + * Class AirportController + * @package App\Http\Controllers\Api + */ +class AirportController extends Controller { - protected $airportRepo; + private $airportRepo; /** * AirportController constructor. @@ -66,6 +71,7 @@ class AirportController extends RestController public function get($id) { $id = strtoupper($id); + return new AirportResource($this->airportRepo->find($id)); } @@ -77,13 +83,14 @@ class AirportController extends RestController public function lookup($id) { $airport = Cache::remember( - config('cache.keys.AIRPORT_VACENTRAL_LOOKUP.key') . $id, + config('cache.keys.AIRPORT_VACENTRAL_LOOKUP.key').$id, config('cache.keys.RANKS_PILOT_LIST.time'), function () use ($id) { try { return AirportLookup::get($id); } catch (\VaCentral\HttpException $e) { Log::error($e); + return []; } } diff --git a/app/Http/Controllers/Api/FleetController.php b/app/Http/Controllers/Api/FleetController.php index 5b727636..b93d4c2a 100644 --- a/app/Http/Controllers/Api/FleetController.php +++ b/app/Http/Controllers/Api/FleetController.php @@ -4,13 +4,19 @@ namespace App\Http\Controllers\Api; use App\Http\Resources\Aircraft as AircraftResource; use App\Http\Resources\Subfleet as SubfleetResource; +use App\Interfaces\Controller; use App\Repositories\AircraftRepository; use App\Repositories\SubfleetRepository; use Illuminate\Http\Request; -class FleetController extends RestController +/** + * Class FleetController + * @package App\Http\Controllers\Api + */ +class FleetController extends Controller { - protected $aircraftRepo, $subfleetRepo; + private $aircraftRepo, + $subfleetRepo; /** * FleetController constructor. @@ -32,8 +38,8 @@ class FleetController extends RestController public function index() { $subfleets = $this->subfleetRepo - ->with(['aircraft', 'airline', 'fares', 'ranks']) - ->paginate(); + ->with(['aircraft', 'airline', 'fares', 'ranks']) + ->paginate(); return SubfleetResource::collection($subfleets); } @@ -41,23 +47,23 @@ class FleetController extends RestController /** * Get a specific aircraft. Query string required to specify the tail * /api/aircraft/XYZ?type=registration - * @param $id + * @param $id * @param Request $request * @return AircraftResource */ public function get_aircraft($id, Request $request) { $where = []; - if($request->filled('type')) { + if ($request->filled('type')) { $where[$request->get('type')] = $id; } else { $where['id'] = $id; } $aircraft = $this->aircraftRepo - ->with(['subfleet', 'subfleet.fares']) - ->findWhere($where) - ->first(); + ->with(['subfleet', 'subfleet.fares']) + ->findWhere($where) + ->first(); return new AircraftResource($aircraft); } diff --git a/app/Http/Controllers/Api/FlightController.php b/app/Http/Controllers/Api/FlightController.php index 3b70ee3c..947edd90 100644 --- a/app/Http/Controllers/Api/FlightController.php +++ b/app/Http/Controllers/Api/FlightController.php @@ -4,10 +4,10 @@ namespace App\Http\Controllers\Api; use App\Http\Resources\Flight as FlightResource; use App\Http\Resources\Navdata as NavdataResource; +use App\Interfaces\Controller; use App\Repositories\Criteria\WhereCriteria; use App\Repositories\FlightRepository; use App\Services\FlightService; -use App\Services\UserService; use Auth; use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; @@ -17,24 +17,22 @@ use Prettus\Repository\Exceptions\RepositoryException; * Class FlightController * @package App\Http\Controllers\Api */ -class FlightController extends RestController +class FlightController extends Controller { - protected $flightRepo, $flightSvc, $userSvc; + private $flightRepo, + $flightSvc; /** * FlightController constructor. * @param FlightRepository $flightRepo - * @param FlightService $flightSvc - * @param UserService $userSvc + * @param FlightService $flightSvc */ public function __construct( FlightRepository $flightRepo, - FlightService $flightSvc, - UserService $userSvc + FlightService $flightSvc ) { $this->flightRepo = $flightRepo; $this->flightSvc = $flightSvc; - $this->userSvc = $userSvc; } /** @@ -52,10 +50,10 @@ class FlightController extends RestController } $flights = $this->flightRepo - ->whereOrder($where, 'flight_number', 'asc') - ->paginate(); + ->whereOrder($where, 'flight_number', 'asc') + ->paginate(); - foreach($flights as $flight) { + foreach ($flights as $flight) { $this->flightSvc->filterSubfleets($user, $flight); } @@ -105,7 +103,7 @@ class FlightController extends RestController /** * Get a flight's route - * @param $id + * @param $id * @param Request $request * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection */ diff --git a/app/Http/Controllers/Api/PirepController.php b/app/Http/Controllers/Api/PirepController.php index fd3ec117..045aaf82 100644 --- a/app/Http/Controllers/Api/PirepController.php +++ b/app/Http/Controllers/Api/PirepController.php @@ -16,6 +16,7 @@ use App\Http\Resources\AcarsRoute as AcarsRouteResource; use App\Http\Resources\JournalTransaction as JournalTransactionResource; use App\Http\Resources\Pirep as PirepResource; use App\Http\Resources\PirepComment as PirepCommentResource; +use App\Interfaces\Controller; use App\Models\Acars; use App\Models\Enums\AcarsType; use App\Models\Enums\PirepSource; @@ -35,7 +36,11 @@ use Auth; use Illuminate\Http\Request; use Log; -class PirepController extends RestController +/** + * Class PirepController + * @package App\Http\Controllers\Api + */ +class PirepController extends Controller { private $acarsRepo, $fareSvc, @@ -48,13 +53,14 @@ class PirepController extends RestController /** * PirepController constructor. - * @param AcarsRepository $acarsRepo + * @param AcarsRepository $acarsRepo + * @param FareService $fareSvc * @param PirepFinanceService $financeSvc - * @param GeoService $geoSvc - * @param JournalRepository $journalRepo - * @param PirepRepository $pirepRepo - * @param PirepService $pirepSvc - * @param UserService $userSvc + * @param GeoService $geoSvc + * @param JournalRepository $journalRepo + * @param PirepRepository $pirepRepo + * @param PirepService $pirepSvc + * @param UserService $userSvc */ public function __construct( AcarsRepository $acarsRepo, @@ -98,7 +104,7 @@ class PirepController extends RestController } /** - * @param $pirep + * @param $pirep * @param Request $request */ protected function updateFields($pirep, Request $request) @@ -110,8 +116,8 @@ class PirepController extends RestController $pirep_fields = []; foreach ($request->input('fields') as $field_name => $field_value) { $pirep_fields[] = [ - 'name' => $field_name, - 'value' => $field_value, + 'name' => $field_name, + 'value' => $field_value, 'source' => $pirep->source, ]; } @@ -121,21 +127,21 @@ class PirepController extends RestController /** * Save the fares - * @param $pirep + * @param $pirep * @param Request $request * @throws \Exception */ protected function updateFares($pirep, Request $request) { - if(!$request->filled('fares')) { + if (!$request->filled('fares')) { return; } $fares = []; - foreach($request->post('fares') as $fare) { + foreach ($request->post('fares') as $fare) { $fares[] = [ 'fare_id' => $fare['id'], - 'count' => $fare['count'], + 'count' => $fare['count'], ]; } @@ -168,7 +174,7 @@ class PirepController extends RestController $pirep = new Pirep($attrs); # See if this user is allowed to fly this aircraft - if(setting('pireps.restrict_aircraft_to_rank', false)) { + if (setting('pireps.restrict_aircraft_to_rank', false)) { $can_use_ac = $this->userSvc->aircraftAllowed($user, $pirep->aircraft_id); if (!$can_use_ac) { throw new AircraftPermissionDenied(); @@ -177,7 +183,7 @@ class PirepController extends RestController # Find if there's a duplicate, if so, let's work on that $dupe_pirep = $this->pirepSvc->findDuplicate($pirep); - if($dupe_pirep !== false) { + if ($dupe_pirep !== false) { $pirep = $dupe_pirep; $this->checkCancelled($pirep); } @@ -198,7 +204,7 @@ class PirepController extends RestController * Once ACARS updates are being processed, then it can go into an 'ENROUTE' * status, and whatever other statuses may be defined * - * @param $id + * @param $id * @param UpdateRequest $request * @return PirepResource * @throws \App\Exceptions\PirepCancelled @@ -208,7 +214,7 @@ class PirepController extends RestController */ public function update($id, UpdateRequest $request) { - Log::info('PIREP Update, user ' . Auth::id(), $request->post()); + Log::info('PIREP Update, user '.Auth::id(), $request->post()); $user = Auth::user(); $pirep = $this->pirepRepo->find($id); @@ -236,7 +242,7 @@ class PirepController extends RestController /** * File the PIREP - * @param $id + * @param $id * @param FileRequest $request * @return PirepResource * @throws \App\Exceptions\PirepCancelled @@ -246,7 +252,7 @@ class PirepController extends RestController */ public function file($id, FileRequest $request) { - Log::info('PIREP file, user ' . Auth::id(), $request->post()); + Log::info('PIREP file, user '.Auth::id(), $request->post()); $user = Auth::user(); @@ -283,7 +289,7 @@ class PirepController extends RestController # route that's been posted from the PIREP $w = ['pirep_id' => $pirep->id, 'type' => AcarsType::ROUTE]; $count = Acars::where($w)->count(['id']); - if($count === 0) { + if ($count === 0) { $this->pirepSvc->saveRoute($pirep); } @@ -292,14 +298,14 @@ class PirepController extends RestController /** * Cancel the PIREP - * @param $id + * @param $id * @param Request $request * @return PirepResource * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function cancel($id, Request $request) { - Log::info('PIREP Cancel, user ' . Auth::id(), $request->post()); + Log::info('PIREP Cancel, user '.Auth::id(), $request->post()); $pirep = $this->pirepRepo->update([ 'state' => PirepState::CANCELLED, @@ -310,7 +316,7 @@ class PirepController extends RestController /** * Return the GeoJSON for the ACARS line - * @param $id + * @param $id * @param Request $request * @return \Illuminate\Contracts\Routing\ResponseFactory */ @@ -326,7 +332,7 @@ class PirepController extends RestController /** * Return the routes for the ACARS line - * @param $id + * @param $id * @param Request $request * @return AcarsRouteResource */ @@ -336,13 +342,13 @@ class PirepController extends RestController return new AcarsRouteResource(Acars::where([ 'pirep_id' => $id, - 'type' => AcarsType::FLIGHT_PATH + 'type' => AcarsType::FLIGHT_PATH ])->orderBy('created_at', 'asc')->get()); } /** * Post ACARS updates for a PIREP - * @param $id + * @param $id * @param PositionRequest $request * @return \Illuminate\Http\JsonResponse * @throws \App\Exceptions\PirepCancelled @@ -361,8 +367,7 @@ class PirepController extends RestController $count = 0; $positions = $request->post('positions'); - foreach($positions as $position) - { + foreach ($positions as $position) { $position['pirep_id'] = $id; $position['type'] = AcarsType::FLIGHT_PATH; @@ -376,13 +381,13 @@ class PirepController extends RestController $pirep->status = PirepStatus::ENROUTE; $pirep->save(); - return $this->message($count . ' positions added', $count); + return $this->message($count.' positions added', $count); } /** * Post ACARS LOG update for a PIREP. These updates won't show up on the map * But rather in a log file. - * @param $id + * @param $id * @param LogRequest $request * @return \Illuminate\Http\JsonResponse * @throws \App\Exceptions\PirepCancelled @@ -398,8 +403,7 @@ class PirepController extends RestController $count = 0; $logs = $request->post('logs'); - foreach($logs as $log) { - + foreach ($logs as $log) { $log['pirep_id'] = $id; $log['type'] = AcarsType::LOG; @@ -408,13 +412,13 @@ class PirepController extends RestController ++$count; } - return $this->message($count . ' logs added', $count); + return $this->message($count.' logs added', $count); } /** * Post ACARS LOG update for a PIREP. These updates won't show up on the map * But rather in a log file. - * @param $id + * @param $id * @param EventRequest $request * @return \Illuminate\Http\JsonResponse * @throws \App\Exceptions\PirepCancelled @@ -426,12 +430,11 @@ class PirepController extends RestController $pirep = $this->pirepRepo->find($id); $this->checkCancelled($pirep); - Log::debug('Posting ACARS event, PIREP: ' . $id, $request->post()); + Log::debug('Posting ACARS event, PIREP: '.$id, $request->post()); $count = 0; $logs = $request->post('events'); foreach ($logs as $log) { - $log['pirep_id'] = $id; $log['type'] = AcarsType::LOG; $log['log'] = $log['event']; @@ -441,24 +444,25 @@ class PirepController extends RestController ++$count; } - return $this->message($count . ' logs added', $count); + return $this->message($count.' logs added', $count); } /** * Add a new comment - * @param $id + * @param $id * @param Request $request * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection */ public function comments_get($id, Request $request) { $pirep = $this->pirepRepo->find($id); + return PirepCommentResource::collection($pirep->comments); } /** * Add a new comment - * @param $id + * @param $id * @param CommentRequest $request * @return PirepCommentResource * @throws \App\Exceptions\PirepCancelled @@ -480,7 +484,7 @@ class PirepController extends RestController } /** - * @param $id + * @param $id * @param Request $request * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection * @throws \UnexpectedValueException @@ -490,11 +494,12 @@ class PirepController extends RestController { $pirep = $this->pirepRepo->find($id); $transactions = $this->journalRepo->getAllForObject($pirep); + return JournalTransactionResource::collection($transactions); } /** - * @param $id + * @param $id * @param Request $request * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection * @throws \UnexpectedValueException @@ -509,11 +514,12 @@ class PirepController extends RestController $pirep->refresh(); $transactions = $this->journalRepo->getAllForObject($pirep); + return JournalTransactionResource::collection($transactions['transactions']); } /** - * @param $id + * @param $id * @param Request $request * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection */ @@ -523,13 +529,13 @@ class PirepController extends RestController return AcarsRouteResource::collection(Acars::where([ 'pirep_id' => $id, - 'type' => AcarsType::ROUTE + 'type' => AcarsType::ROUTE ])->orderBy('order', 'asc')->get()); } /** * Post the ROUTE for a PIREP, can be done from the ACARS log - * @param $id + * @param $id * @param RouteRequest $request * @return \Illuminate\Http\JsonResponse * @throws \App\Exceptions\PirepCancelled @@ -545,7 +551,7 @@ class PirepController extends RestController $count = 0; $route = $request->post('route', []); - foreach($route as $position) { + foreach ($route as $position) { $position['pirep_id'] = $id; $position['type'] = AcarsType::ROUTE; @@ -555,11 +561,11 @@ class PirepController extends RestController ++$count; } - return $this->message($count . ' points added', $count); + return $this->message($count.' points added', $count); } /** - * @param $id + * @param $id * @param Request $request * @return \Illuminate\Http\JsonResponse * @throws \Exception @@ -570,7 +576,7 @@ class PirepController extends RestController Acars::where([ 'pirep_id' => $id, - 'type' => AcarsType::ROUTE + 'type' => AcarsType::ROUTE ])->delete(); return $this->message('Route deleted'); diff --git a/app/Http/Controllers/Api/SettingsController.php b/app/Http/Controllers/Api/SettingsController.php index 35f82915..3e32caca 100644 --- a/app/Http/Controllers/Api/SettingsController.php +++ b/app/Http/Controllers/Api/SettingsController.php @@ -3,12 +3,17 @@ namespace App\Http\Controllers\Api; use App\Http\Resources\Setting as SettingResource; +use App\Interfaces\Controller; use App\Repositories\SettingRepository; use Illuminate\Http\Request; -class SettingsController extends RestController +/** + * Class SettingsController + * @package App\Http\Controllers\Api + */ +class SettingsController extends Controller { - protected $settingRepo; + private $settingRepo; /** * SettingsController constructor. diff --git a/app/Http/Controllers/Api/StatusController.php b/app/Http/Controllers/Api/StatusController.php index 69d079ad..a79ed9d0 100644 --- a/app/Http/Controllers/Api/StatusController.php +++ b/app/Http/Controllers/Api/StatusController.php @@ -2,9 +2,14 @@ namespace App\Http\Controllers\Api; +use App\Interfaces\Controller; use PragmaRX\Version\Package\Facade as Version; -class StatusController extends RestController +/** + * Class StatusController + * @package App\Http\Controllers\Api + */ +class StatusController extends Controller { /** * @return \Illuminate\Http\JsonResponse @@ -13,7 +18,7 @@ class StatusController extends RestController { return response()->json([ 'version' => Version::compact(), - 'php' => PHP_VERSION, + 'php' => PHP_VERSION, ]); } } diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index 23b047b0..9c39dac7 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -3,12 +3,12 @@ namespace App\Http\Controllers\Api; use App\Http\Resources\Bid as BidResource; -use App\Http\Resources\Flight as FlightResource; use App\Http\Resources\Pirep as PirepResource; use App\Http\Resources\Subfleet as SubfleetResource; use App\Http\Resources\User as UserResource; -use App\Models\Enums\PirepState; +use App\Interfaces\Controller; use App\Models\Bid; +use App\Models\Enums\PirepState; use App\Repositories\Criteria\WhereCriteria; use App\Repositories\FlightRepository; use App\Repositories\PirepRepository; @@ -21,24 +21,27 @@ use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; use Prettus\Repository\Exceptions\RepositoryException; - -class UserController extends RestController +/** + * Class UserController + * @package App\Http\Controllers\Api + */ +class UserController extends Controller { - protected $flightRepo, - $flightSvc, - $pirepRepo, - $subfleetRepo, - $userRepo, - $userSvc; + private $flightRepo, + $flightSvc, + $pirepRepo, + $subfleetRepo, + $userRepo, + $userSvc; /** * UserController constructor. - * @param FlightRepository $flightRepo - * @param FlightService $flightSvc - * @param PirepRepository $pirepRepo + * @param FlightRepository $flightRepo + * @param FlightService $flightSvc + * @param PirepRepository $pirepRepo * @param SubfleetRepository $subfleetRepo - * @param UserRepository $userRepo - * @param UserService $userSvc + * @param UserRepository $userRepo + * @param UserService $userSvc */ public function __construct( FlightRepository $flightRepo, @@ -106,11 +109,12 @@ class UserController extends RestController $flight_id = $request->input('flight_id'); $flight = $this->flightRepo->find($flight_id); $bid = $this->flightSvc->addBid($flight, $user); + return new BidResource($bid); } if ($request->isMethod('DELETE')) { - if($request->filled('bid_id')) { + if ($request->filled('bid_id')) { $bid = Bid::findOrFail($request->input('bid_id')); $flight_id = $bid->flight_id; } else { @@ -123,6 +127,7 @@ class UserController extends RestController # Return the flights they currently have bids on $bids = Bid::where(['user_id' => $user->id])->get(); + return BidResource::collection($bids); } @@ -152,7 +157,7 @@ class UserController extends RestController 'user_id' => $this->getUserId($request), ]; - if(filled($request->query('state'))) { + if (filled($request->query('state'))) { $where['state'] = $request->query('state'); } else { $where[] = ['state', '!=', PirepState::CANCELLED]; diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index 2182c418..01391717 100755 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -2,9 +2,13 @@ namespace App\Http\Controllers\Auth; -use App\Http\Controllers\Controller; +use App\Interfaces\Controller; use Illuminate\Foundation\Auth\SendsPasswordResetEmails; +/** + * Class ForgotPasswordController + * @package App\Http\Controllers\Auth + */ class ForgotPasswordController extends Controller { use SendsPasswordResetEmails; diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index f15fa3e3..668bd419 100755 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -2,13 +2,17 @@ namespace App\Http\Controllers\Auth; -use App\Http\Controllers\Controller; +use App\Interfaces\Controller; use App\Models\Enums\UserState; use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; +/** + * Class LoginController + * @package App\Http\Controllers\Auth + */ class LoginController extends Controller { use AuthenticatesUsers; @@ -44,17 +48,16 @@ class LoginController extends Controller $user->save(); // TODO: How to handle ON_LEAVE? - if($user->state !== UserState::ACTIVE) { - - Log::info('Trying to login '. $user->pilot_id .', state ' - . UserState::label($user->state)); + if ($user->state !== UserState::ACTIVE) { + Log::info('Trying to login '.$user->pilot_id.', state ' + .UserState::label($user->state)); // Log them out $this->guard()->logout(); $request->session()->invalidate(); // Redirect to one of the error pages - if($user->state === UserState::PENDING) { + if ($user->state === UserState::PENDING) { return view('auth.pending'); } elseif ($user->state === UserState::REJECTED) { return view('auth.rejected'); diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 4dc9fd68..44158d79 100755 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers\Auth; use App\Facades\Utils; -use App\Http\Controllers\Controller; +use App\Interfaces\Controller; use App\Models\Enums\UserState; use App\Models\User; use App\Repositories\AirlineRepository; @@ -16,6 +16,10 @@ use Jackiedo\Timezonelist\Facades\Timezonelist; use Log; use Validator; +/** + * Class RegisterController + * @package App\Http\Controllers\Auth + */ class RegisterController extends Controller { use RegistersUsers; @@ -26,15 +30,15 @@ class RegisterController extends Controller */ protected $redirectTo = '/'; - protected $airlineRepo, - $airportRepo, - $userService; + private $airlineRepo, + $airportRepo, + $userService; /** * RegisterController constructor. * @param AirlineRepository $airlineRepo * @param AirportRepository $airportRepo - * @param UserService $userService + * @param UserService $userService */ public function __construct( AirlineRepository $airlineRepo, @@ -58,25 +62,25 @@ class RegisterController extends Controller $airlines = $this->airlineRepo->selectBoxList(); return view('auth.register', [ - 'airports' => $airports, - 'airlines' => $airlines, + 'airports' => $airports, + 'airlines' => $airlines, 'timezones' => Timezonelist::toArray(), ]); } /** * Get a validator for an incoming registration request. - * @param array $data + * @param array $data * @return \Illuminate\Contracts\Validation\Validator */ protected function validator(array $data) { $rules = [ - 'name' => 'required|max:255', - 'email' => 'required|email|max:255|unique:users', - 'airline_id' => 'required', + 'name' => 'required|max:255', + 'email' => 'required|email|max:255|unique:users', + 'airline_id' => 'required', 'home_airport_id' => 'required', - 'password' => 'required|min:5|confirmed', + 'password' => 'required|min:5|confirmed', ]; if (config('captcha.enabled')) { @@ -96,13 +100,13 @@ class RegisterController extends Controller protected function create(array $data) { $opts = [ - 'name' => $data['name'], - 'email' => $data['email'], - 'api_key' => Utils::generateApiKey(), - 'airline_id' => $data['airline_id'], + 'name' => $data['name'], + 'email' => $data['email'], + 'api_key' => Utils::generateApiKey(), + 'airline_id' => $data['airline_id'], 'home_airport_id' => $data['home_airport_id'], 'curr_airport_id' => $data['home_airport_id'], - 'password' => Hash::make($data['password']) + 'password' => Hash::make($data['password']) ]; $user = User::create($opts); @@ -122,25 +126,26 @@ class RegisterController extends Controller public function register(Request $request) { $rules = [ - 'name' => 'required', - 'email' => 'required|email|unique:users,email', - 'airline_id' => 'required', + 'name' => 'required', + 'email' => 'required|email|unique:users,email', + 'airline_id' => 'required', 'home_airport_id' => 'required', - 'password' => 'required|confirmed' + 'password' => 'required|confirmed' ]; - if(config('captcha.enabled')) { + if (config('captcha.enabled')) { $rules['g-recaptcha-response'] = 'required|captcha'; } $this->validate(request(), $rules); $user = $this->create($request->all()); - if($user->state === UserState::PENDING) { + if ($user->state === UserState::PENDING) { return view('auth.pending'); } $this->guard()->login($user); + return redirect('/dashboard'); } } diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 91a6a3c7..87bc20bf 100755 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -2,19 +2,23 @@ namespace App\Http\Controllers\Auth; -use App\Http\Controllers\Controller; +use App\Interfaces\Controller; use Illuminate\Foundation\Auth\ResetsPasswords; use Illuminate\Http\Request; +/** + * Class ResetPasswordController + * @package App\Http\Controllers\Auth + */ class ResetPasswordController extends Controller { - protected $redirectTo = '/login'; - use ResetsPasswords; + protected $redirectTo = '/login'; + /** * @param Request $request - * @param null $token + * @param null $token * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function showResetForm(Request $request, $token = null) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php deleted file mode 100755 index e8f6fd1d..00000000 --- a/app/Http/Controllers/Controller.php +++ /dev/null @@ -1,25 +0,0 @@ -acarsRepo->getPositions(); $positions = $this->geoSvc->getFeatureForLiveFlights($pireps); - return view('acars.index',[ - 'pireps' => $pireps, + return view('acars.index', [ + 'pireps' => $pireps, 'positions' => $positions, ]); } diff --git a/app/Http/Controllers/Frontend/DashboardController.php b/app/Http/Controllers/Frontend/DashboardController.php index 62b88900..0da7082a 100644 --- a/app/Http/Controllers/Frontend/DashboardController.php +++ b/app/Http/Controllers/Frontend/DashboardController.php @@ -2,26 +2,26 @@ namespace App\Http\Controllers\Frontend; -use App\Http\Controllers\Controller; +use App\Interfaces\Controller; use App\Repositories\PirepRepository; -use App\Repositories\UserRepository; use Illuminate\Support\Facades\Auth; +/** + * Class DashboardController + * @package App\Http\Controllers\Frontend + */ class DashboardController extends Controller { - private $pirepRepo, $userRepo; + private $pirepRepo; /** * DashboardController constructor. * @param PirepRepository $pirepRepo - * @param UserRepository $userRepo */ public function __construct( - PirepRepository $pirepRepo, - UserRepository $userRepo + PirepRepository $pirepRepo ) { $this->pirepRepo = $pirepRepo; - $this->userRepo = $userRepo; } /** @@ -34,7 +34,8 @@ class DashboardController extends Controller try { $last_pirep = $this->pirepRepo->find($user->last_pirep_id); - } catch(\Exception $e) { } + } catch (\Exception $e) { + } return view('dashboard.index', [ 'user' => $user, diff --git a/app/Http/Controllers/Frontend/FlightController.php b/app/Http/Controllers/Frontend/FlightController.php index 94f6c2cb..a4d22bdf 100644 --- a/app/Http/Controllers/Frontend/FlightController.php +++ b/app/Http/Controllers/Frontend/FlightController.php @@ -2,19 +2,22 @@ namespace App\Http\Controllers\Frontend; -use App\Http\Controllers\Controller; +use App\Interfaces\Controller; use App\Models\Bid; use App\Repositories\AirlineRepository; use App\Repositories\AirportRepository; use App\Repositories\Criteria\WhereCriteria; use App\Repositories\FlightRepository; -use App\Services\FlightService; use App\Services\GeoService; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Log; use Prettus\Repository\Exceptions\RepositoryException; +/** + * Class FlightController + * @package App\Http\Controllers\Frontend + */ class FlightController extends Controller { private $airlineRepo, @@ -26,21 +29,19 @@ class FlightController extends Controller * FlightController constructor. * @param AirlineRepository $airlineRepo * @param AirportRepository $airportRepo - * @param FlightRepository $flightRepo - * @param FlightService $flightSvc - * @param GeoService $geoSvc + * @param FlightRepository $flightRepo + * @param GeoService $geoSvc */ public function __construct( AirlineRepository $airlineRepo, AirportRepository $airportRepo, FlightRepository $flightRepo, - FlightService $flightSvc, GeoService $geoSvc - ) { + ) + { $this->airlineRepo = $airlineRepo; $this->airportRepo = $airportRepo; $this->flightRepo = $flightRepo; - $this->flightSvc = $flightSvc; $this->geoSvc = $geoSvc; } @@ -66,13 +67,13 @@ class FlightController extends Controller $flights = $this->flightRepo->paginate(); $saved_flights = Bid::where('user_id', Auth::id()) - ->pluck('flight_id')->toArray(); + ->pluck('flight_id')->toArray(); return view('flights.index', [ 'airlines' => $this->airlineRepo->selectBoxList(true), 'airports' => $this->airportRepo->selectBoxList(true), - 'flights' => $flights, - 'saved' => $saved_flights, + 'flights' => $flights, + 'saved' => $saved_flights, ]); } @@ -87,13 +88,13 @@ class FlightController extends Controller $flights = $this->flightRepo->searchCriteria($request)->paginate(); $saved_flights = Bid::where('user_id', Auth::id()) - ->pluck('flight_id')->toArray(); + ->pluck('flight_id')->toArray(); return view('flights.index', [ 'airlines' => $this->airlineRepo->selectBoxList(true), 'airports' => $this->airportRepo->selectBoxList(true), - 'flights' => $flights, - 'saved' => $saved_flights, + 'flights' => $flights, + 'saved' => $saved_flights, ]); } @@ -107,13 +108,14 @@ class FlightController extends Controller $flight = $this->flightRepo->find($id); if (empty($flight)) { Flash::error('Flight not found!'); + return redirect(route('frontend.dashboard.index')); } $map_features = $this->geoSvc->flightGeoJson($flight); return view('flights.show', [ - 'flight' => $flight, + 'flight' => $flight, 'map_features' => $map_features, ]); } diff --git a/app/Http/Controllers/Frontend/HomeController.php b/app/Http/Controllers/Frontend/HomeController.php index 6c36a4d4..2c47e360 100644 --- a/app/Http/Controllers/Frontend/HomeController.php +++ b/app/Http/Controllers/Frontend/HomeController.php @@ -2,10 +2,14 @@ namespace App\Http\Controllers\Frontend; -use App\Http\Controllers\Controller; +use App\Interfaces\Controller; use App\Models\User; use Illuminate\Database\QueryException; +/** + * Class HomeController + * @package App\Http\Controllers\Frontend + */ class HomeController extends Controller { /** diff --git a/app/Http/Controllers/Frontend/PirepController.php b/app/Http/Controllers/Frontend/PirepController.php index 65f769f2..446afa55 100644 --- a/app/Http/Controllers/Frontend/PirepController.php +++ b/app/Http/Controllers/Frontend/PirepController.php @@ -3,9 +3,9 @@ namespace App\Http\Controllers\Frontend; use App\Facades\Utils; -use App\Http\Controllers\Controller; use App\Http\Requests\CreatePirepRequest; use App\Http\Requests\UpdatePirepRequest; +use App\Interfaces\Controller; use App\Models\Enums\PirepSource; use App\Models\Enums\PirepState; use App\Models\Pirep; @@ -25,7 +25,10 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Log; - +/** + * Class PirepController + * @package App\Http\Controllers\Frontend + */ class PirepController extends Controller { private $aircraftRepo, @@ -40,15 +43,15 @@ class PirepController extends Controller /** * PirepController constructor. - * @param AircraftRepository $aircraftRepo - * @param AirlineRepository $airlineRepo - * @param AirportRepository $airportRepo - * @param FareService $fareSvc - * @param GeoService $geoSvc - * @param PirepRepository $pirepRepo + * @param AircraftRepository $aircraftRepo + * @param AirlineRepository $airlineRepo + * @param AirportRepository $airportRepo + * @param FareService $fareSvc + * @param GeoService $geoSvc + * @param PirepRepository $pirepRepo * @param PirepFieldRepository $pirepFieldRepo - * @param PirepService $pirepSvc - * @param UserService $userSvc + * @param PirepService $pirepSvc + * @param UserService $userSvc */ public function __construct( AircraftRepository $aircraftRepo, @@ -78,19 +81,19 @@ class PirepController extends Controller * @param null $user * @return array */ - public function aircraftList($user=null, $add_blank=false) + public function aircraftList($user = null, $add_blank = false) { $aircraft = []; $subfleets = $this->userSvc->getAllowableSubfleets($user); - if($add_blank) { + if ($add_blank) { $aircraft[''] = ''; } foreach ($subfleets as $subfleet) { $tmp = []; foreach ($subfleet->aircraft as $ac) { - $tmp[$ac->id] = $ac['name'] . ' - ' . $ac['registration']; + $tmp[$ac->id] = $ac['name'].' - '.$ac['registration']; } $aircraft[$subfleet->name] = $tmp; @@ -101,7 +104,7 @@ class PirepController extends Controller /** * Save any custom fields found - * @param Pirep $pirep + * @param Pirep $pirep * @param Request $request */ protected function saveCustomFields(Pirep $pirep, Request $request) @@ -114,8 +117,8 @@ class PirepController extends Controller } $custom_fields[] = [ - 'name' => $field->name, - 'value' => $request->input($field->slug), + 'name' => $field->name, + 'value' => $request->input($field->slug), 'source' => PirepSource::MANUAL ]; } @@ -126,17 +129,16 @@ class PirepController extends Controller /** * Save the fares that have been specified/saved - * @param Pirep $pirep + * @param Pirep $pirep * @param Request $request * @throws \Exception */ protected function saveFares(Pirep $pirep, Request $request) { $fares = []; - foreach($pirep->aircraft->subfleet->fares as $fare) { - + foreach ($pirep->aircraft->subfleet->fares as $fare) { $field_name = 'fare_'.$fare->id; - if(!$request->filled($field_name)) { + if (!$request->filled($field_name)) { $count = 0; } else { $count = $request->input($field_name); @@ -144,7 +146,7 @@ class PirepController extends Controller $fares[] = [ 'fare_id' => $fare->id, - 'count' => $count, + 'count' => $count, ]; } @@ -167,7 +169,7 @@ class PirepController extends Controller $pireps = $this->pirepRepo->orderBy('created_at', 'desc')->paginate(); return view('pireps.index', [ - 'user' => $user, + 'user' => $user, 'pireps' => $pireps, ]); } @@ -181,13 +183,14 @@ class PirepController extends Controller $pirep = $this->pirepRepo->find($id); if (empty($pirep)) { Flash::error('Pirep not found'); + return redirect(route('frontend.pirep.index')); } $map_features = $this->geoSvc->pirepGeoJson($pirep); return view('pireps.show', [ - 'pirep' => $pirep, + 'pirep' => $pirep, 'map_features' => $map_features, ]); } @@ -203,7 +206,7 @@ class PirepController extends Controller $aircraft = $this->aircraftRepo->find($aircraft_id); return view('pireps.fares', [ - 'aircraft' => $aircraft, + 'aircraft' => $aircraft, 'read_only' => false, ]); } @@ -217,13 +220,13 @@ class PirepController extends Controller $user = Auth::user(); return view('pireps.create', [ - 'aircraft' => null, - 'read_only' => false, - 'airline_list' => $this->airlineRepo->selectBoxList(true), + 'aircraft' => null, + 'read_only' => false, + 'airline_list' => $this->airlineRepo->selectBoxList(true), 'aircraft_list' => $this->aircraftList($user, true), - 'airport_list' => $this->airportRepo->selectBoxList(true), - 'pirep_fields' => $this->pirepFieldRepo->all(), - 'field_values' => [], + 'airport_list' => $this->airportRepo->selectBoxList(true), + 'pirep_fields' => $this->pirepFieldRepo->all(), + 'field_values' => [], ]); } @@ -242,6 +245,7 @@ class PirepController extends Controller $dupe_pirep = $this->pirepSvc->findDuplicate($pirep); if ($dupe_pirep !== false) { flash()->error('This PIREP has already been filed.'); + return redirect(route('frontend.pireps.create'))->withInput(); } @@ -268,6 +272,7 @@ class PirepController extends Controller $pirep = $this->pirepRepo->findWithoutFail($id); if (empty($pirep)) { Flash::error('Pirep not found'); + return redirect(route('frontend.pireps.index')); } @@ -279,29 +284,29 @@ class PirepController extends Controller $read_only = $pirep->state !== PirepState::PENDING; # set the custom fields - foreach($pirep->fields as $field) { + foreach ($pirep->fields as $field) { $pirep->{$field->slug} = $field->value; } # set the fares - foreach($pirep->fares as $fare) { + foreach ($pirep->fares as $fare) { $field_name = 'fare_'.$fare->fare_id; $pirep->{$field_name} = $fare->count; } return view('pireps.edit', [ - 'pirep' => $pirep, - 'read_only' => $read_only, - 'aircraft' => $pirep->aircraft, + 'pirep' => $pirep, + 'read_only' => $read_only, + 'aircraft' => $pirep->aircraft, 'aircraft_list' => $this->aircraftList(), - 'airline_list' => $this->airlineRepo->selectBoxList(), - 'airport_list' => $this->airportRepo->selectBoxList(), - 'pirep_fields' => $this->pirepFieldRepo->all(), + 'airline_list' => $this->airlineRepo->selectBoxList(), + 'airport_list' => $this->airportRepo->selectBoxList(), + 'pirep_fields' => $this->pirepFieldRepo->all(), ]); } /** - * @param $id + * @param $id * @param UpdatePirepRequest $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @throws \Prettus\Validator\Exceptions\ValidatorException @@ -313,6 +318,7 @@ class PirepController extends Controller if (empty($pirep)) { Flash::error('Pirep not found'); + return redirect(route('admin.pireps.index')); } @@ -336,6 +342,7 @@ class PirepController extends Controller $this->saveFares($pirep, $request); Flash::success('Pirep updated successfully.'); + return redirect(route('frontend.pireps.show', ['id' => $pirep->id])); } } diff --git a/app/Http/Controllers/Frontend/ProfileController.php b/app/Http/Controllers/Frontend/ProfileController.php index beaeabf3..9f9ad2ac 100644 --- a/app/Http/Controllers/Frontend/ProfileController.php +++ b/app/Http/Controllers/Frontend/ProfileController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers\Frontend; use App\Facades\Utils; -use App\Http\Controllers\Controller; +use App\Interfaces\Controller; use App\Models\User; use App\Repositories\AirlineRepository; use App\Repositories\AirportRepository; @@ -17,6 +17,10 @@ use Jackiedo\Timezonelist\Facades\Timezonelist; use Log; use Validator; +/** + * Class ProfileController + * @package App\Http\Controllers\Frontend + */ class ProfileController extends Controller { private $airlineRepo, @@ -27,7 +31,7 @@ class ProfileController extends Controller * ProfileController constructor. * @param AirlineRepository $airlineRepo * @param AirportRepository $airportRepo - * @param UserRepository $userRepo + * @param UserRepository $userRepo */ public function __construct( AirlineRepository $airlineRepo, @@ -44,14 +48,14 @@ class ProfileController extends Controller */ public function index() { - if(setting('pilots.home_hubs_only')) { + if (setting('pilots.home_hubs_only')) { $airports = $this->airportRepo->findWhere(['hub' => true]); } else { $airports = $this->airportRepo->all(); } return view('profile.index', [ - 'user' => Auth::user(), + 'user' => Auth::user(), 'airports' => $airports, ]); } @@ -65,13 +69,14 @@ class ProfileController extends Controller $user = User::where('id', $id)->first(); if (empty($user)) { Flash::error('User not found!'); + return redirect(route('frontend.dashboard.index')); } $airports = $this->airportRepo->all(); return view('profile.index', [ - 'user' => $user, + 'user' => $user, 'airports' => $airports, ]); } @@ -86,6 +91,7 @@ class ProfileController extends Controller $user = User::where('id', Auth::user()->id)->first(); if (empty($user)) { Flash::error('User not found!'); + return redirect(route('frontend.dashboard.index')); } @@ -112,10 +118,10 @@ class ProfileController extends Controller $user = $this->userRepo->findWithoutFail($id); $validator = Validator::make($request->toArray(), [ - 'name' => 'required', - 'email' => 'required|unique:users,email,'.$id, + 'name' => 'required', + 'email' => 'required|unique:users,email,'.$id, 'airline_id' => 'required', - 'password' => 'confirmed' + 'password' => 'confirmed' ]); if ($validator->fails()) { @@ -137,6 +143,7 @@ class ProfileController extends Controller $this->userRepo->update($req_data, $id); Flash::success('Profile updated successfully!'); + return redirect(route('frontend.profile.index')); } @@ -154,6 +161,7 @@ class ProfileController extends Controller $user->save(); flash('New API key generated!')->success(); + return redirect(route('frontend.profile.index')); } } diff --git a/app/Http/Controllers/Frontend/UserController.php b/app/Http/Controllers/Frontend/UserController.php index e513857b..b30d24ee 100644 --- a/app/Http/Controllers/Frontend/UserController.php +++ b/app/Http/Controllers/Frontend/UserController.php @@ -2,10 +2,14 @@ namespace App\Http\Controllers\Frontend; -use App\Http\Controllers\Controller; +use App\Interfaces\Controller; use App\Repositories\UserRepository; use Illuminate\Http\Request; +/** + * Class UserController + * @package App\Http\Controllers\Frontend + */ class UserController extends Controller { private $userRepo; @@ -26,9 +30,9 @@ class UserController extends Controller */ public function index(Request $request) { - return view('users.index',[ + return view('users.index', [ 'country' => new \League\ISO3166\ISO3166(), - 'users' => $this->userRepo->orderBy('name', 'desc')->paginate(), + 'users' => $this->userRepo->orderBy('name', 'desc')->paginate(), ]); } } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 43ee7be6..6b799490 100755 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -11,7 +11,6 @@ class Kernel extends HttpKernel \Illuminate\Foundation\Http\Middleware\TrimStrings::class, \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, ]; - protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware\InstalledCheck::class, @@ -30,15 +29,14 @@ class Kernel extends HttpKernel 'json', ], ]; - protected $routeMiddleware = [ - 'api.auth' => \App\Http\Middleware\ApiAuth::class, - 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, + 'api.auth' => \App\Http\Middleware\ApiAuth::class, + 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, - 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, - 'can' => \Illuminate\Auth\Middleware\Authorize::class, - 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, - 'json' => \App\Http\Middleware\JsonResponse::class, - 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, + 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, + 'can' => \Illuminate\Auth\Middleware\Authorize::class, + 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, + 'json' => \App\Http\Middleware\JsonResponse::class, + 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, ]; } diff --git a/app/Http/Middleware/ApiAuth.php b/app/Http/Middleware/ApiAuth.php index 89500c1a..08abc31e 100644 --- a/app/Http/Middleware/ApiAuth.php +++ b/app/Http/Middleware/ApiAuth.php @@ -16,14 +16,14 @@ class ApiAuth * Handle an incoming request. * * @param \Illuminate\Http\Request $request - * @param \Closure $next + * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { // Check if Authorization header is in place $api_key = $request->header('x-api-key', null); - if($api_key === null) { + if ($api_key === null) { $api_key = $request->header('Authorization', null); if ($api_key === null) { return $this->unauthorized('X-API-KEY header missing'); @@ -32,11 +32,11 @@ class ApiAuth // Try to find the user via API key. Cache this lookup $user = User::where('api_key', $api_key)->first(); - if($user === null) { + if ($user === null) { return $this->unauthorized('User not found with key "'.$api_key.'"'); } - if($user->state !== UserState::ACTIVE) { + if ($user->state !== UserState::ACTIVE) { return $this->unauthorized('User is not ACTIVE, please contact an administrator'); } @@ -54,13 +54,13 @@ class ApiAuth * Return an unauthorized message * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response */ - private function unauthorized($details='') + private function unauthorized($details = '') { return response([ 'error' => [ - 'code' => '401', + 'code' => '401', 'http_code' => 'Unauthorized', - 'message' => 'Invalid or missing API key ('. $details .')', + 'message' => 'Invalid or missing API key ('.$details.')', ], ], 401); } diff --git a/app/Http/Middleware/JsonResponse.php b/app/Http/Middleware/JsonResponse.php index 5eb06262..5ec02757 100644 --- a/app/Http/Middleware/JsonResponse.php +++ b/app/Http/Middleware/JsonResponse.php @@ -13,6 +13,7 @@ class JsonResponse { $response = $next($request); $response->headers->set('Content-Type', 'application/json'); + return $response; } } diff --git a/app/Http/Middleware/MeasureExecutionTime.php b/app/Http/Middleware/MeasureExecutionTime.php index 04ccef4d..2a6ca73f 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; } @@ -31,8 +31,8 @@ class MeasureExecutionTime // I assume you're using valid json in your responses // Then I manipulate them below $content = json_decode($response->getContent(), true) + [ - 'execution_time' => $executionTime, - ]; + 'execution_time' => $executionTime, + ]; // Change the content of your response $response->setData($content); diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index e27860e2..8b10025e 100755 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -10,9 +10,9 @@ class RedirectIfAuthenticated /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @param string|null $guard + * @param \Illuminate\Http\Request $request + * @param \Closure $next + * @param string|null $guard * @return mixed */ public function handle($request, Closure $next, $guard = null) diff --git a/app/Http/Requests/Acars/CommentRequest.php b/app/Http/Requests/Acars/CommentRequest.php index 94bae9ab..9954c2af 100644 --- a/app/Http/Requests/Acars/CommentRequest.php +++ b/app/Http/Requests/Acars/CommentRequest.php @@ -18,7 +18,7 @@ class CommentRequest extends FormRequest public function rules() { $rules = [ - 'comment' => 'required', + 'comment' => 'required', 'created_at' => 'nullable|date', ]; diff --git a/app/Http/Requests/Acars/EventRequest.php b/app/Http/Requests/Acars/EventRequest.php index 8f155945..c5175c9f 100644 --- a/app/Http/Requests/Acars/EventRequest.php +++ b/app/Http/Requests/Acars/EventRequest.php @@ -12,19 +12,24 @@ use Illuminate\Foundation\Http\FormRequest; */ class EventRequest extends FormRequest { + /** + * @return bool + * @throws \Illuminate\Database\Eloquent\ModelNotFoundException + */ public function authorize() { $pirep = Pirep::findOrFail($this->route('pirep_id'), ['user_id']); + return $pirep->user_id === Auth::id(); } public function rules() { $rules = [ - 'events' => 'required|array', - 'events.*.event' => 'required', - 'events.*.lat' => 'nullable|numeric', - 'events.*.lon' => 'nullable|numeric', + 'events' => 'required|array', + 'events.*.event' => 'required', + 'events.*.lat' => 'nullable|numeric', + 'events.*.lon' => 'nullable|numeric', 'events.*.created_at' => 'nullable|date', ]; diff --git a/app/Http/Requests/Acars/FileRequest.php b/app/Http/Requests/Acars/FileRequest.php index dfac03f6..8417adb2 100644 --- a/app/Http/Requests/Acars/FileRequest.php +++ b/app/Http/Requests/Acars/FileRequest.php @@ -15,39 +15,40 @@ class FileRequest extends FormRequest public function authorize() { $pirep = Pirep::findOrFail($this->route('pirep_id'), ['user_id']); + return $pirep->user_id === Auth::id(); } public function rules() { $rules = [ - 'distance' => 'required|numeric', - 'flight_time' => 'required|integer', - 'fuel_used' => 'required|numeric', + 'distance' => 'required|numeric', + 'flight_time' => 'required|integer', + 'fuel_used' => 'required|numeric', - 'airline_id' => 'nullable|exists:airlines,id', - 'aircraft_id' => 'nullable|exists:aircraft,id', - 'flight_number' => 'nullable', - 'dpt_airport_id' => 'nullable', - 'arr_airport_id' => 'nullable', - 'route_code' => 'nullable', - 'route_leg' => 'nullable', - 'planned_distance' => 'nullable|numeric', - 'planned_flight_time' => 'nullable|integer', - 'level' => 'nullable|numeric', - 'zfw' => 'nullable|numeric', - 'block_fuel' => 'nullable|numeric', - 'route' => 'nullable', - 'notes' => 'nullable', - 'source_name' => 'nullable|max:25', - 'landing_rate' => 'nullable|numeric', - 'flight_type' => 'nullable|integer', - 'created_at' => 'nullable|date', + 'airline_id' => 'nullable|exists:airlines,id', + 'aircraft_id' => 'nullable|exists:aircraft,id', + 'flight_number' => 'nullable', + 'dpt_airport_id' => 'nullable', + 'arr_airport_id' => 'nullable', + 'route_code' => 'nullable', + 'route_leg' => 'nullable', + 'planned_distance' => 'nullable|numeric', + 'planned_flight_time' => 'nullable|integer', + 'level' => 'nullable|numeric', + 'zfw' => 'nullable|numeric', + 'block_fuel' => 'nullable|numeric', + 'route' => 'nullable', + 'notes' => 'nullable', + 'source_name' => 'nullable|max:25', + 'landing_rate' => 'nullable|numeric', + 'flight_type' => 'nullable|integer', + 'created_at' => 'nullable|date', # See if the fare objects are included and formatted properly - 'fares' => 'nullable|array', - 'fares.*.id' => 'required', - 'fares.*.count' => 'required|numeric', + 'fares' => 'nullable|array', + 'fares.*.id' => 'required', + 'fares.*.count' => 'required|numeric', ]; return $rules; diff --git a/app/Http/Requests/Acars/LogRequest.php b/app/Http/Requests/Acars/LogRequest.php index 21da0861..a2a94431 100644 --- a/app/Http/Requests/Acars/LogRequest.php +++ b/app/Http/Requests/Acars/LogRequest.php @@ -15,16 +15,17 @@ class LogRequest extends FormRequest public function authorize() { $pirep = Pirep::findOrFail($this->route('pirep_id'), ['user_id']); + return $pirep->user_id === Auth::id(); } public function rules() { $rules = [ - 'logs' => 'required|array', - 'logs.*.log' => 'required', - 'logs.*.lat' => 'nullable|numeric', - 'logs.*.lon' => 'nullable|numeric', + 'logs' => 'required|array', + 'logs.*.log' => 'required', + 'logs.*.lat' => 'nullable|numeric', + 'logs.*.lon' => 'nullable|numeric', 'logs.*.created_at' => 'nullable|date', ]; diff --git a/app/Http/Requests/Acars/PositionRequest.php b/app/Http/Requests/Acars/PositionRequest.php index 65958d3c..21ca418d 100644 --- a/app/Http/Requests/Acars/PositionRequest.php +++ b/app/Http/Requests/Acars/PositionRequest.php @@ -15,24 +15,25 @@ class PositionRequest extends FormRequest public function authorize() { $pirep = Pirep::findOrFail($this->route('pirep_id'), ['user_id']); + return $pirep->user_id === Auth::id(); } public function rules() { $rules = [ - 'positions' => 'required|array', - 'positions.*.lat' => 'required|numeric', - 'positions.*.lon' => 'required|numeric', - 'positions.*.altitude' => 'nullable|numeric', - 'positions.*.heading' => 'nullable|integer|between:0,360', - 'positions.*.vs' => 'nullable', - 'positions.*.gs' => 'nullable', + 'positions' => 'required|array', + 'positions.*.lat' => 'required|numeric', + 'positions.*.lon' => 'required|numeric', + 'positions.*.altitude' => 'nullable|numeric', + 'positions.*.heading' => 'nullable|integer|between:0,360', + 'positions.*.vs' => 'nullable', + 'positions.*.gs' => 'nullable', 'positions.*.transponder' => 'nullable', - 'positions.*.autopilot' => 'nullable', - 'positions.*.fuel_flow' => 'nullable', - 'positions.*.log' => 'nullable', - 'positions.*.created_at' => 'nullable|date', + 'positions.*.autopilot' => 'nullable', + 'positions.*.fuel_flow' => 'nullable', + 'positions.*.log' => 'nullable', + 'positions.*.created_at' => 'nullable|date', ]; return $rules; diff --git a/app/Http/Requests/Acars/PrefileRequest.php b/app/Http/Requests/Acars/PrefileRequest.php index 3536c175..ddcf8fb1 100644 --- a/app/Http/Requests/Acars/PrefileRequest.php +++ b/app/Http/Requests/Acars/PrefileRequest.php @@ -18,31 +18,31 @@ class PrefileRequest extends FormRequest public function rules() { $rules = [ - 'airline_id' => 'required|exists:airlines,id', - 'aircraft_id' => 'required|exists:aircraft,id', - 'flight_number' => 'required', - 'dpt_airport_id' => 'required', - 'arr_airport_id' => 'required', - 'source_name' => 'required|max:25', + 'airline_id' => 'required|exists:airlines,id', + 'aircraft_id' => 'required|exists:aircraft,id', + 'flight_number' => 'required', + 'dpt_airport_id' => 'required', + 'arr_airport_id' => 'required', + 'source_name' => 'required|max:25', - 'level' => 'nullable|numeric', - 'route_code' => 'nullable', - 'route_leg' => 'nullable', - 'distance' => 'nullable|numeric', - 'flight_time' => 'nullable|integer', - 'planned_distance' => 'nullable|numeric', - 'planned_flight_time' => 'nullable|integer', - 'zfw' => 'nullable|numeric', - 'block_fuel' => 'nullable|numeric', - 'route' => 'nullable', - 'notes' => 'nullable', - 'flight_type' => 'nullable|integer', - 'created_at' => 'nullable|date', + 'level' => 'nullable|numeric', + 'route_code' => 'nullable', + 'route_leg' => 'nullable', + 'distance' => 'nullable|numeric', + 'flight_time' => 'nullable|integer', + 'planned_distance' => 'nullable|numeric', + 'planned_flight_time' => 'nullable|integer', + 'zfw' => 'nullable|numeric', + 'block_fuel' => 'nullable|numeric', + 'route' => 'nullable', + 'notes' => 'nullable', + 'flight_type' => 'nullable|integer', + 'created_at' => 'nullable|date', # See if the fare objects are included and formatted properly - 'fares' => 'nullable|array', - 'fares.*.id' => 'required', - 'fares.*.count' => 'required|numeric', + 'fares' => 'nullable|array', + 'fares.*.id' => 'required', + 'fares.*.count' => 'required|numeric', ]; return $rules; diff --git a/app/Http/Requests/Acars/RouteRequest.php b/app/Http/Requests/Acars/RouteRequest.php index f38b1adf..9500cf2c 100644 --- a/app/Http/Requests/Acars/RouteRequest.php +++ b/app/Http/Requests/Acars/RouteRequest.php @@ -15,18 +15,19 @@ class RouteRequest extends FormRequest public function authorize() { $pirep = Pirep::findOrFail($this->route('pirep_id'), ['user_id']); + return $pirep->user_id === Auth::id(); } public function rules() { $rules = [ - 'route' => 'required|array', - 'route.*.name' => 'required', - 'route.*.order' => 'required|int', + 'route' => 'required|array', + 'route.*.name' => 'required', + 'route.*.order' => 'required|int', 'route.*.nav_type' => 'nullable|int', - 'route.*.lat' => 'required|numeric', - 'route.*.lon' => 'required|numeric', + 'route.*.lat' => 'required|numeric', + 'route.*.lon' => 'required|numeric', ]; return $rules; diff --git a/app/Http/Requests/Acars/UpdateRequest.php b/app/Http/Requests/Acars/UpdateRequest.php index 0fcccfbe..b0a6e99e 100644 --- a/app/Http/Requests/Acars/UpdateRequest.php +++ b/app/Http/Requests/Acars/UpdateRequest.php @@ -15,38 +15,39 @@ class UpdateRequest extends FormRequest public function authorize() { $pirep = Pirep::findOrFail($this->route('pirep_id'), ['user_id']); + return $pirep->user_id === Auth::id(); } public function rules() { $rules = [ - 'airline_id' => 'nullable|exists:airlines,id', - 'aircraft_id' => 'nullable|exists:aircraft,id', - 'flight_number' => 'nullable', - 'dpt_airport_id' => 'nullable', - 'arr_airport_id' => 'nullable', - 'route_code' => 'nullable', - 'route_leg' => 'nullable', - 'distance' => 'nullable|numeric', - 'planned_distance' => 'nullable|numeric', - 'planned_flight_time' => 'nullable|integer', - 'flight_time' => 'nullable|integer', - 'level' => 'nullable|numeric', - 'zfw' => 'nullable|numeric', - 'fuel_used' => 'nullable|numeric', - 'block_fuel' => 'nullable|numeric', - 'route' => 'nullable', - 'notes' => 'nullable', - 'source_name' => 'nullable|max:25', - 'landing_rate' => 'nullable|numeric', - 'flight_type' => 'nullable|integer', - 'created_at' => 'nullable|date', + 'airline_id' => 'nullable|exists:airlines,id', + 'aircraft_id' => 'nullable|exists:aircraft,id', + 'flight_number' => 'nullable', + 'dpt_airport_id' => 'nullable', + 'arr_airport_id' => 'nullable', + 'route_code' => 'nullable', + 'route_leg' => 'nullable', + 'distance' => 'nullable|numeric', + 'planned_distance' => 'nullable|numeric', + 'planned_flight_time' => 'nullable|integer', + 'flight_time' => 'nullable|integer', + 'level' => 'nullable|numeric', + 'zfw' => 'nullable|numeric', + 'fuel_used' => 'nullable|numeric', + 'block_fuel' => 'nullable|numeric', + 'route' => 'nullable', + 'notes' => 'nullable', + 'source_name' => 'nullable|max:25', + 'landing_rate' => 'nullable|numeric', + 'flight_type' => 'nullable|integer', + 'created_at' => 'nullable|date', # See if the fare objects are included and formatted properly - 'fares' => 'nullable|array', - 'fares.*.id' => 'required', - 'fares.*.count' => 'required|numeric', + 'fares' => 'nullable|array', + 'fares.*.id' => 'required', + 'fares.*.count' => 'required|numeric', ]; return $rules; diff --git a/app/Http/Requests/CreateAircraftRequest.php b/app/Http/Requests/CreateAircraftRequest.php index 4497a708..353832d4 100644 --- a/app/Http/Requests/CreateAircraftRequest.php +++ b/app/Http/Requests/CreateAircraftRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class CreateAircraftRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/CreateAirlineRequest.php b/app/Http/Requests/CreateAirlineRequest.php index 86dcc188..6dd8fae1 100644 --- a/app/Http/Requests/CreateAirlineRequest.php +++ b/app/Http/Requests/CreateAirlineRequest.php @@ -17,6 +17,7 @@ class CreateAirlineRequest extends FormRequest $rules = Airline::$rules; $rules['iata'] .= '|unique:airlines'; $rules['icao'] .= '|unique:airlines'; + return $rules; } } diff --git a/app/Http/Requests/CreateAirportRequest.php b/app/Http/Requests/CreateAirportRequest.php index 52e6fa66..3c0259c6 100644 --- a/app/Http/Requests/CreateAirportRequest.php +++ b/app/Http/Requests/CreateAirportRequest.php @@ -16,6 +16,7 @@ class CreateAirportRequest extends FormRequest { $rules = Airport::$rules; $rules['icao'] .= '|unique:airports'; + return $rules; } } diff --git a/app/Http/Requests/CreateAwardRequest.php b/app/Http/Requests/CreateAwardRequest.php index 507ba140..540086ae 100755 --- a/app/Http/Requests/CreateAwardRequest.php +++ b/app/Http/Requests/CreateAwardRequest.php @@ -2,12 +2,11 @@ namespace App\Http\Requests; -use Illuminate\Foundation\Http\FormRequest; use App\Models\Award; +use Illuminate\Foundation\Http\FormRequest; class CreateAwardRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/CreateFareRequest.php b/app/Http/Requests/CreateFareRequest.php index a0402013..f99687f3 100644 --- a/app/Http/Requests/CreateFareRequest.php +++ b/app/Http/Requests/CreateFareRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class CreateFareRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/CreateFlightRequest.php b/app/Http/Requests/CreateFlightRequest.php index fc0429a9..7c7a945e 100644 --- a/app/Http/Requests/CreateFlightRequest.php +++ b/app/Http/Requests/CreateFlightRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class CreateFlightRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/CreatePirepFieldRequest.php b/app/Http/Requests/CreatePirepFieldRequest.php index 9900b7b6..53e5e3a5 100644 --- a/app/Http/Requests/CreatePirepFieldRequest.php +++ b/app/Http/Requests/CreatePirepFieldRequest.php @@ -5,10 +5,8 @@ namespace App\Http\Requests; use App\Models\PirepField; use Illuminate\Foundation\Http\FormRequest; - class CreatePirepFieldRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/CreateRankRequest.php b/app/Http/Requests/CreateRankRequest.php index 02a38db9..c990f508 100644 --- a/app/Http/Requests/CreateRankRequest.php +++ b/app/Http/Requests/CreateRankRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class CreateRankRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/CreateSubfleetRequest.php b/app/Http/Requests/CreateSubfleetRequest.php index 0df16d2b..fabfc91d 100644 --- a/app/Http/Requests/CreateSubfleetRequest.php +++ b/app/Http/Requests/CreateSubfleetRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class CreateSubfleetRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/CreateUserRequest.php b/app/Http/Requests/CreateUserRequest.php index cbf2107f..99f7762e 100644 --- a/app/Http/Requests/CreateUserRequest.php +++ b/app/Http/Requests/CreateUserRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class CreateUserRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * @@ -27,6 +26,7 @@ class CreateUserRequest extends FormRequest { $rules = User::$rules; $rules['email'] .= '|unique:users,email'; + return $rules; } } diff --git a/app/Http/Requests/UpdateAircraftRequest.php b/app/Http/Requests/UpdateAircraftRequest.php index 624e1dbe..1f8a00de 100644 --- a/app/Http/Requests/UpdateAircraftRequest.php +++ b/app/Http/Requests/UpdateAircraftRequest.php @@ -2,12 +2,11 @@ namespace App\Http\Requests; -use Illuminate\Foundation\Http\FormRequest; use App\Models\Aircraft; +use Illuminate\Foundation\Http\FormRequest; class UpdateAircraftRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/UpdateAirlineRequest.php b/app/Http/Requests/UpdateAirlineRequest.php index e17f6306..b84bda48 100644 --- a/app/Http/Requests/UpdateAirlineRequest.php +++ b/app/Http/Requests/UpdateAirlineRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class UpdateAirlineRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/UpdateAirportRequest.php b/app/Http/Requests/UpdateAirportRequest.php index a6a0d2d9..bf635d41 100644 --- a/app/Http/Requests/UpdateAirportRequest.php +++ b/app/Http/Requests/UpdateAirportRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class UpdateAirportRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/UpdateAwardRequest.php b/app/Http/Requests/UpdateAwardRequest.php index 7f695573..252361ab 100755 --- a/app/Http/Requests/UpdateAwardRequest.php +++ b/app/Http/Requests/UpdateAwardRequest.php @@ -2,12 +2,11 @@ namespace App\Http\Requests; -use Illuminate\Foundation\Http\FormRequest; use App\Models\Award; +use Illuminate\Foundation\Http\FormRequest; class UpdateAwardRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/UpdateFareRequest.php b/app/Http/Requests/UpdateFareRequest.php index dfc20c38..5ce7d6d3 100644 --- a/app/Http/Requests/UpdateFareRequest.php +++ b/app/Http/Requests/UpdateFareRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class UpdateFareRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/UpdateFlightRequest.php b/app/Http/Requests/UpdateFlightRequest.php index f5ab1582..58596fa8 100644 --- a/app/Http/Requests/UpdateFlightRequest.php +++ b/app/Http/Requests/UpdateFlightRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class UpdateFlightRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/UpdatePirepFieldRequest.php b/app/Http/Requests/UpdatePirepFieldRequest.php index 78f14eba..c70b5385 100644 --- a/app/Http/Requests/UpdatePirepFieldRequest.php +++ b/app/Http/Requests/UpdatePirepFieldRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class UpdatePirepFieldRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/UpdatePirepRequest.php b/app/Http/Requests/UpdatePirepRequest.php index c0569d39..35f8cf17 100644 --- a/app/Http/Requests/UpdatePirepRequest.php +++ b/app/Http/Requests/UpdatePirepRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class UpdatePirepRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/UpdateRankRequest.php b/app/Http/Requests/UpdateRankRequest.php index e4c5078c..ab83644e 100644 --- a/app/Http/Requests/UpdateRankRequest.php +++ b/app/Http/Requests/UpdateRankRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class UpdateRankRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/UpdateSubfleetRequest.php b/app/Http/Requests/UpdateSubfleetRequest.php index 16cde82c..81b08e8a 100644 --- a/app/Http/Requests/UpdateSubfleetRequest.php +++ b/app/Http/Requests/UpdateSubfleetRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class UpdateSubfleetRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Requests/UpdateUserRequest.php b/app/Http/Requests/UpdateUserRequest.php index 0ea4b288..06eba56b 100644 --- a/app/Http/Requests/UpdateUserRequest.php +++ b/app/Http/Requests/UpdateUserRequest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Http\FormRequest; class UpdateUserRequest extends FormRequest { - /** * Determine if the user is authorized to make this request. * diff --git a/app/Http/Resources/Acars.php b/app/Http/Resources/Acars.php index 0b8f5684..4be289af 100644 --- a/app/Http/Resources/Acars.php +++ b/app/Http/Resources/Acars.php @@ -9,7 +9,7 @@ class Acars extends Resource /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) diff --git a/app/Http/Resources/Airline.php b/app/Http/Resources/Airline.php index 35a4e789..2f945c4b 100644 --- a/app/Http/Resources/Airline.php +++ b/app/Http/Resources/Airline.php @@ -9,12 +9,12 @@ class Airline extends Resource public function toArray($request) { return [ - 'id' => $this->id, - 'icao' => $this->icao, - 'iata' => $this->iata, - 'name' => $this->name, + 'id' => $this->id, + 'icao' => $this->icao, + 'iata' => $this->iata, + 'name' => $this->name, 'country' => $this->country, - 'logo' => $this->logo, + 'logo' => $this->logo, #'active' => $this->active, #'created_at' => $this->created_at, #'updated_at' => $this->updated_at, diff --git a/app/Http/Resources/Award.php b/app/Http/Resources/Award.php index 84f1bb77..2f096945 100755 --- a/app/Http/Resources/Award.php +++ b/app/Http/Resources/Award.php @@ -9,10 +9,10 @@ class Award extends Resource public function toArray($request) { return [ - 'id' => $this->id, - 'title' => $this->title, + 'id' => $this->id, + 'title' => $this->title, 'description' => $this->description, - 'image' => $this->image, + 'image' => $this->image, ]; } } diff --git a/app/Http/Resources/Flight.php b/app/Http/Resources/Flight.php index f7e41a49..b135ff68 100644 --- a/app/Http/Resources/Flight.php +++ b/app/Http/Resources/Flight.php @@ -12,7 +12,7 @@ class Flight extends Resource $flight = parent::toArray($request); // Return multiple measures so the client can pick what they want - if($this->distance instanceof Distance) { + if ($this->distance instanceof Distance) { $flight['distance'] = $this->distance->toObject(); } diff --git a/app/Http/Resources/JournalTransaction.php b/app/Http/Resources/JournalTransaction.php index edadba6e..67865b0b 100644 --- a/app/Http/Resources/JournalTransaction.php +++ b/app/Http/Resources/JournalTransaction.php @@ -9,6 +9,7 @@ class JournalTransaction extends Resource public function toArray($request) { $transaction = parent::toArray($request); + return $transaction; } } diff --git a/app/Http/Resources/Pirep.php b/app/Http/Resources/Pirep.php index 5c746f40..95def93f 100644 --- a/app/Http/Resources/Pirep.php +++ b/app/Http/Resources/Pirep.php @@ -11,7 +11,7 @@ class Pirep extends Resource /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) @@ -40,8 +40,8 @@ class Pirep extends Resource $pirep['position'] = new Acars($this->position); $pirep['comments'] = PirepComment::collection($this->comments); $pirep['user'] = [ - 'id' => $this->user->id, - 'name' => $this->user->name, + 'id' => $this->user->id, + 'name' => $this->user->name, 'home_airport_id' => $this->user->home_airport_id, 'curr_airport_id' => $this->user->curr_airport_id, ]; diff --git a/app/Http/Resources/PirepComment.php b/app/Http/Resources/PirepComment.php index 056f91d8..d2464b89 100644 --- a/app/Http/Resources/PirepComment.php +++ b/app/Http/Resources/PirepComment.php @@ -14,7 +14,7 @@ class PirepComment extends Resource /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) @@ -22,13 +22,13 @@ class PirepComment extends Resource $user = $this->user; return [ - 'id' => $this->id, - 'comment' => $this->comment, - 'created_at' => $this->created_at, - 'user' => [ - 'id' => $user->id, - 'pilot_id' => $user->pilot_id, - 'name' => $user->name, + 'id' => $this->id, + 'comment' => $this->comment, + 'created_at' => $this->created_at, + 'user' => [ + 'id' => $user->id, + 'pilot_id' => $user->pilot_id, + 'name' => $user->name, ], ]; } diff --git a/app/Http/Resources/Rank.php b/app/Http/Resources/Rank.php index 7ec4bc8d..23d91d56 100644 --- a/app/Http/Resources/Rank.php +++ b/app/Http/Resources/Rank.php @@ -15,7 +15,7 @@ class Rank extends Resource public function toArray($request) { return [ - 'name' => $this->name, + 'name' => $this->name, 'subfleets' => Subfleet::collection($this->subfleets), ]; } diff --git a/app/Http/Resources/Response.php b/app/Http/Resources/Response.php index ac0bbc57..b2c89651 100644 --- a/app/Http/Resources/Response.php +++ b/app/Http/Resources/Response.php @@ -14,7 +14,7 @@ class Response extends Resource /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) diff --git a/app/Http/Resources/Setting.php b/app/Http/Resources/Setting.php index ff0214fc..c22b2373 100644 --- a/app/Http/Resources/Setting.php +++ b/app/Http/Resources/Setting.php @@ -9,12 +9,12 @@ class Setting extends Resource public function toArray($request) { return [ - 'id' => $this->id, - 'type' => $this->type, - 'name' => $this->name, - 'value' => $this->value, - 'group' => $this->group, - 'order' => $this->order, + 'id' => $this->id, + 'type' => $this->type, + 'name' => $this->name, + 'value' => $this->value, + 'group' => $this->group, + 'order' => $this->order, 'description' => $this->description, ]; } diff --git a/app/Http/Resources/User.php b/app/Http/Resources/User.php index c5a13622..295d1343 100644 --- a/app/Http/Resources/User.php +++ b/app/Http/Resources/User.php @@ -9,25 +9,25 @@ class User extends Resource public function toArray($request) { return [ - 'id' => $this->id, - 'pilot_id' => $this->pilot_id, - 'name' => $this->name, - 'email' => $this->email, - 'apikey' => $this->apikey, - 'rank_id' => $this->rank_id, - 'home_airport' => $this->home_airport_id, - 'curr_airport' => $this->curr_airport_id, + 'id' => $this->id, + 'pilot_id' => $this->pilot_id, + 'name' => $this->name, + 'email' => $this->email, + 'apikey' => $this->apikey, + 'rank_id' => $this->rank_id, + 'home_airport' => $this->home_airport_id, + 'curr_airport' => $this->curr_airport_id, 'last_pirep_id' => $this->last_pirep_id, - 'flights' => $this->flight, - 'flight_time' => $this->flight_time, - 'balance' => $this->balance, - 'timezone' => $this->timezone, - 'status' => $this->status, - 'state' => $this->state, + 'flights' => $this->flight, + 'flight_time' => $this->flight_time, + 'balance' => $this->balance, + 'timezone' => $this->timezone, + 'status' => $this->status, + 'state' => $this->state, 'airline' => Airline::make($this->airline), - 'bids' => UserBid::collection($this->bids), - 'rank' => Rank::make($this->rank), + 'bids' => UserBid::collection($this->bids), + 'rank' => Rank::make($this->rank), ]; } } diff --git a/app/Http/Resources/UserBid.php b/app/Http/Resources/UserBid.php index 968eb085..b48c717c 100644 --- a/app/Http/Resources/UserBid.php +++ b/app/Http/Resources/UserBid.php @@ -9,10 +9,10 @@ class UserBid extends Resource public function toArray($request) { return [ - 'id' => $this->id, - 'user_id' => $this->user_id, + 'id' => $this->id, + 'user_id' => $this->user_id, 'flight_id' => $this->flight_id, - 'flight' => Flight::collection($this->whenLoaded('flight')) + 'flight' => Flight::collection($this->whenLoaded('flight')) #'created_at' => $this->created_at, #'updated_at' => $this->updated_at, ]; diff --git a/app/Interfaces/AwardInterface.php b/app/Interfaces/Award.php similarity index 55% rename from app/Interfaces/AwardInterface.php rename to app/Interfaces/Award.php index 9ac41da3..88a68100 100644 --- a/app/Interfaces/AwardInterface.php +++ b/app/Interfaces/Award.php @@ -3,22 +3,25 @@ namespace App\Interfaces; use App\Facades\Utils; -use App\Models\Award; +use App\Models\Award as AwardModel; use App\Models\User; use App\Models\UserAward; +use Log; /** - * Base class for the Awards, they need to extend this + * Base class for the Awards, you need to extend this, and implement: + * $name + * $param_description (optional) + * public function check($parameter=null) + * + * See: http://docs.phpvms.net/customizing/awards * @package App\Interfaces */ -abstract class AwardInterface +abstract class Award { public $name = ''; public $param_description = ''; - protected $award; - protected $user; - /** * Each award class just needs to return true or false if it should actually * be awarded to a user. This is the only method that needs to be implemented @@ -27,12 +30,19 @@ abstract class AwardInterface */ abstract public function check($parameter = null): bool; + /* + * You don't really need to mess with anything below here + */ + + protected $award, + $user; + /** * AwardInterface constructor. - * @param Award $award - * @param User $user + * @param AwardModel $award + * @param User $user */ - public function __construct(Award $award = null, User $user = null) + public function __construct(AwardModel $award = null, User $user = null) { $this->award = $award; $this->user = $user; @@ -40,13 +50,14 @@ abstract class AwardInterface /** * Run the main handler for this award class to determine if - * it should be awarded or not + * it should be awarded or not. Declared as final to prevent a child + * from accidentally overriding and breaking something */ - public function handle() + final public function handle(): void { # Check if the params are a JSON object or array $param = $this->award->ref_class_params; - if ($this->award->ref_class_params && Utils::isObject($this->award->ref_class_params)) { + if (Utils::isObject($this->award->ref_class_params)) { $param = json_decode($this->award->ref_class_params); } @@ -59,11 +70,11 @@ abstract class AwardInterface * Add the award to this user, if they don't already have it * @return bool|UserAward */ - protected function addAward() + final protected function addAward() { $w = [ - 'user_id' => $this->user->id, - 'award_id' => $this->award->id + 'user_id' => $this->user->id, + 'award_id' => $this->award->id, ]; $found = UserAward::where($w)->count('id'); @@ -73,7 +84,17 @@ abstract class AwardInterface // Associate this award to the user now $award = new UserAward($w); - $award->save(); + + try { + $award->save(); + } catch(\Exception $e) { + Log::error( + 'Error saving award: '.$e->getMessage(), + $e->getTrace() + ); + + return null; + } return $award; } diff --git a/app/Http/Controllers/Api/RestController.php b/app/Interfaces/Controller.php old mode 100644 new mode 100755 similarity index 64% rename from app/Http/Controllers/Api/RestController.php rename to app/Interfaces/Controller.php index 74617e34..24ae7eb2 --- a/app/Http/Controllers/Api/RestController.php +++ b/app/Interfaces/Controller.php @@ -1,51 +1,60 @@ 0) { + if (\count(array_filter(array_keys($attrs_or_validations), '\is_string')) > 0) { $is_validation = true; } - if($is_validation) { + if ($is_validation) { $this->validate($request, $attrs_or_validations); } $fields = []; - foreach($attrs_or_validations as $idx => $field) { - if($is_validation) { + foreach ($attrs_or_validations as $idx => $field) { + if ($is_validation) { $field = $idx; } - if($request instanceof Request) { + if ($request instanceof Request) { if ($request->filled($field)) { $fields[$field] = $request->input($field); } } else { - if(array_key_exists($field, $request)) { + if (array_key_exists($field, $request)) { $fields[$field] = $request[$field]; } } } - if(!empty($addtl_fields) && \is_array($addtl_fields)) { + if (!empty($addtl_fields) && \is_array($addtl_fields)) { $fields = array_merge($fields, $addtl_fields); } @@ -59,9 +68,9 @@ class RestController * @return bool * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException */ - public function validate($request, $rules) + /*public function validate($request, $rules) { - if($request instanceof Request) { + if ($request instanceof Request) { $validator = Validator::make($request->all(), $rules); } else { $validator = Validator::make($request, $rules); @@ -72,20 +81,20 @@ class RestController } return true; - } + }*/ /** * Simple normalized method for forming the JSON responses * @param $message * @return \Illuminate\Http\JsonResponse */ - public function message($message, $count=null) + public function message($message, $count = null) { $attrs = [ 'message' => $message ]; - if($count !== null) { + if ($count !== null) { $attrs['count'] = $count; } diff --git a/app/Interfaces/Enum.php b/app/Interfaces/Enum.php index fa3c1074..017b61c9 100644 --- a/app/Interfaces/Enum.php +++ b/app/Interfaces/Enum.php @@ -4,20 +4,42 @@ namespace App\Interfaces; /** * Class EnumBase + * Borrowing some features from https://github.com/myclabs/php-enum + * after this was created :) * @package App\Models\Enums */ abstract class Enum { protected static $labels = []; protected static $cache = []; + protected $value; + + /** + * Create an instance of this Enum + * @param $val + */ + public function __construct($val) + { + $this->value = $val; + } + + /** + * Return the value that's been set if this is an instance + * @return mixed + */ + public function getValue() + { + return $this->value; + } /** * Return the label, try to return the translated version as well * @param $value * @return mixed */ - public static function label($value) { - if(isset(static::$labels[$value])) { + public static function label($value) + { + if (isset(static::$labels[$value])) { return trans(static::$labels[$value]); } } @@ -28,7 +50,7 @@ abstract class Enum public static function labels() { $labels = []; - foreach(static::$labels as $key => $label) { + foreach (static::$labels as $key => $label) { $labels[$key] = trans($label); } @@ -38,10 +60,10 @@ abstract class Enum /** * Select box */ - public static function select($add_blank=false) + public static function select($add_blank = false) { $labels = []; - if($add_blank) { + if ($add_blank) { $labels[] = ''; } @@ -59,7 +81,7 @@ abstract class Enum */ public static function toArray() { - $class = get_called_class(); + $class = static::class; if (!array_key_exists($class, static::$cache)) { $reflection = new \ReflectionClass($class); static::$cache[$class] = $reflection->getConstants(); @@ -69,9 +91,19 @@ abstract class Enum } /** - * Returns a value when called statically like so: MyEnum::SOME_VALUE() given SOME_VALUE is a class constant + * @param Enum $enum + * @return bool + */ + protected function equals(Enum $enum): bool + { + return $this->getValue() === $enum->getValue() && get_called_class() == get_class($enum); + } + + /** + * Returns a value when called statically like so: MyEnum::SOME_VALUE() given SOME_VALUE is a + * class constant * @param string $name - * @param array $arguments + * @param array $arguments * @return static * @throws \BadMethodCallException * @throws \ReflectionException diff --git a/app/Interfaces/Listener.php b/app/Interfaces/Listener.php new file mode 100644 index 00000000..555640aa --- /dev/null +++ b/app/Interfaces/Listener.php @@ -0,0 +1,12 @@ +find($id, $columns); } catch (\Exception $e) { - return; + return null; } } @@ -31,7 +31,7 @@ abstract class BaseRepository extends \Prettus\Repository\Eloquent\BaseRepositor $this->model()->rules ); - if($validator->fails()) { + if ($validator->fails()) { return $validator->messages(); } @@ -40,7 +40,7 @@ abstract class BaseRepository extends \Prettus\Repository\Eloquent\BaseRepositor /** * Return N most recent items, sorted by created_at - * @param int $count + * @param int $count * @param string $sort_by created_at (default) or updated_at * @return mixed */ @@ -56,13 +56,13 @@ abstract class BaseRepository extends \Prettus\Repository\Eloquent\BaseRepositor * @param $order_by * @return $this */ - public function whereOrder($where, $sort_by, $order_by='asc') + public function whereOrder($where, $sort_by, $order_by = 'asc') { - return $this->scopeQuery(function($query) use ($where, $sort_by, $order_by) { + return $this->scopeQuery(function ($query) use ($where, $sort_by, $order_by) { $q = $query->where($where); # See if there are multi-column sorts - if(\is_array($sort_by)) { - foreach($sort_by as $key => $sort) { + if (\is_array($sort_by)) { + foreach ($sort_by as $key => $sort) { $q = $q->orderBy($key, $sort); } } else { diff --git a/app/Interfaces/Service.php b/app/Interfaces/Service.php new file mode 100644 index 00000000..8fecf53a --- /dev/null +++ b/app/Interfaces/Service.php @@ -0,0 +1,8 @@ +getReference($award, $event->user); - if($klass) { + if ($klass) { $klass->handle(); } } diff --git a/app/Listeners/Cron/Monthly/ApplyExpenses.php b/app/Listeners/Cron/Monthly/ApplyExpenses.php index 75781cf2..c8f7efdf 100644 --- a/app/Listeners/Cron/Monthly/ApplyExpenses.php +++ b/app/Listeners/Cron/Monthly/ApplyExpenses.php @@ -3,6 +3,7 @@ namespace App\Listeners\Cron\Monthly; use App\Events\CronMonthly; +use App\Interfaces\Listener; use App\Models\Enums\ExpenseType; use App\Services\Finance\RecurringFinanceService; @@ -10,13 +11,17 @@ use App\Services\Finance\RecurringFinanceService; * Go through and apply any finances that are daily * @package App\Listeners\Cron\Nightly */ -class ApplyExpenses +class ApplyExpenses extends Listener { - private $dfSvc; + private $financeSvc; - public function __construct(RecurringFinanceService $dfSvc) + /** + * ApplyExpenses constructor. + * @param RecurringFinanceService $financeSvc + */ + public function __construct(RecurringFinanceService $financeSvc) { - $this->dfSvc = $dfSvc; + $this->financeSvc = $financeSvc; } /** @@ -26,8 +31,8 @@ class ApplyExpenses * @throws \InvalidArgumentException * @throws \Prettus\Validator\Exceptions\ValidatorException */ - public function handle(CronMonthly $event) + public function handle(CronMonthly $event): void { - $this->dfSvc->processExpenses(ExpenseType::MONTHLY); + $this->financeSvc->processExpenses(ExpenseType::MONTHLY); } } diff --git a/app/Listeners/Cron/Nightly/ApplyExpenses.php b/app/Listeners/Cron/Nightly/ApplyExpenses.php index e6612246..7edb6d6e 100644 --- a/app/Listeners/Cron/Nightly/ApplyExpenses.php +++ b/app/Listeners/Cron/Nightly/ApplyExpenses.php @@ -3,6 +3,7 @@ namespace App\Listeners\Cron\Nightly; use App\Events\CronNightly; +use App\Interfaces\Listener; use App\Models\Enums\ExpenseType; use App\Services\Finance\RecurringFinanceService; @@ -10,13 +11,17 @@ use App\Services\Finance\RecurringFinanceService; * Go through and apply any finances that are daily * @package App\Listeners\Cron\Nightly */ -class ApplyExpenses +class ApplyExpenses extends Listener { - private $dfSvc; + private $financeSvc; - public function __construct(RecurringFinanceService $dfSvc) + /** + * ApplyExpenses constructor. + * @param RecurringFinanceService $financeSvc + */ + public function __construct(RecurringFinanceService $financeSvc) { - $this->dfSvc = $dfSvc; + $this->financeSvc = $financeSvc; } /** @@ -28,6 +33,6 @@ class ApplyExpenses */ public function handle(CronNightly $event): void { - $this->dfSvc->processExpenses(ExpenseType::DAILY); + $this->financeSvc->processExpenses(ExpenseType::DAILY); } } diff --git a/app/Listeners/Cron/Nightly/RecalculateBalances.php b/app/Listeners/Cron/Nightly/RecalculateBalances.php index f33d75c0..096114f1 100644 --- a/app/Listeners/Cron/Nightly/RecalculateBalances.php +++ b/app/Listeners/Cron/Nightly/RecalculateBalances.php @@ -3,17 +3,16 @@ namespace App\Listeners\Cron\Nightly; use App\Events\CronNightly; +use App\Interfaces\Listener; use App\Models\Journal; -use App\Models\JournalTransaction; use App\Repositories\JournalRepository; -use App\Support\Money; use Log; /** * This recalculates the balances on all of the journals * @package App\Listeners\Cron */ -class RecalculateBalances +class RecalculateBalances extends Listener { private $journalRepo; @@ -43,9 +42,9 @@ class RecalculateBalances $this->journalRepo->recalculateBalance($journal); $journal->refresh(); - Log::info('Adjusting balance on ' . - $journal->morphed_type . ':' . $journal->morphed_id - . ' from ' . $old_balance . ' to ' . $journal->balance); + Log::info('Adjusting balance on '. + $journal->morphed_type.':'.$journal->morphed_id + .' from '.$old_balance.' to '.$journal->balance); } Log::info('Done calculating balances'); diff --git a/app/Listeners/ExpenseListener.php b/app/Listeners/ExpenseListener.php index e63cfcd1..72432a0f 100644 --- a/app/Listeners/ExpenseListener.php +++ b/app/Listeners/ExpenseListener.php @@ -3,10 +3,13 @@ namespace App\Listeners; use App\Events\Expenses; -use App\Models\Enums\ExpenseType; -use App\Models\Expense; +use App\Interfaces\Listener; -class ExpenseListener +/** + * Class ExpenseListener + * @package App\Listeners + */ +class ExpenseListener extends Listener { /** * Return a list of additional expenses diff --git a/app/Listeners/FinanceEvents.php b/app/Listeners/FinanceEvents.php index 2fb3e1dc..c357205e 100644 --- a/app/Listeners/FinanceEvents.php +++ b/app/Listeners/FinanceEvents.php @@ -4,24 +4,33 @@ namespace App\Listeners; use App\Events\PirepAccepted; use App\Events\PirepRejected; +use App\Interfaces\Listener; use App\Services\Finance\PirepFinanceService; +use Illuminate\Contracts\Events\Dispatcher; /** * Subscribe for events that we do some financial processing for * This includes when a PIREP is accepted, or rejected * @package App\Listeners */ -class FinanceEvents +class FinanceEvents extends Listener { private $financeSvc; + /** + * FinanceEvents constructor. + * @param PirepFinanceService $financeSvc + */ public function __construct( PirepFinanceService $financeSvc ) { $this->financeSvc = $financeSvc; } - public function subscribe($events) + /** + * @param $events + */ + public function subscribe(Dispatcher $events): void { $events->listen( PirepAccepted::class, @@ -42,7 +51,7 @@ class FinanceEvents * @throws \Exception * @throws \Prettus\Validator\Exceptions\ValidatorException */ - public function onPirepAccept(PirepAccepted $event) + public function onPirepAccept(PirepAccepted $event): void { $this->financeSvc->processFinancesForPirep($event->pirep); } @@ -54,7 +63,7 @@ class FinanceEvents * @throws \InvalidArgumentException * @throws \Exception */ - public function onPirepReject(PirepRejected $event) + public function onPirepReject(PirepRejected $event): void { $this->financeSvc->deleteFinancesForPirep($event->pirep); } diff --git a/app/Listeners/NotificationEvents.php b/app/Listeners/NotificationEvents.php index 342a42d0..96f910b7 100644 --- a/app/Listeners/NotificationEvents.php +++ b/app/Listeners/NotificationEvents.php @@ -4,7 +4,9 @@ namespace App\Listeners; use App\Events\UserRegistered; use App\Events\UserStateChanged; +use App\Interfaces\Listener; use App\Models\Enums\UserState; +use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Support\Facades\Mail; use Log; @@ -12,9 +14,12 @@ use Log; * Handle sending emails on different events * @package App\Listeners */ -class NotificationEvents +class NotificationEvents extends Listener { - public function subscribe($events) + /** + * @param Dispatcher $events + */ + public function subscribe(Dispatcher $events): void { $events->listen( \App\Events\UserRegistered::class, @@ -30,7 +35,7 @@ class NotificationEvents /** * @return bool */ - protected function mailerActive() + protected function mailerActive(): bool { if (empty(config('mail.host'))) { Log::info('No mail host specified!'); @@ -49,7 +54,7 @@ class NotificationEvents { try { return Mail::to($to)->send($email); - } catch(\Exception $e) { + } catch (\Exception $e) { Log::error('Error sending email!'); Log::error($e); } @@ -59,14 +64,14 @@ class NotificationEvents * Send an email when the user registered * @param UserRegistered $event */ - public function onUserRegister(UserRegistered $event) + public function onUserRegister(UserRegistered $event): void { Log::info('onUserRegister: ' - . $event->user->pilot_id . ' is ' - . UserState::label($event->user->state) - . ', sending active email'); + .$event->user->pilot_id.' is ' + .UserState::label($event->user->state) + .', sending active email'); - if(!$this->mailerActive()) { + if (!$this->mailerActive()) { return; } @@ -80,9 +85,9 @@ class NotificationEvents } # Then notify the user - if($event->user->state === UserState::ACTIVE) { + if ($event->user->state === UserState::ACTIVE) { $email = new \App\Mail\UserRegistered($event->user); - } else if($event->user->state === UserState::PENDING) { + } else if ($event->user->state === UserState::PENDING) { $email = new \App\Mail\UserPending($event->user); } @@ -93,7 +98,7 @@ class NotificationEvents * When a user's state changes, send an email out * @param UserStateChanged $event */ - public function onUserStateChange(UserStateChanged $event) + public function onUserStateChange(UserStateChanged $event): void { if (!$this->mailerActive()) { return; @@ -102,17 +107,14 @@ class NotificationEvents if ($event->old_state === UserState::PENDING) { if ($event->user->state === UserState::ACTIVE) { $email = new \App\Mail\UserRegistered($event->user, - 'Your registration has been accepted!'); + 'Your registration has been accepted!'); } else if ($event->user->state === UserState::REJECTED) { $email = new \App\Mail\UserRejected($event->user); } $this->sendEmail($event->user->email, $email); - } - - # TODO: Other state transitions - elseif ($event->old_state === UserState::ACTIVE) - { - + } # TODO: Other state transitions + elseif ($event->old_state === UserState::ACTIVE) { + Log::info('User state change from active to ??'); } } } diff --git a/app/Mail/Admin/UserRegistered.php b/app/Mail/Admin/UserRegistered.php index 7d1af3da..1a81d8e3 100644 --- a/app/Mail/Admin/UserRegistered.php +++ b/app/Mail/Admin/UserRegistered.php @@ -2,19 +2,17 @@ namespace App\Mail\Admin; +use App\Models\User; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; -use App\Models\User; - class UserRegistered extends Mailable { use Queueable, SerializesModels; - public $subject, $user; - public function __construct(User $user, $subject=null) + public function __construct(User $user, $subject = null) { $this->subject = $subject ?: 'A new user registered'; $this->user = $user; @@ -22,8 +20,9 @@ class UserRegistered extends Mailable public function build() { - return $this->markdown('emails.admin.registered') - ->subject($this->subject) - ->with(['user' => $this->user]); + return $this + ->markdown('emails.admin.registered') + ->subject($this->subject) + ->with(['user' => $this->user]); } } diff --git a/app/Mail/NewLoginDetails.php b/app/Mail/NewLoginDetails.php index c4a7ba72..f0821467 100644 --- a/app/Mail/NewLoginDetails.php +++ b/app/Mail/NewLoginDetails.php @@ -10,10 +10,9 @@ use Illuminate\Queue\SerializesModels; class NewLoginDetails extends Mailable { use Queueable, SerializesModels; - public $subject, $user, $newpw; - public function __construct(User $user, $newpw=null, $subject=null) + public function __construct(User $user, $newpw = null, $subject = null) { $this->subject = $subject ?: 'New Login Details'; $this->newpw = $newpw ?: 'N/A'; @@ -23,7 +22,7 @@ class NewLoginDetails extends Mailable public function build() { return $this->markdown('emails.user.new_login_details') - ->subject($this->subject) - ->with(['user' => $this->user, 'newpw' => $this->newpw]); + ->subject($this->subject) + ->with(['user' => $this->user, 'newpw' => $this->newpw]); } } diff --git a/app/Mail/UserPending.php b/app/Mail/UserPending.php index 2d36c7d3..541409be 100644 --- a/app/Mail/UserPending.php +++ b/app/Mail/UserPending.php @@ -10,10 +10,9 @@ use Illuminate\Queue\SerializesModels; class UserPending extends Mailable { use Queueable, SerializesModels; - public $subject, $user; - public function __construct(User $user, $subject=null) + public function __construct(User $user, $subject = null) { $this->subject = $subject ?: 'Your registration is pending!'; $this->user = $user; @@ -22,7 +21,7 @@ class UserPending extends Mailable public function build() { return $this->markdown('emails.user.pending') - ->subject($this->subject) - ->with(['user' => $this->user]); + ->subject($this->subject) + ->with(['user' => $this->user]); } } diff --git a/app/Mail/UserRegistered.php b/app/Mail/UserRegistered.php index 81efb7ca..995e00da 100644 --- a/app/Mail/UserRegistered.php +++ b/app/Mail/UserRegistered.php @@ -10,10 +10,9 @@ use Illuminate\Queue\SerializesModels; class UserRegistered extends Mailable { use Queueable, SerializesModels; - public $subject, $user; - public function __construct(User $user, $subject=null) + public function __construct(User $user, $subject = null) { $this->subject = $subject ?: 'Welcome to '.config('app.name').'!'; $this->user = $user; @@ -21,8 +20,9 @@ class UserRegistered extends Mailable public function build() { - return $this->markdown('emails.user.registered') - ->subject($this->subject) - ->with(['user' => $this->user]); + return $this + ->markdown('emails.user.registered') + ->subject($this->subject) + ->with(['user' => $this->user]); } } diff --git a/app/Mail/UserRejected.php b/app/Mail/UserRejected.php index bd2ba5e6..6c8a2021 100644 --- a/app/Mail/UserRejected.php +++ b/app/Mail/UserRejected.php @@ -10,10 +10,9 @@ use Illuminate\Queue\SerializesModels; class UserRejected extends Mailable { use Queueable, SerializesModels; - public $subject, $user; - public function __construct(User $user, $subject=null) + public function __construct(User $user, $subject = null) { $this->subject = $subject ?: 'Your registration has been denied'; $this->user = $user; @@ -21,8 +20,9 @@ class UserRejected extends Mailable public function build() { - return $this->markdown('emails.user.rejected') - ->subject($this->subject) - ->with(['user' => $this->user]); + return $this + ->markdown('emails.user.rejected') + ->subject($this->subject) + ->with(['user' => $this->user]); } } diff --git a/app/Models/Acars.php b/app/Models/Acars.php index 630d928e..bd4a2855 100644 --- a/app/Models/Acars.php +++ b/app/Models/Acars.php @@ -2,9 +2,15 @@ namespace App\Models; +use App\Interfaces\Model; use App\Models\Traits\HashIdTrait; -class Acars extends BaseModel +/** + * Class Acars + * @param string id + * @package App\Models + */ +class Acars extends Model { use HashIdTrait; @@ -31,21 +37,21 @@ class Acars extends BaseModel ]; public $casts = [ - 'type' => 'integer', - 'order' => 'integer', - 'nav_type' => 'integer', - 'lat' => 'float', - 'lon' => 'float', - 'heading' => 'integer', - 'altitude' => 'float', - 'vs' => 'float', - 'gs' => 'float', - 'transponder' => 'integer', - 'fuel_flow' => 'float', + 'type' => 'integer', + 'order' => 'integer', + 'nav_type' => 'integer', + 'lat' => 'float', + 'lon' => 'float', + 'heading' => 'integer', + 'altitude' => 'float', + 'vs' => 'float', + 'gs' => 'float', + 'transponder' => 'integer', + 'fuel_flow' => 'float', ]; public static $rules = [ - 'pirep_id' => 'required', + 'pirep_id' => 'required', ]; /** diff --git a/app/Models/Aircraft.php b/app/Models/Aircraft.php index 17363846..03defed5 100644 --- a/app/Models/Aircraft.php +++ b/app/Models/Aircraft.php @@ -2,21 +2,23 @@ namespace App\Models; +use App\Interfaces\Model; use App\Models\Enums\AircraftStatus; use App\Models\Traits\ExpensableTrait; /** - * @property mixed subfleet_id - * @property string name - * @property string icao - * @property string registration - * @property string hex_code - * @property Airport airport + * @property mixed subfleet_id + * @property string name + * @property string icao + * @property string registration + * @property string hex_code + * @property Airport airport * @property Subfleet subfleet - * @property int status - * @property int state + * @property int status + * @property int state + * @package App\Models */ -class Aircraft extends BaseModel +class Aircraft extends Model { use ExpensableTrait; @@ -40,10 +42,10 @@ class Aircraft extends BaseModel * @var array */ protected $casts = [ - 'subfleet_id' => 'integer', - 'zfw' => 'float', - 'status' => 'integer', - 'state' => 'integer', + 'subfleet_id' => 'integer', + 'zfw' => 'float', + 'status' => 'integer', + 'state' => 'integer', ]; /** @@ -53,7 +55,7 @@ class Aircraft extends BaseModel */ public static $rules = [ 'subfleet_id' => 'required', - 'name' => 'required', + 'name' => 'required', ]; /** diff --git a/app/Models/Airline.php b/app/Models/Airline.php index d73321a1..4de3ea62 100644 --- a/app/Models/Airline.php +++ b/app/Models/Airline.php @@ -2,21 +2,22 @@ namespace App\Models; +use App\Interfaces\Model; use App\Models\Enums\JournalType; use App\Models\Traits\JournalTrait; /** * Class Airline - * @property string code - * @property string icao - * @property string iata - * @property string name - * @property string logo - * @property string country + * @property string code + * @property string icao + * @property string iata + * @property string name + * @property string logo + * @property string country * @property Journal journal * @package App\Models */ -class Airline extends BaseModel +class Airline extends Model { use JournalTrait; @@ -40,7 +41,6 @@ class Airline extends BaseModel /** * The attributes that should be casted to native types. - * * @var array */ protected $casts = [ @@ -51,21 +51,21 @@ class Airline extends BaseModel /** * Validation rules - * * @var array */ public static $rules = [ - 'country' => 'nullable', - 'iata' => 'nullable|max:5', - 'icao' => 'required|max:5', - 'logo' => 'nullable', - 'name' => 'required', + 'country' => 'nullable', + 'iata' => 'nullable|max:5', + 'icao' => 'required|max:5', + 'logo' => 'nullable', + 'name' => 'required', ]; /** * For backwards compatibility */ - public function getCodeAttribute() { + public function getCodeAttribute() + { return $this->icao; } diff --git a/app/Models/Airport.php b/app/Models/Airport.php index d0916f16..2d9e2e5e 100644 --- a/app/Models/Airport.php +++ b/app/Models/Airport.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Interfaces\Model; use App\Models\Traits\ExpensableTrait; /** @@ -9,10 +10,10 @@ use App\Models\Traits\ExpensableTrait; * @property string id * @property string iata * @property string icao - * @property float ground_handling_cost + * @property float ground_handling_cost * @package App\Models */ -class Airport extends BaseModel +class Airport extends Model { use ExpensableTrait; @@ -38,26 +39,26 @@ class Airport extends BaseModel ]; protected $casts = [ - 'lat' => 'float', - 'lon' => 'float', - 'hub' => 'boolean', + 'lat' => 'float', + 'lon' => 'float', + 'hub' => 'boolean', 'ground_handling_cost' => 'float', - 'fuel_100ll_cost' => 'float', - 'fuel_jeta_cost' => 'float', - 'fuel_mogas_cost' => 'float', + 'fuel_100ll_cost' => 'float', + 'fuel_jeta_cost' => 'float', + 'fuel_mogas_cost' => 'float', ]; /** * Validation rules */ public static $rules = [ - 'icao' => 'required', - 'iata' => 'nullable', - 'name' => 'required', - 'location' => 'nullable', - 'lat' => 'required|numeric', - 'lon' => 'required|numeric', - 'ground_handling_cost' => 'nullable|numeric', + 'icao' => 'required', + 'iata' => 'nullable', + 'name' => 'required', + 'location' => 'nullable', + 'lat' => 'required|numeric', + 'lon' => 'required|numeric', + 'ground_handling_cost' => 'nullable|numeric', ]; /** @@ -86,7 +87,7 @@ class Airport extends BaseModel */ public function getFullNameAttribute(): string { - return $this->icao . ' - ' . $this->name; + return $this->icao.' - '.$this->name; } /** diff --git a/app/Models/Award.php b/app/Models/Award.php index b4402fc6..7fcd066c 100755 --- a/app/Models/Award.php +++ b/app/Models/Award.php @@ -2,14 +2,16 @@ namespace App\Models; +use App\Interfaces\Model; + /** * The Award model - * @property mixed id - * @property mixed ref_class + * @property mixed id + * @property mixed ref_class * @property mixed|null ref_class_params * @package Award\Models */ -class Award extends BaseModel +class Award extends Model { public $table = 'awards'; @@ -22,21 +24,20 @@ class Award extends BaseModel ]; public static $rules = [ - 'name' => 'required', - 'description' => 'nullable', - 'image_url' => 'nullable', - - 'ref_class' => 'required', + 'name' => 'required', + 'description' => 'nullable', + 'image_url' => 'nullable', + 'ref_class' => 'required', 'ref_class_params' => 'nullable' ]; /** * Get the referring object * @param Award|null $award - * @param User|null $user + * @param User|null $user * @return null */ - public function getReference(Award $award=null, User $user=null) + public function getReference(Award $award = null, User $user = null) { if (!$this->ref_class) { return null; diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php deleted file mode 100644 index b28c6bc6..00000000 --- a/app/Models/BaseModel.php +++ /dev/null @@ -1,8 +0,0 @@ - 'Inactive', - ActiveState::ACTIVE => 'Active', + ActiveState::INACTIVE => 'Inactive', + ActiveState::ACTIVE => 'Active', ]; } diff --git a/app/Models/Enums/AircraftState.php b/app/Models/Enums/AircraftState.php index 81d7b4a9..82ec2cc2 100644 --- a/app/Models/Enums/AircraftState.php +++ b/app/Models/Enums/AircraftState.php @@ -15,8 +15,8 @@ class AircraftState extends Enum public const IN_AIR = 2; public static $labels = [ - AircraftState::PARKED => 'On Ground', - AircraftState::IN_USE => 'In Use', - AircraftState::IN_AIR => 'In Air', + AircraftState::PARKED => 'On Ground', + AircraftState::IN_USE => 'In Use', + AircraftState::IN_AIR => 'In Air', ]; } diff --git a/app/Models/Enums/AircraftStatus.php b/app/Models/Enums/AircraftStatus.php index b5ce9ed9..9f159c5a 100644 --- a/app/Models/Enums/AircraftStatus.php +++ b/app/Models/Enums/AircraftStatus.php @@ -10,17 +10,17 @@ use App\Interfaces\Enum; */ class AircraftStatus extends Enum { - public const STORED = 0; - public const ACTIVE = 1; - public const RETIRED = 2; - public const SCRAPPED = 3; + public const STORED = 0; + public const ACTIVE = 1; + public const RETIRED = 2; + public const SCRAPPED = 3; public const WRITTEN_OFF = 4; public static $labels = [ - AircraftStatus::STORED => 'Stored', - AircraftStatus::ACTIVE => 'Active', - AircraftStatus::RETIRED => 'Retired', - AircraftStatus::SCRAPPED => 'Scrapped', + AircraftStatus::STORED => 'Stored', + AircraftStatus::ACTIVE => 'Active', + AircraftStatus::RETIRED => 'Retired', + AircraftStatus::SCRAPPED => 'Scrapped', AircraftStatus::WRITTEN_OFF => 'Written Off', ]; } diff --git a/app/Models/Enums/AnalyticsDimensions.php b/app/Models/Enums/AnalyticsDimensions.php index a4d5552f..fa262943 100644 --- a/app/Models/Enums/AnalyticsDimensions.php +++ b/app/Models/Enums/AnalyticsDimensions.php @@ -10,7 +10,7 @@ use App\Interfaces\Enum; */ class AnalyticsDimensions extends Enum { - public const PHP_VERSION = 1; + public const PHP_VERSION = 1; public const DATABASE_VERSION = 2; - public const PHPVMS_VERSION = 3; + public const PHPVMS_VERSION = 3; } diff --git a/app/Models/Enums/AnalyticsMetrics.php b/app/Models/Enums/AnalyticsMetrics.php index f59ba0b9..7a8fc864 100644 --- a/app/Models/Enums/AnalyticsMetrics.php +++ b/app/Models/Enums/AnalyticsMetrics.php @@ -6,6 +6,7 @@ use App\Interfaces\Enum; /** * Class AnalyticsMetrics + * Metrics IDs used in Google Analytics * @package App\Models\Enums */ class AnalyticsMetrics extends Enum diff --git a/app/Models/Enums/Days.php b/app/Models/Enums/Days.php index 420b0a13..a38213ba 100644 --- a/app/Models/Enums/Days.php +++ b/app/Models/Enums/Days.php @@ -8,8 +8,8 @@ use App\Interfaces\Enum; * Class Days * @package App\Models\Enums */ -class Days extends Enum { - +class Days extends Enum +{ public const MONDAY = 1 << 0; public const TUESDAY = 1 << 1; public const WEDNESDAY = 1 << 2; @@ -19,12 +19,12 @@ class Days extends Enum { public const SUNDAY = 1 << 6; protected static $labels = [ - Days::MONDAY => 'system.days.mon', - Days::TUESDAY => 'system.days.tues', - Days::WEDNESDAY => 'system.days.wed', - Days::THURSDAY => 'system.days.thurs', - Days::FRIDAY => 'system.days.fri', - Days::SATURDAY => 'system.days.sat', - Days::SUNDAY => 'system.days.sun', + Days::MONDAY => 'system.days.mon', + Days::TUESDAY => 'system.days.tues', + Days::WEDNESDAY => 'system.days.wed', + Days::THURSDAY => 'system.days.thurs', + Days::FRIDAY => 'system.days.fri', + Days::SATURDAY => 'system.days.sat', + Days::SUNDAY => 'system.days.sun', ]; } diff --git a/app/Models/Enums/ExpenseType.php b/app/Models/Enums/ExpenseType.php index 2a548182..46991a30 100644 --- a/app/Models/Enums/ExpenseType.php +++ b/app/Models/Enums/ExpenseType.php @@ -8,15 +8,15 @@ use App\Interfaces\Enum; * Class ExpenseType * @package App\Models\Enums */ -class ExpenseType extends Enum { - - public const FLIGHT = 0; - public const DAILY = 1; - public const MONTHLY = 2; +class ExpenseType extends Enum +{ + public const FLIGHT = 0; + public const DAILY = 1; + public const MONTHLY = 2; protected static $labels = [ - ExpenseType::FLIGHT => 'Flight', - ExpenseType::DAILY => 'Daily', - ExpenseType::MONTHLY => 'Monthly', + ExpenseType::FLIGHT => 'Flight', + ExpenseType::DAILY => 'Daily', + ExpenseType::MONTHLY => 'Monthly', ]; } diff --git a/app/Models/Enums/FlightType.php b/app/Models/Enums/FlightType.php index a77e8a13..2a87e899 100644 --- a/app/Models/Enums/FlightType.php +++ b/app/Models/Enums/FlightType.php @@ -8,15 +8,15 @@ use App\Interfaces\Enum; * Class FlightType * @package App\Models\Enums */ -class FlightType extends Enum { - - public const PASSENGER = 0; - public const CARGO = 1; - public const CHARTER = 2; +class FlightType extends Enum +{ + public const PASSENGER = 0; + public const CARGO = 1; + public const CHARTER = 2; protected static $labels = [ - FlightType::PASSENGER => 'Passenger', - FlightType::CARGO => 'Cargo', - FlightType::CHARTER => 'Charter', + FlightType::PASSENGER => 'Passenger', + FlightType::CARGO => 'Cargo', + FlightType::CHARTER => 'Charter', ]; } diff --git a/app/Models/Enums/FuelType.php b/app/Models/Enums/FuelType.php index 3be489af..3e8cf130 100644 --- a/app/Models/Enums/FuelType.php +++ b/app/Models/Enums/FuelType.php @@ -8,15 +8,15 @@ use App\Interfaces\Enum; * Class FuelType * @package App\Models\Enums */ -class FuelType extends Enum { - - public const LOW_LEAD = 0; - public const JET_A = 1; - public const MOGAS = 2; +class FuelType extends Enum +{ + public const LOW_LEAD = 0; + public const JET_A = 1; + public const MOGAS = 2; protected static $labels = [ - FuelType::LOW_LEAD => '100LL', - FuelType::JET_A => 'JET A', - FuelType::MOGAS => 'MOGAS', + FuelType::LOW_LEAD => '100LL', + FuelType::JET_A => 'JET A', + FuelType::MOGAS => 'MOGAS', ]; } diff --git a/app/Models/Enums/JournalType.php b/app/Models/Enums/JournalType.php index 166ed160..71f943eb 100644 --- a/app/Models/Enums/JournalType.php +++ b/app/Models/Enums/JournalType.php @@ -5,11 +5,11 @@ namespace App\Models\Enums; use App\Interfaces\Enum; /** - * Class AcarsType + * Class JournalType * @package App\Models\Enums */ class JournalType extends Enum { public const AIRLINE = 0; - public const USER = 1; + public const USER = 1; } diff --git a/app/Models/Enums/NavaidType.php b/app/Models/Enums/NavaidType.php index cb200438..b17a3bdd 100644 --- a/app/Models/Enums/NavaidType.php +++ b/app/Models/Enums/NavaidType.php @@ -1,4 +1,5 @@ 'Manual', diff --git a/app/Models/Enums/PirepState.php b/app/Models/Enums/PirepState.php index 2e22a011..7cf9470e 100644 --- a/app/Models/Enums/PirepState.php +++ b/app/Models/Enums/PirepState.php @@ -8,21 +8,21 @@ use App\Interfaces\Enum; * Class PirepState * @package App\Models\Enums */ -class PirepState extends Enum { - - public const REJECTED = -1; - public const IN_PROGRESS = 0; // flight is ongoing - public const PENDING = 1; // waiting admin approval - public const ACCEPTED = 2; - public const CANCELLED = 3; - public const DELETED = 4; +class PirepState extends Enum +{ + public const REJECTED = -1; + public const IN_PROGRESS = 0; // flight is ongoing + public const PENDING = 1; // waiting admin approval + public const ACCEPTED = 2; + public const CANCELLED = 3; + public const DELETED = 4; protected static $labels = [ - PirepState::REJECTED => 'system.pireps.state.rejected', - PirepState::IN_PROGRESS => 'system.pireps.state.in_progress', - PirepState::PENDING => 'system.pireps.state.pending', - PirepState::ACCEPTED => 'system.pireps.state.accepted', - PirepState::CANCELLED => 'system.pireps.state.cancelled', - PirepState::DELETED => 'system.pireps.state.deleted', + PirepState::REJECTED => 'system.pireps.state.rejected', + PirepState::IN_PROGRESS => 'system.pireps.state.in_progress', + PirepState::PENDING => 'system.pireps.state.pending', + PirepState::ACCEPTED => 'system.pireps.state.accepted', + PirepState::CANCELLED => 'system.pireps.state.cancelled', + PirepState::DELETED => 'system.pireps.state.deleted', ]; } diff --git a/app/Models/Enums/PirepStatus.php b/app/Models/Enums/PirepStatus.php index 5843db25..162930e4 100644 --- a/app/Models/Enums/PirepStatus.php +++ b/app/Models/Enums/PirepStatus.php @@ -11,15 +11,15 @@ use App\Interfaces\Enum; */ class PirepStatus extends Enum { - public const PREFILE = 0; - public const SCHEDULED = 0; - public const ENROUTE = 1; - public const ARRIVED = 2; + public const PREFILE = 0; + public const SCHEDULED = 0; + public const ENROUTE = 1; + public const ARRIVED = 2; protected static $labels = [ - PirepStatus::PREFILE => 'Prefiled', - PirepStatus::SCHEDULED => 'Scheduled', - PirepStatus::ENROUTE => 'Enroute', - PirepStatus::ARRIVED => 'Arrived', + PirepStatus::PREFILE => 'Prefiled', + PirepStatus::SCHEDULED => 'Scheduled', + PirepStatus::ENROUTE => 'Enroute', + PirepStatus::ARRIVED => 'Arrived', ]; } diff --git a/app/Models/Enums/UserState.php b/app/Models/Enums/UserState.php index a0b207dd..504ec958 100644 --- a/app/Models/Enums/UserState.php +++ b/app/Models/Enums/UserState.php @@ -17,10 +17,10 @@ class UserState extends Enum public const SUSPENDED = 4; protected static $labels = [ - UserState::PENDING => 'Pending', - UserState::ACTIVE => 'Active', - UserState::REJECTED => 'Rejected', - UserState::ON_LEAVE => 'On Leave', - UserState::SUSPENDED => 'Suspended', + UserState::PENDING => 'Pending', + UserState::ACTIVE => 'Active', + UserState::REJECTED => 'Rejected', + UserState::ON_LEAVE => 'On Leave', + UserState::SUSPENDED => 'Suspended', ]; } diff --git a/app/Models/Expense.php b/app/Models/Expense.php index b696ee51..a876c20e 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -1,17 +1,18 @@ 'boolean', - 'airline_id' => 'integer', - 'amount' => 'float', - 'type' => 'integer', - 'multiplier' => 'bool', - 'charge_to_user' => 'bool', + 'active' => 'boolean', + 'airline_id' => 'integer', + 'amount' => 'float', + 'type' => 'integer', + 'multiplier' => 'bool', + 'charge_to_user' => 'bool', ]; /** @@ -45,12 +46,13 @@ class Expense extends BaseModel return null; } - if($this->ref_class === __CLASS__) { + if ($this->ref_class === __CLASS__) { return $this; } try { $klass = new $this->ref_class; + return $klass->find($this->ref_class_id); } catch (\Exception $e) { return null; diff --git a/app/Models/Fare.php b/app/Models/Fare.php index 423434f2..0b16b169 100644 --- a/app/Models/Fare.php +++ b/app/Models/Fare.php @@ -1,16 +1,17 @@ 'float', - 'cost' => 'float', - 'capacity' => 'integer', - 'active' => 'boolean', + 'price' => 'float', + 'cost' => 'float', + 'capacity' => 'integer', + 'active' => 'boolean', ]; public static $rules = [ diff --git a/app/Models/Flight.php b/app/Models/Flight.php index c7ee5232..ea55bd06 100644 --- a/app/Models/Flight.php +++ b/app/Models/Flight.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Interfaces\Model; use App\Models\Traits\HashIdTrait; use App\Support\Units\Distance; use PhpUnitsOfMeasure\Exception\NonNumericValue; @@ -9,16 +10,15 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName; /** * @property Airline airline - * @property mixed flight_number - * @property mixed route_code - * @property mixed route_leg + * @property mixed flight_number + * @property mixed route_code + * @property mixed route_leg */ -class Flight extends BaseModel +class Flight extends Model { use HashIdTrait; public const ID_MAX_LENGTH = 12; - public $table = 'flights'; public $incrementing = false; @@ -75,11 +75,11 @@ class Flight extends BaseModel $flight_id .= $this->flight_number; if (filled($this->route_code)) { - $flight_id .= '/C' . $this->route_code; + $flight_id .= '/C'.$this->route_code; } if (filled($this->route_leg)) { - $flight_id .= '/L' . $this->route_leg; + $flight_id .= '/L'.$this->route_leg; } return $flight_id; @@ -97,6 +97,7 @@ class Flight extends BaseModel try { $distance = (float) $this->attributes['distance']; + return new Distance($distance, config('phpvms.internal_units.distance')); } catch (NonNumericValue $e) { return 0; @@ -111,7 +112,7 @@ class Flight extends BaseModel */ public function setDistanceAttribute($value): void { - if($value instanceof Distance) { + if ($value instanceof Distance) { $this->attributes['distance'] = $value->toUnit( config('phpvms.internal_units.distance') ); @@ -147,7 +148,7 @@ class Flight extends BaseModel public function fares() { return $this->belongsToMany(Fare::class, 'flight_fare') - ->withPivot('price', 'cost', 'capacity'); + ->withPivot('price', 'cost', 'capacity'); } public function fields() diff --git a/app/Models/FlightFields.php b/app/Models/FlightFields.php index 35e88fe8..ca69a4ed 100644 --- a/app/Models/FlightFields.php +++ b/app/Models/FlightFields.php @@ -2,11 +2,13 @@ namespace App\Models; +use App\Interfaces\Model; + /** * Class FlightFields * @package App\Models */ -class FlightFields extends BaseModel +class FlightFields extends Model { public $table = 'flight_fields'; diff --git a/app/Models/GeoJson.php b/app/Models/GeoJson.php index ed71b142..3593cce3 100644 --- a/app/Models/GeoJson.php +++ b/app/Models/GeoJson.php @@ -18,21 +18,19 @@ class GeoJson * @var int */ protected $counter; - /** * @var array [lon, lat] pairs */ protected $line_coords = []; - /** * @var Feature[] */ protected $point_coords = []; /** - * @param $lat - * @param $lon - * @param array $attrs Attributes of the Feature + * @param $lat + * @param $lon + * @param array $attrs Attributes of the Feature */ public function addPoint($lat, $lon, array $attrs) { @@ -47,7 +45,7 @@ class GeoJson */ public function getLine(): FeatureCollection { - if(empty($this->line_coords) || \count($this->line_coords) < 2) { + if (empty($this->line_coords) || \count($this->line_coords) < 2) { return new FeatureCollection([]); } diff --git a/app/Models/Journal.php b/app/Models/Journal.php index 594b2075..2be8602d 100644 --- a/app/Models/Journal.php +++ b/app/Models/Journal.php @@ -6,22 +6,23 @@ namespace App\Models; +use App\Interfaces\Model; use App\Support\Money; use Carbon\Carbon; /** * Class Journal - * @property mixed id - * @property Money $balance - * @property string $currency - * @property Carbon $updated_at - * @property Carbon $post_date - * @property Carbon $created_at + * @property mixed id + * @property Money $balance + * @property string $currency + * @property Carbon $updated_at + * @property Carbon $post_date + * @property Carbon $created_at * @property \App\Models\Enums\JournalType type - * @property mixed morphed_type - * @property mixed morphed_id + * @property mixed morphed_type + * @property mixed morphed_id */ -class Journal extends BaseModel +class Journal extends Model { protected $table = 'journals'; @@ -81,6 +82,7 @@ class Journal extends BaseModel public function assignToLedger(Ledger $ledger) { $ledger->journals()->save($this); + return $this; } @@ -117,7 +119,7 @@ class Journal extends BaseModel ? $value : new Money($value); - $this->attributes['balance'] = $value ? (int)$value->getAmount() : null; + $this->attributes['balance'] = $value ? (int) $value->getAmount() : null; } /** @@ -158,7 +160,7 @@ class Journal extends BaseModel public function getBalanceOn(Carbon $date) { return $this->getCreditBalanceOn($date) - ->subtract($this->getDebitBalanceOn($date)); + ->subtract($this->getDebitBalanceOn($date)); } /** diff --git a/app/Models/JournalTransaction.php b/app/Models/JournalTransaction.php index dd541f42..533e8a6c 100644 --- a/app/Models/JournalTransaction.php +++ b/app/Models/JournalTransaction.php @@ -6,8 +6,10 @@ namespace App\Models; +use App\Interfaces\Model; + /** - * @property string id UUID type + * @property string id UUID type * @property string currency * @property string memo * @property string transaction_group @@ -18,9 +20,10 @@ namespace App\Models; * @property integer ref_class_id * @property Journal journal */ -class JournalTransaction extends BaseModel +class JournalTransaction extends Model { protected $table = 'journal_transactions'; + public $incrementing = false; public $fillable = [ @@ -59,7 +62,7 @@ class JournalTransaction extends BaseModel } /** - * @param BaseModel $object + * @param Model $object * @return JournalTransaction */ public function referencesObject($object) @@ -67,6 +70,7 @@ class JournalTransaction extends BaseModel $this->ref_class = \get_class($object); $this->ref_class_id = $object->id; $this->save(); + return $this; } @@ -77,8 +81,10 @@ class JournalTransaction extends BaseModel { if ($classname = $this->ref_class) { $klass = new $this->ref_class; + return $klass->find($this->ref_class_id); } + return false; } diff --git a/app/Models/Ledger.php b/app/Models/Ledger.php index d7276d2e..868ff5bc 100644 --- a/app/Models/Ledger.php +++ b/app/Models/Ledger.php @@ -6,19 +6,20 @@ namespace App\Models; +use App\Interfaces\Model; use App\Support\Money; use Carbon\Carbon; /** * Class Journal * @package Scottlaurent\Accounting - * @property Money $balance + * @property Money $balance * @property string $currency * @property Carbon $updated_at * @property Carbon $post_date * @property Carbon $created_at */ -class Ledger extends BaseModel +class Ledger extends Model { protected $table = 'ledgers'; diff --git a/app/Models/Migrations/Migration.php b/app/Models/Migrations/Migration.php index e3fbff1b..108a1dac 100644 --- a/app/Models/Migrations/Migration.php +++ b/app/Models/Migrations/Migration.php @@ -5,33 +5,37 @@ namespace App\Models\Migrations; +use App\Interfaces\Migration as MigrationInterface; use App\Models\Setting; use DB; -use Illuminate\Database\Migrations\Migration as MigrationBase; -class Migration extends MigrationBase +/** + * Class Migration + * @package App\Models\Migrations + */ +class Migration extends MigrationInterface { - private $counters = []; - private $offsets = []; + protected $counters = []; + protected $offsets = []; /** * Dynamically figure out the offset and the start number for a group. * This way we don't need to mess with how to order things * When calling getNextOrderNumber(users) 31, will be returned, then 32, and so on - * @param $name + * @param $name * @param null $offset - * @param int $start_offset + * @param int $start_offset */ - protected function addCounterGroup($name, $offset=null, $start_offset=0) + protected function addCounterGroup($name, $offset = null, $start_offset = 0) { - if($offset === null) { + if ($offset === null) { $group = DB::table('settings') - ->where('group', $name) - ->first(); + ->where('group', $name) + ->first(); - if($group === null) { + if ($group === null) { $offset = (int) DB::table('settings')->max('offset'); - if($offset === null) { + if ($offset === null) { $offset = 0; $start_offset = 1; } else { @@ -39,10 +43,9 @@ class Migration extends MigrationBase $start_offset = $offset + 1; } } else { - # Now find the number to start from $start_offset = (int) DB::table('settings')->where('group', $name)->max('order'); - if($start_offset === null) { + if ($start_offset === null) { $start_offset = $offset + 1; } else { ++$start_offset; @@ -63,7 +66,7 @@ class Migration extends MigrationBase */ public function getNextOrderNumber($group): int { - if(!\in_array($group, $this->counters, true)) { + if (!\in_array($group, $this->counters, true)) { $this->addCounterGroup($group); } @@ -83,16 +86,16 @@ class Migration extends MigrationBase $order = $this->getNextOrderNumber($group); $attrs = array_merge([ - 'id' => Setting::formatKey($key), - 'key' => $key, - 'offset' => $this->offsets[$group], - 'order' => $order, - 'name' => '', - 'group' => $group, - 'value' => '', - 'default' => '', - 'options' => '', - 'type' => 'hidden', + 'id' => Setting::formatKey($key), + 'key' => $key, + 'offset' => $this->offsets[$group], + 'order' => $order, + 'name' => '', + 'group' => $group, + 'value' => '', + 'default' => '', + 'options' => '', + 'type' => 'hidden', 'description' => '', ], $attrs); @@ -101,11 +104,11 @@ class Migration extends MigrationBase /** * Update a setting - * @param $key - * @param $value + * @param $key + * @param $value * @param array $attrs */ - public function updateSetting($key, $value, array $attrs=[]) + public function updateSetting($key, $value, array $attrs = []) { $attrs['value'] = $value; DB::table('settings') diff --git a/app/Models/Navdata.php b/app/Models/Navdata.php index 4316be57..0b4a4976 100644 --- a/app/Models/Navdata.php +++ b/app/Models/Navdata.php @@ -2,7 +2,13 @@ namespace App\Models; -class Navdata extends BaseModel +use App\Interfaces\Model; + +/** + * Class Navdata + * @package App\Models + */ +class Navdata extends Model { public $table = 'navdata'; public $timestamps = false; @@ -18,10 +24,10 @@ class Navdata extends BaseModel ]; public $casts = [ - 'type' => 'integer', - 'lat' => 'float', - 'lon' => 'float', - 'freq' => 'float', + 'type' => 'integer', + 'lat' => 'float', + 'lon' => 'float', + 'freq' => 'float', ]; /** diff --git a/app/Models/News.php b/app/Models/News.php index 4d3bf0d1..a2704773 100644 --- a/app/Models/News.php +++ b/app/Models/News.php @@ -2,11 +2,13 @@ namespace App\Models; +use App\Interfaces\Model; + /** * Class News * @package App\Models */ -class News extends BaseModel +class News extends Model { public $table = 'news'; @@ -18,7 +20,7 @@ class News extends BaseModel public static $rules = [ 'subject' => 'required', - 'body' => 'required', + 'body' => 'required', ]; /** diff --git a/app/Models/Observers/AircraftObserver.php b/app/Models/Observers/AircraftObserver.php index f6d2829f..2d6b7ee6 100644 --- a/app/Models/Observers/AircraftObserver.php +++ b/app/Models/Observers/AircraftObserver.php @@ -11,6 +11,9 @@ use App\Support\ICAO; */ class AircraftObserver { + /** + * @param Aircraft $aircraft + */ public function creating(Aircraft $aircraft): void { if (empty($aircraft->hex_code)) { diff --git a/app/Models/Observers/JournalTransactionObserver.php b/app/Models/Observers/JournalTransactionObserver.php index fd9c9b6d..f7fe785e 100644 --- a/app/Models/Observers/JournalTransactionObserver.php +++ b/app/Models/Observers/JournalTransactionObserver.php @@ -4,6 +4,10 @@ namespace App\Models\Observers; use App\Models\JournalTransaction; +/** + * Class JournalTransactionObserver + * @package App\Models\Observers + */ class JournalTransactionObserver { /** @@ -31,7 +35,6 @@ class JournalTransactionObserver if ($transaction['debit']) { $balance = $journal->balance->toAmount(); - #$journal->balance = $journal->balance->subtract($transaction['debit']); $journal->balance = (int) $balance - $transaction->debit; } diff --git a/app/Models/Observers/SettingObserver.php b/app/Models/Observers/SettingObserver.php index 5d7eb51d..e1eb293e 100644 --- a/app/Models/Observers/SettingObserver.php +++ b/app/Models/Observers/SettingObserver.php @@ -4,6 +4,10 @@ namespace App\Models\Observers; use App\Models\Setting; +/** + * Class SettingObserver + * @package App\Models\Observers + */ class SettingObserver { /** diff --git a/app/Models/Observers/SubfleetObserver.php b/app/Models/Observers/SubfleetObserver.php new file mode 100644 index 00000000..1d92bb3b --- /dev/null +++ b/app/Models/Observers/SubfleetObserver.php @@ -0,0 +1,22 @@ +ground_handling_multiplier)) { + $model->ground_handling_multiplier = 100; + } + } +} diff --git a/app/Models/Permission.php b/app/Models/Permission.php index b7f527b9..beaa2e89 100644 --- a/app/Models/Permission.php +++ b/app/Models/Permission.php @@ -1,4 +1,5 @@ 'integer', - 'airline_id' => 'integer', - 'aircraft_id' => 'integer', - 'level' => 'integer', - 'distance' => 'float', - 'planned_distance' => 'float', - 'flight_time' => 'integer', - 'planned_flight_time' => 'integer', - 'zfw' => 'float', - 'block_fuel' => 'float', - 'fuel_used' => 'float', - 'landing_rate' => 'float', - 'source' => 'integer', - 'flight_type' => 'integer', - 'state' => 'integer', - 'status' => 'integer', + 'user_id' => 'integer', + 'airline_id' => 'integer', + 'aircraft_id' => 'integer', + 'level' => 'integer', + 'distance' => 'float', + 'planned_distance' => 'float', + 'flight_time' => 'integer', + 'planned_flight_time' => 'integer', + 'zfw' => 'float', + 'block_fuel' => 'float', + 'fuel_used' => 'float', + 'landing_rate' => 'float', + 'source' => 'integer', + 'flight_type' => 'integer', + 'state' => 'integer', + 'status' => 'integer', ]; public static $rules = [ - 'airline_id' => 'required|exists:airlines,id', - 'aircraft_id' => 'required|exists:aircraft,id', - 'flight_number' => 'required', - 'dpt_airport_id' => 'required', - 'arr_airport_id' => 'required', - 'notes' => 'nullable', - 'route' => 'nullable', + 'airline_id' => 'required|exists:airlines,id', + 'aircraft_id' => 'required|exists:aircraft,id', + 'flight_number' => 'required', + 'dpt_airport_id' => 'required', + 'arr_airport_id' => 'required', + 'notes' => 'nullable', + 'route' => 'nullable', ]; /** @@ -107,11 +108,11 @@ class Pirep extends BaseModel $flight_id = $this->airline->code; $flight_id .= $this->flight_number; - if(filled($this->route_code)) { + if (filled($this->route_code)) { $flight_id .= '/C'.$this->route_code; } - if(filled($this->route_leg)) { + if (filled($this->route_leg)) { $flight_id .= '/L'.$this->route_leg; } @@ -124,12 +125,13 @@ class Pirep extends BaseModel */ public function getDistanceAttribute() { - if(!array_key_exists('distance', $this->attributes)) { + if (!array_key_exists('distance', $this->attributes)) { return null; } try { $distance = (float) $this->attributes['distance']; + return new Distance($distance, config('phpvms.internal_units.distance')); } catch (NonNumericValue $e) { return 0; @@ -164,6 +166,7 @@ class Pirep extends BaseModel try { $fuel_used = (float) $this->attributes['fuel_used']; + return new Fuel($fuel_used, config('phpvms.internal_units.fuel')); } catch (NonNumericValue $e) { return 0; @@ -184,6 +187,7 @@ class Pirep extends BaseModel try { $distance = (float) $this->attributes['planned_distance']; + return new Distance($distance, config('phpvms.internal_units.distance')); } catch (NonNumericValue $e) { return 0; @@ -199,9 +203,9 @@ class Pirep extends BaseModel public function getFlightAttribute(): ?Flight { $where = [ - 'airline_id' => $this->airline_id, + 'airline_id' => $this->airline_id, 'flight_number' => $this->flight_number, - 'active' => true, + 'active' => true, ]; if (filled($this->route_code)) { @@ -261,14 +265,13 @@ class Pirep extends BaseModel */ public function allowedUpdates(): bool { - if($this->state === PirepState::CANCELLED) { + if ($this->state === PirepState::CANCELLED) { return false; } return true; } - /** * Foreign Keys */ @@ -276,22 +279,22 @@ class Pirep extends BaseModel public function acars() { return $this->hasMany(Acars::class, 'pirep_id') - ->where('type', AcarsType::FLIGHT_PATH) - ->orderBy('created_at', 'desc'); + ->where('type', AcarsType::FLIGHT_PATH) + ->orderBy('created_at', 'desc'); } public function acars_logs() { return $this->hasMany(Acars::class, 'pirep_id') - ->where('type', AcarsType::LOG) - ->orderBy('created_at', 'asc'); + ->where('type', AcarsType::LOG) + ->orderBy('created_at', 'asc'); } public function acars_route() { return $this->hasMany(Acars::class, 'pirep_id') - ->where('type', AcarsType::ROUTE) - ->orderBy('order', 'asc'); + ->where('type', AcarsType::ROUTE) + ->orderBy('order', 'asc'); } public function aircraft() @@ -317,7 +320,7 @@ class Pirep extends BaseModel public function comments() { return $this->hasMany(PirepComment::class, 'pirep_id') - ->orderBy('created_at', 'desc'); + ->orderBy('created_at', 'desc'); } public function fares() @@ -342,16 +345,16 @@ class Pirep extends BaseModel public function position() { return $this->hasOne(Acars::class, 'pirep_id') - ->where('type', AcarsType::FLIGHT_PATH) - ->latest(); + ->where('type', AcarsType::FLIGHT_PATH) + ->latest(); } public function transactions() { return $this->hasMany(JournalTransaction::class, 'ref_class_id') - ->where('ref_class', __CLASS__) - ->orderBy('credit', 'desc') - ->orderBy('debit', 'desc'); + ->where('ref_class', __CLASS__) + ->orderBy('credit', 'desc') + ->orderBy('debit', 'desc'); } public function user() diff --git a/app/Models/PirepComment.php b/app/Models/PirepComment.php index b1bad10a..df26c708 100644 --- a/app/Models/PirepComment.php +++ b/app/Models/PirepComment.php @@ -2,12 +2,14 @@ namespace App\Models; +use App\Interfaces\Model; + /** * Class PirepEvent * * @package App\Models */ -class PirepComment extends BaseModel +class PirepComment extends Model { public $table = 'pirep_comments'; diff --git a/app/Models/PirepFare.php b/app/Models/PirepFare.php index c1e5ca5c..d32d709d 100644 --- a/app/Models/PirepFare.php +++ b/app/Models/PirepFare.php @@ -2,11 +2,13 @@ namespace App\Models; +use App\Interfaces\Model; + /** * Class PirepFare * @package App\Models */ -class PirepFare extends BaseModel +class PirepFare extends Model { public $table = 'pirep_fares'; public $timestamps = false; diff --git a/app/Models/PirepField.php b/app/Models/PirepField.php index c303cdf3..97936854 100644 --- a/app/Models/PirepField.php +++ b/app/Models/PirepField.php @@ -2,13 +2,15 @@ namespace App\Models; +use App\Interfaces\Model; + /** * Class PirepField * @property string name * @property string slug * @package App\Models */ -class PirepField extends BaseModel +class PirepField extends Model { public $table = 'pirep_fields'; public $timestamps = false; diff --git a/app/Models/PirepFieldValues.php b/app/Models/PirepFieldValues.php index 40d58719..af986686 100644 --- a/app/Models/PirepFieldValues.php +++ b/app/Models/PirepFieldValues.php @@ -2,11 +2,13 @@ namespace App\Models; +use App\Interfaces\Model; + /** * Class PirepFieldValues * @package App\Models */ -class PirepFieldValues extends BaseModel +class PirepFieldValues extends Model { public $table = 'pirep_field_values'; diff --git a/app/Models/Rank.php b/app/Models/Rank.php index b5a93e24..84bcd1c3 100644 --- a/app/Models/Rank.php +++ b/app/Models/Rank.php @@ -2,14 +2,16 @@ namespace App\Models; +use App\Interfaces\Model; + /** * Class Rank - * @property int hours + * @property int hours * @property float manual_base_pay_rate * @property float acars_base_pay_rate * @package App\Models */ -class Rank extends BaseModel +class Rank extends Model { public $table = 'ranks'; @@ -25,17 +27,17 @@ class Rank extends BaseModel ]; protected $casts = [ - 'hours' => 'integer', - 'base_pay_rate' => 'float', - 'auto_approve_acars' => 'bool', + 'hours' => 'integer', + 'base_pay_rate' => 'float', + 'auto_approve_acars' => 'bool', 'auto_approve_manual' => 'bool', - 'auto_promote' => 'bool', + 'auto_promote' => 'bool', ]; public static $rules = [ - 'name' => 'required', - 'hours' => 'required|integer', - 'acars_base_pay_rate' => 'nullable|numeric', + 'name' => 'required', + 'hours' => 'required|integer', + 'acars_base_pay_rate' => 'nullable|numeric', 'manual_base_pay_rate' => 'nullable|numeric', ]; diff --git a/app/Models/Role.php b/app/Models/Role.php index 0a5a08cb..d3d08724 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -1,9 +1,9 @@ 'integer', - 'fuel_type' => 'integer', - 'ground_handling_multiplier' => 'float', - 'cargo_capacity' => 'float', - 'fuel_capacity' => 'float', - 'gross_weight' => 'float', + 'airline_id' => 'integer', + 'fuel_type' => 'integer', + 'ground_handling_multiplier' => 'float', + 'cargo_capacity' => 'float', + 'fuel_capacity' => 'float', + 'gross_weight' => 'float', ]; - public static $rules = [ - 'name' => 'required', - 'type' => 'required', - 'ground_handling_multiplier' => 'nullable|numeric', + protected static $rules = [ + 'name' => 'required', + 'type' => 'required', + 'ground_handling_multiplier' => 'nullable|numeric', ]; /** - * Modify some fields on the fly. Make sure the subfleet names don't - * have spaces in them, so the csv import/export can use the types + * @param $type */ - public static function boot() + public function setTypeAttribute($type) { - parent::boot(); + $type = str_replace(' ', '-', $type); + $type = str_replace(',', '', $type); - static::creating(function ($model) { - if (filled($model->type)) { - $model->type = str_replace(' ', '-', $model->type); - $model->type = str_replace(',', '', $model->type); - } - - if(!filled($model->ground_handling_multiplier)) { - $model->ground_handling_multiplier = 100; - } - }); - - static::updating(function ($model) { - if (filled($model->type)) { - $model->type = str_replace(' ', '-', $model->type); - $model->type = str_replace(',', '', $model->type); - } - }); + $this->attributes['type'] = $type; } /** @@ -83,7 +65,7 @@ class Subfleet extends BaseModel public function aircraft() { return $this->hasMany(Aircraft::class, 'subfleet_id') - ->where('status', AircraftStatus::ACTIVE); + ->where('status', AircraftStatus::ACTIVE); } public function airline() @@ -94,7 +76,7 @@ class Subfleet extends BaseModel public function fares() { return $this->belongsToMany(Fare::class, 'subfleet_fare') - ->withPivot('price', 'cost', 'capacity'); + ->withPivot('price', 'cost', 'capacity'); } public function flights() @@ -105,6 +87,6 @@ class Subfleet extends BaseModel public function ranks() { return $this->belongsToMany(Rank::class, 'subfleet_rank') - ->withPivot('acars_pay', 'manual_pay'); + ->withPivot('acars_pay', 'manual_pay'); } } diff --git a/app/Models/Traits/ExpensableTrait.php b/app/Models/Traits/ExpensableTrait.php index fae227f5..28ca8a8b 100644 --- a/app/Models/Traits/ExpensableTrait.php +++ b/app/Models/Traits/ExpensableTrait.php @@ -8,7 +8,6 @@ trait ExpensableTrait { public static function bootExpensableTrait() { - } /** diff --git a/app/Models/Traits/HashIdTrait.php b/app/Models/Traits/HashIdTrait.php index dafe7a81..9776eabc 100644 --- a/app/Models/Traits/HashIdTrait.php +++ b/app/Models/Traits/HashIdTrait.php @@ -1,4 +1,5 @@ encode($mt); } diff --git a/app/Models/Traits/JournalTrait.php b/app/Models/Traits/JournalTrait.php index 2594243b..5fbf7b7d 100644 --- a/app/Models/Traits/JournalTrait.php +++ b/app/Models/Traits/JournalTrait.php @@ -6,7 +6,6 @@ use App\Models\Journal; trait JournalTrait { - /** * Initialize a new journal when a new record is created */ @@ -44,6 +43,7 @@ trait JournalTrait $this->journal()->save($journal); $journal->refresh(); + return $journal; } } diff --git a/app/Models/User.php b/app/Models/User.php index 22317ce1..d1fe5a67 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -10,20 +10,20 @@ use Illuminate\Notifications\Notifiable; use Laratrust\Traits\LaratrustUserTrait; /** - * @property integer $id - * @property string $name - * @property string $email - * @property string $password - * @property string $api_key - * @property Flight[] $flights - * @property string $flight_time - * @property string $remember_token + * @property integer $id + * @property string $name + * @property string $email + * @property string $password + * @property string $api_key + * @property Flight[] $flights + * @property string $flight_time + * @property string $remember_token * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at - * @property Rank rank - * @property Journal journal - * @property string pilot_id - * @property int state + * @property Rank rank + * @property Journal journal + * @property string pilot_id + * @property int state * @mixin \Illuminate\Notifications\Notifiable * @mixin \Laratrust\Traits\LaratrustUserTrait */ @@ -72,16 +72,16 @@ class User extends Authenticatable ]; protected $casts = [ - 'flights' => 'integer', - 'flight_time' => 'integer', - 'transferred_time' => 'integer', - 'balance' => 'double', - 'state' => 'integer', - 'status' => 'integer', + 'flights' => 'integer', + 'flight_time' => 'integer', + 'transferred_time' => 'integer', + 'balance' => 'double', + 'state' => 'integer', + 'status' => 'integer', ]; public static $rules = [ - 'name' => 'required', + 'name' => 'required', 'email' => 'required|email', ]; @@ -91,7 +91,8 @@ class User extends Authenticatable public function getPilotIdAttribute() { $length = setting('pilots.id_length'); - return $this->airline->icao . str_pad($this->id, $length, '0', STR_PAD_LEFT); + + return $this->airline->icao.str_pad($this->id, $length, '0', STR_PAD_LEFT); } /** @@ -124,14 +125,14 @@ class User extends Authenticatable * @param mixed $size Size of the gravatar, in pixels * @return string */ - public function gravatar($size=null) + public function gravatar($size = null) { $default = config('gravatar.default'); $uri = config('gravatar.url') - . md5(strtolower(trim($this->email))).'?d='.urlencode($default); + .md5(strtolower(trim($this->email))).'?d='.urlencode($default); - if($size !== null) { + if ($size !== null) { $uri .= '&s='.$size; } @@ -175,7 +176,7 @@ class User extends Authenticatable public function pireps() { return $this->hasMany(Pirep::class, 'user_id') - ->where('state', '!=', PirepState::CANCELLED); + ->where('state', '!=', PirepState::CANCELLED); } public function rank() diff --git a/app/Models/UserAward.php b/app/Models/UserAward.php index fec2c55d..2e39ce3d 100644 --- a/app/Models/UserAward.php +++ b/app/Models/UserAward.php @@ -2,11 +2,13 @@ namespace App\Models; +use App\Interfaces\Model; + /** * Class UserAward * @package App\Models */ -class UserAward extends BaseModel +class UserAward extends Model { public $table = 'user_awards'; diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 819f97fd..68c4a014 100755 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -12,8 +12,10 @@ use App\Models\Observers\JournalObserver; use App\Models\Observers\JournalTransactionObserver; use App\Models\Observers\PirepFieldObserver; use App\Models\Observers\SettingObserver; +use App\Models\Observers\SubfleetObserver; use App\Models\PirepField; use App\Models\Setting; +use App\Models\Subfleet; use App\Repositories\SettingRepository; use App\Services\ModuleService; use Illuminate\Support\Facades\Schema; @@ -36,6 +38,7 @@ class AppServiceProvider extends ServiceProvider JournalTransaction::observe(JournalTransactionObserver::class); PirepField::observe(PirepFieldObserver::class); Setting::observe(SettingObserver::class); + Subfleet::observe(SubfleetObserver::class); } /** @@ -43,6 +46,5 @@ class AppServiceProvider extends ServiceProvider */ public function register(): void { - } } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 9e68caa6..66d92779 100755 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -23,7 +23,6 @@ class AuthServiceProvider extends ServiceProvider public function boot() { $this->registerPolicies(); - // } } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 7496b143..4f04c4c0 100755 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -14,12 +14,11 @@ use App\Listeners\FinanceEvents; use App\Listeners\NotificationEvents; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; - class EventServiceProvider extends ServiceProvider { protected $listen = [ - Expenses::class => [ + Expenses::class => [ ExpenseListener::class ], @@ -40,7 +39,6 @@ class EventServiceProvider extends ServiceProvider AwardListener::class, ], ]; - protected $subscribe = [ FinanceEvents::class, NotificationEvents::class, diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 59fca23e..07079a18 100755 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -50,7 +50,7 @@ class RouteServiceProvider extends ServiceProvider { Route::group([ 'middleware' => 'web', - 'namespace' => $this->namespace, + 'namespace' => $this->namespace, ], function ($router) { require app_path('Routes/web.php'); }); @@ -67,9 +67,9 @@ class RouteServiceProvider extends ServiceProvider { Route::group([ 'middleware' => ['api'], - 'namespace' => $this->namespace."\\Api", - 'prefix' => 'api', - 'as' => 'api.', + 'namespace' => $this->namespace."\\Api", + 'prefix' => 'api', + 'as' => 'api.', ], function ($router) { require app_path('Routes/api.php'); }); diff --git a/app/Providers/vaCentralServiceProvider.php b/app/Providers/vaCentralServiceProvider.php index ef3e5187..361baeaf 100755 --- a/app/Providers/vaCentralServiceProvider.php +++ b/app/Providers/vaCentralServiceProvider.php @@ -1,4 +1,5 @@ $pirep_id, - 'type' => $type, + 'type' => $type, ]; - switch($type) { + switch ($type) { default: case AcarsType::FLIGHT_PATH: case AcarsType::LOG: @@ -50,8 +56,8 @@ class AcarsRepository extends BaseRepository //implements CacheableInterface public function getPositions() { return Pirep::with(['airline', 'position']) - ->where(['state' => PirepState::IN_PROGRESS]) - ->get(); + ->where(['state' => PirepState::IN_PROGRESS]) + ->get(); } /** diff --git a/app/Repositories/AircraftRepository.php b/app/Repositories/AircraftRepository.php index 51156961..2c2bfcb8 100644 --- a/app/Repositories/AircraftRepository.php +++ b/app/Repositories/AircraftRepository.php @@ -2,16 +2,21 @@ namespace App\Repositories; +use App\Interfaces\Repository; use App\Models\Aircraft; use Prettus\Repository\Contracts\CacheableInterface; use Prettus\Repository\Traits\CacheableRepository; -class AircraftRepository extends BaseRepository implements CacheableInterface +/** + * Class AircraftRepository + * @package App\Repositories + */ +class AircraftRepository extends Repository implements CacheableInterface { use CacheableRepository; protected $fieldSearchable = [ - 'name' => 'like', + 'name' => 'like', 'registration' => 'like', 'active', ]; @@ -31,7 +36,7 @@ class AircraftRepository extends BaseRepository implements CacheableInterface $items = $this->all(); foreach ($items as $i) { - $retval[$i->id] = $i->subfleet->name . ' - ' . $i->name . ' (' . $i->registration . ')'; + $retval[$i->id] = $i->subfleet->name.' - '.$i->name.' ('.$i->registration.')'; } return $retval; diff --git a/app/Repositories/AirlineRepository.php b/app/Repositories/AirlineRepository.php index a68a1d15..abb7d8f9 100644 --- a/app/Repositories/AirlineRepository.php +++ b/app/Repositories/AirlineRepository.php @@ -2,12 +2,16 @@ namespace App\Repositories; +use App\Interfaces\Repository; use App\Models\Airline; use Prettus\Repository\Contracts\CacheableInterface; use Prettus\Repository\Traits\CacheableRepository; - -class AirlineRepository extends BaseRepository implements CacheableInterface +/** + * Class AirlineRepository + * @package App\Repositories + */ +class AirlineRepository extends Repository implements CacheableInterface { use CacheableRepository; @@ -25,12 +29,12 @@ class AirlineRepository extends BaseRepository implements CacheableInterface * Return the list of airline formatted for a select box * @return array */ - public function selectBoxList($add_blank=false): array + public function selectBoxList($add_blank = false): array { $retval = []; $items = $this->all(); - if($add_blank) { + if ($add_blank) { $retval[''] = ''; } diff --git a/app/Repositories/AirportRepository.php b/app/Repositories/AirportRepository.php index fd9c86de..fabb96bf 100644 --- a/app/Repositories/AirportRepository.php +++ b/app/Repositories/AirportRepository.php @@ -2,12 +2,16 @@ namespace App\Repositories; +use App\Interfaces\Repository; use App\Models\Airport; use Prettus\Repository\Contracts\CacheableInterface; use Prettus\Repository\Traits\CacheableRepository; - -class AirportRepository extends BaseRepository implements CacheableInterface +/** + * Class AirportRepository + * @package App\Repositories + */ +class AirportRepository extends Repository implements CacheableInterface { use CacheableRepository; @@ -25,12 +29,12 @@ class AirportRepository extends BaseRepository implements CacheableInterface * Return the list of airports formatted for a select box * @return array */ - public function selectBoxList($add_blank=false, $only_hubs=false): array + public function selectBoxList($add_blank = false, $only_hubs = false): array { $retval = []; $where = []; - if($only_hubs) { + if ($only_hubs) { $where['hub'] = 1; } @@ -41,7 +45,7 @@ class AirportRepository extends BaseRepository implements CacheableInterface } foreach ($items as $i) { - $retval[$i->icao] = $i->icao . ' - ' . $i->name; + $retval[$i->icao] = $i->icao.' - '.$i->name; } return $retval; diff --git a/app/Repositories/AwardRepository.php b/app/Repositories/AwardRepository.php index 3f8b4c5c..6b731bfc 100755 --- a/app/Repositories/AwardRepository.php +++ b/app/Repositories/AwardRepository.php @@ -2,11 +2,16 @@ namespace App\Repositories; +use App\Interfaces\Repository; use App\Models\Award; use Prettus\Repository\Contracts\CacheableInterface; use Prettus\Repository\Traits\CacheableRepository; -class AwardRepository extends BaseRepository implements CacheableInterface +/** + * Class AwardRepository + * @package App\Repositories + */ +class AwardRepository extends Repository implements CacheableInterface { use CacheableRepository; @@ -19,7 +24,8 @@ class AwardRepository extends BaseRepository implements CacheableInterface return Award::class; } - public function findByTitle($title) { + public function findByTitle($title) + { return $this->findByField('title', $title)->first(); } } diff --git a/app/Repositories/Criteria/WhereCriteria.php b/app/Repositories/Criteria/WhereCriteria.php index 7b39d6ae..2a32a4cb 100644 --- a/app/Repositories/Criteria/WhereCriteria.php +++ b/app/Repositories/Criteria/WhereCriteria.php @@ -24,19 +24,18 @@ class WhereCriteria implements CriteriaInterface $this->where = $where; } - /** * Apply criteria in query repository * * @param Builder|Model $model - * @param RepositoryInterface $repository + * @param RepositoryInterface $repository * * @return mixed * @throws \Exception */ public function apply($model, RepositoryInterface $repository) { - if($this->where) { + if ($this->where) { $model = $model->where($this->where); } diff --git a/app/Repositories/ExpenseRepository.php b/app/Repositories/ExpenseRepository.php index b215899c..120ec7f4 100644 --- a/app/Repositories/ExpenseRepository.php +++ b/app/Repositories/ExpenseRepository.php @@ -2,6 +2,7 @@ namespace App\Repositories; +use App\Interfaces\Repository; use App\Models\Expense; use Illuminate\Support\Collection; use Prettus\Repository\Contracts\CacheableInterface; @@ -11,7 +12,7 @@ use Prettus\Repository\Traits\CacheableRepository; * Class ExpenseRepository * @package App\Repositories */ -class ExpenseRepository extends BaseRepository implements CacheableInterface +class ExpenseRepository extends Repository implements CacheableInterface { use CacheableRepository; @@ -23,28 +24,27 @@ class ExpenseRepository extends BaseRepository implements CacheableInterface /** * Get all of the expenses for a given type, and also * include expenses for a given airline ID - * @param $type + * @param $type * @param null $airline_id * @param null $ref_class * @return Collection */ - public function getAllForType($type, $airline_id=null, $ref_class=null) + public function getAllForType($type, $airline_id = null, $ref_class = null) { $where = [ 'type' => $type, ['airline_id', '=', null] ]; - if($ref_class) { + if ($ref_class) { $where['ref_class'] = $ref_class; } $expenses = $this->findWhere($where); - if($airline_id) { - + if ($airline_id) { $where = [ - 'type' => $type, + 'type' => $type, 'airline_id' => $airline_id ]; diff --git a/app/Repositories/FareRepository.php b/app/Repositories/FareRepository.php index 71c0b56a..c5833ca2 100644 --- a/app/Repositories/FareRepository.php +++ b/app/Repositories/FareRepository.php @@ -2,17 +2,22 @@ namespace App\Repositories; +use App\Interfaces\Repository; use App\Models\Fare; use Prettus\Repository\Contracts\CacheableInterface; use Prettus\Repository\Traits\CacheableRepository; -class FareRepository extends BaseRepository implements CacheableInterface +/** + * Class FareRepository + * @package App\Repositories + */ +class FareRepository extends Repository implements CacheableInterface { use CacheableRepository; protected $fieldSearchable = [ - 'code' => 'like', - 'name' => 'like', + 'code' => 'like', + 'name' => 'like', 'notes' => 'like', ]; @@ -21,7 +26,8 @@ class FareRepository extends BaseRepository implements CacheableInterface return Fare::class; } - public function findByCode($code) { + public function findByCode($code) + { return $this->findByField('code', $code)->first(); } } diff --git a/app/Repositories/FlightRepository.php b/app/Repositories/FlightRepository.php index b763fba2..350772c5 100644 --- a/app/Repositories/FlightRepository.php +++ b/app/Repositories/FlightRepository.php @@ -2,13 +2,18 @@ namespace App\Repositories; +use App\Interfaces\Repository; use App\Models\Flight; use App\Repositories\Criteria\WhereCriteria; use Illuminate\Http\Request; use Prettus\Repository\Contracts\CacheableInterface; use Prettus\Repository\Traits\CacheableRepository; -class FlightRepository extends BaseRepository implements CacheableInterface +/** + * Class FlightRepository + * @package App\Repositories + */ +class FlightRepository extends Repository implements CacheableInterface { use CacheableRepository; @@ -16,10 +21,10 @@ class FlightRepository extends BaseRepository implements CacheableInterface 'arr_airport_id', 'dpt_airport_id', 'flight_number' => 'like', - 'flight_code' => 'like', - 'flight_leg' => 'like', - 'route' => 'like', - 'notes' => 'like', + 'flight_code' => 'like', + 'flight_leg' => 'like', + 'route' => 'like', + 'notes' => 'like', ]; public function model() @@ -29,25 +34,25 @@ class FlightRepository extends BaseRepository implements CacheableInterface /** * Find a flight based on the given criterea - * @param $airline_id - * @param $flight_num + * @param $airline_id + * @param $flight_num * @param null $route_code * @param null $route_leg * @return mixed */ - public function findFlight($airline_id, $flight_num, $route_code=null, $route_leg=null) + public function findFlight($airline_id, $flight_num, $route_code = null, $route_leg = null) { $where = [ - 'airline_id' => $airline_id, + 'airline_id' => $airline_id, 'flight_number' => $flight_num, - 'active' => true, + 'active' => true, ]; - if(filled($route_code)) { + if (filled($route_code)) { $where['route_code'] = $route_code; } - if(filled($route_leg)) { + if (filled($route_leg)) { $where['route_leg'] = $route_leg; } @@ -57,15 +62,15 @@ class FlightRepository extends BaseRepository implements CacheableInterface /** * Create the search criteria and return this with the stuff pushed * @param Request $request - * @param bool $only_active + * @param bool $only_active * @return $this * @throws \Prettus\Repository\Exceptions\RepositoryException */ - public function searchCriteria(Request $request, bool $only_active=true) + public function searchCriteria(Request $request, bool $only_active = true) { $where = []; - if($only_active === true) { + if ($only_active === true) { $where['active'] = $only_active; } @@ -77,7 +82,7 @@ class FlightRepository extends BaseRepository implements CacheableInterface $where['airline_id'] = $request->airline_id; } - if($request->filled('flight_number')) { + if ($request->filled('flight_number')) { $where['flight_number'] = $request->flight_number; } @@ -94,6 +99,7 @@ class FlightRepository extends BaseRepository implements CacheableInterface } $this->pushCriteria(new WhereCriteria($request, $where)); + return $this; } } diff --git a/app/Repositories/JournalRepository.php b/app/Repositories/JournalRepository.php index e4a212d3..b45e5048 100644 --- a/app/Repositories/JournalRepository.php +++ b/app/Repositories/JournalRepository.php @@ -2,6 +2,7 @@ namespace App\Repositories; +use App\Interfaces\Repository; use App\Models\Journal; use App\Models\JournalTransaction; use App\Support\Money; @@ -15,7 +16,7 @@ use Prettus\Validator\Exceptions\ValidatorException; * Class JournalRepository * @package App\Repositories */ -class JournalRepository extends BaseRepository implements CacheableInterface +class JournalRepository extends Repository implements CacheableInterface { use CacheableRepository; @@ -32,9 +33,9 @@ class JournalRepository extends BaseRepository implements CacheableInterface * @param Carbon $date * @return string */ - public function formatPostDate(Carbon $date=null) + public function formatPostDate(Carbon $date = null) { - if(!$date) { + if (!$date) { return null; } @@ -69,13 +70,13 @@ class JournalRepository extends BaseRepository implements CacheableInterface * on the transaction itself. A cron will run to reconcile the journal * balance nightly, since they're not atomic operations * - * @param Journal $journal - * @param Money|null $credit Amount to credit - * @param Money|null $debit Amount to debit - * @param Model|null $reference The object this is a reference to - * @param string|null $memo Memo for this transaction - * @param string|null $post_date Date of the posting - * @param string|null $transaction_group + * @param Journal $journal + * @param Money|null $credit Amount to credit + * @param Money|null $debit Amount to debit + * @param Model|null $reference The object this is a reference to + * @param string|null $memo Memo for this transaction + * @param string|null $post_date Date of the posting + * @param string|null $transaction_group * @param array|string|null $tags * @return mixed * @throws ValidatorException @@ -89,25 +90,26 @@ class JournalRepository extends BaseRepository implements CacheableInterface $post_date = null, $transaction_group = null, $tags = null - ) { + ) + { # tags can be passed in a list if ($tags && \is_array($tags)) { $tags = implode(',', $tags); } - if(!$post_date) { + if (!$post_date) { $post_date = Carbon::now('UTC'); } $attrs = [ - 'journal_id' => $journal->id, - 'credit' => $credit ? $credit->getAmount() : null, - 'debit' => $debit ? $debit->getAmount() : null, - 'currency' => config('phpvms.currency'), - 'memo' => $memo, - 'post_date' => $post_date, + 'journal_id' => $journal->id, + 'credit' => $credit ? $credit->getAmount() : null, + 'debit' => $debit ? $debit->getAmount() : null, + 'currency' => config('phpvms.currency'), + 'memo' => $memo, + 'post_date' => $post_date, 'transaction_group' => $transaction_group, - 'tags' => $tags + 'tags' => $tags ]; if ($reference !== null) { @@ -127,17 +129,17 @@ class JournalRepository extends BaseRepository implements CacheableInterface } /** - * @param Journal $journal + * @param Journal $journal * @param Carbon|null $date * @return Money * @throws \UnexpectedValueException * @throws \InvalidArgumentException */ - public function getBalance(Journal $journal=null, Carbon $date=null) + public function getBalance(Journal $journal = null, Carbon $date = null) { $journal->refresh(); - if(!$date) { + if (!$date) { $date = Carbon::now(); } @@ -149,19 +151,19 @@ class JournalRepository extends BaseRepository implements CacheableInterface /** * Get the credit only balance of the journal based on a given date. - * @param Carbon $date - * @param Journal $journal + * @param Carbon $date + * @param Journal $journal * @param Carbon|null $start_date - * @param null $transaction_group + * @param null $transaction_group * @return Money * @throws \UnexpectedValueException * @throws \InvalidArgumentException */ public function getCreditBalanceBetween( Carbon $date, - Journal $journal=null, - Carbon $start_date=null, - $transaction_group=null + Journal $journal = null, + Carbon $start_date = null, + $transaction_group = null ): Money { $where = []; @@ -187,10 +189,10 @@ class JournalRepository extends BaseRepository implements CacheableInterface } /** - * @param Carbon $date - * @param Journal $journal + * @param Carbon $date + * @param Journal $journal * @param Carbon|null $start_date - * @param null $transaction_group + * @param null $transaction_group * @return Money * @throws \UnexpectedValueException * @throws \InvalidArgumentException @@ -226,8 +228,8 @@ class JournalRepository extends BaseRepository implements CacheableInterface /** * Return all transactions for a given object - * @param $object - * @param null $journal + * @param $object + * @param null $journal * @param Carbon|null $date * @return array * @throws \UnexpectedValueException @@ -236,7 +238,7 @@ class JournalRepository extends BaseRepository implements CacheableInterface public function getAllForObject($object, $journal = null, Carbon $date = null) { $where = [ - 'ref_class' => \get_class($object), + 'ref_class' => \get_class($object), 'ref_class_id' => $object->id, ]; @@ -251,26 +253,26 @@ class JournalRepository extends BaseRepository implements CacheableInterface $transactions = $this->whereOrder($where, [ 'credit' => 'desc', - 'debit' => 'desc' + 'debit' => 'desc' ])->get(); return [ - 'credits' => new Money($transactions->sum('credit')), - 'debits' => new Money($transactions->sum('debit')), + 'credits' => new Money($transactions->sum('credit')), + 'debits' => new Money($transactions->sum('debit')), 'transactions' => $transactions, ]; } /** * Delete all transactions for a given object - * @param $object + * @param $object * @param null $journal * @return void */ public function deleteAllForObject($object, $journal = null) { $where = [ - 'ref_class' => \get_class($object), + 'ref_class' => \get_class($object), 'ref_class_id' => $object->id, ]; diff --git a/app/Repositories/NavdataRepository.php b/app/Repositories/NavdataRepository.php index 68b90eca..9ed69a80 100644 --- a/app/Repositories/NavdataRepository.php +++ b/app/Repositories/NavdataRepository.php @@ -2,11 +2,16 @@ namespace App\Repositories; +use App\Interfaces\Repository; use App\Models\Navdata; use Prettus\Repository\Contracts\CacheableInterface; use Prettus\Repository\Traits\CacheableRepository; -class NavdataRepository extends BaseRepository implements CacheableInterface +/** + * Class NavdataRepository + * @package App\Repositories + */ +class NavdataRepository extends Repository implements CacheableInterface { use CacheableRepository; diff --git a/app/Repositories/NewsRepository.php b/app/Repositories/NewsRepository.php index c4b2ca43..819e42b4 100644 --- a/app/Repositories/NewsRepository.php +++ b/app/Repositories/NewsRepository.php @@ -2,11 +2,16 @@ namespace App\Repositories; +use App\Interfaces\Repository; use App\Models\News; use Prettus\Repository\Contracts\CacheableInterface; use Prettus\Repository\Traits\CacheableRepository; -class NewsRepository extends BaseRepository implements CacheableInterface +/** + * Class NewsRepository + * @package App\Repositories + */ +class NewsRepository extends Repository implements CacheableInterface { use CacheableRepository; @@ -20,10 +25,10 @@ class NewsRepository extends BaseRepository implements CacheableInterface * @param int $count * @return mixed */ - public function getLatest($count=5) + public function getLatest($count = 5) { return $this->orderBy('created_at', 'desc') - ->with(['user']) - ->paginate($count); + ->with(['user']) + ->paginate($count); } } diff --git a/app/Repositories/PirepFieldRepository.php b/app/Repositories/PirepFieldRepository.php index 546f0bb5..b17b1c99 100644 --- a/app/Repositories/PirepFieldRepository.php +++ b/app/Repositories/PirepFieldRepository.php @@ -2,9 +2,14 @@ namespace App\Repositories; +use App\Interfaces\Repository; use App\Models\PirepField; -class PirepFieldRepository extends BaseRepository +/** + * Class PirepFieldRepository + * @package App\Repositories + */ +class PirepFieldRepository extends Repository { protected $fieldSearchable = [ 'name' => 'like', diff --git a/app/Repositories/PirepRepository.php b/app/Repositories/PirepRepository.php index 92141180..f7f74960 100644 --- a/app/Repositories/PirepRepository.php +++ b/app/Repositories/PirepRepository.php @@ -2,11 +2,16 @@ namespace App\Repositories; +use App\Interfaces\Repository; use App\Models\Enums\PirepState; use App\Models\Pirep; use App\Models\User; -class PirepRepository extends BaseRepository +/** + * Class PirepRepository + * @package App\Repositories + */ +class PirepRepository extends Repository { protected $fieldSearchable = [ 'user_id', @@ -14,6 +19,9 @@ class PirepRepository extends BaseRepository 'state', ]; + /** + * @return string + */ public function model() { return Pirep::class; @@ -25,14 +33,15 @@ class PirepRepository extends BaseRepository * @param User|null $user * @return Pirep */ - public function getPending(User $user=null) + public function getPending(User $user = null) { $where = []; - if($user !== null) { + if ($user !== null) { $where['user_id'] = $user->id; } $pireps = $this->orderBy('created_at', 'desc')->findWhere($where)->all(); + return $pireps; } @@ -52,8 +61,9 @@ class PirepRepository extends BaseRepository } $pireps = $this->orderBy('created_at', 'desc') - ->findWhere($where, ['id']) - ->count(); + ->findWhere($where, ['id']) + ->count(); + return $pireps; } } diff --git a/app/Repositories/RankRepository.php b/app/Repositories/RankRepository.php index bfbac8a0..9b466983 100644 --- a/app/Repositories/RankRepository.php +++ b/app/Repositories/RankRepository.php @@ -2,18 +2,25 @@ namespace App\Repositories; +use App\Interfaces\Repository; use App\Models\Rank; use Prettus\Repository\Contracts\CacheableInterface; use Prettus\Repository\Traits\CacheableRepository; -class RankRepository extends BaseRepository implements CacheableInterface +/** + * Class RankRepository + * @package App\Repositories + */ +class RankRepository extends Repository implements CacheableInterface { use CacheableRepository; - protected $fieldSearchable = [ 'name' => 'like', ]; + /** + * @return string + */ public function model() { return Rank::class; diff --git a/app/Repositories/SettingRepository.php b/app/Repositories/SettingRepository.php index cc9d7f07..d5541e8f 100644 --- a/app/Repositories/SettingRepository.php +++ b/app/Repositories/SettingRepository.php @@ -3,6 +3,7 @@ namespace App\Repositories; use App\Exceptions\SettingNotFound; +use App\Interfaces\Repository; use App\Models\Setting; use Illuminate\Support\Carbon; use Log; @@ -10,12 +11,19 @@ use Prettus\Repository\Contracts\CacheableInterface; use Prettus\Repository\Traits\CacheableRepository; use Prettus\Validator\Exceptions\ValidatorException; -class SettingRepository extends BaseRepository implements CacheableInterface +/** + * Class SettingRepository + * @package App\Repositories + */ +class SettingRepository extends Repository implements CacheableInterface { use CacheableRepository; public $cacheMinutes = 1; + /** + * @return string + */ public function model() { return Setting::class; @@ -32,18 +40,18 @@ class SettingRepository extends BaseRepository implements CacheableInterface $key = Setting::formatKey($key); $setting = $this->findWhere(['id' => $key], ['type', 'value'])->first(); - if(!$setting) { - throw new SettingNotFound($key . ' not found'); + if (!$setting) { + throw new SettingNotFound($key.' not found'); } # cast some types - switch($setting->type) { + switch ($setting->type) { case 'bool': case 'boolean': $value = $setting->value; - if($value === 'true' || $value === '1') { + if ($value === 'true' || $value === '1') { $value = true; - } elseif($value === 'false' || $value === '0') { + } elseif ($value === 'false' || $value === '0') { $value = false; } @@ -93,7 +101,7 @@ class SettingRepository extends BaseRepository implements CacheableInterface } try { - if(\is_bool($value)) { + if (\is_bool($value)) { $value = $value === true ? 1 : 0; } diff --git a/app/Repositories/SubfleetRepository.php b/app/Repositories/SubfleetRepository.php index 178268a4..9e0c9467 100644 --- a/app/Repositories/SubfleetRepository.php +++ b/app/Repositories/SubfleetRepository.php @@ -2,11 +2,16 @@ namespace App\Repositories; +use App\Interfaces\Repository; use App\Models\Subfleet; use Prettus\Repository\Contracts\CacheableInterface; use Prettus\Repository\Traits\CacheableRepository; -class SubfleetRepository extends BaseRepository implements CacheableInterface +/** + * Class SubfleetRepository + * @package App\Repositories + */ +class SubfleetRepository extends Repository implements CacheableInterface { use CacheableRepository; @@ -15,6 +20,9 @@ class SubfleetRepository extends BaseRepository implements CacheableInterface 'type' => 'like', ]; + /** + * @return string + */ public function model() { return Subfleet::class; diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index c2aab2e9..a9e4c6a9 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -1,21 +1,30 @@ 'like', + 'name' => 'like', 'email' => 'like', 'home_airport_id', 'curr_airport_id', 'state' ]; + /** + * @return string + */ public function model() { return User::class; @@ -32,8 +41,8 @@ class UserRepository extends BaseRepository ]; $users = $this->orderBy('created_at', 'desc') - ->findWhere($where, ['id']) - ->count(); + ->findWhere($where, ['id']) + ->count(); return $users; } @@ -41,7 +50,7 @@ class UserRepository extends BaseRepository /** * Create the search criteria and return this with the stuff pushed * @param Request $request - * @param bool $only_active + * @param bool $only_active * @return $this * @throws \Prettus\Repository\Exceptions\RepositoryException */ @@ -49,7 +58,7 @@ class UserRepository extends BaseRepository { $where = []; - if($only_active) { + if ($only_active) { $where['state'] = UserState::ACTIVE; } @@ -66,6 +75,7 @@ class UserRepository extends BaseRepository } $this->pushCriteria(new WhereCriteria($request, $where)); + return $this; } } diff --git a/app/Routes/admin.php b/app/Routes/admin.php index 5bd7b12d..21b8e23b 100644 --- a/app/Routes/admin.php +++ b/app/Routes/admin.php @@ -4,9 +4,9 @@ */ Route::group([ - 'namespace' => 'Admin', 'prefix' => 'admin', 'as' => 'admin.', - 'middleware' => ['role:admin'], - ], function () { + 'namespace' => 'Admin', 'prefix' => 'admin', 'as' => 'admin.', + 'middleware' => ['role:admin'], +], function () { Route::resource('airlines', 'AirlinesController'); Route::match(['get', 'post', 'put'], 'airports/fuel', 'AirportController@fuel'); @@ -60,7 +60,7 @@ Route::group([ Route::resource('users', 'UserController'); Route::get('users/{id}/regen_apikey', - 'UserController@regen_apikey')->name('users.regen_apikey'); + 'UserController@regen_apikey')->name('users.regen_apikey'); # defaults Route::get('', ['uses' => 'DashboardController@index']); @@ -68,6 +68,6 @@ Route::group([ Route::get('dashboard', ['uses' => 'DashboardController@index', 'name' => 'dashboard']); Route::match(['get', 'post', 'delete'], - 'dashboard/news', ['uses' => 'DashboardController@news']) + 'dashboard/news', ['uses' => 'DashboardController@news']) ->name('dashboard.news'); }); diff --git a/app/Routes/api.php b/app/Routes/api.php index af9a544c..41d6ad73 100755 --- a/app/Routes/api.php +++ b/app/Routes/api.php @@ -3,8 +3,7 @@ /** * Public routes */ -Route::group([], function() -{ +Route::group([], function () { Route::get('acars', 'AcarsController@index'); Route::get('pireps/{pirep_id}/acars/geojson', 'PirepController@acars_geojson'); @@ -15,8 +14,7 @@ Route::group([], function() /** * these need to be authenticated with a user's API key */ -Route::group(['middleware' => ['api.auth']], function () -{ +Route::group(['middleware' => ['api.auth']], function () { Route::get('airlines', 'AirlineController@index'); Route::get('airlines/{id}', 'AirlineController@get'); @@ -79,5 +77,4 @@ Route::group(['middleware' => ['api.auth']], function () Route::get('users/{id}/bids', 'UserController@bids'); Route::put('users/{id}/bids', 'UserController@bids'); - }); diff --git a/app/Routes/web.php b/app/Routes/web.php index c3c77016..4c2a5669 100755 --- a/app/Routes/web.php +++ b/app/Routes/web.php @@ -1,12 +1,11 @@ 'Frontend', 'prefix' => '', 'as' => 'frontend.' -], function() { +], function () { Route::get('/', 'HomeController@index')->name('home'); Route::get('r/{id}', 'PirepController@show')->name('pirep.show.public'); Route::get('p/{id}', 'ProfileController@show')->name('profile.show.public'); @@ -21,7 +20,7 @@ Route::group([ * These are only visible to a logged in user */ Route::group([ - 'namespace' => 'Frontend', 'prefix' => '', 'as' => 'frontend.', + 'namespace' => 'Frontend', 'prefix' => '', 'as' => 'frontend.', 'middleware' => ['role:admin|user'], ], function () { Route::resource('dashboard', 'DashboardController'); diff --git a/app/Services/AnalyticsService.php b/app/Services/AnalyticsService.php index 33536127..62a639fb 100644 --- a/app/Services/AnalyticsService.php +++ b/app/Services/AnalyticsService.php @@ -2,20 +2,25 @@ namespace App\Services; +use App\Interfaces\Service; use App\Models\Enums\AnalyticsDimensions; use DB; use Irazasyed\LaravelGAMP\Facades\GAMP; use Log; use PDO; -class AnalyticsService +/** + * Class AnalyticsService + * @package App\Services + */ +class AnalyticsService extends Service { /** * Send out some stats about the install */ public function sendInstall() { - if(config('app.analytics') === false) { + if (config('app.analytics') === false) { return; } @@ -38,5 +43,4 @@ class AnalyticsService Log::error($e->getMessage()); } } - } diff --git a/app/Services/AwardService.php b/app/Services/AwardService.php index 5694c838..01462116 100644 --- a/app/Services/AwardService.php +++ b/app/Services/AwardService.php @@ -2,16 +2,21 @@ namespace App\Services; +use App\Interfaces\Service; use App\Support\ClassLoader; use Module; -class AwardService +/** + * Class AwardService + * @package App\Services + */ +class AwardService extends Service { /** * Find any of the award classes - * @return \App\Interfaces\AwardInterface[] + * @return \App\Interfaces\Award[] */ - public function findAllAwardClasses() + public function findAllAwardClasses(): array { $awards = []; $formatted_awards = []; diff --git a/app/Services/BaseService.php b/app/Services/BaseService.php deleted file mode 100644 index da589486..00000000 --- a/app/Services/BaseService.php +++ /dev/null @@ -1,8 +0,0 @@ -format('Y-m-d H:i:s'); } /** - * @param $yaml_file + * @param $yaml_file * @param bool $ignore_errors * @return array * @throws \Exception */ - public function seed_from_yaml_file($yaml_file, $ignore_errors=false): array + public function seed_from_yaml_file($yaml_file, $ignore_errors = false): array { $yml = file_get_contents($yaml_file); + return $this->seed_from_yaml($yml, $ignore_errors); } /** - * @param $yml + * @param $yml * @param bool $ignore_errors * @return array * @throws \Exception */ - public function seed_from_yaml($yml, $ignore_errors=false): array + public function seed_from_yaml($yml, $ignore_errors = false): array { $imported = []; $yml = Yaml::parse($yml); foreach ($yml as $table => $rows) { - $imported[$table] = 0; foreach ($rows as $row) { - # see if this table uses a UUID as the PK # if no ID is specified - if(in_array($table, $this->uuid_tables)) { - if(!array_key_exists('id', $row)) { + if (in_array($table, $this->uuid_tables)) { + if (!array_key_exists('id', $row)) { $row['id'] = Uuid::generate()->string; } } # encrypt any password fields - if(array_key_exists('password', $row)) { + if (array_key_exists('password', $row)) { $row['password'] = bcrypt($row['password']); } # if any time fields are == to "now", then insert the right time - foreach($this->time_fields as $tf) { - if(array_key_exists($tf, $row) && strtolower($row[$tf]) === 'now') { + foreach ($this->time_fields as $tf) { + if (array_key_exists($tf, $row) && strtolower($row[$tf]) === 'now') { $row[$tf] = $this->time(); } } @@ -79,8 +84,8 @@ class DatabaseService extends BaseService try { DB::table($table)->insert($row); ++$imported[$table]; - } catch(QueryException $e) { - if($ignore_errors) { + } catch (QueryException $e) { + if ($ignore_errors) { continue; } diff --git a/app/Services/FareService.php b/app/Services/FareService.php index 92271d5a..7d2e1bbc 100644 --- a/app/Services/FareService.php +++ b/app/Services/FareService.php @@ -2,6 +2,7 @@ namespace App\Services; +use App\Interfaces\Service; use App\Models\Fare; use App\Models\Flight; use App\Models\Pirep; @@ -14,7 +15,7 @@ use Illuminate\Support\Collection; * Class FareService * @package App\Services */ -class FareService extends BaseService +class FareService extends Service { /** * Get the fares for a particular flight, with an optional subfleet @@ -23,13 +24,13 @@ class FareService extends BaseService * final "authoritative" list of the fares for a flight. * * If a subfleet is passed in, - * @param Flight|null $flight + * @param Flight|null $flight * @param Subfleet|null $subfleet * @return Collection */ public function getAllFares($flight, $subfleet) { - if(!$flight) { + if (!$flight) { $flight_fares = collect(); } else { $flight_fares = $this->getForFlight($flight); @@ -39,10 +40,9 @@ class FareService extends BaseService # Go through all of the fares assigned by the subfleet # See if any of the same fares are assigned to the flight - $fares = $subfleet_fares->map(function($fare, $idx) use ($flight_fares) - { + $fares = $subfleet_fares->map(function ($fare, $idx) use ($flight_fares) { $flight_fare = $flight_fares->whereStrict('id', $fare->id)->first(); - if(!$flight_fare) { + if (!$flight_fare) { return $fare; } @@ -90,7 +90,7 @@ class FareService extends BaseService * Attach a fare to an flight * * @param Flight $flight - * @param Fare $fare + * @param Fare $fare * @param array set the price/cost/capacity * @return Flight */ @@ -105,6 +105,7 @@ class FareService extends BaseService $flight->save(); $flight->refresh(); + return $flight; } @@ -126,13 +127,14 @@ class FareService extends BaseService /** * @param Flight $flight - * @param Fare $fare + * @param Fare $fare * @return Flight */ public function delFareFromFlight(Flight $flight, Fare $fare) { $flight->fares()->detach($fare->id); $flight->refresh(); + return $flight; } @@ -144,17 +146,18 @@ class FareService extends BaseService * @param array set the price/cost/capacity * @return Subfleet */ - public function setForSubfleet(Subfleet $subfleet, Fare $fare, array $override=[]): Subfleet + public function setForSubfleet(Subfleet $subfleet, Fare $fare, array $override = []): Subfleet { $subfleet->fares()->syncWithoutDetaching([$fare->id]); # modify any pivot values? - if(count($override) > 0) { + if (count($override) > 0) { $subfleet->fares()->updateExistingPivot($fare->id, $override); } $subfleet->save(); $subfleet->refresh(); + return $subfleet; } @@ -167,7 +170,7 @@ class FareService extends BaseService */ public function getForSubfleet(Subfleet $subfleet) { - $fares = $subfleet->fares->map(function($fare) { + $fares = $subfleet->fares->map(function ($fare) { return $this->getFares($fare); }); @@ -177,13 +180,14 @@ class FareService extends BaseService /** * Delete the fare from a subfleet * @param Subfleet $subfleet - * @param Fare $fare + * @param Fare $fare * @return Subfleet|null|static */ public function delFareFromSubfleet(Subfleet &$subfleet, Fare &$fare) { $subfleet->fares()->detach($fare->id); $subfleet->refresh(); + return $subfleet; } @@ -197,6 +201,7 @@ class FareService extends BaseService { $fares = []; $found_fares = PirepFare::where('pirep_id', $pirep->id)->get(); + return $found_fares; } diff --git a/app/Services/Finance/PirepFinanceService.php b/app/Services/Finance/PirepFinanceService.php index 78cdd530..2606a809 100644 --- a/app/Services/Finance/PirepFinanceService.php +++ b/app/Services/Finance/PirepFinanceService.php @@ -3,13 +3,13 @@ namespace App\Services\Finance; use App\Events\Expenses as ExpensesEvent; +use App\Interfaces\Service; use App\Models\Enums\ExpenseType; use App\Models\Enums\PirepSource; use App\Models\Expense; use App\Models\Pirep; use App\Repositories\ExpenseRepository; use App\Repositories\JournalRepository; -use App\Services\BaseService; use App\Services\FareService; use App\Services\PirepService; use App\Support\Math; @@ -21,7 +21,7 @@ use Log; * @package App\Services * */ -class PirepFinanceService extends BaseService +class PirepFinanceService extends Service { private $expenseRepo, $fareSvc, @@ -31,16 +31,17 @@ class PirepFinanceService extends BaseService /** * FinanceService constructor. * @param ExpenseRepository $expenseRepo - * @param FareService $fareSvc + * @param FareService $fareSvc * @param JournalRepository $journalRepo - * @param PirepService $pirepSvc + * @param PirepService $pirepSvc */ public function __construct( ExpenseRepository $expenseRepo, FareService $fareSvc, JournalRepository $journalRepo, PirepService $pirepSvc - ) { + ) + { $this->expenseRepo = $expenseRepo; $this->fareSvc = $fareSvc; $this->journalRepo = $journalRepo; @@ -59,7 +60,7 @@ class PirepFinanceService extends BaseService */ public function processFinancesForPirep(Pirep $pirep) { - if(!$pirep->airline->journal) { + if (!$pirep->airline->journal) { $pirep->airline->journal = $pirep->airline->initJournal(config('phpvms.currency')); } @@ -108,7 +109,6 @@ class PirepFinanceService extends BaseService $fares = $this->getReconciledFaresForPirep($pirep); /** @var \App\Models\Fare $fare */ foreach ($fares as $fare) { - Log::info('Finance: PIREP: '.$pirep->id.', fare:', $fare->toArray()); $credit = Money::createFromAmount($fare->count * $fare->price); @@ -119,8 +119,8 @@ class PirepFinanceService extends BaseService $credit, $debit, $pirep, - 'Fares ' . $fare->code . $fare->count - .'; price: '.$fare->price.', cost: '.$fare->cost, + 'Fares '.$fare->code.$fare->count + .'; price: '.$fare->price.', cost: '.$fare->cost, null, 'Fares', 'fare' @@ -145,8 +145,7 @@ class PirepFinanceService extends BaseService /** * Go through the expenses and apply a mulitplier if present */ - $expenses->map(function ($expense, $i) use ($pirep) - { + $expenses->map(function ($expense, $i) use ($pirep) { /*if ($expense->multiplier) { # TODO: Modify the amount }*/ @@ -157,7 +156,7 @@ class PirepFinanceService extends BaseService # This way it can be more dynamic and don't have to add special # tables or specific expense calls to accomodate all of these $klass = 'Expense'; - if($expense->ref_class) { + if ($expense->ref_class) { $ref = explode('\\', $expense->ref_class); $klass = end($ref); } @@ -240,7 +239,7 @@ class PirepFinanceService extends BaseService null, $debit, $pirep, - 'Expense: ' . $expense->name, + 'Expense: '.$expense->name, null, $expense->transaction_group ?? 'Expenses', 'expense' @@ -284,7 +283,7 @@ class PirepFinanceService extends BaseService { $pilot_pay = $this->getPilotPay($pirep); $pilot_pay_rate = $this->getPilotPayRateForPirep($pirep); - $memo = 'Pilot Payment @ ' . $pilot_pay_rate; + $memo = 'Pilot Payment @ '.$pilot_pay_rate; Log::info('Finance: PIREP: '.$pirep->id .'; pilot pay: '.$pilot_pay_rate.', total: '.$pilot_pay); @@ -329,29 +328,27 @@ class PirepFinanceService extends BaseService { # Collect all of the fares and prices $flight_fares = $this->fareSvc->getForPirep($pirep); - Log::info('Finance: PIREP: ' . $pirep->id . ', flight fares: ', $flight_fares->toArray()); + Log::info('Finance: PIREP: '.$pirep->id.', flight fares: ', $flight_fares->toArray()); $all_fares = $this->fareSvc->getAllFares($pirep->flight, $pirep->aircraft->subfleet); - $fares = $all_fares->map(function($fare, $i) use ($flight_fares, $pirep) { - + $fares = $all_fares->map(function ($fare, $i) use ($flight_fares, $pirep) { $fare_count = $flight_fares ->where('fare_id', $fare->id) ->first(); - if($fare_count) { - - Log::info('Finance: PIREP: ' . $pirep->id . ', fare count: '. $fare_count); + if ($fare_count) { + Log::info('Finance: PIREP: '.$pirep->id.', fare count: '.$fare_count); # If the count is greater than capacity, then just set it # to the maximum amount - if($fare_count->count > $fare->capacity) { + if ($fare_count->count > $fare->capacity) { $fare->count = $fare->capacity; } else { $fare->count = $fare_count->count; } } else { - Log::info('Finance: PIREP: ' . $pirep->id . ', no fare count found', $fare->toArray()); + Log::info('Finance: PIREP: '.$pirep->id.', no fare count found', $fare->toArray()); } return $fare; @@ -368,9 +365,10 @@ class PirepFinanceService extends BaseService */ public function getGroundHandlingCost(Pirep $pirep) { - if(filled($pirep->aircraft->subfleet->ground_handling_multiplier)) { + if (filled($pirep->aircraft->subfleet->ground_handling_multiplier)) { // force into percent mode $multiplier = $pirep->aircraft->subfleet->ground_handling_multiplier.'%'; + return Math::applyAmountOrPercent( $pirep->arr_airport->ground_handling_cost, $multiplier @@ -397,28 +395,28 @@ class PirepFinanceService extends BaseService ->where('subfleet_id', $subfleet_id) ->first(); - if($override_rate) { + if ($override_rate) { $override_rate = $override_rate->pivot; } - if($pirep->source === PirepSource::ACARS) { + if ($pirep->source === PirepSource::ACARS) { Log::debug('Source is ACARS'); $base_rate = $rank->acars_base_pay_rate; - if($override_rate) { + if ($override_rate) { $override_rate = $override_rate->acars_pay; } - } else { Log::debug('Source is Manual'); $base_rate = $rank->manual_base_pay_rate; - if($override_rate) { + if ($override_rate) { $override_rate = $override_rate->manual_pay; } } - Log::debug('pilot pay: base rate=' . $base_rate . ', override=' . $override_rate); + Log::debug('pilot pay: base rate='.$base_rate.', override='.$override_rate); + return Math::applyAmountOrPercent( $base_rate, $override_rate diff --git a/app/Services/Finance/RecurringFinanceService.php b/app/Services/Finance/RecurringFinanceService.php index a91cd0db..6c9b616f 100644 --- a/app/Services/Finance/RecurringFinanceService.php +++ b/app/Services/Finance/RecurringFinanceService.php @@ -2,12 +2,12 @@ namespace App\Services\Finance; +use App\Interfaces\Service; use App\Models\Airline; use App\Models\Enums\ExpenseType; use App\Models\Expense; use App\Models\JournalTransaction; use App\Repositories\JournalRepository; -use App\Services\BaseService; use App\Support\Money; use Log; @@ -15,10 +15,14 @@ use Log; * Process all of the daily expenses and charge them * @package App\Services\Finance */ -class RecurringFinanceService extends BaseService +class RecurringFinanceService extends Service { private $journalRepo; + /** + * RecurringFinanceService constructor. + * @param JournalRepository $journalRepo + */ public function __construct(JournalRepository $journalRepo) { $this->journalRepo = $journalRepo; @@ -32,14 +36,14 @@ class RecurringFinanceService extends BaseService */ protected function findJournals(Expense $expense) { - if($expense->airline_id) { + if ($expense->airline_id) { $airline = Airline::find($expense->airline_id)->first(['id', 'icao']); - Log::info('Charging to ' . $airline->icao); + Log::info('Charging to '.$airline->icao); yield $airline->journal; } else { $airlines = Airline::all(['id', 'icao']); - foreach($airlines as $airline) { - Log::info('Charging to ' . $airline->icao); + foreach ($airlines as $airline) { + Log::info('Charging to '.$airline->icao); yield $airline->journal; } } @@ -76,7 +80,6 @@ class RecurringFinanceService extends BaseService return [$memo, $transaction_group]; } - /** * Run all of the daily expense/financials * @param int $type @@ -84,12 +87,12 @@ class RecurringFinanceService extends BaseService * @throws \InvalidArgumentException * @throws \Prettus\Validator\Exceptions\ValidatorException */ - public function processExpenses($type=ExpenseType::DAILY): void + public function processExpenses($type = ExpenseType::DAILY): void { $expenses = Expense::where(['type' => $type])->get(); $tag = 'expense_recurring'; - if($type === ExpenseType::DAILY) { + if ($type === ExpenseType::DAILY) { $tag = 'expenses_daily'; } elseif ($type === ExpenseType::MONTHLY) { $tag === 'expenses_monthly'; @@ -99,18 +102,16 @@ class RecurringFinanceService extends BaseService * @var $expenses Expense[] */ foreach ($expenses as $expense) { - # Apply the expenses to the appropriate journals $journals = $this->findJournals($expense); - foreach($journals as $journal) { - + foreach ($journals as $journal) { $amount = $expense->amount; # Has this expense already been charged? Check # against this specific journal, on today $w = [ - 'journal_id' => $journal->id, - 'ref_class' => Expense::class, + 'journal_id' => $journal->id, + 'ref_class' => Expense::class, 'ref_class_id' => $expense->id, ]; @@ -118,7 +119,7 @@ class RecurringFinanceService extends BaseService ->whereDate('post_date', '=', \Carbon::now('UTC')->toDateString()) ->count(['id']); - if($found > 0) { + if ($found > 0) { Log::info('Expense "'.$expense->name.'" already charged for today, skipping'); continue; } @@ -136,7 +137,7 @@ class RecurringFinanceService extends BaseService $tag ); - Log::info('Expense memo: "'.$memo.'"; group: "'. $ta_group. '" charged!'); + Log::info('Expense memo: "'.$memo.'"; group: "'.$ta_group.'" charged!'); } } } diff --git a/app/Services/FleetService.php b/app/Services/FleetService.php index d1907279..1106b7c2 100644 --- a/app/Services/FleetService.php +++ b/app/Services/FleetService.php @@ -2,27 +2,33 @@ namespace App\Services; +use App\Interfaces\Service; use App\Models\Rank; use App\Models\Subfleet; -class FleetService extends BaseService +/** + * Class FleetService + * @package App\Services + */ +class FleetService extends Service { /** * @param Subfleet $subfleet - * @param Rank $rank - * @param array $overrides + * @param Rank $rank + * @param array $overrides * @return Subfleet */ - public function addSubfleetToRank(Subfleet $subfleet, Rank $rank, array $overrides=[]) + public function addSubfleetToRank(Subfleet $subfleet, Rank $rank, array $overrides = []) { $subfleet->ranks()->syncWithoutDetaching([$rank->id]); - if($overrides) { + if ($overrides) { $subfleet->ranks()->updateExistingPivot($rank->id, $overrides); } $subfleet->save(); $subfleet->refresh(); + return $subfleet; } @@ -32,6 +38,7 @@ class FleetService extends BaseService $subfleet->save(); $subfleet->refresh(); + return $subfleet; } } diff --git a/app/Services/FlightService.php b/app/Services/FlightService.php index 52d54efc..6cc5e22a 100644 --- a/app/Services/FlightService.php +++ b/app/Services/FlightService.php @@ -3,10 +3,10 @@ namespace App\Services; use App\Exceptions\BidExists; -use App\Models\Flight; -use App\Models\Subfleet; -use App\Models\User; +use App\Interfaces\Service; use App\Models\Bid; +use App\Models\Flight; +use App\Models\User; use App\Repositories\FlightRepository; use App\Repositories\NavdataRepository; use Log; @@ -15,20 +15,26 @@ use Log; * Class FlightService * @package App\Services */ -class FlightService extends BaseService +class FlightService extends Service { private $fareSvc, - $flightRepo, - $navDataRepo, - $userSvc; + $flightRepo, + $navDataRepo, + $userSvc; + /** + * 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; @@ -59,7 +65,6 @@ class FlightService extends BaseService */ public function filterSubfleets($user, $flight) { - $subfleets = $flight->subfleets; /** @@ -135,7 +140,7 @@ class FlightService extends BaseService /** * Allow a user to bid on a flight. Check settings and all that good stuff * @param Flight $flight - * @param User $user + * @param User $user * @return Bid|null * @throws \App\Exceptions\BidExists */ @@ -143,7 +148,7 @@ class FlightService extends BaseService { # If it's already been bid on, then it can't be bid on again if ($flight->has_bid && setting('bids.disable_flight_on_bid')) { - Log::info($flight->id . ' already has a bid, skipping'); + Log::info($flight->id.' already has a bid, skipping'); throw new BidExists(); } @@ -151,14 +156,14 @@ class FlightService extends BaseService if (!setting('bids.allow_multiple_bids')) { $user_bids = Bid::where(['user_id' => $user->id])->first(); if ($user_bids) { - Log::info('User "' . $user->id . '" already has bids, skipping'); + Log::info('User "'.$user->id.'" already has bids, skipping'); throw new BidExists(); } } # See if this user has this flight bid on already $bid_data = [ - 'user_id' => $user->id, + 'user_id' => $user->id, 'flight_id' => $flight->id ]; @@ -178,7 +183,7 @@ class FlightService extends BaseService /** * Remove a bid from a given flight * @param Flight $flight - * @param User $user + * @param User $user */ public function removeBid(Flight $flight, User $user) { diff --git a/app/Services/GeoService.php b/app/Services/GeoService.php index e01184a6..51516fe2 100644 --- a/app/Services/GeoService.php +++ b/app/Services/GeoService.php @@ -2,6 +2,7 @@ namespace App\Services; +use App\Interfaces\Service; use App\Models\Acars; use App\Models\Enums\AcarsType; use App\Models\Flight; @@ -19,10 +20,15 @@ use Log; * Class GeoService * @package App\Services */ -class GeoService extends BaseService +class GeoService extends Service { private $acarsRepo, $navRepo; + /** + * GeoService constructor. + * @param AcarsRepository $acarsRepo + * @param NavdataRepository $navRepo + */ public function __construct( AcarsRepository $acarsRepo, NavdataRepository $navRepo @@ -44,7 +50,7 @@ class GeoService extends BaseService $geotools = new Geotools(); $start = new Coordinate($coordStart); - foreach($all_coords as $coords) { + foreach ($all_coords as $coords) { $coord = new Coordinate($coords); $dist = $geotools->distance()->setFrom($start)->setTo($coord); $distance[] = $dist->greatCircle(); @@ -52,7 +58,8 @@ class GeoService extends BaseService $distance = collect($distance); $min = $distance->min(); - return $all_coords[ $distance->search($min, true) ]; + + return $all_coords[$distance->search($min, true)]; } /** @@ -70,10 +77,13 @@ class GeoService extends BaseService $coords = []; $filter_points = [$dep_icao, $arr_icao, 'SID', 'STAR']; - $split_route = collect(explode(' ', $route))->transform(function($point) { - if(empty($point)) { return false; } + $split_route = collect(explode(' ', $route))->transform(function ($point) { + if (empty($point)) { + return false; + } + return strtoupper(trim($point)); - })->filter(function($point) use ($filter_points) { + })->filter(function ($point) use ($filter_points) { return !(empty($point) || \in_array($point, $filter_points, true)); }); @@ -81,13 +91,12 @@ class GeoService extends BaseService * @var $split_route Collection * @var $route_point Acars */ - foreach ($split_route as $route_point) - { - Log::debug('Looking for ' . $route_point); + foreach ($split_route as $route_point) { + Log::debug('Looking for '.$route_point); try { $points = $this->navRepo->findWhere(['id' => $route_point]); - } catch(ModelNotFoundException $e){ + } catch (ModelNotFoundException $e) { continue; } catch (\Exception $e) { Log::error($e); @@ -100,13 +109,13 @@ class GeoService extends BaseService continue; } elseif ($size === 1) { $point = $points[0]; - Log::debug('name: ' . $point->id . ' - ' . $point->lat . 'x' . $point->lon); + Log::debug('name: '.$point->id.' - '.$point->lat.'x'.$point->lon); $coords[] = $point; continue; } # Find the point with the shortest distance - Log::info('found ' . $size . ' for '. $route_point); + Log::info('found '.$size.' for '.$route_point); # Get the start point and then reverse the lat/lon reference # If the first point happens to have multiple possibilities, use @@ -121,14 +130,14 @@ class GeoService extends BaseService # Put all of the lat/lon sets into an array to pick of what's clsest # to the starting point $potential_coords = []; - foreach($points as $point) { + foreach ($points as $point) { $potential_coords[] = [$point->lat, $point->lon]; } # returns an array with the closest lat/lon to start point $closest_coords = $this->getClosestCoords($start_point, $potential_coords); - foreach($points as $point) { - if($point->lat === $closest_coords[0] && $point->lon === $closest_coords[1]) { + foreach ($points as $point) { + if ($point->lat === $closest_coords[0] && $point->lon === $closest_coords[1]) { break; } } @@ -181,14 +190,13 @@ class GeoService extends BaseService foreach ($pirep->acars as $point) { $route->addPoint($point->lat, $point->lon, [ 'pirep_id' => $pirep->id, - 'name' => $point->altitude, - 'popup' => $counter . '
GS: ' . $point->gs . '
Alt: ' . $point->altitude, + 'name' => $point->altitude, + 'popup' => $counter.'
GS: '.$point->gs.'
Alt: '.$point->altitude, ]); - } return [ - 'line' => $route->getLine(), + 'line' => $route->getLine(), 'points' => $route->getPoints() ]; } @@ -203,22 +211,21 @@ class GeoService extends BaseService /** * @var Pirep $pirep */ - foreach($pireps as $pirep) { - + foreach ($pireps as $pirep) { /** * @var $point \App\Models\Acars */ $point = $pirep->position; - if(!$point) { + if (!$point) { continue; } $flight->addPoint($point->lat, $point->lon, [ - 'pirep_id' => $pirep->id, - 'gs' => $point->gs, - 'alt' => $point->altitude, - 'heading' => $point->heading ?: 0, - 'popup' => $pirep->ident . '
GS: ' . $point->gs . '
Alt: ' . $point->altitude, + 'pirep_id' => $pirep->id, + 'gs' => $point->gs, + 'alt' => $point->altitude, + 'heading' => $point->heading ?: 0, + 'popup' => $pirep->ident.'
GS: '.$point->gs.'
Alt: '.$point->altitude, ]); } @@ -236,12 +243,12 @@ class GeoService extends BaseService ## Departure Airport $route->addPoint($flight->dpt_airport->lat, $flight->dpt_airport->lon, [ - 'name' => $flight->dpt_airport->icao, + 'name' => $flight->dpt_airport->icao, 'popup' => $flight->dpt_airport->full_name, - 'icon' => 'airport', + 'icon' => 'airport', ]); - if($flight->route) { + if ($flight->route) { $all_route_points = $this->getCoordsFromRoute( $flight->dpt_airport->icao, $flight->arr_airport->icao, @@ -249,10 +256,10 @@ class GeoService extends BaseService $flight->route); // lat, lon needs to be reversed for GeoJSON - foreach($all_route_points as $point) { + foreach ($all_route_points as $point) { $route->addPoint($point->lat, $point->lon, [ 'name' => $point->name, - 'popup' => $point->name . ' (' . $point->name . ')', + 'popup' => $point->name.' ('.$point->name.')', 'icon' => '' ]); } @@ -265,8 +272,8 @@ class GeoService extends BaseService ]); return [ - 'route_points' => $route->getPoints(), - 'planned_route_line' => $route->getLine(), + 'route_points' => $route->getPoints(), + 'planned_route_line' => $route->getLine(), ]; } @@ -284,22 +291,22 @@ class GeoService extends BaseService * PLANNED ROUTE */ $planned->addPoint($pirep->dpt_airport->lat, $pirep->dpt_airport->lon, [ - 'name' => $pirep->dpt_airport->icao, + 'name' => $pirep->dpt_airport->icao, 'popup' => $pirep->dpt_airport->full_name, ]); $planned_route = $this->acarsRepo->forPirep($pirep->id, AcarsType::ROUTE); - foreach($planned_route as $point) { + foreach ($planned_route as $point) { $planned->addPoint($point->lat, $point->lon, [ - 'name' => $point->name, - 'popup' => $point->name . ' (' . $point->name . ')', + 'name' => $point->name, + 'popup' => $point->name.' ('.$point->name.')', ]); } $planned->addPoint($pirep->arr_airport->lat, $pirep->arr_airport->lon, [ - 'name' => $pirep->arr_airport->icao, + 'name' => $pirep->arr_airport->icao, 'popup' => $pirep->arr_airport->full_name, - 'icon' => 'airport', + 'icon' => 'airport', ]); /** @@ -309,14 +316,14 @@ class GeoService extends BaseService foreach ($actual_route as $point) { $actual->addPoint($point->lat, $point->lon, [ 'pirep_id' => $pirep->id, - 'name' => $point->altitude, - 'popup' => 'GS: ' . $point->gs . '
Alt: ' . $point->altitude, + 'name' => $point->altitude, + 'popup' => 'GS: '.$point->gs.'
Alt: '.$point->altitude, ]); } return [ - 'planned_rte_points' => $planned->getPoints(), - 'planned_rte_line' => $planned->getLine(), + 'planned_rte_points' => $planned->getPoints(), + 'planned_rte_line' => $planned->getLine(), 'actual_route_points' => $actual->getPoints(), 'actual_route_line' => $actual->getLine(), diff --git a/app/Services/ImporterService.php b/app/Services/ImporterService.php index 0f7598c4..013c0c10 100644 --- a/app/Services/ImporterService.php +++ b/app/Services/ImporterService.php @@ -2,16 +2,21 @@ namespace App\Services; +use App\Interfaces\Service; use App\Repositories\FlightRepository; /** * Class ImporterService * @package App\Services */ -class ImporterService extends BaseService +class ImporterService extends Service { protected $flightRepo; + /** + * ImporterService constructor. + * @param FlightRepository $flightRepo + */ public function __construct( FlightRepository $flightRepo ) { @@ -20,13 +25,13 @@ class ImporterService extends BaseService /** * Set a key-value pair to an array - * @param $kvp_str + * @param $kvp_str * @param array $arr */ protected function setKvp($kvp_str, array &$arr) { $item = explode('=', $kvp_str); - if(\count($item) === 1) { # just a list? + if (\count($item) === 1) { # just a list? $arr[] = trim($item[0]); } else { # actually a key-value pair $k = trim($item[0]); @@ -52,15 +57,14 @@ class ImporterService extends BaseService $split_values = explode(';', $field); # No multiple values in here, just a straight value - if(\count($split_values) === 1) { + if (\count($split_values) === 1) { return $split_values[0]; } - foreach($split_values as $value) { - + foreach ($split_values as $value) { # This isn't in the query string format, so it's # just a straight key-value pair set - if(strpos($value, '?') === false) { + if (strpos($value, '?') === false) { $this->setKvp($value, $ret); continue; } @@ -73,7 +77,7 @@ class ImporterService extends BaseService $children = []; $kvp = explode('&', trim($query_str[1])); - foreach($kvp as $items) { + foreach ($kvp as $items) { $this->setKvp($items, $children); } @@ -85,11 +89,10 @@ class ImporterService extends BaseService /** * Import flights - * @param $csv_str + * @param $csv_str * @param bool $delete_previous */ - public function importFlights($csv_str, bool $delete_previous=true) + public function importFlights($csv_str, bool $delete_previous = true) { - } } diff --git a/app/Services/ModuleService.php b/app/Services/ModuleService.php index 02cef0a2..9b990d7e 100644 --- a/app/Services/ModuleService.php +++ b/app/Services/ModuleService.php @@ -2,15 +2,23 @@ namespace App\Services; -class ModuleService extends BaseService +use App\Interfaces\Service; + +/** + * Class ModuleService + * @package App\Services + */ +class ModuleService extends Service { protected static $adminLinks = []; /** * @var array 0 == logged out, 1 == logged in */ - protected static $frontendLinks = [0 => [], 1 => []]; - + protected static $frontendLinks = [ + 0 => [], + 1 => [] + ]; /** * Add a module link in the frontend @@ -18,12 +26,12 @@ class ModuleService extends BaseService * @param string $url * @param string $icon */ - public function addFrontendLink(string $title, string $url, string $icon = '', $logged_in=true) + public function addFrontendLink(string $title, string $url, string $icon = '', $logged_in = true) { self::$frontendLinks[$logged_in][] = [ 'title' => $title, - 'url' => $url, - 'icon' => 'pe-7s-users', + 'url' => $url, + 'icon' => 'pe-7s-users', ]; } @@ -42,12 +50,12 @@ class ModuleService extends BaseService * @param string $url * @param string $icon */ - public function addAdminLink(string $title, string $url, string $icon='') + public function addAdminLink(string $title, string $url, string $icon = '') { self::$adminLinks[] = [ 'title' => $title, - 'url' => $url, - 'icon' => 'pe-7s-users' + 'url' => $url, + 'icon' => 'pe-7s-users' ]; } diff --git a/app/Services/PirepService.php b/app/Services/PirepService.php index 93db1f68..eadea636 100644 --- a/app/Services/PirepService.php +++ b/app/Services/PirepService.php @@ -6,6 +6,7 @@ use App\Events\PirepAccepted; use App\Events\PirepFiled; use App\Events\PirepRejected; use App\Events\UserStatsChanged; +use App\Interfaces\Service; use App\Models\Acars; use App\Models\Bid; use App\Models\Enums\AcarsType; @@ -27,23 +28,23 @@ use Log; * Class PirepService * @package App\Services */ -class PirepService extends BaseService +class PirepService extends Service { private $acarsRepo, - $flightRepo, - $geoSvc, - $navRepo, - $pilotSvc, - $pirepRepo; + $flightRepo, + $geoSvc, + $navRepo, + $pilotSvc, + $pirepRepo; /** * PirepService constructor. - * @param AcarsRepository $acarsRepo - * @param FlightRepository $flightRepo - * @param GeoService $geoSvc + * @param AcarsRepository $acarsRepo + * @param FlightRepository $flightRepo + * @param GeoService $geoSvc * @param NavdataRepository $navRepo - * @param PirepRepository $pirepRepo - * @param UserService $pilotSvc + * @param PirepRepository $pirepRepo + * @param UserService $pilotSvc */ public function __construct( AcarsRepository $acarsRepo, @@ -52,8 +53,7 @@ class PirepService extends BaseService NavdataRepository $navRepo, PirepRepository $pirepRepo, UserService $pilotSvc - ) - { + ) { $this->acarsRepo = $acarsRepo; $this->flightRepo = $flightRepo; $this->geoSvc = $geoSvc; @@ -74,8 +74,8 @@ class PirepService extends BaseService $time_limit = Carbon::now()->subMinutes($minutes)->toDateTimeString(); $where = [ - 'user_id' => $pirep->user_id, - 'airline_id' => $pirep->airline_id, + 'user_id' => $pirep->user_id, + 'airline_id' => $pirep->airline_id, 'flight_number' => $pirep->flight_number, ]; @@ -114,7 +114,7 @@ class PirepService extends BaseService # Delete all the existing nav points Acars::where([ 'pirep_id' => $pirep->id, - 'type' => AcarsType::ROUTE, + 'type' => AcarsType::ROUTE, ])->delete(); # See if a route exists @@ -123,7 +123,8 @@ class PirepService extends BaseService } if (!filled($pirep->dpt_airport)) { - Log::error('saveRoute: dpt_airport not found: ' . $pirep->dpt_airport_id); + Log::error('saveRoute: dpt_airport not found: '.$pirep->dpt_airport_id); + return $pirep; } @@ -203,7 +204,7 @@ class PirepService extends BaseService /** * Update any custom PIREP fields - * @param $pirep_id + * @param $pirep_id * @param array $field_values */ public function updateCustomFields($pirep_id, array $field_values) @@ -211,10 +212,10 @@ class PirepService extends BaseService foreach ($field_values as $fv) { PirepFieldValues::updateOrCreate( ['pirep_id' => $pirep_id, - 'name' => $fv['name'] + 'name' => $fv['name'] ], - ['value' => $fv['value'], - 'source' => $fv['source'] + ['value' => $fv['value'], + 'source' => $fv['source'] ] ); } @@ -222,12 +223,12 @@ class PirepService extends BaseService /** * @param Pirep $pirep - * @param int $new_state + * @param int $new_state * @return Pirep */ public function changeState(Pirep $pirep, int $new_state) { - Log::info('PIREP ' . $pirep->id . ' state change from ' . $pirep->state . ' to ' . $new_state); + Log::info('PIREP '.$pirep->id.' state change from '.$pirep->state.' to '.$new_state); if ($pirep->state === $new_state) { return $pirep; @@ -249,12 +250,14 @@ class PirepService extends BaseService */ elseif ($pirep->state === PirepState::ACCEPTED) { $pirep = $this->reject($pirep); + return $pirep; } /** * Move from REJECTED to ACCEPTED */ elseif ($pirep->state === PirepState::REJECTED) { $pirep = $this->accept($pirep); + return $pirep; } @@ -285,7 +288,7 @@ class PirepService extends BaseService $pirep->save(); $pirep->refresh(); - Log::info('PIREP ' . $pirep->id . ' state change to ACCEPTED'); + Log::info('PIREP '.$pirep->id.' state change to ACCEPTED'); # Update the aircraft $pirep->aircraft->flight_time += $pirep->flight_time; @@ -330,7 +333,7 @@ class PirepService extends BaseService $pirep->aircraft->flight_time -= $pirep->flight_time; $pirep->aircraft->save(); - Log::info('PIREP ' . $pirep->id . ' state change to REJECTED'); + Log::info('PIREP '.$pirep->id.' state change to REJECTED'); event(new PirepRejected($pirep)); @@ -366,16 +369,16 @@ class PirepService extends BaseService } $flight = $pirep->flight; - if(!$flight) { + if (!$flight) { return; } $bid = Bid::where([ - 'user_id' => $pirep->user->id, + 'user_id' => $pirep->user->id, 'flight_id' => $flight->id, ]); - if($bid) { + if ($bid) { Log::info('Bid for user: '.$pirep->user->pilot_id.' on flight '.$flight->ident); $bid->delete(); } diff --git a/app/Services/UserService.php b/app/Services/UserService.php index e719c2d7..5c8b45b3 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -5,7 +5,7 @@ namespace App\Services; use App\Events\UserRegistered; use App\Events\UserStateChanged; use App\Events\UserStatsChanged; -use App\Facades\Utils; +use App\Interfaces\Service; use App\Models\Enums\UserState; use App\Models\Rank; use App\Models\Role; @@ -16,9 +16,14 @@ use App\Support\Units\Time; use Illuminate\Support\Collection; use Log; -class UserService extends BaseService +/** + * Class UserService + * @package App\Services + */ +class UserService extends Service { - protected $aircraftRepo, $subfleetRepo; + private $aircraftRepo, + $subfleetRepo; /** * UserService constructor. @@ -36,15 +41,15 @@ class UserService extends BaseService /** * Register a pilot. Also attaches the initial roles * required, and then triggers the UserRegistered event - * @param User $user User model + * @param User $user User model * @param array $groups Additional groups to assign * @return mixed * @throws \Exception */ - public function createPilot(User $user, array $groups=null) + public function createPilot(User $user, array $groups = null) { # Determine if we want to auto accept - if(setting('pilots.auto_accept') === true) { + if (setting('pilots.auto_accept') === true) { $user->state = UserState::ACTIVE; } else { $user->state = UserState::PENDING; @@ -56,7 +61,7 @@ class UserService extends BaseService $role = Role::where('name', 'user')->first(); $user->attachRole($role); - if(!empty($groups) && \is_array($groups)) { + if (!empty($groups) && \is_array($groups)) { foreach ($groups as $group) { $role = Role::where('name', $group)->first(); $user->attachRole($role); @@ -80,11 +85,12 @@ class UserService extends BaseService */ public function getAllowableSubfleets($user) { - if($user === null || setting('pireps.restrict_aircraft_to_rank') === false) { + if ($user === null || setting('pireps.restrict_aircraft_to_rank') === false) { return $this->subfleetRepo->with('aircraft')->all(); } $subfleets = $user->rank->subfleets(); + return $subfleets->with('aircraft')->get(); } @@ -107,18 +113,18 @@ class UserService extends BaseService * Change the user's state. PENDING to ACCEPTED, etc * Send out an email * @param User $user - * @param $old_state + * @param $old_state * @return User */ public function changeUserState(User $user, $old_state): User { - if($user->state === $old_state) { + if ($user->state === $old_state) { return $user; } - Log::info('User ' . $user->pilot_id . ' state changing from ' - . UserState::label($old_state) . ' to ' - . UserState::label($user->state)); + Log::info('User '.$user->pilot_id.' state changing from ' + .UserState::label($old_state).' to ' + .UserState::label($user->state)); event(new UserStateChanged($user, $old_state)); @@ -129,7 +135,7 @@ class UserService extends BaseService * Adjust the number of flights a user has. Triggers * UserStatsChanged event * @param User $user - * @param int $count + * @param int $count * @return User */ public function adjustFlightCount(User $user, int $count): User @@ -147,7 +153,7 @@ class UserService extends BaseService /** * Update a user's flight times * @param User $user - * @param int $minutes + * @param int $minutes * @return User */ public function adjustFlightTime(User $user, int $minutes): User @@ -159,7 +165,6 @@ class UserService extends BaseService return $user; } - /** * See if a pilot's rank has change. Triggers the UserStatsChanged event * @param User $user @@ -171,7 +176,7 @@ class UserService extends BaseService # If their current rank is one they were assigned, then # don't change away from it automatically. - if($user->rank && $user->rank->auto_promote === false) { + if ($user->rank && $user->rank->auto_promote === false) { return $user; } @@ -180,7 +185,7 @@ class UserService extends BaseService # The current rank's hours are over the pilot's current hours, # so assume that they were "placed" here by an admin so don't # bother with updating it - if($user->rank && $user->rank->hours > $pilot_hours->hours) { + if ($user->rank && $user->rank->hours > $pilot_hours->hours) { return $user; } @@ -188,10 +193,10 @@ class UserService extends BaseService $original_rank_id = $user->rank_id; $ranks = Rank::where('auto_promote', true) - ->orderBy('hours', 'asc')->get(); + ->orderBy('hours', 'asc')->get(); foreach ($ranks as $rank) { - if($rank->hours > $pilot_hours->hours) { + if ($rank->hours > $pilot_hours->hours) { break; } else { $user->rank_id = $rank->id; @@ -199,7 +204,7 @@ class UserService extends BaseService } // Only trigger the event/update if there's been a change - if($user->rank_id !== $original_rank_id) { + if ($user->rank_id !== $original_rank_id) { $user->save(); $user->refresh(); event(new UserStatsChanged($user, 'rank', $old_rank)); diff --git a/app/Support/ClassLoader.php b/app/Support/ClassLoader.php index 5223adb8..ec9b3f61 100644 --- a/app/Support/ClassLoader.php +++ b/app/Support/ClassLoader.php @@ -2,8 +2,8 @@ namespace App\Support; -use Symfony\Component\ClassLoader\ClassMapGenerator; use Log; +use Symfony\Component\ClassLoader\ClassMapGenerator; class ClassLoader { @@ -11,7 +11,7 @@ class ClassLoader * @param $path * @return array */ - public static function getClassesInPath($path) + public static function getClassesInPath($path): array { if (!file_exists($path)) { return []; @@ -23,7 +23,7 @@ class ClassLoader try { $klass = new $cl; } catch (\Exception $e) { - Log::error('Error loading class: ' . $e->getMessage()); + Log::error('Error loading class: '.$e->getMessage()); continue; } diff --git a/app/Support/Dates.php b/app/Support/Dates.php index 3c00320e..4a69cba8 100644 --- a/app/Support/Dates.php +++ b/app/Support/Dates.php @@ -1,7 +1,4 @@ format('Y-m'); - $months[$last_value] = $last_month->format ('Y F'); + $months[$last_value] = $last_month->format('Y F'); $last_month = $last_month->addMonth(); - } while($last_value !== $now); + } while ($last_value !== $now); return $months; } diff --git a/app/Support/ICAO.php b/app/Support/ICAO.php index 6cc92b68..71080394 100644 --- a/app/Support/ICAO.php +++ b/app/Support/ICAO.php @@ -8,14 +8,13 @@ namespace App\Support; */ class ICAO { - /** * Create a random hex code. Eventually this may follow the format in: * ICAO Aeronautical Telecommunications, Annex 10, Vol. III, chapter 9 * @param null $country * @return string */ - public static function createHexCode($country=null) + public static function createHexCode($country = null) { $bytes = random_bytes(4); return bin2hex($bytes); diff --git a/app/Support/Math.php b/app/Support/Math.php index badda574..8e963752 100644 --- a/app/Support/Math.php +++ b/app/Support/Math.php @@ -37,14 +37,14 @@ class Math */ public static function addPercent($number, $percent): float { - if(!is_numeric($number)) { + if (!is_numeric($number)) { $number = (float) $number; } - if(!is_numeric($percent)) { + if (!is_numeric($percent)) { $percent = (float) $percent; } - return $number + ($number * ($percent/100)); + return $number + ($number * ($percent / 100)); } } diff --git a/app/Support/Money.php b/app/Support/Money.php index 03109928..d6dbcaba 100644 --- a/app/Support/Money.php +++ b/app/Support/Money.php @@ -16,7 +16,6 @@ class Money { public $money; public $subunit_amount; - public static $iso_currencies; public static $subunit_multiplier; @@ -60,6 +59,7 @@ class Money * Create a new currency object using the currency setting * Fall back to USD if it's not valid * @return Currency + * @throws \OutOfBoundsException */ public static function currency() { @@ -68,7 +68,6 @@ class Money } catch (\OutOfBoundsException $e) { return new Currency('USD'); } - } /** @@ -145,16 +144,19 @@ class Money /** * Add an amount * @param $amount + * @return Money * @throws \UnexpectedValueException * @throws \InvalidArgumentException */ public function add($amount) { - if(!($amount instanceof self)) { + if (!($amount instanceof self)) { $amount = static::createFromAmount($amount); } $this->money = $this->money->add($amount->money); + + return $this; } /** @@ -166,11 +168,12 @@ class Money public function addPercent($percent) { if (!is_numeric($percent)) { - $percent = (float)$percent; + $percent = (float) $percent; } $amount = $this->money->multiply($percent / 100); $this->money = $this->money->add($amount); + return $this; } @@ -188,6 +191,7 @@ class Money } $this->money = $this->money->subtract($amount->money); + return $this; } @@ -206,6 +210,7 @@ class Money } $this->money = $this->money->multiply($amount->money); + return $this; } @@ -230,15 +235,16 @@ class Money */ public function equals($money) { - if($money instanceof self) { + if ($money instanceof self) { return $this->money->equals($money->money); } - if($money instanceof MoneyBase) { + if ($money instanceof MoneyBase) { return $this->money->equals($money); } $money = static::convertToSubunit($money); + return $this->money->equals(static::create($money)); } } diff --git a/app/Support/Units/Altitude.php b/app/Support/Units/Altitude.php index f3a5cb79..61724201 100644 --- a/app/Support/Units/Altitude.php +++ b/app/Support/Units/Altitude.php @@ -17,6 +17,7 @@ class Altitude extends \PhpUnitsOfMeasure\PhysicalQuantity\Length implements Arr { $unit = setting('units.altitude'); $value = $this->toUnit($unit); + return (string) round($value, 2); } @@ -35,8 +36,8 @@ class Altitude extends \PhpUnitsOfMeasure\PhysicalQuantity\Length implements Arr public function toObject() { return [ - 'ft' => round($this->toUnit('feet'), 2), - 'm' => round($this->toUnit('meters') / 1000, 2), + 'ft' => round($this->toUnit('feet'), 2), + 'm' => round($this->toUnit('meters') / 1000, 2), ]; } diff --git a/app/Support/Units/Distance.php b/app/Support/Units/Distance.php index 65db2628..87cb6d52 100644 --- a/app/Support/Units/Distance.php +++ b/app/Support/Units/Distance.php @@ -17,6 +17,7 @@ class Distance extends \PhpUnitsOfMeasure\PhysicalQuantity\Length implements Arr { $unit = setting('units.distance'); $value = $this->toUnit($unit); + return (string) round($value, 2); } diff --git a/app/Support/Units/Fuel.php b/app/Support/Units/Fuel.php index 7572fb8c..783fd4b3 100644 --- a/app/Support/Units/Fuel.php +++ b/app/Support/Units/Fuel.php @@ -17,6 +17,7 @@ class Fuel extends \PhpUnitsOfMeasure\PhysicalQuantity\Mass implements Arrayable { $unit = setting('units.fuel'); $value = $this->toUnit($unit); + return (string) round($value, 2); } @@ -35,7 +36,7 @@ class Fuel extends \PhpUnitsOfMeasure\PhysicalQuantity\Mass implements Arrayable public function toObject() { return [ - 'kg' => round($this->toUnit('kg'), 2), + 'kg' => round($this->toUnit('kg'), 2), 'lbs' => round($this->toUnit('lbs'), 2), ]; } diff --git a/app/Support/Units/Mass.php b/app/Support/Units/Mass.php index 4828d245..72c8b95e 100644 --- a/app/Support/Units/Mass.php +++ b/app/Support/Units/Mass.php @@ -17,6 +17,7 @@ class Mass extends \PhpUnitsOfMeasure\PhysicalQuantity\Mass implements Arrayable { $unit = setting('units.weight'); $value = $this->toUnit($unit); + return (string) round($value, 2); } @@ -35,7 +36,7 @@ class Mass extends \PhpUnitsOfMeasure\PhysicalQuantity\Mass implements Arrayable public function toObject() { return [ - 'kg' => round($this->toUnit('kg'), 2), + 'kg' => round($this->toUnit('kg'), 2), 'lbs' => round($this->toUnit('lbs'), 2), ]; } diff --git a/app/Support/Units/Time.php b/app/Support/Units/Time.php index 2814db3c..9285a67a 100644 --- a/app/Support/Units/Time.php +++ b/app/Support/Units/Time.php @@ -11,7 +11,7 @@ use Illuminate\Contracts\Support\Arrayable; class Time implements Arrayable { public $hours, - $minutes; + $minutes; /** * @param $minutes @@ -29,11 +29,11 @@ class Time implements Arrayable * @param $minutes * @param $hours */ - public function __construct($minutes, $hours=null) + public function __construct($minutes, $hours = null) { $minutes = (int) $minutes; - if(!empty($hours)) { + if (!empty($hours)) { $this->hours = (int) $hours; } else { $this->hours = floor($minutes / 60); @@ -67,7 +67,7 @@ class Time implements Arrayable */ public function __toString() { - return $this->hours . 'h ' . $this->minutes . 'm'; + return $this->hours.'h '.$this->minutes.'m'; } /** diff --git a/app/Support/Units/Velocity.php b/app/Support/Units/Velocity.php index c0b9196d..f077aee2 100644 --- a/app/Support/Units/Velocity.php +++ b/app/Support/Units/Velocity.php @@ -17,6 +17,7 @@ class Velocity extends \PhpUnitsOfMeasure\PhysicalQuantity\Velocity implements A { $unit = setting('units.speed'); $value = $this->toUnit($unit); + return (string) round($value, 2); } @@ -36,7 +37,7 @@ class Velocity extends \PhpUnitsOfMeasure\PhysicalQuantity\Velocity implements A { return [ 'knots' => round($this->toUnit('knots'), 2), - 'km/h' => round($this->toUnit('km/h'), 2), + 'km/h' => round($this->toUnit('km/h'), 2), ]; } diff --git a/app/Support/Units/Volume.php b/app/Support/Units/Volume.php index a3a22878..10cccfb0 100644 --- a/app/Support/Units/Volume.php +++ b/app/Support/Units/Volume.php @@ -17,6 +17,7 @@ class Volume extends \PhpUnitsOfMeasure\PhysicalQuantity\Volume implements Array { $unit = setting('units.volume'); $value = $this->toUnit($unit); + return (string) round($value, 2); } @@ -35,8 +36,8 @@ class Volume extends \PhpUnitsOfMeasure\PhysicalQuantity\Volume implements Array public function toObject() { return [ - 'gal' => round($this->toUnit('gal'), 2), - 'liters' => round($this->toUnit('liters'), 2), + 'gal' => round($this->toUnit('gal'), 2), + 'liters' => round($this->toUnit('liters'), 2), ]; } diff --git a/app/Widgets/BaseWidget.php b/app/Widgets/BaseWidget.php deleted file mode 100644 index 844ac8b4..00000000 --- a/app/Widgets/BaseWidget.php +++ /dev/null @@ -1,16 +0,0 @@ - 5, @@ -23,7 +24,7 @@ class LatestNews extends BaseWidget return view('widgets.latest_news', [ 'config' => $this->config, - 'news' => $newsRepo->recent($this->config['count']), + 'news' => $newsRepo->recent($this->config['count']), ]); } } diff --git a/app/Widgets/LatestPilots.php b/app/Widgets/LatestPilots.php index ecbc49c1..0d026c13 100644 --- a/app/Widgets/LatestPilots.php +++ b/app/Widgets/LatestPilots.php @@ -2,13 +2,14 @@ namespace App\Widgets; +use App\Interfaces\Widget; use App\Repositories\UserRepository; /** * Show the latest pilots in a view * @package App\Widgets */ -class LatestPilots extends BaseWidget +class LatestPilots extends Widget { protected $config = [ 'count' => 5, @@ -23,7 +24,7 @@ class LatestPilots extends BaseWidget return view('widgets.latest_pilots', [ 'config' => $this->config, - 'users' => $userRepo->recent($this->config['count']), + 'users' => $userRepo->recent($this->config['count']), ]); } } diff --git a/app/Widgets/LatestPireps.php b/app/Widgets/LatestPireps.php index 72b230be..4a40ce23 100644 --- a/app/Widgets/LatestPireps.php +++ b/app/Widgets/LatestPireps.php @@ -2,13 +2,14 @@ namespace App\Widgets; +use App\Interfaces\Widget; use App\Repositories\PirepRepository; /** * Show the latest PIREPs in a view * @package App\Widgets */ -class LatestPireps extends BaseWidget +class LatestPireps extends Widget { protected $config = [ 'count' => 5, diff --git a/app/Widgets/LiveMap.php b/app/Widgets/LiveMap.php index 50e29099..c4bc7ec8 100644 --- a/app/Widgets/LiveMap.php +++ b/app/Widgets/LiveMap.php @@ -2,6 +2,7 @@ namespace App\Widgets; +use App\Interfaces\Widget; use App\Repositories\AcarsRepository; use App\Services\GeoService; @@ -9,11 +10,11 @@ use App\Services\GeoService; * Show the live map in a view * @package App\Widgets */ -class LiveMap extends BaseWidget +class LiveMap extends Widget { protected $config = [ 'height' => '800px', - 'width' => '100%', + 'width' => '100%', ]; /** @@ -28,8 +29,8 @@ class LiveMap extends BaseWidget $positions = $geoSvc->getFeatureForLiveFlights($pireps); return view('widgets.live_map', [ - 'config' => $this->config, - 'pireps' => $pireps, + 'config' => $this->config, + 'pireps' => $pireps, 'positions' => $positions, ]); } diff --git a/app/helpers.php b/app/helpers.php index 7dd4ed27..3c51f1d2 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -1,6 +1,6 @@ $key) { + foreach ($list as $value => $key) { $editable[] = [ 'text' => $key, 'value' => $value, @@ -84,7 +84,7 @@ if(!function_exists('list_to_editable')) { if (!function_exists('skin_view')) { /** * Render a skin - * @param $template + * @param $template * @param array $vars * @param array $merge_data * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View @@ -93,12 +93,13 @@ if (!function_exists('skin_view')) { { # 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 - if(View::exists($template)) { + if (View::exists($template)) { return view($template, $vars, $merge_data); } # TODO: Look for an overridden template in a special folder - $tpl = 'layouts/' . config('phpvms.skin') . '/' . $template; + $tpl = 'layouts/'.config('phpvms.skin').'/'.$template; + return view($tpl, $vars, $merge_data); } } @@ -128,7 +129,7 @@ if (!function_exists('public_asset')) { function public_asset($path, $parameters = [], $secure = null) { $publicBaseUrl = app()->publicUrlPath(); - $path = $publicBaseUrl . $path; + $path = $publicBaseUrl.$path; $path = str_replace('//', '/', $path); @@ -139,16 +140,16 @@ if (!function_exists('public_asset')) { /** * Show a date/time in the proper timezone for a user */ -if(!function_exists('show_datetime')) { +if (!function_exists('show_datetime')) { /** * Format the a Carbon date into the datetime string * but convert it into the user's timezone * @param \Carbon\Carbon $date * @return string */ - function show_datetime(\Carbon\Carbon $date=null) + function show_datetime(\Carbon\Carbon $date = null) { - if(empty($date)) { + if (empty($date)) { return '-'; } diff --git a/config/auth.php b/config/auth.php index 56043f68..6811517a 100755 --- a/config/auth.php +++ b/config/auth.php @@ -14,7 +14,7 @@ return [ */ 'defaults' => [ - 'guard' => 'web', + 'guard' => 'web', 'passwords' => 'users', ], @@ -37,12 +37,12 @@ return [ 'guards' => [ 'web' => [ - 'driver' => 'session', + 'driver' => 'session', 'provider' => 'users', ], 'api' => [ - 'driver' => 'token', + 'driver' => 'token', 'provider' => 'users', ], ], @@ -50,8 +50,8 @@ return [ 'providers' => [ 'users' => [ 'driver' => 'eloquent', - 'model' => App\Models\User::class, - 'table' => 'users', + 'model' => App\Models\User::class, + 'table' => 'users', ], ], @@ -77,8 +77,8 @@ return [ 'passwords' => [ 'users' => [ 'provider' => 'users', - 'table' => 'password_resets', - 'expire' => 60, + 'table' => 'password_resets', + 'expire' => 60, ], ], diff --git a/config/database.php b/config/database.php index 804160fe..50a259bf 100755 --- a/config/database.php +++ b/config/database.php @@ -1,45 +1,45 @@ PDO::FETCH_ASSOC, - 'default' => env('DB_CONNECTION', 'mysql'), + 'fetch' => PDO::FETCH_ASSOC, + 'default' => env('DB_CONNECTION', 'mysql'), 'connections' => [ - 'mysql' => [ - 'driver' => 'mysql', - 'host' => env('DB_HOST', '127.0.0.1'), - 'port' => env('DB_PORT', 3306), - 'database' => env('DB_DATABASE', ''), - 'username' => env('DB_USERNAME', ''), - 'password' => env('DB_PASSWORD', ''), + 'mysql' => [ + 'driver' => 'mysql', + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', 3306), + 'database' => env('DB_DATABASE', ''), + 'username' => env('DB_USERNAME', ''), + 'password' => env('DB_PASSWORD', ''), //'unix_socket' => env('DB_SOCKET', ''), - 'prefix' => env('DB_PREFIX', ''), - 'timezone' => '+00:00', - 'charset' => 'utf8', + 'prefix' => env('DB_PREFIX', ''), + 'timezone' => '+00:00', + 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', - 'strict' => false, - 'engine' => null, - 'options' => [ + 'strict' => false, + 'engine' => null, + 'options' => [ PDO::ATTR_EMULATE_PREPARES => env('DB_EMULATE_PREPARES', false), #PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ], ], - 'sqlite' => [ - 'driver' => 'sqlite', + 'sqlite' => [ + 'driver' => 'sqlite', 'database' => storage_path('db.sqlite'), 'timezone' => '+00:00', - 'prefix' => '', + 'prefix' => '', ], 'unittest' => [ - 'driver' => 'sqlite', + 'driver' => 'sqlite', 'database' => storage_path('unittest.sqlite'), 'timezone' => '+00:00', - 'prefix' => '', + 'prefix' => '', ], - 'memory' => [ - 'driver' => 'sqlite', + 'memory' => [ + 'driver' => 'sqlite', 'database' => ':memory:', 'timezone' => '+00:00', - 'prefix' => '', + 'prefix' => '', ], ], @@ -48,9 +48,9 @@ return [ 'redis' => [ 'cluster' => false, 'default' => [ - 'host' => env('REDIS_HOST', 'localhost'), + 'host' => env('REDIS_HOST', 'localhost'), 'password' => env('REDIS_PASSWORD', null), - 'port' => env('REDIS_PORT', 6379), + 'port' => env('REDIS_PORT', 6379), 'database' => env('REDIS_DATABASE', 1), ], ] diff --git a/config/datatables.php b/config/datatables.php deleted file mode 100644 index 89000cac..00000000 --- a/config/datatables.php +++ /dev/null @@ -1,86 +0,0 @@ - [ - /** - * Smart search will enclose search keyword with wildcard string "%keyword%". - * SQL: column LIKE "%keyword%" - */ - 'smart' => true, - - /** - * Case insensitive will search the keyword in lower case format. - * SQL: LOWER(column) LIKE LOWER(keyword) - */ - 'case_insensitive' => true, - - /** - * Wild card will add "%" in between every characters of the keyword. - * SQL: column LIKE "%k%e%y%w%o%r%d%" - */ - 'use_wildcards' => false, - ], - - /** - * DataTables fractal configurations. - */ - 'fractal' => [ - /** - * Request key name to parse includes on fractal. - */ - 'includes' => 'include', - - /** - * Default fractal serializer. - */ - 'serializer' => 'League\Fractal\Serializer\DataArraySerializer', - ], - - /** - * DataTables script view template. - */ - 'script_template' => 'datatables::script', - - /** - * DataTables internal index id response column name. - */ - 'index_column' => 'DT_Row_Index', - - /** - * Namespaces used by the generator. - */ - 'namespace' => [ - /** - * Base namespace/directory to create the new file. - * This is appended on default Laravel namespace. - * - * Usage: php artisan datatables:make User - * Output: App\DataTables\UserDataTable - * With Model: App\User (default model) - * Export filename: users_timestamp - */ - 'base' => 'DataTables', - - /** - * Base namespace/directory where your model's are located. - * This is appended on default Laravel namespace. - * - * Usage: php artisan datatables:make Post --model - * Output: App\DataTables\PostDataTable - * With Model: App\Post - * Export filename: posts_timestamp - */ - 'model' => '', - ], - - /** - * PDF generator to be used when converting the table to pdf. - * Available generators: excel, snappy - * Snappy package: barryvdh/laravel-snappy - * Excel package: maatwebsite/excel - */ - 'pdf_generator' => 'excel', -]; diff --git a/config/gamp.php b/config/gamp.php index 668f3809..4979b8f8 100644 --- a/config/gamp.php +++ b/config/gamp.php @@ -1,10 +1,10 @@ 'UA-100567975-1', + 'tracking_id' => 'UA-100567975-1', 'protocol_version' => 1, - 'is_ssl' => false, - 'is_disabled' => false, - 'anonymize_ip' => false, - 'async_requests' => false, + 'is_ssl' => false, + 'is_disabled' => false, + 'anonymize_ip' => false, + 'async_requests' => false, ]; diff --git a/config/gravatar.php b/config/gravatar.php index 2b3c1090..bd504671 100644 --- a/config/gravatar.php +++ b/config/gravatar.php @@ -4,6 +4,6 @@ */ return [ - 'url' => 'https://www.gravatar.com/avatar/', + 'url' => 'https://www.gravatar.com/avatar/', 'default' => 'https://en.gravatar.com/userimage/12856995/aa6c0527a723abfd5fb9e246f0ff8af4.png', ]; diff --git a/config/laravel-widgets.php b/config/laravel-widgets.php index 38d0f2ea..108a50aa 100644 --- a/config/laravel-widgets.php +++ b/config/laravel-widgets.php @@ -1,22 +1,15 @@ 'App\Widgets', + 'default_namespace' => 'App\Widgets', - 'use_jquery_for_ajax_calls' => false, + 'use_jquery_for_ajax_calls' => true, /* * Set Ajax widget middleware */ 'route_middleware' => [], - /* - * Relative path from the base directory to a regular widget stub. - */ - 'widget_stub' => 'vendor/arrilot/laravel-widgets/src/Console/stubs/widget.stub', - - /* - * Relative path from the base directory to a plain widget stub. - */ - 'widget_plain_stub' => 'vendor/arrilot/laravel-widgets/src/Console/stubs/widget_plain.stub', + 'widget_stub' => 'resources/stubs/widgets/widget.stub', + 'widget_plain_stub' => 'resources/stubs/widgets/widget_plain.stub', ]; diff --git a/config/modules.php b/config/modules.php index 6e66ce66..1929a665 100644 --- a/config/modules.php +++ b/config/modules.php @@ -2,39 +2,39 @@ return [ 'namespace' => 'Modules', - 'stubs' => [ - 'enabled' => true, - 'path' => resource_path() . '/stubs/modules', - 'files' => [ - 'routes' => 'Http/Routes/web.php', - 'routes-api' => 'Http/Routes/api.php', - 'routes-admin' => 'Http/Routes/admin.php', + 'stubs' => [ + 'enabled' => true, + 'path' => resource_path().'/stubs/modules', + 'files' => [ + 'routes' => 'Http/Routes/web.php', + 'routes-api' => 'Http/Routes/api.php', + 'routes-admin' => 'Http/Routes/admin.php', 'event-service-provider' => 'Providers/EventServiceProvider.php', - 'views/index' => 'Resources/views/index.blade.php', - 'views/index-admin' => 'Resources/views/admin/index.blade.php', - 'views/frontend' => 'Resources/views/layouts/frontend.blade.php', - 'views/admin' => 'Resources/views/layouts/admin.blade.php', - 'listener-test' => 'Listeners/TestEventListener.php', - 'controller-api' => 'Http/Controllers/Api/SampleController.php', - 'controller-admin' => 'Http/Controllers/Admin/AdminController.php', - 'scaffold/config' => 'Config/config.php', - 'composer' => 'composer.json', + 'views/index' => 'Resources/views/index.blade.php', + 'views/index-admin' => 'Resources/views/admin/index.blade.php', + 'views/frontend' => 'Resources/views/layouts/frontend.blade.php', + 'views/admin' => 'Resources/views/layouts/admin.blade.php', + 'listener-test' => 'Listeners/TestEventListener.php', + 'controller-api' => 'Http/Controllers/Api/SampleController.php', + 'controller-admin' => 'Http/Controllers/Admin/AdminController.php', + 'scaffold/config' => 'Config/config.php', + 'composer' => 'composer.json', ], 'replacements' => [ - 'start' => ['LOWER_NAME', 'ROUTES_LOCATION'], - 'routes' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'], - 'routes-api' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'], - 'json' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'], + 'start' => ['LOWER_NAME', 'ROUTES_LOCATION'], + 'routes' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'], + 'routes-api' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'], + 'json' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'], 'event-service-provider' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'], - 'listener-test' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'], - 'views/index' => ['LOWER_NAME'], - 'views/index-admin' => ['LOWER_NAME', 'STUDLY_NAME'], - 'views/frontend' => ['STUDLY_NAME'], - 'views/admin' => ['STUDLY_NAME'], - 'controller-admin' => ['MODULE_NAMESPACE', 'STUDLY_NAME', 'CLASS_NAMESPACE', 'LOWER_NAME'], - 'controller-api' => ['MODULE_NAMESPACE', 'STUDLY_NAME', 'CLASS_NAMESPACE', 'LOWER_NAME'], - 'scaffold/config' => ['STUDLY_NAME'], - 'composer' => [ + 'listener-test' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'], + 'views/index' => ['LOWER_NAME'], + 'views/index-admin' => ['LOWER_NAME', 'STUDLY_NAME'], + 'views/frontend' => ['STUDLY_NAME'], + 'views/admin' => ['STUDLY_NAME'], + 'controller-admin' => ['MODULE_NAMESPACE', 'STUDLY_NAME', 'CLASS_NAMESPACE', 'LOWER_NAME'], + 'controller-api' => ['MODULE_NAMESPACE', 'STUDLY_NAME', 'CLASS_NAMESPACE', 'LOWER_NAME'], + 'scaffold/config' => ['STUDLY_NAME'], + 'composer' => [ 'LOWER_NAME', 'STUDLY_NAME', 'VENDOR', @@ -43,39 +43,39 @@ return [ 'MODULE_NAMESPACE', ], ], - 'gitkeep' => false, + 'gitkeep' => false, ], - 'paths' => [ - 'modules' => base_path('modules'), - 'assets' => public_path('modules'), + 'paths' => [ + 'modules' => base_path('modules'), + 'assets' => public_path('modules'), 'migration' => base_path('database/migrations'), 'generator' => [ - 'config' => ['path' => 'Config', 'generate' => true], - 'command' => ['path' => 'Console', 'generate' => true], - 'migration' => ['path' => 'Database/migrations', 'generate' => true], - 'seeder' => ['path' => 'Database/seeders', 'generate' => true], - 'factory' => ['path' => 'Database/factories', 'generate' => true], - 'model' => ['path' => 'Models', 'generate' => true], - 'controller' => ['path' => 'Http/Controllers', 'generate' => true], + 'config' => ['path' => 'Config', 'generate' => true], + 'command' => ['path' => 'Console', 'generate' => true], + 'migration' => ['path' => 'Database/migrations', 'generate' => true], + 'seeder' => ['path' => 'Database/seeders', 'generate' => true], + 'factory' => ['path' => 'Database/factories', 'generate' => true], + 'model' => ['path' => 'Models', 'generate' => true], + 'controller' => ['path' => 'Http/Controllers', 'generate' => true], 'controller-admin' => ['path' => 'Http/Controllers/Admin', 'generate' => true], - 'controller-api' => ['path' => 'Http/Controllers/Api', 'generate' => true], - 'filter' => ['path' => 'Http/Middleware', 'generate' => true], - 'request' => ['path' => 'Http/Requests', 'generate' => true], - 'routes' => ['path' => 'Http/Routes', 'generate' => true], - 'provider' => ['path' => 'Providers', 'generate' => true], - 'assets' => ['path' => 'Resources/assets', 'generate' => true], - 'lang' => ['path' => 'Resources/lang', 'generate' => true], - 'views' => ['path' => 'Resources/views', 'generate' => true], - 'test' => ['path' => 'tests', 'generate' => true], - 'repository' => ['path' => 'Repositories', 'generate' => false], - 'event' => ['path' => 'Events', 'generate' => false], - 'listener' => ['path' => 'Listeners', 'generate' => true], - 'policies' => ['path' => 'Policies', 'generate' => false], - 'rules' => ['path' => 'Rules', 'generate' => false], - 'jobs' => ['path' => 'Jobs', 'generate' => false], - 'emails' => ['path' => 'Resources/Emails', 'generate' => false], - 'notifications' => ['path' => 'Notifications', 'generate' => false], - 'resource' => ['path' => 'Models/Transformers', 'generate' => false], + 'controller-api' => ['path' => 'Http/Controllers/Api', 'generate' => true], + 'filter' => ['path' => 'Http/Middleware', 'generate' => true], + 'request' => ['path' => 'Http/Requests', 'generate' => true], + 'routes' => ['path' => 'Http/Routes', 'generate' => true], + 'provider' => ['path' => 'Providers', 'generate' => true], + 'assets' => ['path' => 'Resources/assets', 'generate' => true], + 'lang' => ['path' => 'Resources/lang', 'generate' => true], + 'views' => ['path' => 'Resources/views', 'generate' => true], + 'test' => ['path' => 'tests', 'generate' => true], + 'repository' => ['path' => 'Repositories', 'generate' => false], + 'event' => ['path' => 'Events', 'generate' => false], + 'listener' => ['path' => 'Listeners', 'generate' => true], + 'policies' => ['path' => 'Policies', 'generate' => false], + 'rules' => ['path' => 'Rules', 'generate' => false], + 'jobs' => ['path' => 'Jobs', 'generate' => false], + 'emails' => ['path' => 'Resources/Emails', 'generate' => false], + 'notifications' => ['path' => 'Notifications', 'generate' => false], + 'resource' => ['path' => 'Models/Transformers', 'generate' => false], ], ], /* @@ -90,7 +90,7 @@ return [ 'scan' => [ 'enabled' => false, - 'paths' => [ + 'paths' => [ base_path('vendor/*/*'), ], ], @@ -106,7 +106,7 @@ return [ 'composer' => [ 'vendor' => '', 'author' => [ - 'name' => '', + 'name' => '', 'email' => '', ], ], @@ -118,9 +118,9 @@ return [ | Here is the config for setting up caching feature. | */ - 'cache' => [ - 'enabled' => true, - 'key' => 'phpvms-modules', + 'cache' => [ + 'enabled' => true, + 'key' => 'phpvms-modules', 'lifetime' => 60, ], /* diff --git a/modules/Installer/Http/Controllers/InstallerController.php b/modules/Installer/Http/Controllers/InstallerController.php index 57fdd1d7..6d1f35d9 100644 --- a/modules/Installer/Http/Controllers/InstallerController.php +++ b/modules/Installer/Http/Controllers/InstallerController.php @@ -2,39 +2,48 @@ namespace Modules\Installer\Http\Controllers; -use App\Support\Countries; -use Log; -use Illuminate\Http\Request; -use Illuminate\Support\Facades\Hash; -use Illuminate\Database\QueryException; -use Illuminate\Support\Facades\Validator; - -use App\Models\User; - -use App\Repositories\AirlineRepository; use App\Facades\Utils; +use App\Interfaces\Controller; +use App\Models\User; +use App\Repositories\AirlineRepository; use App\Services\AnalyticsService; use App\Services\UserService; - -use App\Http\Controllers\Controller; - -use Modules\Installer\Services\DatabaseService; +use App\Support\Countries; +use Illuminate\Database\QueryException; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Validator; +use Log; use Modules\Installer\Services\ConfigService; +use Modules\Installer\Services\DatabaseService; use Modules\Installer\Services\MigrationService; use Modules\Installer\Services\RequirementsService; - use Symfony\Component\HttpFoundation\File\Exception\FileException; +/** + * Class InstallerController + * @package Modules\Installer\Http\Controllers + */ class InstallerController extends Controller { - protected $airlineRepo, - $analyticsSvc, - $dbService, - $envService, - $migrationSvc, - $reqService, - $userService; + private $airlineRepo, + $analyticsSvc, + $dbService, + $envService, + $migrationSvc, + $reqService, + $userService; + /** + * InstallerController constructor. + * @param AirlineRepository $airlineRepo + * @param AnalyticsService $analyticsSvc + * @param DatabaseService $dbService + * @param ConfigService $envService + * @param MigrationService $migrationSvc + * @param RequirementsService $reqService + * @param UserService $userService + */ public function __construct( AirlineRepository $airlineRepo, AnalyticsService $analyticsSvc, diff --git a/modules/Installer/Http/Controllers/UpdaterController.php b/modules/Installer/Http/Controllers/UpdaterController.php index b9a949ae..a56271f8 100644 --- a/modules/Installer/Http/Controllers/UpdaterController.php +++ b/modules/Installer/Http/Controllers/UpdaterController.php @@ -2,17 +2,23 @@ namespace Modules\Installer\Http\Controllers; -use Log; +use App\Interfaces\Controller; use Illuminate\Http\Request; - -use App\Http\Controllers\Controller; - +use Log; use Modules\Installer\Services\MigrationService; +/** + * Class UpdaterController + * @package Modules\Installer\Http\Controllers + */ class UpdaterController extends Controller { - protected $migrationSvc; + private $migrationSvc; + /** + * UpdaterController constructor. + * @param MigrationService $migrationSvc + */ public function __construct( MigrationService $migrationSvc ) { diff --git a/modules/Installer/Services/ConfigService.php b/modules/Installer/Services/ConfigService.php index 35d52fae..9e0dc9c8 100644 --- a/modules/Installer/Services/ConfigService.php +++ b/modules/Installer/Services/ConfigService.php @@ -2,6 +2,7 @@ namespace Modules\Installer\Services; +use App\Interfaces\Service; use Illuminate\Encryption\Encrypter; use Log; use Nwidart\Modules\Support\Stub; @@ -12,7 +13,7 @@ use Symfony\Component\HttpFoundation\File\Exception\FileException; * Class ConfigService * @package Modules\Installer\Services */ -class ConfigService +class ConfigService extends Service { /** * Create the .env file diff --git a/modules/Installer/Services/DatabaseService.php b/modules/Installer/Services/DatabaseService.php index 4ecc3f21..7d21c255 100644 --- a/modules/Installer/Services/DatabaseService.php +++ b/modules/Installer/Services/DatabaseService.php @@ -2,11 +2,12 @@ namespace Modules\Installer\Services; +use App\Interfaces\Service; use Log; use PDO; -class DatabaseService { - +class DatabaseService extends Service +{ /** * Check the PHP version that it meets the minimum requirement * @param $driver diff --git a/modules/Installer/Services/MigrationService.php b/modules/Installer/Services/MigrationService.php index e4d07d52..6e6f7b57 100644 --- a/modules/Installer/Services/MigrationService.php +++ b/modules/Installer/Services/MigrationService.php @@ -2,6 +2,7 @@ namespace Modules\Installer\Services; +use App\Interfaces\Service; use Log; use Nwidart\Modules\Facades\Module; @@ -9,7 +10,7 @@ use Nwidart\Modules\Facades\Module; * Class MigrationsService * @package Modules\Installer\Services */ -class MigrationService +class MigrationService extends Service { /** * @return \Illuminate\Database\Migrations\Migrator diff --git a/modules/Installer/Services/RequirementsService.php b/modules/Installer/Services/RequirementsService.php index 4bc310a6..f3bba76b 100644 --- a/modules/Installer/Services/RequirementsService.php +++ b/modules/Installer/Services/RequirementsService.php @@ -3,7 +3,10 @@ namespace Modules\Installer\Services; -class RequirementsService { +use App\Interfaces\Service; + +class RequirementsService extends Service +{ /** * Check the PHP version that it meets the minimum requirement diff --git a/modules/Sample/Awards/SampleAward.php b/modules/Sample/Awards/SampleAward.php index a1efe624..f31664cf 100644 --- a/modules/Sample/Awards/SampleAward.php +++ b/modules/Sample/Awards/SampleAward.php @@ -2,13 +2,13 @@ namespace Modules\Sample\Awards; -use App\Interfaces\AwardInterface; +use App\Interfaces\Award; /** * Class SampleAward * @package Modules\Sample\Awards */ -class SampleAward extends AwardInterface +class SampleAward extends Award { public $name = 'Sample Award'; diff --git a/modules/Sample/Http/Controllers/Admin/AdminController.php b/modules/Sample/Http/Controllers/Admin/AdminController.php index f83d0bae..7b23b11f 100644 --- a/modules/Sample/Http/Controllers/Admin/AdminController.php +++ b/modules/Sample/Http/Controllers/Admin/AdminController.php @@ -2,10 +2,13 @@ namespace Modules\Sample\Http\Controllers\Admin; -use App\Http\Controllers\Controller; +use App\Interfaces\Controller; use Illuminate\Http\Request; - +/** + * Class AdminController + * @package Modules\Sample\Http\Controllers\Admin + */ class AdminController extends Controller { /** diff --git a/modules/Sample/Http/Controllers/Api/SampleController.php b/modules/Sample/Http/Controllers/Api/SampleController.php index 3abfd816..9e5a28d4 100644 --- a/modules/Sample/Http/Controllers/Api/SampleController.php +++ b/modules/Sample/Http/Controllers/Api/SampleController.php @@ -2,14 +2,19 @@ namespace Modules\Sample\Http\Controllers\Api; -use App\Http\Controllers\Api\RestController; +use App\Interfaces\Controller; use Illuminate\Http\Request; -class SampleController extends RestController +/** + * Class SampleController + * @package Modules\Sample\Http\Controllers\Api + */ +class SampleController extends Controller { /** * Just send out a message * @param Request $request + * @return \Illuminate\Http\JsonResponse */ public function index(Request $request) { @@ -18,6 +23,7 @@ class SampleController extends RestController /** * @param Request $request + * @return \Illuminate\Http\JsonResponse */ public function hello(Request $request) { diff --git a/modules/Sample/Http/Controllers/SampleController.php b/modules/Sample/Http/Controllers/SampleController.php index 9255736e..3745a406 100644 --- a/modules/Sample/Http/Controllers/SampleController.php +++ b/modules/Sample/Http/Controllers/SampleController.php @@ -2,10 +2,13 @@ namespace Modules\Sample\Http\Controllers; -use App\Http\Controllers\Controller; +use App\Interfaces\Controller; use Illuminate\Http\Request; - +/** + * Class SampleController + * @package Modules\Sample\Http\Controllers + */ class SampleController extends Controller { /** diff --git a/modules/Sample/Models/SampleTable.php b/modules/Sample/Models/SampleTable.php index 05768bce..780da808 100644 --- a/modules/Sample/Models/SampleTable.php +++ b/modules/Sample/Models/SampleTable.php @@ -2,10 +2,15 @@ namespace Modules\Sample\Models; -use App\Models\BaseModel; +use App\Interfaces\Model; -class SampleTable extends BaseModel +/** + * Class SampleTable + * @package Modules\Sample\Models + */ +class SampleTable extends Model { public $table = ''; + protected $fillable = []; } diff --git a/resources/stubs/modules/controller-admin.stub b/resources/stubs/modules/controller-admin.stub index 7da89e7c..ab6fd68f 100644 --- a/resources/stubs/modules/controller-admin.stub +++ b/resources/stubs/modules/controller-admin.stub @@ -2,10 +2,13 @@ namespace $MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers\Admin; -use App\Http\Controllers\Controller; +use App\Interfaces\Controller; use Illuminate\Http\Request; - +/** + * Class AdminController + * @package $MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers\Admin + */ class AdminController extends Controller { /** diff --git a/resources/stubs/modules/controller-api.stub b/resources/stubs/modules/controller-api.stub index 72c20657..75396eb7 100644 --- a/resources/stubs/modules/controller-api.stub +++ b/resources/stubs/modules/controller-api.stub @@ -2,9 +2,13 @@ namespace $MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers\Api; -use App\Http\Controllers\Api\RestController; +use App\Interfaces\Controller; use Illuminate\Http\Request; +/** + * class SampleController + * @package $MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers\Api + */ class SampleController extends RestController { /** diff --git a/resources/stubs/modules/controller-plain.stub b/resources/stubs/modules/controller-plain.stub index 3652877e..a4850f87 100644 --- a/resources/stubs/modules/controller-plain.stub +++ b/resources/stubs/modules/controller-plain.stub @@ -2,8 +2,13 @@ namespace $CLASS_NAMESPACE$; -use App\Http\Controllers\Controller; +use App\Interfaces\Controller; +/** + * Class $CLASS$ + * @package $CLASS_NAMESPACE$ + */ class $CLASS$ extends Controller { + } diff --git a/resources/stubs/modules/controller.stub b/resources/stubs/modules/controller.stub index 8894c777..b3f8a0ab 100644 --- a/resources/stubs/modules/controller.stub +++ b/resources/stubs/modules/controller.stub @@ -2,10 +2,13 @@ namespace $CLASS_NAMESPACE$; -use App\Http\Controllers\Controller; +use App\Interfaces\Controller; use Illuminate\Http\Request; - +/** + * Class $CLASS$ + * @package $CLASS_NAMESPACE$ + */ class $CLASS$ extends Controller { /** diff --git a/resources/stubs/modules/event.stub b/resources/stubs/modules/event.stub index ad1cb696..a658a8c9 100644 --- a/resources/stubs/modules/event.stub +++ b/resources/stubs/modules/event.stub @@ -4,6 +4,10 @@ namespace $NAMESPACE$; use Illuminate\Queue\SerializesModels; +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ class $CLASS$ { use SerializesModels; diff --git a/resources/stubs/modules/job-queued.stub b/resources/stubs/modules/job-queued.stub index 5bcccf1a..f6faa6d5 100644 --- a/resources/stubs/modules/job-queued.stub +++ b/resources/stubs/modules/job-queued.stub @@ -8,6 +8,10 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ class $CLASS$ implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; diff --git a/resources/stubs/modules/job.stub b/resources/stubs/modules/job.stub index 3a883699..fa9fa7ab 100644 --- a/resources/stubs/modules/job.stub +++ b/resources/stubs/modules/job.stub @@ -5,6 +5,10 @@ namespace $NAMESPACE$; use Illuminate\Bus\Queueable; use Illuminate\Foundation\Bus\Dispatchable; +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ class $CLASS$ implements ShouldQueue { use Dispatchable, Queueable; diff --git a/resources/stubs/modules/listener-duck.stub b/resources/stubs/modules/listener-duck.stub index 5d700db5..3f02052e 100644 --- a/resources/stubs/modules/listener-duck.stub +++ b/resources/stubs/modules/listener-duck.stub @@ -2,10 +2,15 @@ namespace $NAMESPACE$; +use App\Interfaces\Listener; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -class $CLASS$ +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ +class $CLASS$ extends Listener { /** * Create the event listener. diff --git a/resources/stubs/modules/listener-queued-duck.stub b/resources/stubs/modules/listener-queued-duck.stub index d61c9922..5cb8325d 100644 --- a/resources/stubs/modules/listener-queued-duck.stub +++ b/resources/stubs/modules/listener-queued-duck.stub @@ -2,10 +2,15 @@ namespace $NAMESPACE$; +use App\Interfaces\Listener; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -class $CLASS$ implements ShouldQueue +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ +class $CLASS$ extends Listener implements ShouldQueue { use InteractsWithQueue; diff --git a/resources/stubs/modules/listener-queued.stub b/resources/stubs/modules/listener-queued.stub index f60ddf7a..789f7e8d 100644 --- a/resources/stubs/modules/listener-queued.stub +++ b/resources/stubs/modules/listener-queued.stub @@ -3,10 +3,15 @@ namespace $NAMESPACE$; use $EVENTNAME$; +use App\Interfaces\Listener; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -class $CLASS$ implements ShouldQueue +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ +class $CLASS$ extends Listener implements ShouldQueue { use InteractsWithQueue; diff --git a/resources/stubs/modules/listener.stub b/resources/stubs/modules/listener.stub index d5275166..414fda8c 100644 --- a/resources/stubs/modules/listener.stub +++ b/resources/stubs/modules/listener.stub @@ -3,10 +3,15 @@ namespace $NAMESPACE$; use $EVENTNAME$; +use App\Interfaces\Listener; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -class $CLASS$ +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ +class $CLASS$ extends Listener { /** * Create the event listener. diff --git a/resources/stubs/modules/mail.stub b/resources/stubs/modules/mail.stub index 66369e46..aa3f514f 100644 --- a/resources/stubs/modules/mail.stub +++ b/resources/stubs/modules/mail.stub @@ -7,6 +7,10 @@ use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Queue\ShouldQueue; +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ class $CLASS$ extends Mailable { use Queueable, SerializesModels; diff --git a/resources/stubs/modules/middleware.stub b/resources/stubs/modules/middleware.stub index 954583ed..ee094a84 100644 --- a/resources/stubs/modules/middleware.stub +++ b/resources/stubs/modules/middleware.stub @@ -5,6 +5,10 @@ namespace $NAMESPACE$; use Closure; use Illuminate\Http\Request; +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ class $CLASS$ { /** diff --git a/resources/stubs/modules/migration/add.stub b/resources/stubs/modules/migration/add.stub index b20294af..0b5bf4f4 100644 --- a/resources/stubs/modules/migration/add.stub +++ b/resources/stubs/modules/migration/add.stub @@ -1,9 +1,12 @@ increments('id'); -$FIELDS$ + $FIELDS$ $table->timestamps(); }); } diff --git a/resources/stubs/modules/migration/delete.stub b/resources/stubs/modules/migration/delete.stub index b20294af..0b5bf4f4 100644 --- a/resources/stubs/modules/migration/delete.stub +++ b/resources/stubs/modules/migration/delete.stub @@ -1,9 +1,12 @@ increments('id'); -$FIELDS$ + $FIELDS$ $table->timestamps(); }); } diff --git a/resources/stubs/modules/migration/plain.stub b/resources/stubs/modules/migration/plain.stub index 3cacabf7..f0e15374 100644 --- a/resources/stubs/modules/migration/plain.stub +++ b/resources/stubs/modules/migration/plain.stub @@ -1,9 +1,12 @@ line('The introduction to the notification.') - ->action('Notification Action', 'https://laravel.com') - ->line('Thank you for using our application!'); + ->line('The introduction to the notification.') + ->action('Notification Action', 'https://laravel.com') + ->line('Thank you for using our application!'); } /** diff --git a/resources/stubs/modules/policy.plain.stub b/resources/stubs/modules/policy.plain.stub index 02e16df3..e148f07b 100644 --- a/resources/stubs/modules/policy.plain.stub +++ b/resources/stubs/modules/policy.plain.stub @@ -4,6 +4,10 @@ namespace $NAMESPACE$; use Illuminate\Auth\Access\HandlesAuthorization; +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ class $CLASS$ { use HandlesAuthorization; diff --git a/resources/stubs/modules/provider.stub b/resources/stubs/modules/provider.stub index 4fd17be8..9f006645 100644 --- a/resources/stubs/modules/provider.stub +++ b/resources/stubs/modules/provider.stub @@ -4,6 +4,10 @@ namespace $NAMESPACE$; use Illuminate\Support\ServiceProvider; +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ class $CLASS$ extends ServiceProvider { /** diff --git a/resources/stubs/modules/request.stub b/resources/stubs/modules/request.stub index 96e06163..cefbb6c2 100644 --- a/resources/stubs/modules/request.stub +++ b/resources/stubs/modules/request.stub @@ -4,6 +4,10 @@ namespace $NAMESPACE$; use Illuminate\Foundation\Http\FormRequest; +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ class $CLASS$ extends FormRequest { /** diff --git a/resources/stubs/modules/resource-collection.stub b/resources/stubs/modules/resource-collection.stub index c88f43b8..dac7c7c4 100644 --- a/resources/stubs/modules/resource-collection.stub +++ b/resources/stubs/modules/resource-collection.stub @@ -4,6 +4,10 @@ namespace $NAMESPACE$; use Illuminate\Http\Resources\Json\ResourceCollection; +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ class $CLASS$ extends ResourceCollection { /** diff --git a/resources/stubs/modules/resource.stub b/resources/stubs/modules/resource.stub index c67afeea..09064195 100644 --- a/resources/stubs/modules/resource.stub +++ b/resources/stubs/modules/resource.stub @@ -4,6 +4,10 @@ namespace $NAMESPACE$; use Illuminate\Http\Resources\Json\Resource; +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ class $CLASS$ extends Resource { /** diff --git a/resources/stubs/modules/route-provider.stub b/resources/stubs/modules/route-provider.stub index 75821007..45d782dc 100644 --- a/resources/stubs/modules/route-provider.stub +++ b/resources/stubs/modules/route-provider.stub @@ -5,6 +5,10 @@ namespace $NAMESPACE$; use Illuminate\Routing\Router; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ class $CLASS$ extends ServiceProvider { /** diff --git a/resources/stubs/modules/rule.stub b/resources/stubs/modules/rule.stub index 9b716321..1bd87b13 100644 --- a/resources/stubs/modules/rule.stub +++ b/resources/stubs/modules/rule.stub @@ -4,6 +4,10 @@ namespace $NAMESPACE$; use Illuminate\Contracts\Validation\Rule; +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ class $CLASS$ implements Rule { /** diff --git a/resources/stubs/modules/scaffold/config.stub b/resources/stubs/modules/scaffold/config.stub index 74c3001c..d11bb66a 100644 --- a/resources/stubs/modules/scaffold/config.stub +++ b/resources/stubs/modules/scaffold/config.stub @@ -1,4 +1,7 @@ '$STUDLY_NAME$' diff --git a/resources/stubs/modules/scaffold/provider.stub b/resources/stubs/modules/scaffold/provider.stub index 0e24f2d4..4466c543 100644 --- a/resources/stubs/modules/scaffold/provider.stub +++ b/resources/stubs/modules/scaffold/provider.stub @@ -6,11 +6,15 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Database\Eloquent\Factory; use Route; - +/** + * Class $CLASS$ + * @package $NAMESPACE$ + */ class $CLASS$ extends ServiceProvider { + private $moduleSvc; + protected $defer = false; - protected $moduleSvc; /** * Boot the application events. diff --git a/resources/stubs/widgets/widget.stub b/resources/stubs/widgets/widget.stub new file mode 100644 index 00000000..18159133 --- /dev/null +++ b/resources/stubs/widgets/widget.stub @@ -0,0 +1,31 @@ + $this->config, + ]); + } +} diff --git a/resources/stubs/widgets/widget_plain.stub b/resources/stubs/widgets/widget_plain.stub new file mode 100644 index 00000000..c22ab715 --- /dev/null +++ b/resources/stubs/widgets/widget_plain.stub @@ -0,0 +1,21 @@ +