diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..6abee311d --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,30 @@ +name: Fix Code Style + +on: [push] + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php: [8.3] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: json, dom, curl, libxml, mbstring + coverage: none + + - name: Install Pint + run: composer global require laravel/pint + working-directory: ./src/backend + + - name: Run Pint + run: pint + working-directory: ./src/backend diff --git a/src/backend/.php-cs-fixer.dist.php b/src/backend/.php-cs-fixer.dist.php index 3c7dfce40..a16b630b5 100644 --- a/src/backend/.php-cs-fixer.dist.php +++ b/src/backend/.php-cs-fixer.dist.php @@ -15,9 +15,23 @@ return (new PhpCsFixer\Config()) ->setRules([ '@Symfony' => true, - // customisation 'no_superfluous_phpdoc_tags' => false, 'yoda_style' => false, + 'method_chaining_indentation' => true, + 'braces_position' => [ + 'control_structures_opening_brace' => 'same_line', + 'functions_opening_brace' => 'same_line', + 'anonymous_functions_opening_brace' => 'same_line', + 'classes_opening_brace' => 'same_line', + 'anonymous_classes_opening_brace' => 'same_line', + 'allow_single_line_empty_anonymous_classes' => true, + 'allow_single_line_anonymous_functions' => true, + ], + 'method_argument_space' => [ + 'on_multiline' => 'ensure_fully_multiline', + ], + 'single_line_empty_body' => true, + ]) ->setFinder($finder) ; diff --git a/src/backend/app/Console/Commands/AbstractSharedCommand.php b/src/backend/app/Console/Commands/AbstractSharedCommand.php index 43c617c9a..49b28024a 100644 --- a/src/backend/app/Console/Commands/AbstractSharedCommand.php +++ b/src/backend/app/Console/Commands/AbstractSharedCommand.php @@ -9,9 +9,9 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -abstract class AbstractSharedCommand extends Command -{ +abstract class AbstractSharedCommand extends Command { protected const EXECUTE_FOR_ONE = 1; + protected const EXECUTE_FOR_ALL = 0; protected int $EXECUTION_TYPE = self::EXECUTE_FOR_ALL; @@ -19,8 +19,7 @@ abstract class AbstractSharedCommand extends Command /** * Configure the command. */ - protected function configure(): void - { + protected function configure(): void { parent::configure(); $this->addOption( @@ -31,8 +30,7 @@ protected function configure(): void ); } - protected function execute(InputInterface $input, OutputInterface $output) - { + protected function execute(InputInterface $input, OutputInterface $output) { /** @var DatabaseProxyManagerService $databaseProxyManagerService */ $databaseProxyManagerService = app()->make(DatabaseProxyManagerService::class); diff --git a/src/backend/app/Console/Commands/AccessRateChecker.php b/src/backend/app/Console/Commands/AccessRateChecker.php index b9e56bf22..b7b3737c2 100644 --- a/src/backend/app/Console/Commands/AccessRateChecker.php +++ b/src/backend/app/Console/Commands/AccessRateChecker.php @@ -5,13 +5,12 @@ use App\Models\AccessRate\AccessRatePayment; use Carbon\Carbon; -class AccessRateChecker extends AbstractSharedCommand -{ +class AccessRateChecker extends AbstractSharedCommand { protected $signature = 'accessrate:check'; + protected $description = 'Updates the "debt" field, based on "due_date" field'; - public function runInCompanyScope(): void - { + public function runInCompanyScope(): void { // get all access-rate payments where due Date is <= today $accessRatePayments = AccessRatePayment::where('due_date', '<=', Carbon::now())->get(); diff --git a/src/backend/app/Console/Commands/AddMeterAddress.php b/src/backend/app/Console/Commands/AddMeterAddress.php index 30425d4ee..874e67d39 100644 --- a/src/backend/app/Console/Commands/AddMeterAddress.php +++ b/src/backend/app/Console/Commands/AddMeterAddress.php @@ -5,18 +5,16 @@ use App\Models\Address\Address; use App\Models\Meter\MeterParameter; -class AddMeterAddress extends AbstractSharedCommand -{ +class AddMeterAddress extends AbstractSharedCommand { protected $signature = 'meters:addAddress'; + protected $description = 'Creates an address entry for all every registered meter. Sets them all to village 1'; - public function __construct(private MeterParameter $meterParameter, private Address $address) - { + public function __construct(private MeterParameter $meterParameter, private Address $address) { parent::__construct(); } - public function runInCompanyScope(): void - { + public function runInCompanyScope(): void { $usedMeters = $this->meterParameter::all(); foreach ($usedMeters as $meter) { diff --git a/src/backend/app/Console/Commands/AddPlugin.php b/src/backend/app/Console/Commands/AddPlugin.php index db0b06821..81bf9a84d 100644 --- a/src/backend/app/Console/Commands/AddPlugin.php +++ b/src/backend/app/Console/Commands/AddPlugin.php @@ -4,18 +4,16 @@ use App\Services\PluginsService; -class AddPlugin extends AbstractSharedCommand -{ +class AddPlugin extends AbstractSharedCommand { protected $signature = 'plugin:add {name} {composer_name} {description}'; + protected $description = 'Plugin Details adding to database'; - public function __construct(private PluginsService $pluginsService) - { + public function __construct(private PluginsService $pluginsService) { parent::__construct(); } - public function runInCompanyScope(): void - { + public function runInCompanyScope(): void { $name = $this->argument('name'); $composer_name = $this->argument('composer_name'); $description = $this->argument('description'); diff --git a/src/backend/app/Console/Commands/AdminPasswordResetter.php b/src/backend/app/Console/Commands/AdminPasswordResetter.php index c02f11cc4..5ad795609 100644 --- a/src/backend/app/Console/Commands/AdminPasswordResetter.php +++ b/src/backend/app/Console/Commands/AdminPasswordResetter.php @@ -4,18 +4,16 @@ use App\Services\UserService; -class AdminPasswordResetter extends AbstractSharedCommand -{ +class AdminPasswordResetter extends AbstractSharedCommand { protected $signature = 'reset:admin-password'; + protected $description = 'Reset forgotten password'; - public function __construct(private UserService $userService) - { + public function __construct(private UserService $userService) { parent::__construct(); } - public function runInCompanyScope(): void - { + public function runInCompanyScope(): void { $admin = $this->userService->resetAdminPassword(); $this->alert(' Please use following credentials to login: diff --git a/src/backend/app/Console/Commands/AssetRateChecker.php b/src/backend/app/Console/Commands/AssetRateChecker.php index c733109ee..4a629962c 100644 --- a/src/backend/app/Console/Commands/AssetRateChecker.php +++ b/src/backend/app/Console/Commands/AssetRateChecker.php @@ -13,9 +13,9 @@ use Inensus\Ticket\Models\TicketCategory; use Inensus\Ticket\Services\TicketService; -class AssetRateChecker extends AbstractSharedCommand -{ +class AssetRateChecker extends AbstractSharedCommand { protected $signature = 'asset-rate:check'; + protected $description = 'Checks if any asset rate is due and creates a ticket and reminds the customer'; public function __construct( @@ -29,14 +29,12 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->remindUpComingRates(); $this->findOverDueRates(); } - private function remindUpComingRates(): void - { + private function remindUpComingRates(): void { $smsApplianceRemindRates = $this->getApplianceRemindRates(); $smsApplianceRemindRates->each(function ($smsApplianceRemindRate) { $dueAssetRates = $this->assetRate::with([ @@ -60,8 +58,7 @@ function ($q) { }); } - private function findOverDueRates(): void - { + private function findOverDueRates(): void { $smsApplianceRemindRates = $this->getApplianceRemindRates(); $smsApplianceRemindRates->each(function ($smsApplianceRemindRate) { $overDueRates = $this->assetRate::with(['assetPerson.asset', 'assetPerson.person.addresses']) @@ -78,14 +75,12 @@ private function findOverDueRates(): void }); } - private function sendReminderSms(AssetRate $assetRate): void - { + private function sendReminderSms(AssetRate $assetRate): void { $smsService = app()->make(SmsService::class); $smsService->sendSms($assetRate, SmsTypes::APPLIANCE_RATE, SmsConfigs::class); } - private function sendReminders($dueAssetRates, $smsType) - { + private function sendReminders($dueAssetRates, $smsType) { $dueAssetRates->each(function ($dueAssetRate) use ($smsType) { $this->sendReminderSms($dueAssetRate); if ($smsType === SmsTypes::OVER_DUE_APPLIANCE_RATE) { @@ -96,8 +91,7 @@ private function sendReminders($dueAssetRates, $smsType) }); } - private function createReminderTicket(AssetRate $assetRate, $overDue = false): void - { + private function createReminderTicket(AssetRate $assetRate, $overDue = false): void { $currency = $this->mainSettingsService->getAll()->first()->currency; // create ticket for customer service $creator = $this->user->newQuery()->firstOrCreate([ @@ -127,8 +121,7 @@ private function createReminderTicket(AssetRate $assetRate, $overDue = false): v ); } - private function getApplianceRemindRates(): Collection|array - { + private function getApplianceRemindRates(): Collection|array { return $this->smsApplianceRemindRateService->getApplianceRemindRates(); } } diff --git a/src/backend/app/Console/Commands/BackupFull.php b/src/backend/app/Console/Commands/BackupFull.php index a8d9ccc50..cc71d9eaa 100644 --- a/src/backend/app/Console/Commands/BackupFull.php +++ b/src/backend/app/Console/Commands/BackupFull.php @@ -6,13 +6,12 @@ use Illuminate\Console\Command; -class BackupFull extends Command -{ +class BackupFull extends Command { protected $signature = 'backup:full'; + protected $description = 'Run the backup for core base database and all tenant databases'; - public function handle(): void - { + public function handle(): void { $this->info('Starting backup for core database'); config(['database.connections.mysql' => config('database.connections.micro_power_manager')]); $this->call('backup:run', [ diff --git a/src/backend/app/Console/Commands/BackupTenantDatabase.php b/src/backend/app/Console/Commands/BackupTenantDatabase.php index 0d61742f0..e3164e6b9 100644 --- a/src/backend/app/Console/Commands/BackupTenantDatabase.php +++ b/src/backend/app/Console/Commands/BackupTenantDatabase.php @@ -4,13 +4,12 @@ namespace App\Console\Commands; -class BackupTenantDatabase extends AbstractSharedCommand -{ +class BackupTenantDatabase extends AbstractSharedCommand { protected $signature = 'backup-tenant:run'; + protected $description = 'Run the backup for provided tenant database(s)'; - public function handle() - { + public function handle() { $databaseName = config('database.connections.shard'); $this->info('Starting backup for tenant databases'); dump($this->arguments()); diff --git a/src/backend/app/Console/Commands/CalinMeterReader.php b/src/backend/app/Console/Commands/CalinMeterReader.php index 3fee9b062..99281a857 100644 --- a/src/backend/app/Console/Commands/CalinMeterReader.php +++ b/src/backend/app/Console/Commands/CalinMeterReader.php @@ -9,17 +9,14 @@ * Reads the daily consumptions of meters * Class CalinMeterReader. */ -class CalinMeterReader extends AbstractSharedCommand -{ +class CalinMeterReader extends AbstractSharedCommand { protected $signature = 'calinMeters:readOnline'; - public function __construct(private Meter $meter, private CalinReadMeter $calinReadMeter) - { + public function __construct(private Meter $meter, private CalinReadMeter $calinReadMeter) { parent::__construct(); } - public function runInCompanyScope(): void - { + public function runInCompanyScope(): void { $meters = $this->meter::whereHas( 'meterType', function ($q) { diff --git a/src/backend/app/Console/Commands/ClustersDashboardCacheDataGenerator.php b/src/backend/app/Console/Commands/ClustersDashboardCacheDataGenerator.php index b95e086b0..7c57988d6 100644 --- a/src/backend/app/Console/Commands/ClustersDashboardCacheDataGenerator.php +++ b/src/backend/app/Console/Commands/ClustersDashboardCacheDataGenerator.php @@ -4,9 +4,9 @@ use App\Services\ClustersDashboardCacheDataService; -class ClustersDashboardCacheDataGenerator extends AbstractSharedCommand -{ +class ClustersDashboardCacheDataGenerator extends AbstractSharedCommand { protected $signature = 'update:cachedClustersDashboardData'; + protected $description = 'Update Clusters Dashboard Data'; public function __construct( @@ -15,8 +15,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->clustersDashboardCacheDataService->setData(); } } diff --git a/src/backend/app/Console/Commands/CreateDummyCompanyWithData.php b/src/backend/app/Console/Commands/CreateDummyCompanyWithData.php index f518f94f2..0c35666ca 100644 --- a/src/backend/app/Console/Commands/CreateDummyCompanyWithData.php +++ b/src/backend/app/Console/Commands/CreateDummyCompanyWithData.php @@ -7,8 +7,7 @@ use Illuminate\Support\Facades\DB; use MPM\DatabaseProxy\DatabaseProxyManagerService; -class CreateDummyCompanyWithData extends Command -{ +class CreateDummyCompanyWithData extends Command { public const SQL_DUMMY_DATA_FILE_NAMES = [ 'dummy_agent_data.sql', 'dummy_data.sql', @@ -17,6 +16,7 @@ class CreateDummyCompanyWithData extends Command 'dummy_ticket_data.sql', 'dummy_transaction_data.sql', ]; + public const DUMMY_COMPANY_DATA = [ 'name' => 'Dummy Company', 'address' => 'Dummy Address', @@ -25,14 +25,17 @@ class CreateDummyCompanyWithData extends Command 'email' => 'dummy@company.com', 'protected_page_password' => '123123', ]; + public const DUMMY_COMPANY_USER = [ 'password' => '123123', 'email' => 'dummy@user.com', 'name' => 'Dummy User', ]; + public const DUMMY_DATABASE_NAME = 'DummyCompany_1'; protected $signature = 'dummy:create-company-with-dummy-data'; + protected $description = 'Create a dummy company with dummy data for development environment'; public function __construct( @@ -42,8 +45,7 @@ public function __construct( parent::__construct(); } - public function handle() - { + public function handle() { try { foreach (self::SQL_DUMMY_DATA_FILE_NAMES as $sqlFile) { $path = __DIR__.'/../../../database/dummyData/'.$sqlFile; @@ -63,8 +65,7 @@ public function handle() } } - private function importSqlDump($path, $databaseName) - { + private function importSqlDump($path, $databaseName) { try { DB::select("USE $databaseName"); $sql = file_get_contents($path); diff --git a/src/backend/app/Console/Commands/DummyDataCreator.php b/src/backend/app/Console/Commands/DummyDataCreator.php index aa892ba4d..6286e3371 100644 --- a/src/backend/app/Console/Commands/DummyDataCreator.php +++ b/src/backend/app/Console/Commands/DummyDataCreator.php @@ -24,9 +24,9 @@ use Inensus\WavecomPaymentProvider\Models\WaveComTransaction; use Inensus\WaveMoneyPaymentProvider\Models\WaveMoneyTransaction; -class DummyDataCreator extends AbstractSharedCommand -{ +class DummyDataCreator extends AbstractSharedCommand { protected $signature = 'dummy:create-data {amount} {--company-id=} {--type=}'; + protected $description = 'creates dummy data for demo company'; private $transactionTypes = [ @@ -61,8 +61,7 @@ public function __construct( parent::__construct(); } - public function handle() - { + public function handle() { $companyId = $this->option('company-id'); $type = $this->option('type') ?? 'transaction'; $amount = $this->argument('amount'); @@ -90,8 +89,7 @@ public function handle() } } - private function generateTransaction(): void - { + private function generateTransaction(): void { try { // get randomly a user $randomMeter = $this->meter::inRandomOrder()->with([ @@ -287,13 +285,11 @@ private function generateTransaction(): void } } - private function getTransactionTypeRandomlyFromTransactionTypes() - { + private function getTransactionTypeRandomlyFromTransactionTypes() { return $this->transactionTypes[array_rand($this->transactionTypes)]; } - private function generateTicket() - { + private function generateTicket() { $randomCategory = $this->ticketCategory->newQuery()->inRandomOrder()->first(); $fakeSentence = $this->generateFakeSentence(); $randomCreator = $this->user->inRandomOrder()->first(); @@ -341,8 +337,7 @@ private function generateTicket() } } - private function generateFakeSentence($minWords = 5, $maxWords = 15) - { + private function generateFakeSentence($minWords = 5, $maxWords = 15) { $loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; $words = explode(' ', $loremIpsum); diff --git a/src/backend/app/Console/Commands/EcosysCustomerDatabaseParser.php b/src/backend/app/Console/Commands/EcosysCustomerDatabaseParser.php index c29ac1371..3c294f13a 100644 --- a/src/backend/app/Console/Commands/EcosysCustomerDatabaseParser.php +++ b/src/backend/app/Console/Commands/EcosysCustomerDatabaseParser.php @@ -5,19 +5,17 @@ use Illuminate\Support\Facades\Log; use MPM\CustomBulkRegistration\Ecosys\CustomerDatabaseParser; -class EcosysCustomerDatabaseParser extends AbstractSharedCommand -{ +class EcosysCustomerDatabaseParser extends AbstractSharedCommand { // --company-id=36 protected $signature = 'ecosys:db-file-parser {--company-id=}'; + protected $description = 'custom database file parser for ecosys'; - public function __construct(private CustomerDatabaseParser $customerDatabaseParser) - { + public function __construct(private CustomerDatabaseParser $customerDatabaseParser) { parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Command started'); Log::info('command running w '.$this->option('company-id')); $result = $this->customerDatabaseParser->insertFromCsv(); diff --git a/src/backend/app/Console/Commands/MailApplianceDebtsCommand.php b/src/backend/app/Console/Commands/MailApplianceDebtsCommand.php index d4c93a855..2902e4332 100644 --- a/src/backend/app/Console/Commands/MailApplianceDebtsCommand.php +++ b/src/backend/app/Console/Commands/MailApplianceDebtsCommand.php @@ -5,14 +5,12 @@ use App\Services\ApplianceRateService; use MPM\OutstandingDebts\OutstandingDebtsExportService; -class MailApplianceDebtsCommand extends AbstractSharedCommand -{ +class MailApplianceDebtsCommand extends AbstractSharedCommand { protected $signature = 'mail:appliance-debts'; protected $description = 'Send mail to customers with appliance debts'; - public function handle(ApplianceRateService $applianceRateService, OutstandingDebtsExportService $outstandingDebtsExportService): void - { + public function handle(ApplianceRateService $applianceRateService, OutstandingDebtsExportService $outstandingDebtsExportService): void { $applianceDebtHavingCustomerCount = $applianceRateService->queryOutstandingDebtsByApplianceRates()->count(); // do not send mail if there is no customer with appliance debt if ($applianceDebtHavingCustomerCount > 0) { diff --git a/src/backend/app/Console/Commands/MakeMigrationTenant.php b/src/backend/app/Console/Commands/MakeMigrationTenant.php index b30d1de24..b27584c94 100644 --- a/src/backend/app/Console/Commands/MakeMigrationTenant.php +++ b/src/backend/app/Console/Commands/MakeMigrationTenant.php @@ -4,13 +4,12 @@ use Illuminate\Console\Command; -class MakeMigrationTenant extends Command -{ +class MakeMigrationTenant extends Command { protected $signature = 'make:migration-tenant {migration-name}'; + protected $description = 'Create new migration file for tenant database(s)'; - public function handle() - { + public function handle() { $migrationName = $this->argument('migration-name'); $this->call('make:migration', [ 'name' => $migrationName, diff --git a/src/backend/app/Console/Commands/MigrateTenant.php b/src/backend/app/Console/Commands/MigrateTenant.php index 131dc9888..e0352d971 100644 --- a/src/backend/app/Console/Commands/MigrateTenant.php +++ b/src/backend/app/Console/Commands/MigrateTenant.php @@ -2,13 +2,12 @@ namespace App\Console\Commands; -class MigrateTenant extends AbstractSharedCommand -{ +class MigrateTenant extends AbstractSharedCommand { protected $signature = 'migrate-tenant {--company-id=}'; + protected $description = 'Run the database migrations on provided tenant database(s)'; - public function handle() - { + public function handle() { $this->call('optimize:clear'); $this->call('migrate', [ '--database' => 'shard', diff --git a/src/backend/app/Console/Commands/MigrateTenantDrop.php b/src/backend/app/Console/Commands/MigrateTenantDrop.php index ba5d448a8..9a1ca6cea 100644 --- a/src/backend/app/Console/Commands/MigrateTenantDrop.php +++ b/src/backend/app/Console/Commands/MigrateTenantDrop.php @@ -6,13 +6,12 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; -class MigrateTenantDrop extends Command -{ +class MigrateTenantDrop extends Command { protected $signature = 'migrate-tenant:drop-demo-company'; + protected $description = 'Drop all tables on the Demo tenant database'; - public function handle() - { + public function handle() { $this->call('optimize:clear'); $database = DummyCompany::DUMMY_COMPANY_DATABASE_NAME; DB::statement("DROP DATABASE `$database`"); diff --git a/src/backend/app/Console/Commands/MigrateTenantFresh.php b/src/backend/app/Console/Commands/MigrateTenantFresh.php index cb2c8fec8..31e3c2de3 100644 --- a/src/backend/app/Console/Commands/MigrateTenantFresh.php +++ b/src/backend/app/Console/Commands/MigrateTenantFresh.php @@ -2,13 +2,12 @@ namespace App\Console\Commands; -class MigrateTenantFresh extends AbstractSharedCommand -{ +class MigrateTenantFresh extends AbstractSharedCommand { protected $signature = 'migrate-tenant:fresh {--company-id=}'; + protected $description = 'Drop all tables and re-run all migrations on provided tenant database(s)'; - public function handle() - { + public function handle() { $this->call('optimize:clear'); $this->call('migrate:fresh', [ '--database' => 'shard', diff --git a/src/backend/app/Console/Commands/MigrateTenantInstall.php b/src/backend/app/Console/Commands/MigrateTenantInstall.php index 461043ef2..c96eff549 100644 --- a/src/backend/app/Console/Commands/MigrateTenantInstall.php +++ b/src/backend/app/Console/Commands/MigrateTenantInstall.php @@ -2,13 +2,12 @@ namespace App\Console\Commands; -class MigrateTenantInstall extends AbstractSharedCommand -{ +class MigrateTenantInstall extends AbstractSharedCommand { protected $signature = 'migrate-tenant:install {--company-id=}'; + protected $description = 'Create the migration repository on provided tenant database(s)'; - public function handle() - { + public function handle() { $this->call('optimize:clear'); $this->call('migrate:install', [ '--database' => 'shard', diff --git a/src/backend/app/Console/Commands/MigrateTenantRefresh.php b/src/backend/app/Console/Commands/MigrateTenantRefresh.php index fbc7f612c..beb7259fa 100644 --- a/src/backend/app/Console/Commands/MigrateTenantRefresh.php +++ b/src/backend/app/Console/Commands/MigrateTenantRefresh.php @@ -2,13 +2,12 @@ namespace App\Console\Commands; -class MigrateTenantRefresh extends AbstractSharedCommand -{ +class MigrateTenantRefresh extends AbstractSharedCommand { protected $signature = 'migrate-tenant:refresh {--company-id=}'; + protected $description = 'Reset and re-run all migrations on provided tenant database(s)'; - public function handle() - { + public function handle() { $this->call('optimize:clear'); $this->call('migrate:refresh', [ '--database' => 'shard', diff --git a/src/backend/app/Console/Commands/MigrateTenantReset.php b/src/backend/app/Console/Commands/MigrateTenantReset.php index 77be445c3..1e7fbd041 100644 --- a/src/backend/app/Console/Commands/MigrateTenantReset.php +++ b/src/backend/app/Console/Commands/MigrateTenantReset.php @@ -2,13 +2,12 @@ namespace App\Console\Commands; -class MigrateTenantReset extends AbstractSharedCommand -{ +class MigrateTenantReset extends AbstractSharedCommand { protected $signature = 'migrate-tenant:reset {--company-id=}'; + protected $description = 'Rollback all database migrations on provided tenant database(s)'; - public function handle() - { + public function handle() { $this->call('optimize:clear'); $this->call('migrate:reset', [ '--database' => 'shard', diff --git a/src/backend/app/Console/Commands/MigrateTenantRollback.php b/src/backend/app/Console/Commands/MigrateTenantRollback.php index fd13d5784..622bd269a 100644 --- a/src/backend/app/Console/Commands/MigrateTenantRollback.php +++ b/src/backend/app/Console/Commands/MigrateTenantRollback.php @@ -2,13 +2,12 @@ namespace App\Console\Commands; -class MigrateTenantRollback extends AbstractSharedCommand -{ +class MigrateTenantRollback extends AbstractSharedCommand { protected $signature = 'migrate-tenant:rollback {--company-id=}'; + protected $description = 'Rollback the last database migration on provided tenant database(s)'; - public function handle() - { + public function handle() { $this->call('optimize:clear'); $this->call('migrate:rollback', [ '--database' => 'shard', diff --git a/src/backend/app/Console/Commands/MigrateTenantStatus.php b/src/backend/app/Console/Commands/MigrateTenantStatus.php index 5947c927c..5f173d2cf 100644 --- a/src/backend/app/Console/Commands/MigrateTenantStatus.php +++ b/src/backend/app/Console/Commands/MigrateTenantStatus.php @@ -2,13 +2,12 @@ namespace App\Console\Commands; -class MigrateTenantStatus extends AbstractSharedCommand -{ +class MigrateTenantStatus extends AbstractSharedCommand { protected $signature = 'migrate-tenant:status {--company-id=}'; + protected $description = 'Show the status of each migrations on provided tenant database(s)'; - public function handle() - { + public function handle() { $this->call('optimize:clear'); $this->call('migrate:status', [ '--database' => 'shard', diff --git a/src/backend/app/Console/Commands/ModelShowTenant.php b/src/backend/app/Console/Commands/ModelShowTenant.php index 45c011286..3b1fdb2ad 100644 --- a/src/backend/app/Console/Commands/ModelShowTenant.php +++ b/src/backend/app/Console/Commands/ModelShowTenant.php @@ -5,8 +5,7 @@ use Illuminate\Console\Command; use MPM\DatabaseProxy\DatabaseProxyManagerService; -class ModelShowTenant extends Command -{ +class ModelShowTenant extends Command { /** * The name and signature of the console command. * @@ -38,8 +37,7 @@ public function __construct( * * @return int */ - public function handle() - { + public function handle() { $this->databaseProxyManagerService->buildDatabaseConnectionDummyCompany(); $this->call('model:show', [ diff --git a/src/backend/app/Console/Commands/OutsourceReportGenerator.php b/src/backend/app/Console/Commands/OutsourceReportGenerator.php index aedd72874..ac3e1ed9f 100644 --- a/src/backend/app/Console/Commands/OutsourceReportGenerator.php +++ b/src/backend/app/Console/Commands/OutsourceReportGenerator.php @@ -7,18 +7,16 @@ use PhpOffice\PhpSpreadsheet\Writer\Exception; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; -class OutsourceReportGenerator extends AbstractSharedCommand -{ +class OutsourceReportGenerator extends AbstractSharedCommand { protected $signature = 'reports:outsource {--start-date=}'; + protected $description = 'Create outsources reports'; - public function __construct(private TicketExportController $reports) - { + public function __construct(private TicketExportController $reports) { parent::__construct(); } - public function runInCompanyScope(): void - { + public function runInCompanyScope(): void { if ($this->option('start-date') !== '') { $toDay = Carbon::parse($this->option('start-date'))->format('Y-m-d'); } else { diff --git a/src/backend/app/Console/Commands/PackageGenerator.php b/src/backend/app/Console/Commands/PackageGenerator.php index 8c190d5b4..cb6817d5e 100644 --- a/src/backend/app/Console/Commands/PackageGenerator.php +++ b/src/backend/app/Console/Commands/PackageGenerator.php @@ -4,13 +4,12 @@ use Illuminate\Console\Command; -class PackageGenerator extends Command -{ +class PackageGenerator extends Command { protected $signature = 'micropowermanager:new-package {package-name}'; + protected $description = 'Clones package development starter pack'; - public function handle(): void - { + public function handle(): void { $packageNameArg = $this->argument('package-name'); $packageName = strtolower($packageNameArg); $nameSpace = ''; diff --git a/src/backend/app/Console/Commands/ReportGenerator.php b/src/backend/app/Console/Commands/ReportGenerator.php index b0dc6e405..f01eb0568 100644 --- a/src/backend/app/Console/Commands/ReportGenerator.php +++ b/src/backend/app/Console/Commands/ReportGenerator.php @@ -5,18 +5,16 @@ use App\Http\Controllers\Reports; use Carbon\Carbon; -class ReportGenerator extends AbstractSharedCommand -{ +class ReportGenerator extends AbstractSharedCommand { protected $signature = 'reports:city-revenue {type} {--start-date=} {--company-id=}'; + protected $description = 'Creates city revenue reports'; - public function __construct(private Reports $reports) - { + public function __construct(private Reports $reports) { parent::__construct(); } - public function handle(): void - { + public function handle(): void { $startDay = Carbon::now()->format('Y-m-d'); if ($this->option('start-date') != '') { $toDay = Carbon::parse($this->option('start-date'))->format('Y-m-d'); diff --git a/src/backend/app/Console/Commands/ResendRejectedMessages.php b/src/backend/app/Console/Commands/ResendRejectedMessages.php index 70be32c90..67f880735 100644 --- a/src/backend/app/Console/Commands/ResendRejectedMessages.php +++ b/src/backend/app/Console/Commands/ResendRejectedMessages.php @@ -7,8 +7,7 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\Log; -class ResendRejectedMessages extends AbstractSharedCommand -{ +class ResendRejectedMessages extends AbstractSharedCommand { /** * The name and signature of the console command. * @@ -28,13 +27,11 @@ class ResendRejectedMessages extends AbstractSharedCommand * * @return void */ - public function __construct(private Sms $sms) - { + public function __construct(private Sms $sms) { parent::__construct(); } - public function handle(): void - { + public function handle(): void { $amountToSend = $this->argument('amount'); $messagesToSend = $this->sms ->where('direction', 1) diff --git a/src/backend/app/Console/Commands/RoutesGenerator.php b/src/backend/app/Console/Commands/RoutesGenerator.php index 78fdad8a1..1bd80e32b 100644 --- a/src/backend/app/Console/Commands/RoutesGenerator.php +++ b/src/backend/app/Console/Commands/RoutesGenerator.php @@ -2,13 +2,12 @@ namespace App\Console\Commands; -class RoutesGenerator extends AbstractSharedCommand -{ +class RoutesGenerator extends AbstractSharedCommand { protected $signature = 'routes:generate'; + protected $description = 'Generates new routes from packages'; - public function runInCompanyScope(): void - { + public function runInCompanyScope(): void { $routeTmp = 'storage/skeletons/routes.tmp'; fopen($routeTmp, 'w'); @@ -28,8 +27,7 @@ public function runInCompanyScope(): void } } - private function createPluginRoutesTmp(string $src, string $coreRoutesTmp): void - { + private function createPluginRoutesTmp(string $src, string $coreRoutesTmp): void { $packageRoutes = $src.'/js/routes.js'; $packageRoutesTmp = $src.'/js/routes.tmp'; fopen($packageRoutesTmp, 'w'); @@ -42,8 +40,7 @@ private function createPluginRoutesTmp(string $src, string $coreRoutesTmp): void /** * @return void */ - private function removeLine(string $packageRoutesTmp, string $type) - { + private function removeLine(string $packageRoutesTmp, string $type) { $lines = file($packageRoutesTmp); if ($type === 'first') { array_shift($lines); @@ -52,12 +49,11 @@ private function removeLine(string $packageRoutesTmp, string $type) } else { return; } - $file = join('', $lines); + $file = implode('', $lines); file_put_contents($packageRoutesTmp, $file); } - private function appendLines(string $packageRoutesTmp, $coreRoutesTmp): void - { + private function appendLines(string $packageRoutesTmp, $coreRoutesTmp): void { $lines = file($packageRoutesTmp); $tmp = fopen($coreRoutesTmp, 'a+'); $counter = 1; diff --git a/src/backend/app/Console/Commands/SendNonPayingCustomerMailCommand.php b/src/backend/app/Console/Commands/SendNonPayingCustomerMailCommand.php index 6dbbbd142..560728626 100644 --- a/src/backend/app/Console/Commands/SendNonPayingCustomerMailCommand.php +++ b/src/backend/app/Console/Commands/SendNonPayingCustomerMailCommand.php @@ -12,12 +12,13 @@ use Carbon\CarbonImmutable; use Illuminate\Support\Collection; -class SendNonPayingCustomerMailCommand extends AbstractSharedCommand -{ +class SendNonPayingCustomerMailCommand extends AbstractSharedCommand { private const EMAIL_TEMPLATE = 'templates.mail.non_paying_mail'; + private const REPORT_TEMPLATE = 'templates.mail.non_paying_pdf'; protected $signature = 'reports:send-non-paying-customer-mail {--start-date=} {--end-date=}'; + protected $description = 'Creates a report that includes a list of customers that didnt buy anything in the given period'; @@ -32,8 +33,7 @@ public function __construct( parent::__construct(); } - public function runInCompanyScope(): void - { + public function runInCompanyScope(): void { $startDate = $this->option('start-date') ? CarbonImmutable::make( $this->option('start-date') ) : CarbonImmutable::make('first day of last month'); diff --git a/src/backend/app/Console/Commands/ShiftEcosysSHSdataForDeviceFeature.php b/src/backend/app/Console/Commands/ShiftEcosysSHSdataForDeviceFeature.php index 26048ad52..9ad4bc6a5 100644 --- a/src/backend/app/Console/Commands/ShiftEcosysSHSdataForDeviceFeature.php +++ b/src/backend/app/Console/Commands/ShiftEcosysSHSdataForDeviceFeature.php @@ -9,10 +9,10 @@ use App\Models\SolarHomeSystem; use Illuminate\Support\Facades\DB; -class ShiftEcosysSHSdataForDeviceFeature extends AbstractSharedCommand -{ +class ShiftEcosysSHSdataForDeviceFeature extends AbstractSharedCommand { // --company-id=36 protected $signature = 'ecosys:shift-data {--company-id=}'; + protected $description = 'custom data shifting command for ecosys'; private $assetTypePricePeer = [ @@ -25,13 +25,11 @@ class ShiftEcosysSHSdataForDeviceFeature extends AbstractSharedCommand 3 => 2, ]; - public function __construct() - { + public function __construct() { parent::__construct(); } - public function handle() - { + public function handle() { $this->info('Command started'); $this->info('command running w '.$this->option('company-id')); $manufacturer = Manufacturer::query()->where('name', 'SunKing SHS')->first(); diff --git a/src/backend/app/Console/Kernel.php b/src/backend/app/Console/Kernel.php index 37cb47820..e93540ca5 100644 --- a/src/backend/app/Console/Kernel.php +++ b/src/backend/app/Console/Kernel.php @@ -23,8 +23,7 @@ use Inensus\WavecomPaymentProvider\Console\Commands\InstallPackage as InstallWaveComPackage; use Inensus\WaveMoneyPaymentProvider\Console\Commands\InstallPackage as InstallWaveMoneyPaymentProviderPackage; -class Kernel extends ConsoleKernel -{ +class Kernel extends ConsoleKernel { /** * The Artisan commands provided by your application. * @@ -54,12 +53,9 @@ class Kernel extends ConsoleKernel /** * Define the application's command schedule. * - * @param Schedule $schedule - * * @return void */ - protected function schedule(Schedule $schedule) - { + protected function schedule(Schedule $schedule) { $schedule->command('reports:city-revenue weekly')->weeklyOn(1, '3:00'); $schedule->command('reports:city-revenue monthly')->monthlyOn(1, '3:00'); $schedule->command('reports:outsource')->monthlyOn(1, '3:30'); @@ -77,8 +73,7 @@ protected function schedule(Schedule $schedule) * * @return void */ - protected function commands() - { + protected function commands() { $this->load(__DIR__.'/Commands'); include base_path('routes/console.php'); diff --git a/src/backend/app/Events/AssetPersonCreated.php b/src/backend/app/Events/AssetPersonCreated.php index 8154a8f8d..15b005cf8 100644 --- a/src/backend/app/Events/AssetPersonCreated.php +++ b/src/backend/app/Events/AssetPersonCreated.php @@ -8,8 +8,7 @@ use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; -class AssetPersonCreated -{ +class AssetPersonCreated { use Dispatchable; use InteractsWithSockets; use SerializesModels; @@ -19,18 +18,14 @@ class AssetPersonCreated */ private $assetPerson; - public function __construct(AssetPerson $assetPerson) - { + public function __construct(AssetPerson $assetPerson) { $this->assetPerson = $assetPerson; } /** * Get the channels the event should broadcast on. - * - * @return PrivateChannel */ - public function broadcastOn(): PrivateChannel - { + public function broadcastOn(): PrivateChannel { return new PrivateChannel('assetPerson.created'); } } diff --git a/src/backend/app/Events/ClusterEvent.php b/src/backend/app/Events/ClusterEvent.php index 060339e07..53a3092ec 100644 --- a/src/backend/app/Events/ClusterEvent.php +++ b/src/backend/app/Events/ClusterEvent.php @@ -9,8 +9,7 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Log; -class ClusterEvent -{ +class ClusterEvent { use Dispatchable; use InteractsWithSockets; use SerializesModels; @@ -19,10 +18,12 @@ class ClusterEvent * @var Cluster */ public $cluster; + /** * @var string */ public $type; + /** * @var mixed contains geo coordinates array or external url to fetch */ @@ -30,13 +31,8 @@ class ClusterEvent /** * Create a new event instance. - * - * @param Cluster $cluster - * @param string $type - * @param $data */ - public function __construct(Cluster $cluster, string $type, $data) - { + public function __construct(Cluster $cluster, string $type, $data) { Log::debug('cluster event created'); $this->cluster = $cluster; $this->type = $type; @@ -45,11 +41,8 @@ public function __construct(Cluster $cluster, string $type, $data) /** * Get the channels the event should broadcast on. - * - * @return PrivateChannel */ - public function broadcastOn(): PrivateChannel - { + public function broadcastOn(): PrivateChannel { return new PrivateChannel('clusters'); } } diff --git a/src/backend/app/Events/HistoryEvent.php b/src/backend/app/Events/HistoryEvent.php index 0d13afea6..cd7f14bd7 100644 --- a/src/backend/app/Events/HistoryEvent.php +++ b/src/backend/app/Events/HistoryEvent.php @@ -9,28 +9,20 @@ use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; -class HistoryEvent implements ShouldBroadcast -{ +class HistoryEvent implements ShouldBroadcast { use Dispatchable; use InteractsWithSockets; use SerializesModels; /** * Create a new event instance. - * - * @param History $historyModel */ - public function __construct(private readonly History $historyModel) - { - } + public function __construct(private readonly History $historyModel) {} /** * Get the channels the event should broadcast on. - * - * @return PrivateChannel */ - public function broadcastOn(): PrivateChannel - { + public function broadcastOn(): PrivateChannel { return new PrivateChannel('histories'); } } diff --git a/src/backend/app/Events/NewTicket.php b/src/backend/app/Events/NewTicket.php index 924945116..2455b25f6 100644 --- a/src/backend/app/Events/NewTicket.php +++ b/src/backend/app/Events/NewTicket.php @@ -9,19 +9,15 @@ use Illuminate\Queue\SerializesModels; use Inensus\Ticket\Models\Ticket; -class NewTicket implements ShouldBroadcast -{ +class NewTicket implements ShouldBroadcast { use Dispatchable; use InteractsWithSockets; use SerializesModels; /** * Create a new event instance. - * - * @param Ticket $ticket */ - public function __construct(private Ticket $ticket) - { + public function __construct(private Ticket $ticket) { $this->ticket = $ticket; } @@ -30,8 +26,7 @@ public function __construct(private Ticket $ticket) * * @return PrivateChannel */ - public function broadcastOn() - { + public function broadcastOn() { return new PrivateChannel('ticketcreated'); } } diff --git a/src/backend/app/Events/PersonDeleting.php b/src/backend/app/Events/PersonDeleting.php index 614e2c69b..bc781030e 100644 --- a/src/backend/app/Events/PersonDeleting.php +++ b/src/backend/app/Events/PersonDeleting.php @@ -8,8 +8,7 @@ use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; -class PersonDeleting -{ +class PersonDeleting { use Dispatchable; use InteractsWithSockets; use SerializesModels; @@ -21,18 +20,14 @@ class PersonDeleting * * @return void */ - public function __construct(Person $person) - { + public function __construct(Person $person) { $this->person = $person; } /** * Get the channels the event should broadcast on. - * - * @return PrivateChannel */ - public function broadcastOn(): PrivateChannel - { + public function broadcastOn(): PrivateChannel { return new PrivateChannel('person.deleted'); } } diff --git a/src/backend/app/Exceptions/AccessRates/NoAccessRateFound.php b/src/backend/app/Exceptions/AccessRates/NoAccessRateFound.php index d6235e778..e2ee7b607 100644 --- a/src/backend/app/Exceptions/AccessRates/NoAccessRateFound.php +++ b/src/backend/app/Exceptions/AccessRates/NoAccessRateFound.php @@ -2,6 +2,4 @@ namespace App\Exceptions\AccessRates; -class NoAccessRateFound extends \Exception -{ -} +class NoAccessRateFound extends \Exception {} diff --git a/src/backend/app/Exceptions/ActiveSheetNotCreatedException.php b/src/backend/app/Exceptions/ActiveSheetNotCreatedException.php index 15050ae28..00ab89f41 100644 --- a/src/backend/app/Exceptions/ActiveSheetNotCreatedException.php +++ b/src/backend/app/Exceptions/ActiveSheetNotCreatedException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class ActiveSheetNotCreatedException extends \Exception -{ -} +class ActiveSheetNotCreatedException extends \Exception {} diff --git a/src/backend/app/Exceptions/AgentRiskBalanceExceeded.php b/src/backend/app/Exceptions/AgentRiskBalanceExceeded.php index 0d3dabe95..ab293d85d 100644 --- a/src/backend/app/Exceptions/AgentRiskBalanceExceeded.php +++ b/src/backend/app/Exceptions/AgentRiskBalanceExceeded.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class AgentRiskBalanceExceeded extends \Exception -{ -} +class AgentRiskBalanceExceeded extends \Exception {} diff --git a/src/backend/app/Exceptions/CustomerGroup/CustomerGroupNotFound.php b/src/backend/app/Exceptions/CustomerGroup/CustomerGroupNotFound.php index ad4f23d0f..42aa2753a 100644 --- a/src/backend/app/Exceptions/CustomerGroup/CustomerGroupNotFound.php +++ b/src/backend/app/Exceptions/CustomerGroup/CustomerGroupNotFound.php @@ -2,6 +2,4 @@ namespace App\Exceptions\CustomerGroup; -class CustomerGroupNotFound extends \Exception -{ -} +class CustomerGroupNotFound extends \Exception {} diff --git a/src/backend/app/Exceptions/Device/DeviceIsNotAssignedToCustomer.php b/src/backend/app/Exceptions/Device/DeviceIsNotAssignedToCustomer.php index 2bc75c1b8..f84ec75f0 100644 --- a/src/backend/app/Exceptions/Device/DeviceIsNotAssignedToCustomer.php +++ b/src/backend/app/Exceptions/Device/DeviceIsNotAssignedToCustomer.php @@ -2,6 +2,4 @@ namespace App\Exceptions\Device; -class DeviceIsNotAssignedToCustomer extends \Exception -{ -} +class DeviceIsNotAssignedToCustomer extends \Exception {} diff --git a/src/backend/app/Exceptions/DownPaymentBiggerThanAmountException.php b/src/backend/app/Exceptions/DownPaymentBiggerThanAmountException.php index 27781ada7..8d61ef9e9 100644 --- a/src/backend/app/Exceptions/DownPaymentBiggerThanAmountException.php +++ b/src/backend/app/Exceptions/DownPaymentBiggerThanAmountException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class DownPaymentBiggerThanAmountException extends \Exception -{ -} +class DownPaymentBiggerThanAmountException extends \Exception {} diff --git a/src/backend/app/Exceptions/DownPaymentBiggerThanAppliancePriceException.php b/src/backend/app/Exceptions/DownPaymentBiggerThanAppliancePriceException.php index 390707fee..7841d0b5b 100644 --- a/src/backend/app/Exceptions/DownPaymentBiggerThanAppliancePriceException.php +++ b/src/backend/app/Exceptions/DownPaymentBiggerThanAppliancePriceException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class DownPaymentBiggerThanAppliancePriceException extends \Exception -{ -} +class DownPaymentBiggerThanAppliancePriceException extends \Exception {} diff --git a/src/backend/app/Exceptions/DownPaymentNotFoundException.php b/src/backend/app/Exceptions/DownPaymentNotFoundException.php index 40aca906f..ad5558551 100644 --- a/src/backend/app/Exceptions/DownPaymentNotFoundException.php +++ b/src/backend/app/Exceptions/DownPaymentNotFoundException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class DownPaymentNotFoundException extends \Exception -{ -} +class DownPaymentNotFoundException extends \Exception {} diff --git a/src/backend/app/Exceptions/GeoFormatException.php b/src/backend/app/Exceptions/GeoFormatException.php index 983c839ff..97898c940 100644 --- a/src/backend/app/Exceptions/GeoFormatException.php +++ b/src/backend/app/Exceptions/GeoFormatException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class GeoFormatException extends \Exception -{ -} +class GeoFormatException extends \Exception {} diff --git a/src/backend/app/Exceptions/Handler.php b/src/backend/app/Exceptions/Handler.php index a1eec9f81..0ed09f91c 100644 --- a/src/backend/app/Exceptions/Handler.php +++ b/src/backend/app/Exceptions/Handler.php @@ -9,8 +9,7 @@ use Illuminate\Http\Response; use Illuminate\Support\Facades\Log; -class Handler extends ExceptionHandler -{ +class Handler extends ExceptionHandler { use RestExceptionHandler; /** @@ -34,12 +33,9 @@ class Handler extends ExceptionHandler /** * Report or log an exception. * - * @param \Throwable $exception - * * @return void */ - public function report(\Throwable $exception) - { + public function report(\Throwable $exception) { Log::critical(get_class($exception), ['message' => $exception->getMessage(), 'trace' => array_slice($exception->getTrace(), 0, 10)]); parent::report($exception); } @@ -52,8 +48,7 @@ public function report(\Throwable $exception) * * @return \Illuminate\Http\JsonResponse */ - public function render($request, \Exception|\Throwable $exception) - { + public function render($request, \Exception|\Throwable $exception) { // api request outputs are json if (preg_match('/.*\.local\/api.*/', $request->url()) || preg_match('/.*\.com\/api.*/', $request->url())) { return $this->getJsonResponseForException($request, $exception); diff --git a/src/backend/app/Exceptions/InvalidBingApiKeyException.php b/src/backend/app/Exceptions/InvalidBingApiKeyException.php index 1de422650..76a1e6db7 100644 --- a/src/backend/app/Exceptions/InvalidBingApiKeyException.php +++ b/src/backend/app/Exceptions/InvalidBingApiKeyException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class InvalidBingApiKeyException extends \Exception -{ -} +class InvalidBingApiKeyException extends \Exception {} diff --git a/src/backend/app/Exceptions/MailNotSentException.php b/src/backend/app/Exceptions/MailNotSentException.php index 3d1906639..44dac52ea 100644 --- a/src/backend/app/Exceptions/MailNotSentException.php +++ b/src/backend/app/Exceptions/MailNotSentException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class MailNotSentException extends \Exception -{ -} +class MailNotSentException extends \Exception {} diff --git a/src/backend/app/Exceptions/Manufacturer/ApiCallDoesNotSupportedException.php b/src/backend/app/Exceptions/Manufacturer/ApiCallDoesNotSupportedException.php index 545df482e..4e40fbc1b 100644 --- a/src/backend/app/Exceptions/Manufacturer/ApiCallDoesNotSupportedException.php +++ b/src/backend/app/Exceptions/Manufacturer/ApiCallDoesNotSupportedException.php @@ -2,6 +2,4 @@ namespace App\Exceptions\Manufacturer; -class ApiCallDoesNotSupportedException extends \Exception -{ -} +class ApiCallDoesNotSupportedException extends \Exception {} diff --git a/src/backend/app/Exceptions/Manufacturer/MeterIsNotReadable.php b/src/backend/app/Exceptions/Manufacturer/MeterIsNotReadable.php index 0ba7e64fc..fc34249d1 100644 --- a/src/backend/app/Exceptions/Manufacturer/MeterIsNotReadable.php +++ b/src/backend/app/Exceptions/Manufacturer/MeterIsNotReadable.php @@ -2,6 +2,4 @@ namespace App\Exceptions\Manufacturer; -class MeterIsNotReadable extends \Exception -{ -} +class MeterIsNotReadable extends \Exception {} diff --git a/src/backend/app/Exceptions/MeterParameter/MeterParameterNotFound.php b/src/backend/app/Exceptions/MeterParameter/MeterParameterNotFound.php index e6626356f..c1aaa2541 100644 --- a/src/backend/app/Exceptions/MeterParameter/MeterParameterNotFound.php +++ b/src/backend/app/Exceptions/MeterParameter/MeterParameterNotFound.php @@ -2,6 +2,4 @@ namespace App\Exceptions\MeterParameter; -class MeterParameterNotFound extends \Exception -{ -} +class MeterParameterNotFound extends \Exception {} diff --git a/src/backend/app/Exceptions/Meters/MeterIsNotAssignedToCustomer.php b/src/backend/app/Exceptions/Meters/MeterIsNotAssignedToCustomer.php index 654c62302..a4eac9638 100644 --- a/src/backend/app/Exceptions/Meters/MeterIsNotAssignedToCustomer.php +++ b/src/backend/app/Exceptions/Meters/MeterIsNotAssignedToCustomer.php @@ -2,6 +2,4 @@ namespace App\Exceptions\Meters; -class MeterIsNotAssignedToCustomer extends \Exception -{ -} +class MeterIsNotAssignedToCustomer extends \Exception {} diff --git a/src/backend/app/Exceptions/Meters/MeterIsNotInUse.php b/src/backend/app/Exceptions/Meters/MeterIsNotInUse.php index 07b393f18..f5889877f 100644 --- a/src/backend/app/Exceptions/Meters/MeterIsNotInUse.php +++ b/src/backend/app/Exceptions/Meters/MeterIsNotInUse.php @@ -2,6 +2,4 @@ namespace App\Exceptions\Meters; -class MeterIsNotInUse extends \Exception -{ -} +class MeterIsNotInUse extends \Exception {} diff --git a/src/backend/app/Exceptions/MissingSmsReferencesException.php b/src/backend/app/Exceptions/MissingSmsReferencesException.php index 1d8433f92..194b81871 100644 --- a/src/backend/app/Exceptions/MissingSmsReferencesException.php +++ b/src/backend/app/Exceptions/MissingSmsReferencesException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class MissingSmsReferencesException extends \Exception -{ -} +class MissingSmsReferencesException extends \Exception {} diff --git a/src/backend/app/Exceptions/NotificationSendFailedException.php b/src/backend/app/Exceptions/NotificationSendFailedException.php index 92a565e89..51c61ae21 100644 --- a/src/backend/app/Exceptions/NotificationSendFailedException.php +++ b/src/backend/app/Exceptions/NotificationSendFailedException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class NotificationSendFailedException extends \Exception -{ -} +class NotificationSendFailedException extends \Exception {} diff --git a/src/backend/app/Exceptions/PaymentAmountBiggerThanTotalRemainingAmount.php b/src/backend/app/Exceptions/PaymentAmountBiggerThanTotalRemainingAmount.php index cb54ff880..677de17a8 100644 --- a/src/backend/app/Exceptions/PaymentAmountBiggerThanTotalRemainingAmount.php +++ b/src/backend/app/Exceptions/PaymentAmountBiggerThanTotalRemainingAmount.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class PaymentAmountBiggerThanTotalRemainingAmount extends \Exception -{ -} +class PaymentAmountBiggerThanTotalRemainingAmount extends \Exception {} diff --git a/src/backend/app/Exceptions/PaymentAmountSmallerThanZero.php b/src/backend/app/Exceptions/PaymentAmountSmallerThanZero.php index 24ac1608b..df6a1a9f0 100644 --- a/src/backend/app/Exceptions/PaymentAmountSmallerThanZero.php +++ b/src/backend/app/Exceptions/PaymentAmountSmallerThanZero.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class PaymentAmountSmallerThanZero extends \Exception -{ -} +class PaymentAmountSmallerThanZero extends \Exception {} diff --git a/src/backend/app/Exceptions/PaymentProviderNotIdentified.php b/src/backend/app/Exceptions/PaymentProviderNotIdentified.php index 2329b28cf..dfe162a50 100644 --- a/src/backend/app/Exceptions/PaymentProviderNotIdentified.php +++ b/src/backend/app/Exceptions/PaymentProviderNotIdentified.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class PaymentProviderNotIdentified extends \Exception -{ -} +class PaymentProviderNotIdentified extends \Exception {} diff --git a/src/backend/app/Exceptions/PurchaseNotProcessable.php b/src/backend/app/Exceptions/PurchaseNotProcessable.php index 532d80829..616376ab8 100644 --- a/src/backend/app/Exceptions/PurchaseNotProcessable.php +++ b/src/backend/app/Exceptions/PurchaseNotProcessable.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class PurchaseNotProcessable extends \Exception -{ -} +class PurchaseNotProcessable extends \Exception {} diff --git a/src/backend/app/Exceptions/SmsAndroidSettingNotExistingException.php b/src/backend/app/Exceptions/SmsAndroidSettingNotExistingException.php index 68734f748..2255ebfa2 100644 --- a/src/backend/app/Exceptions/SmsAndroidSettingNotExistingException.php +++ b/src/backend/app/Exceptions/SmsAndroidSettingNotExistingException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class SmsAndroidSettingNotExistingException extends \Exception -{ -} +class SmsAndroidSettingNotExistingException extends \Exception {} diff --git a/src/backend/app/Exceptions/SmsBodyParserNotExtendedException.php b/src/backend/app/Exceptions/SmsBodyParserNotExtendedException.php index d1d728b80..6c51bbf00 100644 --- a/src/backend/app/Exceptions/SmsBodyParserNotExtendedException.php +++ b/src/backend/app/Exceptions/SmsBodyParserNotExtendedException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class SmsBodyParserNotExtendedException extends \Exception -{ -} +class SmsBodyParserNotExtendedException extends \Exception {} diff --git a/src/backend/app/Exceptions/SmsTypeNotFoundException.php b/src/backend/app/Exceptions/SmsTypeNotFoundException.php index af2112275..72bf5e6e6 100644 --- a/src/backend/app/Exceptions/SmsTypeNotFoundException.php +++ b/src/backend/app/Exceptions/SmsTypeNotFoundException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class SmsTypeNotFoundException extends \Exception -{ -} +class SmsTypeNotFoundException extends \Exception {} diff --git a/src/backend/app/Exceptions/SpreadSheetNotCreatedException.php b/src/backend/app/Exceptions/SpreadSheetNotCreatedException.php index 4d2144d5d..03bf69994 100644 --- a/src/backend/app/Exceptions/SpreadSheetNotCreatedException.php +++ b/src/backend/app/Exceptions/SpreadSheetNotCreatedException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class SpreadSheetNotCreatedException extends \Exception -{ -} +class SpreadSheetNotCreatedException extends \Exception {} diff --git a/src/backend/app/Exceptions/SpreadSheetNotSavedException.php b/src/backend/app/Exceptions/SpreadSheetNotSavedException.php index a2e4d6bdf..4cd121be1 100644 --- a/src/backend/app/Exceptions/SpreadSheetNotSavedException.php +++ b/src/backend/app/Exceptions/SpreadSheetNotSavedException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class SpreadSheetNotSavedException extends \Exception -{ -} +class SpreadSheetNotSavedException extends \Exception {} diff --git a/src/backend/app/Exceptions/Tariffs/TariffNotFound.php b/src/backend/app/Exceptions/Tariffs/TariffNotFound.php index 361c1168a..3bdb79c3d 100644 --- a/src/backend/app/Exceptions/Tariffs/TariffNotFound.php +++ b/src/backend/app/Exceptions/Tariffs/TariffNotFound.php @@ -2,6 +2,4 @@ namespace App\Exceptions\Tariffs; -class TariffNotFound extends \Exception -{ -} +class TariffNotFound extends \Exception {} diff --git a/src/backend/app/Exceptions/TransactionAmountNotEnoughException.php b/src/backend/app/Exceptions/TransactionAmountNotEnoughException.php index 539125a97..a73731e7b 100644 --- a/src/backend/app/Exceptions/TransactionAmountNotEnoughException.php +++ b/src/backend/app/Exceptions/TransactionAmountNotEnoughException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class TransactionAmountNotEnoughException extends \Exception -{ -} +class TransactionAmountNotEnoughException extends \Exception {} diff --git a/src/backend/app/Exceptions/TransactionAmountNotFoundException.php b/src/backend/app/Exceptions/TransactionAmountNotFoundException.php index c8d2dcb1f..c1e3e959b 100644 --- a/src/backend/app/Exceptions/TransactionAmountNotFoundException.php +++ b/src/backend/app/Exceptions/TransactionAmountNotFoundException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class TransactionAmountNotFoundException extends \Exception -{ -} +class TransactionAmountNotFoundException extends \Exception {} diff --git a/src/backend/app/Exceptions/TransactionFetchingException.php b/src/backend/app/Exceptions/TransactionFetchingException.php index 04e2b11d1..1342ac6b5 100644 --- a/src/backend/app/Exceptions/TransactionFetchingException.php +++ b/src/backend/app/Exceptions/TransactionFetchingException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class TransactionFetchingException extends \Exception -{ -} +class TransactionFetchingException extends \Exception {} diff --git a/src/backend/app/Exceptions/TransactionIsInvalidForProcessingIncomingRequestException.php b/src/backend/app/Exceptions/TransactionIsInvalidForProcessingIncomingRequestException.php index 7e676b2f7..c3072f9d0 100644 --- a/src/backend/app/Exceptions/TransactionIsInvalidForProcessingIncomingRequestException.php +++ b/src/backend/app/Exceptions/TransactionIsInvalidForProcessingIncomingRequestException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class TransactionIsInvalidForProcessingIncomingRequestException extends \Exception -{ -} +class TransactionIsInvalidForProcessingIncomingRequestException extends \Exception {} diff --git a/src/backend/app/Exceptions/TransactionNotInitializedException.php b/src/backend/app/Exceptions/TransactionNotInitializedException.php index 72bb1fb9a..4f1a18b22 100644 --- a/src/backend/app/Exceptions/TransactionNotInitializedException.php +++ b/src/backend/app/Exceptions/TransactionNotInitializedException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class TransactionNotInitializedException extends \Exception -{ -} +class TransactionNotInitializedException extends \Exception {} diff --git a/src/backend/app/Exceptions/TrelloAPIException.php b/src/backend/app/Exceptions/TrelloAPIException.php index 7ef91cb43..0d4efe486 100644 --- a/src/backend/app/Exceptions/TrelloAPIException.php +++ b/src/backend/app/Exceptions/TrelloAPIException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class TrelloAPIException extends \Exception -{ -} +class TrelloAPIException extends \Exception {} diff --git a/src/backend/app/Exceptions/UserAddressNorFoundException.php b/src/backend/app/Exceptions/UserAddressNorFoundException.php index 719bcbecc..ab0988f00 100644 --- a/src/backend/app/Exceptions/UserAddressNorFoundException.php +++ b/src/backend/app/Exceptions/UserAddressNorFoundException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class UserAddressNorFoundException extends \Exception -{ -} +class UserAddressNorFoundException extends \Exception {} diff --git a/src/backend/app/Exceptions/ValidationException.php b/src/backend/app/Exceptions/ValidationException.php index f71d1829e..3fdeb2d7a 100644 --- a/src/backend/app/Exceptions/ValidationException.php +++ b/src/backend/app/Exceptions/ValidationException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class ValidationException extends \Exception -{ -} +class ValidationException extends \Exception {} diff --git a/src/backend/app/Exceptions/VodacomHeartBeatException.php b/src/backend/app/Exceptions/VodacomHeartBeatException.php index 11b8f4871..0eb591ca4 100644 --- a/src/backend/app/Exceptions/VodacomHeartBeatException.php +++ b/src/backend/app/Exceptions/VodacomHeartBeatException.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class VodacomHeartBeatException extends \Exception -{ -} +class VodacomHeartBeatException extends \Exception {} diff --git a/src/backend/app/Exceptions/WeatherParametersMissing.php b/src/backend/app/Exceptions/WeatherParametersMissing.php index 872494fcc..7dbd55f3d 100644 --- a/src/backend/app/Exceptions/WeatherParametersMissing.php +++ b/src/backend/app/Exceptions/WeatherParametersMissing.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class WeatherParametersMissing extends \Exception -{ -} +class WeatherParametersMissing extends \Exception {} diff --git a/src/backend/app/Exceptions/WeatherProviderUnreachable.php b/src/backend/app/Exceptions/WeatherProviderUnreachable.php index 06f5e6c76..ca2e60999 100644 --- a/src/backend/app/Exceptions/WeatherProviderUnreachable.php +++ b/src/backend/app/Exceptions/WeatherProviderUnreachable.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class WeatherProviderUnreachable extends \Exception -{ -} +class WeatherProviderUnreachable extends \Exception {} diff --git a/src/backend/app/Helpers/MailHelper.php b/src/backend/app/Helpers/MailHelper.php index becf42d89..1214ca07b 100644 --- a/src/backend/app/Helpers/MailHelper.php +++ b/src/backend/app/Helpers/MailHelper.php @@ -6,8 +6,7 @@ use PHPMailer\PHPMailer\Exception as PHPMailerException; use PHPMailer\PHPMailer\PHPMailer; -class MailHelper implements MailHelperInterface -{ +class MailHelper implements MailHelperInterface { /** * @var PHPMailer */ @@ -15,15 +14,13 @@ class MailHelper implements MailHelperInterface private $mailSettings; - public function __construct(PHPMailer $mailer) - { + public function __construct(PHPMailer $mailer) { $this->mailer = $mailer; $this->mailSettings = config('mail.mailers.strato'); $this->configure(); } - private function configure(): void - { + private function configure(): void { $this->mailer->Host = $this->mailSettings['host']; $this->mailer->Port = $this->mailSettings['port']; $this->mailer->SMTPSecure = $this->mailSettings['smtp_secure']; @@ -35,16 +32,12 @@ private function configure(): void } /** - * @param $to - * @param $title - * @param $body * @param null $attachment * * @throws MailNotSentException * @throws PHPMailerException */ - public function sendPlain($to, $title, $body, $attachment = null): void - { + public function sendPlain($to, $title, $body, $attachment = null): void { // don't send any mails while testing if (config('app.env') === 'local') { return; @@ -68,8 +61,7 @@ public function sendPlain($to, $title, $body, $attachment = null): void } } - public function sendViaTemplate(string $to, string $title, string $templatePath, ?array $variables = null, ?string $attachmentPath = null): void - { + public function sendViaTemplate(string $to, string $title, string $templatePath, ?array $variables = null, ?string $attachmentPath = null): void { // don't send any mails while testing if (config('app.env') === 'demo') { return; diff --git a/src/backend/app/Helpers/MailHelperInterface.php b/src/backend/app/Helpers/MailHelperInterface.php index 1497c93c3..552e55762 100644 --- a/src/backend/app/Helpers/MailHelperInterface.php +++ b/src/backend/app/Helpers/MailHelperInterface.php @@ -5,12 +5,8 @@ use App\Exceptions\MailNotSentException; use PHPMailer\PHPMailer\Exception as PHPMailerException; -interface MailHelperInterface -{ +interface MailHelperInterface { /** - * @param $to - * @param $title - * @param $body * @param null $attachment * * @throws MailNotSentException diff --git a/src/backend/app/Helpers/MailHelperMock.php b/src/backend/app/Helpers/MailHelperMock.php index 43f3d186a..3e037f4f4 100644 --- a/src/backend/app/Helpers/MailHelperMock.php +++ b/src/backend/app/Helpers/MailHelperMock.php @@ -5,24 +5,14 @@ use App\Exceptions\MailNotSentException; use PHPMailer\PHPMailer\Exception as PHPMailerException; -class MailHelperMock implements MailHelperInterface -{ +class MailHelperMock implements MailHelperInterface { /** - * @param $to - * @param $title - * @param $body * @param null $attachment * * @throws MailNotSentException * @throws PHPMailerException */ - public function sendPlain($to, $title, $body, $attachment = null): void - { - return; - } + public function sendPlain($to, $title, $body, $attachment = null): void {} - public function sendViaTemplate(string $to, string $title, string $templatePath, ?array $variables = null, ?string $attachmentPath = null): void - { - return; - } + public function sendViaTemplate(string $to, string $title, string $templatePath, ?array $variables = null, ?string $attachmentPath = null): void {} } diff --git a/src/backend/app/Helpers/PasswordGenerator.php b/src/backend/app/Helpers/PasswordGenerator.php index 3b7307928..607cf46a8 100644 --- a/src/backend/app/Helpers/PasswordGenerator.php +++ b/src/backend/app/Helpers/PasswordGenerator.php @@ -2,10 +2,8 @@ namespace App\Helpers; -class PasswordGenerator -{ - public static function generatePassword($passwordLength = 5): int - { +class PasswordGenerator { + public static function generatePassword($passwordLength = 5): int { return random_int(10 ** ($passwordLength - 1), (10 ** $passwordLength) - 1); } } diff --git a/src/backend/app/Helpers/PowerConverter.php b/src/backend/app/Helpers/PowerConverter.php index 181ba96ac..727a8dd7f 100644 --- a/src/backend/app/Helpers/PowerConverter.php +++ b/src/backend/app/Helpers/PowerConverter.php @@ -2,8 +2,7 @@ namespace App\Helpers; -class PowerConverter -{ +class PowerConverter { private static $powerUnits = [ 'W' => 1, 'kW' => 1000, @@ -16,8 +15,7 @@ class PowerConverter /** * @param int|string $power */ - public static function convert($power, $powerUnit, string $expectedUnit = 'Wh') - { + public static function convert($power, $powerUnit, string $expectedUnit = 'Wh') { return $power * self::$powerUnits[$powerUnit] / self::$powerUnits[$expectedUnit]; } } diff --git a/src/backend/app/Helpers/RelationsManager.php b/src/backend/app/Helpers/RelationsManager.php index a9ee86ac7..b759daa4e 100644 --- a/src/backend/app/Helpers/RelationsManager.php +++ b/src/backend/app/Helpers/RelationsManager.php @@ -11,8 +11,7 @@ use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphTo; -trait RelationsManager -{ +trait RelationsManager { protected static $relationsList = []; protected static $relationsInitialized = false; @@ -28,8 +27,7 @@ trait RelationsManager 'morphmany' => MorphMany::class, ]; - public static function getAllRelations($type = null): array - { + public static function getAllRelations($type = null): array { if (!self::$relationsInitialized) { self::initAllRelations(); } @@ -40,8 +38,7 @@ public static function getAllRelations($type = null): array } } - protected static function initAllRelations(): void - { + protected static function initAllRelations(): void { self::$relationsInitialized = true; $reflect = new \ReflectionClass(static::class); @@ -57,8 +54,7 @@ protected static function initAllRelations(): void } } - public static function withAll($type = null): array - { + public static function withAll($type = null): array { $relations = array_flatten(static::getAllRelations($type)); return $relations; diff --git a/src/backend/app/Http/Controllers/AddressController.php b/src/backend/app/Http/Controllers/AddressController.php index fa76d322e..ce15d8bb4 100644 --- a/src/backend/app/Http/Controllers/AddressController.php +++ b/src/backend/app/Http/Controllers/AddressController.php @@ -7,22 +7,18 @@ use App\Services\PersonAddressService; use App\Services\PersonService; -class AddressController extends Controller -{ +class AddressController extends Controller { public function __construct( private AddressesService $addressService, private PersonService $personService, private PersonAddressService $personAddressService, - ) { - } + ) {} - public function index(): ApiResource - { + public function index(): ApiResource { return ApiResource::make($this->addressService->getAll()); } - public function show($id): ApiResource - { + public function show($id): ApiResource { return ApiResource::make($this->addressService->getById($id)); } } diff --git a/src/backend/app/Http/Controllers/AgentAssignedApplianceWebController.php b/src/backend/app/Http/Controllers/AgentAssignedApplianceWebController.php index 7d705f424..16dcbdc9a 100644 --- a/src/backend/app/Http/Controllers/AgentAssignedApplianceWebController.php +++ b/src/backend/app/Http/Controllers/AgentAssignedApplianceWebController.php @@ -8,12 +8,10 @@ use App\Services\AgentAssignedApplianceService; use Illuminate\Http\Request; -class AgentAssignedApplianceWebController extends Controller -{ +class AgentAssignedApplianceWebController extends Controller { public function __construct( private AgentAssignedApplianceService $agentAssignedApplianceService, - ) { - } + ) {} /** * Store a newly created resource in storage. @@ -23,12 +21,9 @@ public function __construct( * @bodyParam appliance_type_id integer required * @bodyParam cost integer required * - * @param CreateAgentAssignedApplianceRequest $request - * * @return ApiResource */ - public function store(CreateAgentAssignedApplianceRequest $request) - { + public function store(CreateAgentAssignedApplianceRequest $request) { $assignedApplianceData = $request->only([ 'agent_id', 'user_id', @@ -42,13 +37,11 @@ public function store(CreateAgentAssignedApplianceRequest $request) /** * List for Web interface. * - * @param Agent $agent - * @param Request $request + * @param Agent $agent * * @return ApiResource */ - public function index($agentId, Request $request) - { + public function index($agentId, Request $request) { $limit = $request->input('per_page'); return ApiResource::make($this->agentAssignedApplianceService->getAll($limit, $agentId)); diff --git a/src/backend/app/Http/Controllers/AgentAssignedAppliancesController.php b/src/backend/app/Http/Controllers/AgentAssignedAppliancesController.php index 50117b109..cb6e4b7d3 100644 --- a/src/backend/app/Http/Controllers/AgentAssignedAppliancesController.php +++ b/src/backend/app/Http/Controllers/AgentAssignedAppliancesController.php @@ -12,23 +12,18 @@ * @group Agent-Appliances * Class AgentAssignedApplianceController */ -class AgentAssignedAppliancesController extends Controller -{ +class AgentAssignedAppliancesController extends Controller { public function __construct( private AgentAssignedApplianceService $agentAssignedApplianceService, private AgentService $agentService, - ) { - } + ) {} /** * List for Android-APP. * - * @param Request $request - * * @return ApiResource */ - public function index(Request $request) - { + public function index(Request $request) { $agent = $this->agentService->getByAuthenticatedUser(); $limit = $request->input('per_page'); diff --git a/src/backend/app/Http/Controllers/AgentAuthController.php b/src/backend/app/Http/Controllers/AgentAuthController.php index 19a8994eb..75a8a7cbb 100644 --- a/src/backend/app/Http/Controllers/AgentAuthController.php +++ b/src/backend/app/Http/Controllers/AgentAuthController.php @@ -12,15 +12,11 @@ * Class AgentAuthController * Responsible for AgentAPP-API-Call authentications. */ -class AgentAuthController extends Controller -{ +class AgentAuthController extends Controller { /** * Create a new AuthController instance. - * - * @param AgentService $agentService */ - public function __construct(private AgentService $agentService) - { + public function __construct(private AgentService $agentService) { $this->middleware('auth:agent_api', ['except' => ['login']]); } @@ -32,8 +28,7 @@ public function __construct(private AgentService $agentService) * * @return JsonResponse */ - public function login(Request $request) - { + public function login(Request $request) { $credentials = $request->only(['email', 'password']); if (!$token = auth('agent_api')->setTTL(525600)->attempt($credentials)) { @@ -53,8 +48,7 @@ public function login(Request $request) * * @return JsonResponse */ - public function me() - { + public function me() { return response()->json(auth('agent_api')->user()); } @@ -63,8 +57,7 @@ public function me() * * @return JsonResponse */ - public function logout() - { + public function logout() { auth('agent_api')->logout(); return response()->json(['message' => 'Successfully logged out']); @@ -76,8 +69,7 @@ public function logout() * * @return JsonResponse */ - public function refresh() - { + public function refresh() { return $this->respondWithToken(auth('agent_api')->refresh()); } @@ -88,8 +80,7 @@ public function refresh() * * @return JsonResponse */ - protected function respondWithToken($token) - { + protected function respondWithToken($token) { return response()->json( [ 'access_token' => $token, diff --git a/src/backend/app/Http/Controllers/AgentBalanceController.php b/src/backend/app/Http/Controllers/AgentBalanceController.php index 6725fb5e5..78f4a9b24 100644 --- a/src/backend/app/Http/Controllers/AgentBalanceController.php +++ b/src/backend/app/Http/Controllers/AgentBalanceController.php @@ -5,15 +5,12 @@ use App\Services\AgentService; use Illuminate\Http\Request; -class AgentBalanceController extends Controller -{ +class AgentBalanceController extends Controller { public function __construct( private AgentService $agentService, - ) { - } + ) {} - public function show(Request $request) - { + public function show(Request $request) { $agent = $this->agentService->getByAuthenticatedUser(); return $this->agentService->getAgentBalance($agent); diff --git a/src/backend/app/Http/Controllers/AgentBalanceHistoryController.php b/src/backend/app/Http/Controllers/AgentBalanceHistoryController.php index 776c3b337..1521d2dc7 100644 --- a/src/backend/app/Http/Controllers/AgentBalanceHistoryController.php +++ b/src/backend/app/Http/Controllers/AgentBalanceHistoryController.php @@ -9,25 +9,17 @@ use App\Services\AgentBalanceHistoryService; use Illuminate\Http\Request; -class AgentBalanceHistoryController extends Controller -{ +class AgentBalanceHistoryController extends Controller { private $agentBalanceHistoryService; - public function __construct(AgentBalanceHistoryService $agentBalanceHistoryService) - { + public function __construct(AgentBalanceHistoryService $agentBalanceHistoryService) { $this->agentBalanceHistoryService = $agentBalanceHistoryService; } /** * Store a newly created resource in storage. - * - * @param Agent $agent - * @param CreateAgentBalanceHistoryRequest $request - * - * @return ApiResource */ - public function store(Agent $agent, CreateAgentBalanceHistoryRequest $request): ApiResource - { + public function store(Agent $agent, CreateAgentBalanceHistoryRequest $request): ApiResource { $agentBalanceHistory = $this->agentBalanceHistoryService->create( $agent, $request->only( @@ -43,34 +35,21 @@ public function store(Agent $agent, CreateAgentBalanceHistoryRequest $request): /** * Display the specified resource. * - * @param AgentBalanceHistory $agent_balance_history - * * @return void */ - public function show(AgentBalanceHistory $agent_balance_history) - { - } + public function show(AgentBalanceHistory $agent_balance_history) {} /** * Update the specified resource in storage. * - * @param Request $request - * @param AgentBalanceHistory $agent_balance_history - * * @return void */ - public function update(Request $request, AgentBalanceHistory $agent_balance_history) - { - } + public function update(Request $request, AgentBalanceHistory $agent_balance_history) {} /** * Remove the specified resource from storage. * - * @param AgentBalanceHistory $agent_balance_history - * * @return void */ - public function destroy(AgentBalanceHistory $agent_balance_history) - { - } + public function destroy(AgentBalanceHistory $agent_balance_history) {} } diff --git a/src/backend/app/Http/Controllers/AgentBalanceHistoryWebController.php b/src/backend/app/Http/Controllers/AgentBalanceHistoryWebController.php index e943a7ec4..d5d7bd34a 100644 --- a/src/backend/app/Http/Controllers/AgentBalanceHistoryWebController.php +++ b/src/backend/app/Http/Controllers/AgentBalanceHistoryWebController.php @@ -6,14 +6,10 @@ use App\Services\AgentBalanceHistoryService; use Illuminate\Http\Request; -class AgentBalanceHistoryWebController extends Controller -{ - public function __construct(private AgentBalanceHistoryService $agentBalanceHistoryService) - { - } +class AgentBalanceHistoryWebController extends Controller { + public function __construct(private AgentBalanceHistoryService $agentBalanceHistoryService) {} - public function index($agentId, Request $request) - { + public function index($agentId, Request $request) { $limit = $request->input('per_page'); return ApiResource::make($this->agentBalanceHistoryService->getAll($limit, $agentId)); diff --git a/src/backend/app/Http/Controllers/AgentChargeWebController.php b/src/backend/app/Http/Controllers/AgentChargeWebController.php index 15de11c83..642c602e1 100644 --- a/src/backend/app/Http/Controllers/AgentChargeWebController.php +++ b/src/backend/app/Http/Controllers/AgentChargeWebController.php @@ -6,15 +6,12 @@ use App\Http\Resources\ApiResource; use App\Services\AgentChargeService; -class AgentChargeWebController extends Controller -{ +class AgentChargeWebController extends Controller { public function __construct( private AgentChargeService $agentChargeService, - ) { - } + ) {} - public function store(CreateAgentChargeRequest $request): ApiResource - { + public function store(CreateAgentChargeRequest $request): ApiResource { $userId = auth('api')->user()->id; $agentChargeData = [ diff --git a/src/backend/app/Http/Controllers/AgentCommissionWebController.php b/src/backend/app/Http/Controllers/AgentCommissionWebController.php index 75482faf0..feecc8f8e 100644 --- a/src/backend/app/Http/Controllers/AgentCommissionWebController.php +++ b/src/backend/app/Http/Controllers/AgentCommissionWebController.php @@ -7,19 +7,13 @@ use App\Services\AgentCommissionService; use Illuminate\Http\Request; -class AgentCommissionWebController extends Controller -{ - public function __construct(private AgentCommissionService $agentCommissionService) - { - } +class AgentCommissionWebController extends Controller { + public function __construct(private AgentCommissionService $agentCommissionService) {} /** * Display a listing of the resource. - * - * @return ApiResource */ - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $limit = $request->input('per_page'); return ApiResource::make($this->agentCommissionService->getAll($limit)); @@ -28,12 +22,9 @@ public function index(Request $request): ApiResource /** * Store a newly created resource in storage. * - * @param CreateAgentCommissionRequest $request - * * @return ApiResource */ - public function store(CreateAgentCommissionRequest $request) - { + public function store(CreateAgentCommissionRequest $request) { $commissionData = $request->only(['name', 'energy_commission', 'appliance_commission', 'risk_balance']); return ApiResource::make($this->agentCommissionService->create($commissionData)); @@ -41,14 +32,8 @@ public function store(CreateAgentCommissionRequest $request) /** * Update the specified resource in storage. - * - * @param $agentCommissionId - * @param CreateAgentCommissionRequest $request - * - * @return ApiResource */ - public function update($agentCommissionId, CreateAgentCommissionRequest $request): ApiResource - { + public function update($agentCommissionId, CreateAgentCommissionRequest $request): ApiResource { $agentCommission = $this->agentCommissionService->getById($agentCommissionId); return ApiResource::make($this->agentCommissionService->update($agentCommission, $request->all())); @@ -56,13 +41,8 @@ public function update($agentCommissionId, CreateAgentCommissionRequest $request /** * Remove the specified resource from storage. - * - * @param $agentCommissionId - * - * @return ApiResource */ - public function destroy($agentCommissionId): ApiResource - { + public function destroy($agentCommissionId): ApiResource { $agentCommission = $this->agentCommissionService->getById($agentCommissionId); return ApiResource::make($this->agentCommissionService->delete($agentCommission)); diff --git a/src/backend/app/Http/Controllers/AgentCustomerController.php b/src/backend/app/Http/Controllers/AgentCustomerController.php index 19bc26360..6be2762a4 100644 --- a/src/backend/app/Http/Controllers/AgentCustomerController.php +++ b/src/backend/app/Http/Controllers/AgentCustomerController.php @@ -7,30 +7,24 @@ use App\Services\AgentService; use Illuminate\Http\Request; -class AgentCustomerController extends Controller -{ +class AgentCustomerController extends Controller { public function __construct( private AgentCustomerService $agentCustomerService, private AgentService $agentService, - ) { - } + ) {} /** * Display a listing of the resource. * - * @param Request $request - * * @return ApiResource */ - public function index(Request $request) - { + public function index(Request $request) { $agent = $this->agentService->getByAuthenticatedUser(); return ApiResource::make($this->agentCustomerService->list($agent)); } - public function search(Request $request): ApiResource - { + public function search(Request $request): ApiResource { $term = $request->input('term'); $limit = $request->input('paginate', 15); $agent = $this->agentService->getByAuthenticatedUser(); diff --git a/src/backend/app/Http/Controllers/AgentCustomerTicketController.php b/src/backend/app/Http/Controllers/AgentCustomerTicketController.php index d10413907..688db4275 100644 --- a/src/backend/app/Http/Controllers/AgentCustomerTicketController.php +++ b/src/backend/app/Http/Controllers/AgentCustomerTicketController.php @@ -7,14 +7,10 @@ use Illuminate\Http\Request; use Inensus\Ticket\Services\TicketService; -class AgentCustomerTicketController extends Controller -{ - public function __construct(private AgentService $agentService, private TicketService $ticketService) - { - } +class AgentCustomerTicketController extends Controller { + public function __construct(private AgentService $agentService, private TicketService $ticketService) {} - public function show($customerId, Request $request): ApiResource - { + public function show($customerId, Request $request): ApiResource { $agent = $this->agentService->getByAuthenticatedUser(); $limit = $request->input('per_page'); $status = null; diff --git a/src/backend/app/Http/Controllers/AgentCustomersPaymentHistoryController.php b/src/backend/app/Http/Controllers/AgentCustomersPaymentHistoryController.php index da8dcd519..5981f0a18 100644 --- a/src/backend/app/Http/Controllers/AgentCustomersPaymentHistoryController.php +++ b/src/backend/app/Http/Controllers/AgentCustomersPaymentHistoryController.php @@ -5,16 +5,13 @@ use App\Services\AgentCustomersPaymentHistoryService; use App\Services\AgentService; -class AgentCustomersPaymentHistoryController extends Controller -{ +class AgentCustomersPaymentHistoryController extends Controller { public function __construct( private AgentService $agentService, private AgentCustomersPaymentHistoryService $agentCustomersPaymentHistoryService, - ) { - } + ) {} - public function show(int $customerId, string $period, $limit = null, $order = 'ASC') - { + public function show(int $customerId, string $period, $limit = null, $order = 'ASC') { return $this->agentCustomersPaymentHistoryService->getPaymentFlowByCustomerId( $period, $customerId, @@ -23,8 +20,7 @@ public function show(int $customerId, string $period, $limit = null, $order = 'A ); } - public function index(string $period, $limit = null, $order = 'ASC') - { + public function index(string $period, $limit = null, $order = 'ASC') { $agent = $this->agentService->getByAuthenticatedUser(); return $this->agentCustomersPaymentHistoryService->getPaymentFlows($period, $agent->id, $limit, $order); diff --git a/src/backend/app/Http/Controllers/AgentDashboardBalanceHistoryController.php b/src/backend/app/Http/Controllers/AgentDashboardBalanceHistoryController.php index 434d4de10..48512c20d 100644 --- a/src/backend/app/Http/Controllers/AgentDashboardBalanceHistoryController.php +++ b/src/backend/app/Http/Controllers/AgentDashboardBalanceHistoryController.php @@ -8,17 +8,14 @@ use Illuminate\Http\Request; use Illuminate\Http\Response; -class AgentDashboardBalanceHistoryController extends Controller -{ +class AgentDashboardBalanceHistoryController extends Controller { public function __construct( private AgentService $agentService, private AgentBalanceHistoryService $agentBalanceHistoryService, private AgentReceiptService $agentReceiptService, - ) { - } + ) {} - public function show(Request $request, Response $response) - { + public function show(Request $request, Response $response) { $agent = $this->agentService->getByAuthenticatedUser(); $lastReceiptDate = $this->agentReceiptService->getLastReceiptDate($agent); diff --git a/src/backend/app/Http/Controllers/AgentDashboardBoxesController.php b/src/backend/app/Http/Controllers/AgentDashboardBoxesController.php index 00ce9eec1..059f41517 100644 --- a/src/backend/app/Http/Controllers/AgentDashboardBoxesController.php +++ b/src/backend/app/Http/Controllers/AgentDashboardBoxesController.php @@ -8,17 +8,14 @@ use Illuminate\Http\Request; use Illuminate\Http\Response; -class AgentDashboardBoxesController extends Controller -{ +class AgentDashboardBoxesController extends Controller { public function __construct( private AgentService $agentService, private AgentBalanceHistoryService $agentBalanceHistoryService, private AgentReceiptService $agentReceiptService, - ) { - } + ) {} - public function show(Request $request, Response $response) - { + public function show(Request $request, Response $response) { $agent = $this->agentService->getByAuthenticatedUser(); $lastReceipt = $this->agentReceiptService->getLastReceipt($agent->id); $average = $this->agentBalanceHistoryService->getTransactionAverage($agent, $lastReceipt); diff --git a/src/backend/app/Http/Controllers/AgentDashboardRevenueController.php b/src/backend/app/Http/Controllers/AgentDashboardRevenueController.php index a6f16fee1..b9932bf9a 100644 --- a/src/backend/app/Http/Controllers/AgentDashboardRevenueController.php +++ b/src/backend/app/Http/Controllers/AgentDashboardRevenueController.php @@ -7,16 +7,13 @@ use Illuminate\Http\Request; use Illuminate\Http\Response; -class AgentDashboardRevenueController extends Controller -{ +class AgentDashboardRevenueController extends Controller { public function __construct( private AgentService $agentService, private AgentBalanceHistoryService $agentBalanceHistoryService, - ) { - } + ) {} - public function show(Request $request, Response $response) - { + public function show(Request $request, Response $response) { $agent = $this->agentService->getByAuthenticatedUser(); return $this->agentBalanceHistoryService->getAgentRevenuesWeekly($agent); diff --git a/src/backend/app/Http/Controllers/AgentFirebaseController.php b/src/backend/app/Http/Controllers/AgentFirebaseController.php index 0a14c5b57..fad2783c5 100644 --- a/src/backend/app/Http/Controllers/AgentFirebaseController.php +++ b/src/backend/app/Http/Controllers/AgentFirebaseController.php @@ -6,15 +6,12 @@ use App\Services\AgentService; use Illuminate\Http\Request; -class AgentFirebaseController extends Controller -{ +class AgentFirebaseController extends Controller { public function __construct( private AgentService $agentService, - ) { - } + ) {} - public function update(Request $request): ApiResource - { + public function update(Request $request): ApiResource { $agent = $this->agentService->getByAuthenticatedUser(); return ApiResource::make($this->agentService->setFirebaseToken($agent, $request->input('fire_base_token'))); diff --git a/src/backend/app/Http/Controllers/AgentReceiptDetailController.php b/src/backend/app/Http/Controllers/AgentReceiptDetailController.php index 26a7d1a51..6b4f26a3b 100644 --- a/src/backend/app/Http/Controllers/AgentReceiptDetailController.php +++ b/src/backend/app/Http/Controllers/AgentReceiptDetailController.php @@ -2,6 +2,4 @@ namespace App\Http\Controllers; -class AgentReceiptDetailController extends Controller -{ -} +class AgentReceiptDetailController extends Controller {} diff --git a/src/backend/app/Http/Controllers/AgentReceiptWebController.php b/src/backend/app/Http/Controllers/AgentReceiptWebController.php index 7dc73ea5f..62e4bc0fa 100644 --- a/src/backend/app/Http/Controllers/AgentReceiptWebController.php +++ b/src/backend/app/Http/Controllers/AgentReceiptWebController.php @@ -8,24 +8,18 @@ use App\Services\AgentReceiptService; use Illuminate\Http\Request; -class AgentReceiptWebController extends Controller -{ +class AgentReceiptWebController extends Controller { public function __construct( private AgentReceiptService $agentReceiptService, private AgentBalanceHistoryService $agentBalanceHistoryService, - ) { - } + ) {} /** * Display a listing of the resource. * - * @param $agentId - * @param Request $request - * * @return ApiResource */ - public function show($agentId, Request $request) - { + public function show($agentId, Request $request) { $limit = $request->input('per_page'); return ApiResource::make($this->agentReceiptService->getAll($limit, $agentId)); @@ -34,12 +28,9 @@ public function show($agentId, Request $request) /** * Display a listing of the resource. * - * @param Request $request - * * @return ApiResource */ - public function index(Request $request) - { + public function index(Request $request) { $limit = $request->input('per_page'); return ApiResource::make($this->agentReceiptService->getAll($limit)); @@ -48,13 +39,11 @@ public function index(Request $request) /** * Store a newly created resource in storage. * - * @param $agentId - * @param CreateAgentReceiptRequest $request + * @param $agentId * * @return ApiResource */ - public function store(CreateAgentReceiptRequest $request) - { + public function store(CreateAgentReceiptRequest $request) { $userId = auth('api')->user()->id; $agentId = $request->input('agent_id'); $lastBalanceHistory = $this->agentBalanceHistoryService->getLastAgentBalanceHistory($agentId); diff --git a/src/backend/app/Http/Controllers/AgentSoldApplianceController.php b/src/backend/app/Http/Controllers/AgentSoldApplianceController.php index fd2764f5c..213144349 100644 --- a/src/backend/app/Http/Controllers/AgentSoldApplianceController.php +++ b/src/backend/app/Http/Controllers/AgentSoldApplianceController.php @@ -8,26 +8,22 @@ use App\Services\AgentSoldApplianceService; use Illuminate\Http\Request; -class AgentSoldApplianceController extends Controller -{ +class AgentSoldApplianceController extends Controller { public const FOR_APP = true; public function __construct( private AgentSoldApplianceService $agentSoldApplianceService, private AgentService $agentService, - ) { - } + ) {} - public function index(Request $request) - { + public function index(Request $request) { $agent = $this->agentService->getByAuthenticatedUser(); $limit = $request->input('per_page'); return ApiResource::make($this->agentSoldApplianceService->getAll($limit, $agent->id, null, self::FOR_APP)); } - public function show($customerId, Request $request): ApiResource - { + public function show($customerId, Request $request): ApiResource { $agent = $this->agentService->getByAuthenticatedUser(); return ApiResource::make($this->agentSoldApplianceService->getById($agent->id, $customerId)); @@ -36,12 +32,9 @@ public function show($customerId, Request $request): ApiResource /** * Store a newly created resource in storage. * - * @param CreateAgentSoldApplianceRequest $request - * * @return ApiResource */ - public function store(CreateAgentSoldApplianceRequest $request) - { + public function store(CreateAgentSoldApplianceRequest $request) { $soldApplianceData = $request->only(['person_id', 'agent_assigned_appliance_id']); return ApiResource::make($this->agentSoldApplianceService->create($soldApplianceData)); diff --git a/src/backend/app/Http/Controllers/AgentSoldApplianceWebController.php b/src/backend/app/Http/Controllers/AgentSoldApplianceWebController.php index 2ca847494..e913e7f74 100644 --- a/src/backend/app/Http/Controllers/AgentSoldApplianceWebController.php +++ b/src/backend/app/Http/Controllers/AgentSoldApplianceWebController.php @@ -6,14 +6,10 @@ use App\Services\AgentSoldApplianceService; use Illuminate\Http\Request; -class AgentSoldApplianceWebController extends Controller -{ - public function __construct(private AgentSoldApplianceService $agentSoldApplianceService) - { - } +class AgentSoldApplianceWebController extends Controller { + public function __construct(private AgentSoldApplianceService $agentSoldApplianceService) {} - public function index($agentId, Request $request): ApiResource - { + public function index($agentId, Request $request): ApiResource { $limit = $request->input('per_page'); return ApiResource::make($this->agentSoldApplianceService->getAll($limit, $agentId)); diff --git a/src/backend/app/Http/Controllers/AgentTicketController.php b/src/backend/app/Http/Controllers/AgentTicketController.php index 5f111655f..e410625dc 100644 --- a/src/backend/app/Http/Controllers/AgentTicketController.php +++ b/src/backend/app/Http/Controllers/AgentTicketController.php @@ -14,9 +14,9 @@ use Inensus\Ticket\Services\TicketService; use Inensus\Ticket\Services\TicketUserService; -class AgentTicketController extends Controller -{ +class AgentTicketController extends Controller { private $board; + private $card; public function __construct( @@ -31,20 +31,17 @@ public function __construct( // $this->card = $this->cardService->initalizeList($this->board); } - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $agent = $this->agentService->getByAuthenticatedUser(); return ApiResource::make($this->ticketService->getForAgent($agent->id)); } - public function show($ticketId, Request $request): ApiResource - { + public function show($ticketId, Request $request): ApiResource { return ApiResource::make($this->ticketService->getById($ticketId)); } - public function store(CreateAgentTicketRequest $request): TicketResource - { + public function store(CreateAgentTicketRequest $request): TicketResource { $ticketData = $request->only([ 'owner_id', 'due_date', diff --git a/src/backend/app/Http/Controllers/AgentTransactionWebController.php b/src/backend/app/Http/Controllers/AgentTransactionWebController.php index 34fa60bf9..1f19af7f2 100644 --- a/src/backend/app/Http/Controllers/AgentTransactionWebController.php +++ b/src/backend/app/Http/Controllers/AgentTransactionWebController.php @@ -6,14 +6,10 @@ use App\Services\AgentTransactionService; use Illuminate\Http\Request; -class AgentTransactionWebController extends Controller -{ - public function __construct(private AgentTransactionService $agentTransactionService) - { - } +class AgentTransactionWebController extends Controller { + public function __construct(private AgentTransactionService $agentTransactionService) {} - public function index($agentId, Request $request): ApiResource - { + public function index($agentId, Request $request): ApiResource { $limit = $request->input('per_page'); return ApiResource::make($this->agentTransactionService->getAll($limit, $agentId)); diff --git a/src/backend/app/Http/Controllers/AgentTransactionsController.php b/src/backend/app/Http/Controllers/AgentTransactionsController.php index f4c747da3..75d033cc1 100644 --- a/src/backend/app/Http/Controllers/AgentTransactionsController.php +++ b/src/backend/app/Http/Controllers/AgentTransactionsController.php @@ -7,26 +7,22 @@ use App\Services\AgentTransactionService; use Illuminate\Http\Request; -class AgentTransactionsController extends Controller -{ +class AgentTransactionsController extends Controller { public const FOR_APP = true; public function __construct( private AgentTransactionService $agentTransactionService, private AgentService $agentService, - ) { - } + ) {} - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $agent = $this->agentService->getByAuthenticatedUser(); $limit = $request->input('per_page'); return ApiResource::make($this->agentTransactionService->getAll($limit, $agent->id, self::FOR_APP)); } - public function show($customerId, Request $request): ApiResource - { + public function show($customerId, Request $request): ApiResource { $agent = $this->agentService->getByAuthenticatedUser(); return ApiResource::make($this->agentTransactionService->getById($agent->id, $customerId)); diff --git a/src/backend/app/Http/Controllers/AgentWebController.php b/src/backend/app/Http/Controllers/AgentWebController.php index 5554868ba..3b816b4ee 100644 --- a/src/backend/app/Http/Controllers/AgentWebController.php +++ b/src/backend/app/Http/Controllers/AgentWebController.php @@ -15,8 +15,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Response; -class AgentWebController extends Controller -{ +class AgentWebController extends Controller { public function __construct( private AgentService $agentService, private AddressesService $addressService, @@ -25,23 +24,19 @@ public function __construct( private CountryService $countryService, private CompanyDatabaseService $companyDatabaseService, private DatabaseProxyService $databaseProxyService, - ) { - } + ) {} - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $limit = $request->input('per_page'); return ApiResource::make($this->agentService->getAll($limit)); } - public function show($agentId, Request $request): ApiResource - { + public function show($agentId, Request $request): ApiResource { return ApiResource::make($this->agentService->getById($agentId)); } - public function store(CreateAgentRequest $request): ApiResource - { + public function store(CreateAgentRequest $request): ApiResource { $addressData = $this->addressService->createAddressDataFromRequest($request); $personData = $this->personService->createPersonDataFromRequest($request); $country = $this->countryService->getByCode($request->get('nationality')); @@ -75,23 +70,20 @@ public function store(CreateAgentRequest $request): ApiResource )); } - public function update($agentId, Request $request): ApiResource - { + public function update($agentId, Request $request): ApiResource { $agent = $this->agentService->getById($agentId); $agentData = $request->all(); return ApiResource::make($this->agentService->update($agent, $agentData, $this->personService)); } - public function destroy($agentId, Request $request): ApiResource - { + public function destroy($agentId, Request $request): ApiResource { $agent = $this->agentService->getById($agentId); return ApiResource::make($this->agentService->delete($agent)); } - public function search(Request $request): ApiResource - { + public function search(Request $request): ApiResource { $term = $request->input('term'); $paginate = $request->input('paginate', 1); @@ -101,8 +93,7 @@ public function search(Request $request): ApiResource /** * @return Response */ - public function resetPassword(Request $request, Response $response) - { + public function resetPassword(Request $request, Response $response) { $responseMessage = $this->agentService->resetPassword($request->input('email')); if ($responseMessage === 'Invalid email.') { diff --git a/src/backend/app/Http/Controllers/AirtelVoltTerraController.php b/src/backend/app/Http/Controllers/AirtelVoltTerraController.php index 044b2f5f2..b8b99790b 100644 --- a/src/backend/app/Http/Controllers/AirtelVoltTerraController.php +++ b/src/backend/app/Http/Controllers/AirtelVoltTerraController.php @@ -5,10 +5,8 @@ use App\Jobs\ProcessPayment; // WorkAround for only VOLTTERRA -class AirtelVoltTerraController extends Controller -{ - public function store($meterSerial, $amount) - { +class AirtelVoltTerraController extends Controller { + public function store($meterSerial, $amount) { $tempFile = tempnam(sys_get_temp_dir(), 'response'); try { $provider = resolve('AirtelVoltTerra'); diff --git a/src/backend/app/Http/Controllers/AppliancePaymentController.php b/src/backend/app/Http/Controllers/AppliancePaymentController.php index b134182ef..f7f1c1978 100644 --- a/src/backend/app/Http/Controllers/AppliancePaymentController.php +++ b/src/backend/app/Http/Controllers/AppliancePaymentController.php @@ -8,14 +8,10 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -class AppliancePaymentController extends Controller -{ - public function __construct(private AppliancePaymentService $appliancePaymentService) - { - } +class AppliancePaymentController extends Controller { + public function __construct(private AppliancePaymentService $appliancePaymentService) {} - public function store(AssetPerson $appliancePerson, Request $request): ApiResource - { + public function store(AssetPerson $appliancePerson, Request $request): ApiResource { try { DB::connection('shard')->beginTransaction(); $this->appliancePaymentService->getPaymentForAppliance($request, $appliancePerson); diff --git a/src/backend/app/Http/Controllers/AssetController.php b/src/backend/app/Http/Controllers/AssetController.php index 4dcd824d9..741ecc52d 100644 --- a/src/backend/app/Http/Controllers/AssetController.php +++ b/src/backend/app/Http/Controllers/AssetController.php @@ -9,38 +9,29 @@ use App\Services\AssetService; use Illuminate\Http\Request; -class AssetController extends Controller -{ - public function __construct(private AssetService $assetService) - { - } +class AssetController extends Controller { + public function __construct(private AssetService $assetService) {} /** * Display a listing of the resource. - * - * @return ApiResource */ - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { return ApiResource::make($this->assetService->getAssets($request)); } - public function store(CreateAssetRequest $request): ApiResource - { + public function store(CreateAssetRequest $request): ApiResource { $this->assetService->createAsset($request); return ApiResource::make($this->assetService->getAssets($request)); } - public function update(UpdateAssetRequest $request, Asset $asset): ApiResource - { + public function update(UpdateAssetRequest $request, Asset $asset): ApiResource { $this->assetService->updateAsset($request, $asset); return ApiResource::make($this->assetService->getAssets($request)); } - public function destroy(Asset $asset): ApiResource - { + public function destroy(Asset $asset): ApiResource { return ApiResource::make($this->assetService->deleteAsset($asset)); } } diff --git a/src/backend/app/Http/Controllers/AssetPersonController.php b/src/backend/app/Http/Controllers/AssetPersonController.php index 01199feba..29de758a3 100644 --- a/src/backend/app/Http/Controllers/AssetPersonController.php +++ b/src/backend/app/Http/Controllers/AssetPersonController.php @@ -21,8 +21,7 @@ use MPM\Device\DeviceAddressService; use MPM\Device\DeviceService; -class AssetPersonController extends Controller -{ +class AssetPersonController extends Controller { public function __construct( private AssetPerson $assetPerson, private AppliancePersonService $assetPersonService, @@ -36,17 +35,12 @@ public function __construct( private CashTransactionService $cashTransactionService, private AssetService $applianceService, private ApplianceRateService $applianceRateService, - ) { - } + ) {} /** * Store a newly created resource in storage. * * @param AssetType $assetType - * @param Person $person - * @param Request $request - * - * @return ApiResource */ public function store( Asset $asset, @@ -141,14 +135,8 @@ public function store( /** * Display the specified resource. - * - * @param Person $person - * @param Request $request - * - * @return ApiResource */ - public function index(Person $person, Request $request): ApiResource - { + public function index(Person $person, Request $request): ApiResource { $assets = $this->assetPerson::with('asset.assetType', 'rates.logs', 'logs.owner') ->where('person_id', $person->id) ->get(); @@ -156,8 +144,7 @@ public function index(Person $person, Request $request): ApiResource return ApiResource::make($assets); } - public function show($applianceId): ApiResource - { + public function show($applianceId): ApiResource { $appliance = $this->assetPersonService->getApplianceDetails($applianceId); return ApiResource::make($appliance); diff --git a/src/backend/app/Http/Controllers/AssetRateController.php b/src/backend/app/Http/Controllers/AssetRateController.php index 4b0e90d7f..3e903827d 100644 --- a/src/backend/app/Http/Controllers/AssetRateController.php +++ b/src/backend/app/Http/Controllers/AssetRateController.php @@ -8,8 +8,7 @@ use App\Services\CashTransactionService; use Illuminate\Http\Request; -class AssetRateController extends Controller -{ +class AssetRateController extends Controller { /** * Update the specified resource in storage. * @@ -19,6 +18,7 @@ class AssetRateController extends Controller * @return ApiResource */ private $cashTransactionService; + private $applianceRateService; public function __construct( @@ -29,8 +29,7 @@ public function __construct( $this->applianceRateService = $applianceRateService; } - public function update(Request $request, AssetRate $applianceRate): ApiResource - { + public function update(Request $request, AssetRate $applianceRate): ApiResource { $cost = $request->get('cost'); $newCost = $request->get('newCost'); $creatorId = $request->get('admin_id'); diff --git a/src/backend/app/Http/Controllers/AssetTypeController.php b/src/backend/app/Http/Controllers/AssetTypeController.php index 100c724d1..863ca39f1 100644 --- a/src/backend/app/Http/Controllers/AssetTypeController.php +++ b/src/backend/app/Http/Controllers/AssetTypeController.php @@ -10,8 +10,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Http\Request; -class AssetTypeController extends Controller -{ +class AssetTypeController extends Controller { use SoftDeletes; /** @@ -19,30 +18,21 @@ class AssetTypeController extends Controller */ private $applianceTypeService; - public function __construct(ApplianceTypeService $applianceTypeService) - { + public function __construct(ApplianceTypeService $applianceTypeService) { $this->applianceTypeService = $applianceTypeService; } /** * Display a listing of the resource. - * - * @return ApiResource */ - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { return new ApiResource($this->applianceTypeService->getApplianceTypes($request)); } /** * Store a newly created resource in storage. - * - * @param AssetTypeCreateRequest $request - * - * @return ApiResource */ - public function store(AssetTypeCreateRequest $request): ApiResource - { + public function store(AssetTypeCreateRequest $request): ApiResource { $appliance = $this->applianceTypeService->createApplianceType($request); return new ApiResource($appliance); @@ -50,14 +40,8 @@ public function store(AssetTypeCreateRequest $request): ApiResource /** * Update the specified resource in storage. - * - * @param AssetTypeUpdateRequest $request - * @param AssetType $assetType - * - * @return ApiResource */ - public function update(AssetTypeUpdateRequest $request, AssetType $assetType): ApiResource - { + public function update(AssetTypeUpdateRequest $request, AssetType $assetType): ApiResource { $appliance = $this->applianceTypeService->updateApplianceType($request, $assetType); return new ApiResource($appliance); @@ -66,14 +50,9 @@ public function update(AssetTypeUpdateRequest $request, AssetType $assetType): A /** * Remove the specified resource from storage. * - * @param AssetType $assetType - * - * @return ApiResource - * * @throws \Exception */ - public function destroy(AssetType $assetType): ApiResource - { + public function destroy(AssetType $assetType): ApiResource { return new ApiResource( $this->applianceTypeService->deleteApplianceType($assetType) ); diff --git a/src/backend/app/Http/Controllers/AuthController.php b/src/backend/app/Http/Controllers/AuthController.php index 5c0a69433..aa8c21d0c 100644 --- a/src/backend/app/Http/Controllers/AuthController.php +++ b/src/backend/app/Http/Controllers/AuthController.php @@ -9,15 +9,13 @@ * Class AuthController * Responsible for API-Call authentications. */ -class AuthController extends Controller -{ +class AuthController extends Controller { /** * Create a new AuthController instance. * * @return void */ - public function __construct() - { + public function __construct() { $this->middleware('auth:api', ['except' => ['login']]); } @@ -27,8 +25,7 @@ public function __construct() * @bodyParam email string required * @bodyParam password string required */ - public function login() - { + public function login() { $credentials = request(['email', 'password']); if (!$token = auth('api')->attempt($credentials)) { @@ -43,8 +40,7 @@ public function login() * * @return JsonResponse */ - public function me() - { + public function me() { return response()->json(auth('api')->user()); } @@ -53,8 +49,7 @@ public function me() * * @return JsonResponse */ - public function logout() - { + public function logout() { auth('api')->logout(); return response()->json(['message' => 'Successfully logged out']); @@ -67,8 +62,7 @@ public function logout() * * @return JsonResponse */ - public function refresh() - { + public function refresh() { return $this->respondWithToken(auth()->refresh()); } @@ -79,8 +73,7 @@ public function refresh() * * @return JsonResponse */ - protected function respondWithToken($token) - { + protected function respondWithToken($token) { return response()->json( [ 'access_token' => $token, diff --git a/src/backend/app/Http/Controllers/CityController.php b/src/backend/app/Http/Controllers/CityController.php index e2be57a09..e3416292c 100644 --- a/src/backend/app/Http/Controllers/CityController.php +++ b/src/backend/app/Http/Controllers/CityController.php @@ -9,24 +9,20 @@ use App\Services\GeographicalInformationService; use Illuminate\Http\Request; -class CityController extends Controller -{ +class CityController extends Controller { public function __construct( private CityService $cityService, private GeographicalInformationService $geographicalInformationService, private CityGeographicalInformationService $cityGeographicalInformationService, - ) { - } + ) {} - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $limit = $request->get('limit'); return ApiResource::make($this->cityService->getAll($limit)); } - public function show($cityId, Request $request): ApiResource - { + public function show($cityId, Request $request): ApiResource { $relation = $request->get('relation'); if ($relation) { @@ -36,16 +32,14 @@ public function show($cityId, Request $request): ApiResource return ApiResource::make($this->cityService->getById($cityId)); } - public function update($cityId, CityRequest $request): ApiResource - { + public function update($cityId, CityRequest $request): ApiResource { $city = $this->cityService->getById($cityId); $cityData = $request->only(['name', 'mini_grid_id', 'cluster_id', 'country_id']); return ApiResource::make($this->cityService->update($city, $cityData)); } - public function store(CityRequest $request): ApiResource - { + public function store(CityRequest $request): ApiResource { $data = $request->validationData(); $city = $this->cityService->create($data); $geographicalInformation = $this->geographicalInformationService->make($data); diff --git a/src/backend/app/Http/Controllers/ClusterController.php b/src/backend/app/Http/Controllers/ClusterController.php index aa968b833..1902a0dc2 100644 --- a/src/backend/app/Http/Controllers/ClusterController.php +++ b/src/backend/app/Http/Controllers/ClusterController.php @@ -10,29 +10,25 @@ use App\Services\ClusterTransactionService; use Illuminate\Http\Request; -class ClusterController extends Controller -{ +class ClusterController extends Controller { public function __construct( private ClusterService $clusterService, private ClusterMeterService $clusterMetersService, private ClusterTransactionService $clusterTransactionsService, private ClusterPopulationService $clusterPopulationService, - ) { - } + ) {} /** * @throws \Exception */ - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { return ApiResource::make($this->clusterService->getAll()); } /** * @throws \Exception */ - public function show($clusterId, Request $request): ApiResource - { + public function show($clusterId, Request $request): ApiResource { $dateRange = $this->clusterService->getDateRangeFromRequest($request->get('start_date'), $request->get('end_date')); $cluster = $this->clusterService->getById($clusterId); @@ -45,13 +41,11 @@ public function show($clusterId, Request $request): ApiResource )); } - public function showGeo($clusterId): ApiResource - { + public function showGeo($clusterId): ApiResource { return ApiResource::make(['geo_data' => $this->clusterService->getGeoLocationById($clusterId)]); } - public function store(ClusterRequest $request): ApiResource - { + public function store(ClusterRequest $request): ApiResource { $clusterData = $request->only(['name', 'manager_id', 'geo_data']); return ApiResource::make($this->clusterService->create($clusterData)); diff --git a/src/backend/app/Http/Controllers/ClusterMiniGridRevenueController.php b/src/backend/app/Http/Controllers/ClusterMiniGridRevenueController.php index cc58a8509..6d821f5db 100644 --- a/src/backend/app/Http/Controllers/ClusterMiniGridRevenueController.php +++ b/src/backend/app/Http/Controllers/ClusterMiniGridRevenueController.php @@ -6,15 +6,12 @@ use App\Services\ClusterRevenueService; use Illuminate\Http\Request; -class ClusterMiniGridRevenueController extends Controller -{ +class ClusterMiniGridRevenueController extends Controller { public function __construct( private ClusterRevenueService $clusterRevenueService, - ) { - } + ) {} - public function show($clusterId, Request $request): ApiResource - { + public function show($clusterId, Request $request): ApiResource { $startDate = $request->input('startDate') ?? date('Y-01-01'); $endDate = $request->input('endDate') ?? date('Y-m-t'); $period = $request->input('period') ?? 'monthly'; diff --git a/src/backend/app/Http/Controllers/ClusterRevenueAnalysisController.php b/src/backend/app/Http/Controllers/ClusterRevenueAnalysisController.php index 648ce6866..0bbda5223 100644 --- a/src/backend/app/Http/Controllers/ClusterRevenueAnalysisController.php +++ b/src/backend/app/Http/Controllers/ClusterRevenueAnalysisController.php @@ -8,17 +8,14 @@ use App\Services\ConnectionTypeService; use Illuminate\Http\Request; -class ClusterRevenueAnalysisController extends Controller -{ +class ClusterRevenueAnalysisController extends Controller { public function __construct( private ClusterService $clusterService, private ClusterRevenueService $clusterRevenueService, private ConnectionTypeService $connectionTypeService, - ) { - } + ) {} - public function show($clusterId, Request $request): ApiResource - { + public function show($clusterId, Request $request): ApiResource { /** * !!!! * To group revenue by city -> connection type diff --git a/src/backend/app/Http/Controllers/ClusterRevenueController.php b/src/backend/app/Http/Controllers/ClusterRevenueController.php index c17d2cbaa..03dbb962e 100644 --- a/src/backend/app/Http/Controllers/ClusterRevenueController.php +++ b/src/backend/app/Http/Controllers/ClusterRevenueController.php @@ -12,8 +12,7 @@ use App\Services\PeriodService; use Illuminate\Http\Request; -class ClusterRevenueController extends Controller -{ +class ClusterRevenueController extends Controller { public function __construct( private ClusterService $clusterService, private ClusterRevenueService $clusterRevenueService, @@ -22,11 +21,9 @@ public function __construct( private ClusterTransactionService $clusterTransactionService, private ClusterPopulationService $clusterPopulationService, private PeriodService $periodService, - ) { - } + ) {} - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $dates = $this->clusterRevenueService->setDatesForRequest($request->get('startDate'), $request->get('endDate')); $startDate = $dates['startDate']; @@ -46,8 +43,7 @@ public function index(Request $request): ApiResource ); } - public function show($clusterId, Request $request): ApiResource - { + public function show($clusterId, Request $request): ApiResource { $dateRange = $this->clusterRevenueService->setDateRangeForRequest($request->get('startDate'), $request->get('endDate')); $cluster = $this->clusterService->getById($clusterId); diff --git a/src/backend/app/Http/Controllers/ClustersDashboardCacheDataController.php b/src/backend/app/Http/Controllers/ClustersDashboardCacheDataController.php index fe1b2b170..f997e8279 100644 --- a/src/backend/app/Http/Controllers/ClustersDashboardCacheDataController.php +++ b/src/backend/app/Http/Controllers/ClustersDashboardCacheDataController.php @@ -6,25 +6,20 @@ use App\Services\ClustersDashboardCacheDataService; use Illuminate\Http\Request; -class ClustersDashboardCacheDataController extends Controller -{ +class ClustersDashboardCacheDataController extends Controller { public function __construct( private ClustersDashboardCacheDataService $clustersDashboardCacheDataService, - ) { - } + ) {} - public function index() - { + public function index() { return ApiResource::make($this->clustersDashboardCacheDataService->getData()); } - public function show($clusterId) - { + public function show($clusterId) { return ApiResource::make($this->clustersDashboardCacheDataService->getDataById($clusterId)); } - public function update(Request $request) - { + public function update(Request $request) { $fromDate = $request->query('from'); $toDate = $request->query('to'); diff --git a/src/backend/app/Http/Controllers/CompanyController.php b/src/backend/app/Http/Controllers/CompanyController.php index 8b6f0c889..fc84204fd 100644 --- a/src/backend/app/Http/Controllers/CompanyController.php +++ b/src/backend/app/Http/Controllers/CompanyController.php @@ -16,8 +16,7 @@ use Illuminate\Support\Facades\Artisan; use MPM\DatabaseProxy\DatabaseProxyManagerService; -class CompanyController extends Controller -{ +class CompanyController extends Controller { public function __construct( private CompanyService $companyService, private CompanyDatabaseService $companyDatabaseService, @@ -27,11 +26,9 @@ public function __construct( private MpmPluginService $mpmPluginService, private RegistrationTailService $registrationTailService, private MainSettingsService $mainSettingsService, - ) { - } + ) {} - public function store(CompanyRegistrationRequest $request): JsonResponse - { + public function store(CompanyRegistrationRequest $request): JsonResponse { $companyData = $request->only(['name', 'address', 'phone', 'email', 'country_id', 'protected_page_password']); $adminData = $request->input('user'); $plugins = $request->input('plugins'); @@ -109,8 +106,7 @@ function () use ($company, $plugins) { ); } - public function get($email): ApiResource - { + public function get($email): ApiResource { $databaseProxy = $this->databaseProxyManagerService->findByEmail($email); return ApiResource::make($this->companyService->getByDatabaseProxy($databaseProxy)); diff --git a/src/backend/app/Http/Controllers/ConnectionGroupController.php b/src/backend/app/Http/Controllers/ConnectionGroupController.php index 66694b28b..ca568c7ab 100644 --- a/src/backend/app/Http/Controllers/ConnectionGroupController.php +++ b/src/backend/app/Http/Controllers/ConnectionGroupController.php @@ -7,34 +7,28 @@ use App\Services\ConnectionGroupService; use Illuminate\Http\Request; -class ConnectionGroupController -{ +class ConnectionGroupController { public function __construct( private ConnectionGroupService $connectionGroupService, - ) { - } + ) {} - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $limit = $request->input('per_page'); return ApiResource::make($this->connectionGroupService->getAll($limit)); } - public function show($connectionGroupId, Request $request): ApiResource - { + public function show($connectionGroupId, Request $request): ApiResource { return ApiResource::make($this->connectionGroupService->getById($connectionGroupId)); } - public function store(CreateConnectionGroupRequest $request): ApiResource - { + public function store(CreateConnectionGroupRequest $request): ApiResource { $connectionGroupData = $request->all(); return new ApiResource($this->connectionGroupService->create($connectionGroupData)); } - public function update($connectionGroupId, CreateConnectionGroupRequest $request): ApiResource - { + public function update($connectionGroupId, CreateConnectionGroupRequest $request): ApiResource { $connectionGroup = $this->connectionGroupService->getById($connectionGroupId); $connectionGroupData = $request->all(); diff --git a/src/backend/app/Http/Controllers/ConnectionTypeController.php b/src/backend/app/Http/Controllers/ConnectionTypeController.php index 105d13fa1..f24494b1d 100644 --- a/src/backend/app/Http/Controllers/ConnectionTypeController.php +++ b/src/backend/app/Http/Controllers/ConnectionTypeController.php @@ -6,21 +6,16 @@ use App\Services\ConnectionTypeService; use Illuminate\Http\Request; -class ConnectionTypeController extends Controller -{ - public function __construct(private ConnectionTypeService $connectionTypeService) - { - } +class ConnectionTypeController extends Controller { + public function __construct(private ConnectionTypeService $connectionTypeService) {} - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $limit = $request->get('limit'); return ApiResource::make($this->connectionTypeService->getAll($limit)); } - public function show($connectionTypeId, Request $request): ApiResource - { + public function show($connectionTypeId, Request $request): ApiResource { $meterCountRelation = $request->input('meter_count'); if ($meterCountRelation) { @@ -30,15 +25,13 @@ public function show($connectionTypeId, Request $request): ApiResource return ApiResource::make($this->connectionTypeService->getById($connectionTypeId)); } - public function store(Request $request): ApiResource - { + public function store(Request $request): ApiResource { $connectionTypeData = $request->all(); return ApiResource::make($this->connectionTypeService->create($connectionTypeData)); } - public function update($connectionTypeId, Request $request): ApiResource - { + public function update($connectionTypeId, Request $request): ApiResource { $connectionTypeData = $request->all(); $connectionType = $this->connectionTypeService->getById($connectionTypeId); diff --git a/src/backend/app/Http/Controllers/Controller.php b/src/backend/app/Http/Controllers/Controller.php index ce1176ddb..59b8faae6 100644 --- a/src/backend/app/Http/Controllers/Controller.php +++ b/src/backend/app/Http/Controllers/Controller.php @@ -7,8 +7,7 @@ use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Routing\Controller as BaseController; -class Controller extends BaseController -{ +class Controller extends BaseController { use AuthorizesRequests; use DispatchesJobs; use ValidatesRequests; diff --git a/src/backend/app/Http/Controllers/CountryController.php b/src/backend/app/Http/Controllers/CountryController.php index ec99ba65c..7a7aa9796 100644 --- a/src/backend/app/Http/Controllers/CountryController.php +++ b/src/backend/app/Http/Controllers/CountryController.php @@ -7,10 +7,8 @@ use App\Models\Country; use Illuminate\Support\Facades\Config; -class CountryController extends Controller -{ - public function index(): ApiResource - { +class CountryController extends Controller { + public function index(): ApiResource { return new ApiResource( Country::query()->paginate( Config::get('services.pagination') @@ -18,13 +16,11 @@ public function index(): ApiResource ); } - public function show(Country $country): ApiResource - { + public function show(Country $country): ApiResource { return ApiResource::make($country); } - public function store(CountryRequest $request): ApiResource - { + public function store(CountryRequest $request): ApiResource { return ApiResource::make(Country::query()->create(request()->only(['country_name', 'country_code']))); } } diff --git a/src/backend/app/Http/Controllers/CountryListController.php b/src/backend/app/Http/Controllers/CountryListController.php index 62b5c1919..e13202b86 100644 --- a/src/backend/app/Http/Controllers/CountryListController.php +++ b/src/backend/app/Http/Controllers/CountryListController.php @@ -5,10 +5,8 @@ use App\Http\Resources\ApiResource; use Illuminate\Support\Facades\Storage; -class CountryListController extends Controller -{ - public function index(): ApiResource - { +class CountryListController extends Controller { + public function index(): ApiResource { $country = Storage::disk('local')->get('countries.json'); $country = json_decode($country, true); diff --git a/src/backend/app/Http/Controllers/CurrencyController.php b/src/backend/app/Http/Controllers/CurrencyController.php index aaed9f8a3..fc6b523f8 100644 --- a/src/backend/app/Http/Controllers/CurrencyController.php +++ b/src/backend/app/Http/Controllers/CurrencyController.php @@ -5,10 +5,8 @@ use App\Http\Resources\ApiResource; use Illuminate\Support\Facades\Storage; -class CurrencyController extends Controller -{ - public function index(): ApiResource - { +class CurrencyController extends Controller { + public function index(): ApiResource { $currency = Storage::disk('local')->get('currency.json'); $currency = json_decode($currency, true); diff --git a/src/backend/app/Http/Controllers/CustomerRegistrationAppController.php b/src/backend/app/Http/Controllers/CustomerRegistrationAppController.php index 29039e8ff..a7490beff 100644 --- a/src/backend/app/Http/Controllers/CustomerRegistrationAppController.php +++ b/src/backend/app/Http/Controllers/CustomerRegistrationAppController.php @@ -8,14 +8,10 @@ use Illuminate\Support\Facades\Log; use MPM\Apps\CustomerRegistration\CustomerRegistrationAppService; -class CustomerRegistrationAppController extends Controller -{ - public function __construct(private CustomerRegistrationAppService $customerRegistrationAppService) - { - } +class CustomerRegistrationAppController extends Controller { + public function __construct(private CustomerRegistrationAppService $customerRegistrationAppService) {} - public function store(AndroidAppRequest $request) - { + public function store(AndroidAppRequest $request) { try { DB::connection('shard')->beginTransaction(); $person = $this->customerRegistrationAppService->createCustomer($request); diff --git a/src/backend/app/Http/Controllers/DailyTransactions.php b/src/backend/app/Http/Controllers/DailyTransactions.php index dd8607ca5..2dfba1011 100644 --- a/src/backend/app/Http/Controllers/DailyTransactions.php +++ b/src/backend/app/Http/Controllers/DailyTransactions.php @@ -10,8 +10,7 @@ * * @group Export */ -class DailyTransactions extends Controller -{ +class DailyTransactions extends Controller { /** * The used transaction model. * @@ -19,13 +18,11 @@ class DailyTransactions extends Controller */ private $transaction; - public function __construct(Transaction $transaction) - { + public function __construct(Transaction $transaction) { $this->transaction = $transaction; } - public function getDailyReport(Request $request) - { + public function getDailyReport(Request $request) { $date = $request->get('date') ?? date('Y-m-d'); $transactions = $this->transaction::with('originalTransaction')->whereDate('created_at', $date)->get(); @@ -77,8 +74,7 @@ public function getDailyReport(Request $request) return $this->downloadCSV($transactionOutput, $date.'-transactions'); } - private function downloadCSV(array $transactionData, string $fileName) - { + private function downloadCSV(array $transactionData, string $fileName) { if (count($transactionData) === 0) { // to prevent to download an empty file return null; } diff --git a/src/backend/app/Http/Controllers/DeviceAddressController.php b/src/backend/app/Http/Controllers/DeviceAddressController.php index d608d1f36..c34c8211c 100644 --- a/src/backend/app/Http/Controllers/DeviceAddressController.php +++ b/src/backend/app/Http/Controllers/DeviceAddressController.php @@ -7,16 +7,13 @@ use MPM\Device\DeviceAddressService; use MPM\Device\DeviceService; -class DeviceAddressController extends Controller -{ +class DeviceAddressController extends Controller { public function __construct( private DeviceAddressService $deviceAddressService, private DeviceService $deviceService, - ) { - } + ) {} - public function update(Request $request) - { + public function update(Request $request) { $creatorId = auth('api')->user()->id; $devices = $request->all(); foreach ($devices as $deviceData) { diff --git a/src/backend/app/Http/Controllers/DeviceController.php b/src/backend/app/Http/Controllers/DeviceController.php index f51150283..e5882de3f 100644 --- a/src/backend/app/Http/Controllers/DeviceController.php +++ b/src/backend/app/Http/Controllers/DeviceController.php @@ -7,19 +7,14 @@ use App\Models\Device; use MPM\Device\DeviceService; -class DeviceController extends Controller -{ - public function __construct(private DeviceService $deviceService) - { - } +class DeviceController extends Controller { + public function __construct(private DeviceService $deviceService) {} - public function index() - { + public function index() { return ApiResource::make($this->deviceService->getAll()); } - public function update(Device $device, UpdateDeviceRequest $request): ApiResource - { + public function update(Device $device, UpdateDeviceRequest $request): ApiResource { $creatorId = auth('api')->user()->id; $previousOwner = $device->person_id; $newOwner = $request->input('person_id'); diff --git a/src/backend/app/Http/Controllers/EBikeController.php b/src/backend/app/Http/Controllers/EBikeController.php index 893e7c334..9cedced8b 100644 --- a/src/backend/app/Http/Controllers/EBikeController.php +++ b/src/backend/app/Http/Controllers/EBikeController.php @@ -11,26 +11,22 @@ use MPM\EBike\EBikeDeviceService; use MPM\EBike\EBikeService; -class EBikeController extends Controller -{ +class EBikeController extends Controller { public function __construct( private DeviceService $deviceService, private EBikeService $eBikeService, private EBikeDeviceService $eBikeDeviceService, private ManufacturerService $manufacturerService, private AppliancePersonService $appliancePersonService, - ) { - } + ) {} - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $limit = $request->input('per_page'); return ApiResource::make($this->eBikeService->getAll($limit)); } - public function store(StoreEBikeRequest $request) - { + public function store(StoreEBikeRequest $request) { $eBikeData = $request->all(); $deviceData = [ 'device_serial' => $eBikeData['serial_number'], @@ -47,21 +43,18 @@ public function store(StoreEBikeRequest $request) return ApiResource::make($eBike->load(['manufacturer', 'appliance', 'device.person'])); } - public function search(Request $request): ApiResource - { + public function search(Request $request): ApiResource { $term = $request->input('term'); $paginate = $request->input('paginate') ?? 1; return ApiResource::make($this->eBikeService->search($term, $paginate)); } - public function show(string $serialNumber): ApiResource - { + public function show(string $serialNumber): ApiResource { return ApiResource::make($this->eBikeService->getBySerialNumber($serialNumber)); } - public function switch(Request $request): ApiResource - { + public function switch(Request $request): ApiResource { $serialNumber = $request->input('serial_number'); $manufacturerName = $request->input('manufacturer_name'); $status = $request->input('status'); diff --git a/src/backend/app/Http/Controllers/HomeController.php b/src/backend/app/Http/Controllers/HomeController.php index 9a0fbe2ab..e74aaefba 100644 --- a/src/backend/app/Http/Controllers/HomeController.php +++ b/src/backend/app/Http/Controllers/HomeController.php @@ -2,24 +2,20 @@ namespace App\Http\Controllers; -class HomeController extends Controller -{ +class HomeController extends Controller { /** * Create a new controller instance. * * @return void */ - public function __construct() - { - } + public function __construct() {} /** * Show the application dashboard. * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function index() - { + public function index() { return view('layouts.app'); } } diff --git a/src/backend/app/Http/Controllers/MailSettingsController.php b/src/backend/app/Http/Controllers/MailSettingsController.php index 6bbc9861c..65e0fc14b 100644 --- a/src/backend/app/Http/Controllers/MailSettingsController.php +++ b/src/backend/app/Http/Controllers/MailSettingsController.php @@ -7,12 +7,12 @@ use App\Models\MailSettings; use App\Services\MailSettingsService; -class MailSettingsController extends Controller -{ +class MailSettingsController extends Controller { /** * @MailSettings */ private $mailSettings; + private $mailSettingsService; public function __construct( @@ -23,18 +23,15 @@ public function __construct( $this->mailSettingsService = $mailSettingsService; } - public function index(): ApiResource - { + public function index(): ApiResource { return new ApiResource($this->mailSettingsService->list()); } - public function update(MailSettingsRequest $request, MailSettings $mailSettings): ApiResource - { + public function update(MailSettingsRequest $request, MailSettings $mailSettings): ApiResource { return new ApiResource($this->mailSettingsService->update($request, $mailSettings)); } - public function store(MailSettingsRequest $request): ApiResource - { + public function store(MailSettingsRequest $request): ApiResource { return new ApiResource($this->mailSettingsService->create($request)); } } diff --git a/src/backend/app/Http/Controllers/MainSettingsController.php b/src/backend/app/Http/Controllers/MainSettingsController.php index 7147e3728..0213172ad 100644 --- a/src/backend/app/Http/Controllers/MainSettingsController.php +++ b/src/backend/app/Http/Controllers/MainSettingsController.php @@ -7,19 +7,14 @@ use App\Services\MainSettingsService; use Illuminate\Http\Request; -class MainSettingsController extends Controller -{ - public function __construct(private MainSettingsService $mainSettingsService) - { - } +class MainSettingsController extends Controller { + public function __construct(private MainSettingsService $mainSettingsService) {} - public function index(): ApiResource - { + public function index(): ApiResource { return ApiResource::make($this->mainSettingsService->getAll()->first()); } - public function update(MainSettings $mainSettings, Request $request): ApiResource - { + public function update(MainSettings $mainSettings, Request $request): ApiResource { $mainSettingsData = $request->only([ 'site_title', 'company_name', diff --git a/src/backend/app/Http/Controllers/MaintenanceUserController.php b/src/backend/app/Http/Controllers/MaintenanceUserController.php index f32799c85..c5f5d002d 100644 --- a/src/backend/app/Http/Controllers/MaintenanceUserController.php +++ b/src/backend/app/Http/Controllers/MaintenanceUserController.php @@ -11,8 +11,7 @@ use Illuminate\Http\JsonResponse; use Inensus\BulkRegistration\Services\AddressService; -class MaintenanceUserController extends Controller -{ +class MaintenanceUserController extends Controller { private $roles; public function __construct( @@ -20,23 +19,15 @@ public function __construct( private Person $person, private PersonService $personService, private AddressService $addressService, - ) { - } + ) {} - public function index(): ApiResource - { + public function index(): ApiResource { $maintenance_user_list = $this->maintenanceUsers::with('person')->get(); return new ApiResource($maintenance_user_list); } - /** - * @param MaintenanceRequest $request - * - * @return JsonResponse - */ - public function store(MaintenanceRequest $request): JsonResponse - { + public function store(MaintenanceRequest $request): JsonResponse { $phone = $request->get('phone'); try { diff --git a/src/backend/app/Http/Controllers/ManufacturerController.php b/src/backend/app/Http/Controllers/ManufacturerController.php index 76d439325..4a0be1e4c 100644 --- a/src/backend/app/Http/Controllers/ManufacturerController.php +++ b/src/backend/app/Http/Controllers/ManufacturerController.php @@ -10,22 +10,17 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class ManufacturerController extends Controller -{ +class ManufacturerController extends Controller { public function __construct( private ManufacturerService $manufacturerService, private ManufacturerAddressService $manufacturerAddressService, private AddressesService $addressService, - ) { - } + ) {} /** * Display a listing of the resource. - * - * @return ApiResource */ - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $limit = $request->input('per_page'); return ApiResource::make($this->manufacturerService->getAll($limit)); @@ -33,13 +28,8 @@ public function index(Request $request): ApiResource /** * Store a newly created resource in storage. - * - * @param ManufacturerRequest $request - * - * @return JsonResponse */ - public function store(ManufacturerRequest $request): JsonResponse - { + public function store(ManufacturerRequest $request): JsonResponse { $manufacturerData = $this->manufacturerService->createManufacturerDataFromRequest($request); $addressData = $this->addressService->createAddressDataFromRequest($request); $manufacturer = $this->manufacturerService->create($manufacturerData); @@ -56,11 +46,8 @@ public function store(ManufacturerRequest $request): JsonResponse * Display the specified resource. * * @param int $manufacturerId - * - * @return ApiResource */ - public function show($manufacturerId): ApiResource - { + public function show($manufacturerId): ApiResource { return ApiResource::make($this->manufacturerService->getById($manufacturerId)); } } diff --git a/src/backend/app/Http/Controllers/MapSettingsController.php b/src/backend/app/Http/Controllers/MapSettingsController.php index 64c51411a..412fbad5f 100644 --- a/src/backend/app/Http/Controllers/MapSettingsController.php +++ b/src/backend/app/Http/Controllers/MapSettingsController.php @@ -7,22 +7,18 @@ use App\Models\MapSettings; use App\Services\BingMapApiService; -class MapSettingsController extends Controller -{ +class MapSettingsController extends Controller { private $bingMapApiService; - public function __construct(BingMapApiService $bingMapApiService) - { + public function __construct(BingMapApiService $bingMapApiService) { $this->bingMapApiService = $bingMapApiService; } - public function index(): ApiResource - { + public function index(): ApiResource { return new ApiResource(MapSettings::all()); } - public function update($id): ApiResource - { + public function update($id): ApiResource { $mapSettings = MapSettings::query() ->updateOrCreate( ['id' => $id], @@ -38,8 +34,7 @@ public function update($id): ApiResource return new ApiResource([$mapSettings->fresh()]); } - public function checkBingApiKey($key): ApiResource - { + public function checkBingApiKey($key): ApiResource { try { $apiAuthentication = $this->bingMapApiService->checkAuthenticationKey($key); } catch (InvalidBingApiKeyException $exception) { diff --git a/src/backend/app/Http/Controllers/MeterConsumptionController.php b/src/backend/app/Http/Controllers/MeterConsumptionController.php index b0b05511a..12635e259 100644 --- a/src/backend/app/Http/Controllers/MeterConsumptionController.php +++ b/src/backend/app/Http/Controllers/MeterConsumptionController.php @@ -6,13 +6,11 @@ use App\Services\MeterConsumptionService; use App\Services\MeterService; -class MeterConsumptionController extends Controller -{ +class MeterConsumptionController extends Controller { public function __construct( private MeterService $meterService, private MeterConsumptionService $meterConsumptionService, - ) { - } + ) {} /** * Consumption List @@ -24,15 +22,8 @@ public function __construct( * @urlParam end YYYY-mm-dd format * * @responseFile responses/meters/meter.consumption.list.json - * - * @param $serialNumber - * @param $start - * @param $end - * - * @return ApiResource */ - public function show($serialNumber, $start, $end): ApiResource - { + public function show($serialNumber, $start, $end): ApiResource { $meter = $this->meterService->getBySerialNumber($serialNumber); return ApiResource::make($this->meterConsumptionService->getByMeter($meter, $start, $end)); diff --git a/src/backend/app/Http/Controllers/MeterController.php b/src/backend/app/Http/Controllers/MeterController.php index 05c357603..6c7276623 100644 --- a/src/backend/app/Http/Controllers/MeterController.php +++ b/src/backend/app/Http/Controllers/MeterController.php @@ -11,12 +11,10 @@ use Illuminate\Http\Request; use Illuminate\Validation\ValidationException; -class MeterController extends Controller -{ +class MeterController extends Controller { public function __construct( private MeterService $meterService, - ) { - } + ) {} /** * List @@ -27,13 +25,8 @@ public function __construct( * @urlParam in_use int to list wether used or all meters * * @responseFile responses/meters/meters.list.json - * - * @param Request $request - * - * @return ApiResource */ - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $inUse = $request->input('in_use'); $limit = $request->input('limit', config('settings.paginate')); @@ -44,8 +37,6 @@ public function index(Request $request): ApiResource * Create * Stores a new meter. * - * @param MeterRequest $request - * * @bodyParam serial_number string required * @bodyParam meter_type_id int required * @bodyParam manufacturer_id int required @@ -54,8 +45,7 @@ public function index(Request $request): ApiResource * * @throws ValidationException */ - public function store(MeterRequest $request) - { + public function store(MeterRequest $request) { $meterData = (array) $request->all(); return ApiResource::make($this->meterService->create($meterData)); @@ -73,14 +63,9 @@ public function store(MeterRequest $request) * * @urlParam serialNumber string * - * @param string $serialNumber - * - * @return ApiResource - * * @responseFile responses/meters/meter.detail.json */ - public function show(string $serialNumber): ApiResource - { + public function show(string $serialNumber): ApiResource { return ApiResource::make($this->meterService->getBySerialNumber($serialNumber)); } @@ -92,12 +77,9 @@ public function show(string $serialNumber): ApiResource * * @bodyParam term string required * - * @return ApiResource - * * @responseFile responses/meters/meters.search.json */ - public function search(): ApiResource - { + public function search(): ApiResource { $term = request('term'); $paginate = request('paginate') ?? 1; @@ -109,20 +91,14 @@ public function search(): ApiResource * Deletes the meter with its all releations. * * @urlParam meterId. The ID of the meter to be delete - * - * @param $meterId - * - * @return JsonResponse */ - public function destroy($meterId): JsonResponse - { + public function destroy($meterId): JsonResponse { $this->meterService->getById($meterId); return response()->json(null, 204); } - public function update(UpdateMeterRequest $request, Meter $meter): ApiResource - { + public function update(UpdateMeterRequest $request, Meter $meter): ApiResource { $creatorId = auth('api')->user()->id; $previousDataOfMeter = json_encode($meter->toArray()); $updatedMeter = $this->meterService->update($meter, $request->validated()); diff --git a/src/backend/app/Http/Controllers/MeterGeographicalInformationController.php b/src/backend/app/Http/Controllers/MeterGeographicalInformationController.php index 82050b825..d643f5988 100644 --- a/src/backend/app/Http/Controllers/MeterGeographicalInformationController.php +++ b/src/backend/app/Http/Controllers/MeterGeographicalInformationController.php @@ -10,15 +10,13 @@ use App\Services\PersonMeterService; use Illuminate\Http\Request; -class MeterGeographicalInformationController extends Controller -{ +class MeterGeographicalInformationController extends Controller { public function __construct( private MeterGeographicalInformationService $meterGeographicalInformationService, private PersonMeterService $personMeterService, private CityService $cityService, private MeterService $meterService, - ) { - } + ) {} /** * List with geo and access rate @@ -27,12 +25,9 @@ public function __construct( * * @urlParam mini_grid_id * - * @return ApiResource - * * @responseFile responses/meters/meters.geo.list.json */ - public function index($miniGridId): ApiResource - { + public function index($miniGridId): ApiResource { $cityIds = $this->cityService->getCityIdsByMiniGridId($miniGridId); // we can get city id only by address if ($miniGridId === null) { @@ -57,12 +52,9 @@ public function index($miniGridId): ApiResource * * @param int $person * - * @return ApiResource - * * @responseFile responses/people/person.meter.list.json */ - public function show(int $personId): ApiResource - { + public function show(int $personId): ApiResource { return ApiResource::make($this->personMeterService->getPersonMetersGeographicalInformation($personId)); } @@ -74,11 +66,9 @@ public function show(int $personId): ApiResource * * @bodyParam points string. Comma seperated latitude and longitude. Example 1,2 * - * @param Request $request - * @param Meter $meter + * @param Meter $meter */ - public function update(Request $request): ApiResource - { + public function update(Request $request): ApiResource { $meters = $request->all(); return ApiResource::make($this->meterGeographicalInformationService->updateGeographicalInformation($meters)); diff --git a/src/backend/app/Http/Controllers/MeterPaymentHistoryController.php b/src/backend/app/Http/Controllers/MeterPaymentHistoryController.php index 59a7c453c..0b3cebd19 100644 --- a/src/backend/app/Http/Controllers/MeterPaymentHistoryController.php +++ b/src/backend/app/Http/Controllers/MeterPaymentHistoryController.php @@ -5,15 +5,12 @@ use App\Http\Resources\ApiResource; use App\Services\PaymentHistoryService; -class MeterPaymentHistoryController -{ +class MeterPaymentHistoryController { public function __construct( private PaymentHistoryService $paymentHistoryService, - ) { - } + ) {} - public function show(string $serialNumber) - { + public function show(string $serialNumber) { $paginate = request('paginate') ?? 50; return ApiResource::make($this->paymentHistoryService->getBySerialNumber($serialNumber, $paginate)); diff --git a/src/backend/app/Http/Controllers/MeterRevenueController.php b/src/backend/app/Http/Controllers/MeterRevenueController.php index 915bd428f..19ad98e9f 100644 --- a/src/backend/app/Http/Controllers/MeterRevenueController.php +++ b/src/backend/app/Http/Controllers/MeterRevenueController.php @@ -5,12 +5,10 @@ use App\Http\Resources\ApiResource; use App\Services\MeterRevenueService; -class MeterRevenueController extends Controller -{ +class MeterRevenueController extends Controller { public function __construct( private MeterRevenueService $meterRevenueService, - ) { - } + ) {} /** * Revenue @@ -21,13 +19,8 @@ public function __construct( * @bodyParam serialNumber string required. * * @responseFile responses/meters/meter.revenue.json - * - * @param $serialNumber - * - * @return ApiResource */ - public function show(string $serialNumber): ApiResource - { + public function show(string $serialNumber): ApiResource { $revenue = $this->meterRevenueService->getBySerialNumber($serialNumber); return ApiResource::make(['revenue' => $revenue]); diff --git a/src/backend/app/Http/Controllers/MeterTariffController.php b/src/backend/app/Http/Controllers/MeterTariffController.php index a777f9def..cc1fc7a44 100644 --- a/src/backend/app/Http/Controllers/MeterTariffController.php +++ b/src/backend/app/Http/Controllers/MeterTariffController.php @@ -9,12 +9,10 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class MeterTariffController extends Controller -{ +class MeterTariffController extends Controller { public function __construct( private MeterTariffService $meterTariffService, - ) { - } + ) {} /** * List @@ -22,11 +20,8 @@ public function __construct( * The list is paginated and each page contains 15 results. * * @responseFile responses/tariffs/tariffs.list.json - * - * @return ApiResource */ - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $limit = $request->get('limit'); return ApiResource::make($this->meterTariffService->getAll($limit)); @@ -40,11 +35,8 @@ public function index(Request $request): ApiResource * @responseFile responses/tariffs/tariff.detail.json * * @param MeterTariff $tariff - * - * @return ApiResource */ - public function show(Request $request, $meterTariffId): ApiResource - { + public function show(Request $request, $meterTariffId): ApiResource { return ApiResource::make($this->meterTariffService->getById($meterTariffId)); } @@ -56,12 +48,9 @@ public function show(Request $request, $meterTariffId): ApiResource * @bodyParam currency string * @bodyParam price int required. * - * @param TariffCreateRequest $request - * * @return ApiResource */ - public function store(TariffCreateRequest $request): JsonResponse - { + public function store(TariffCreateRequest $request): JsonResponse { $meterTariffData = $request->only(['name', 'factor', 'currency', 'price', 'minimum_purchase_amount']); $newTariff = $this->meterTariffService->create($meterTariffData); @@ -71,8 +60,7 @@ public function store(TariffCreateRequest $request): JsonResponse return ApiResource::make($this->meterTariffService->getById($newTariff->id))->response()->setStatusCode(201); } - public function update($meterTariffId, TariffCreateRequest $request): ApiResource - { + public function update($meterTariffId, TariffCreateRequest $request): ApiResource { $meterTariff = $this->meterTariffService->getById($meterTariffId); $meterTariffData = [ 'name' => $request->input('name'), @@ -90,8 +78,7 @@ public function update($meterTariffId, TariffCreateRequest $request): ApiResourc return ApiResource::make($meterTariff); } - public function destroy($meterTariffId): ?bool - { + public function destroy($meterTariffId): ?bool { $meterTariff = $this->meterTariffService->getById($meterTariffId); return $this->meterTariffService->delete($meterTariff); diff --git a/src/backend/app/Http/Controllers/MeterTariffMeterParameterController.php b/src/backend/app/Http/Controllers/MeterTariffMeterParameterController.php index b19fb416b..7117d7dd6 100644 --- a/src/backend/app/Http/Controllers/MeterTariffMeterParameterController.php +++ b/src/backend/app/Http/Controllers/MeterTariffMeterParameterController.php @@ -5,40 +5,25 @@ use App\Http\Resources\ApiResource; use App\Services\MeterTariffMeterParameterService; -class MeterTariffMeterParameterController extends Controller -{ +class MeterTariffMeterParameterController extends Controller { public function __construct( private MeterTariffMeterParameterService $meterTariffMeterParameterService, - ) { - } + ) {} /** * Display a list of meters which using a particular tariff. - * - * @param $meterTariffId - * - * @return ApiResource */ - public function show($meterTariffId): ApiResource - { + public function show($meterTariffId): ApiResource { return ApiResource::make($this->meterTariffMeterParameterService->getCountById($meterTariffId)); } - /** - * @param $meterTariffId - * @param int $changeId - * - * @return ApiResource - */ - public function update($meterTariffId, int $changeId): ApiResource - { + public function update($meterTariffId, int $changeId): ApiResource { $result = $this->meterTariffMeterParameterService->changeMetersTariff($meterTariffId, $changeId); return ApiResource::make($result); } - public function updateForMeter($meterSerial, $tariffId): ApiResource - { + public function updateForMeter($meterSerial, $tariffId): ApiResource { $result = $this->meterTariffMeterParameterService->changeMeterTariff($meterSerial, $tariffId); return ApiResource::make($result); diff --git a/src/backend/app/Http/Controllers/MeterTypeController.php b/src/backend/app/Http/Controllers/MeterTypeController.php index e87832856..e7e3fdff5 100644 --- a/src/backend/app/Http/Controllers/MeterTypeController.php +++ b/src/backend/app/Http/Controllers/MeterTypeController.php @@ -13,23 +13,17 @@ * @group MeterTypes * Class MeterTypeController */ -class MeterTypeController extends Controller -{ +class MeterTypeController extends Controller { use SoftDeletes; - public function __construct(private MeterTypeService $meterTypeService) - { - } + public function __construct(private MeterTypeService $meterTypeService) {} /** * List. * * @responseFile responses/metertypes/meter.types.list.json - * - * @return ApiResource */ - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $limit = $request->get('limit'); return ApiResource::make($this->meterTypeService->getAll($limit)); @@ -43,12 +37,9 @@ public function index(Request $request): ApiResource * @bodyParam phase int required * @bodyParam max_current int required * - * @param MeterTypeCreateRequest $request - * * @return ApiResource */ - public function store(MeterTypeCreateRequest $request) - { + public function store(MeterTypeCreateRequest $request) { $meterTypeData = $request->only(['online', 'phase', 'max_current']); return ApiResource::make($this->meterTypeService->create($meterTypeData)); @@ -60,11 +51,8 @@ public function store(MeterTypeCreateRequest $request) * @bodyParam id int required * * @param int $meterTypeId - * - * @return ApiResource */ - public function show($meterTypeId): ApiResource - { + public function show($meterTypeId): ApiResource { return ApiResource::make($this->meterTypeService->getById($meterTypeId)); } @@ -78,13 +66,9 @@ public function show($meterTypeId): ApiResource * @bodyParam phase int required * @bodyParam max_current int required * - * @param MeterTypeUpdateRequest $request - * @param int $meterTypeId - * - * @return ApiResource + * @param int $meterTypeId */ - public function update(MeterTypeUpdateRequest $request, $meterTypeId): ApiResource - { + public function update(MeterTypeUpdateRequest $request, $meterTypeId): ApiResource { $meterType = $this->meterTypeService->getById($meterTypeId); $meterTypeData = $request->only(['online', 'phase', 'max_current']); diff --git a/src/backend/app/Http/Controllers/MeterTypeMeterController.php b/src/backend/app/Http/Controllers/MeterTypeMeterController.php index 5241521fa..fb6f4faec 100644 --- a/src/backend/app/Http/Controllers/MeterTypeMeterController.php +++ b/src/backend/app/Http/Controllers/MeterTypeMeterController.php @@ -6,11 +6,8 @@ use App\Services\MeterTypeMeterService; use Illuminate\Http\Request; -class MeterTypeMeterController extends Controller -{ - public function __construct(private MeterTypeMeterService $meterTypeMeterService) - { - } +class MeterTypeMeterController extends Controller { + public function __construct(private MeterTypeMeterService $meterTypeMeterService) {} /** * List with Meters @@ -20,13 +17,9 @@ public function __construct(private MeterTypeMeterService $meterTypeMeterService * * @responseFile responses/metertypes/metertypes.meter.list.json * - * @param Request $request - * @param $meterTypeId - * * @return ApiResource */ - public function show(Request $request, $meterTypeId) - { + public function show(Request $request, $meterTypeId) { return ApiResource::make($this->meterTypeMeterService->getByIdWithMeters($meterTypeId)); } } diff --git a/src/backend/app/Http/Controllers/MiniGridController.php b/src/backend/app/Http/Controllers/MiniGridController.php index a11023534..554bb3fcd 100644 --- a/src/backend/app/Http/Controllers/MiniGridController.php +++ b/src/backend/app/Http/Controllers/MiniGridController.php @@ -11,24 +11,17 @@ use App\Services\MiniGridService; use Illuminate\Http\Request; -class MiniGridController extends Controller -{ +class MiniGridController extends Controller { public function __construct( private MiniGridService $miniGridService, private GeographicalInformationService $geographicalInformationService, private MiniGridGeographicalInformationService $miniGridGeographicalInformationService, - ) { - } + ) {} /** * List. - * - * @param Request $request - * - * @return ApiResource */ - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $limit = $request->input('per_page'); return ApiResource::make($this->miniGridService->getAll($limit)); @@ -39,13 +32,9 @@ public function index(Request $request): ApiResource * * @bodyParam id int required * - * @param int $id - * @param Request $request - * - * @return ApiResource + * @param int $id */ - public function show($miniGridId, Request $request): ApiResource - { + public function show($miniGridId, Request $request): ApiResource { $relation = $request->get('relation'); if ((int) $relation === 1) { @@ -55,8 +44,7 @@ public function show($miniGridId, Request $request): ApiResource } } - public function store(StoreMiniGridRequest $request): ApiResource - { + public function store(StoreMiniGridRequest $request): ApiResource { $data = $request->validationData(); $miniGrid = $this->miniGridService->create($request->only(['name', 'cluster_id'])); $geographicalInformation = $this->geographicalInformationService->make(['points' => $data['geo_data']]); @@ -73,13 +61,9 @@ public function store(StoreMiniGridRequest $request): ApiResource * * @bodyParam name string The name of the MiniGrid. * - * @param MiniGrid $miniGrid - * @param UpdateMiniGridRequest $request - * - * @return ApiResource + * @param MiniGrid $miniGrid */ - public function update($miniGridId, UpdateMiniGridRequest $request): ApiResource - { + public function update($miniGridId, UpdateMiniGridRequest $request): ApiResource { $miniGrid = $this->miniGridService->getById($miniGridId); return ApiResource::make($this->miniGridService->getById($miniGridId)); diff --git a/src/backend/app/Http/Controllers/MiniGridDashboardCacheController.php b/src/backend/app/Http/Controllers/MiniGridDashboardCacheController.php index b3747c48b..1ca08e61c 100644 --- a/src/backend/app/Http/Controllers/MiniGridDashboardCacheController.php +++ b/src/backend/app/Http/Controllers/MiniGridDashboardCacheController.php @@ -6,24 +6,18 @@ use App\Services\MiniGridDashboardCacheDataService; use Illuminate\Http\Request; -class MiniGridDashboardCacheController extends Controller -{ - public function __construct(private MiniGridDashboardCacheDataService $miniGridDashboardCacheDataService) - { - } +class MiniGridDashboardCacheController extends Controller { + public function __construct(private MiniGridDashboardCacheDataService $miniGridDashboardCacheDataService) {} - public function index(): ApiResource - { + public function index(): ApiResource { return ApiResource::make($this->miniGridDashboardCacheDataService->getData()); } - public function show($miniGridId): ApiResource - { + public function show($miniGridId): ApiResource { return ApiResource::make($this->miniGridDashboardCacheDataService->getDataById($miniGridId)); } - public function update(Request $request): array - { + public function update(Request $request): array { $fromDate = $request->query('from'); $toDate = $request->query('to'); diff --git a/src/backend/app/Http/Controllers/MiniGridDeviceController.php b/src/backend/app/Http/Controllers/MiniGridDeviceController.php index 0b5f2d485..1d13334fe 100644 --- a/src/backend/app/Http/Controllers/MiniGridDeviceController.php +++ b/src/backend/app/Http/Controllers/MiniGridDeviceController.php @@ -6,15 +6,12 @@ use Illuminate\Http\Request; use MPM\Device\MiniGridDeviceService; -class MiniGridDeviceController extends Controller -{ +class MiniGridDeviceController extends Controller { public function __construct( private MiniGridDeviceService $miniGridDeviceService, - ) { - } + ) {} - public function index(Request $request, $miniGridId): ApiResource - { + public function index(Request $request, $miniGridId): ApiResource { return ApiResource::make($this->miniGridDeviceService->getDevicesByMiniGridId($miniGridId)); } } diff --git a/src/backend/app/Http/Controllers/MiniGridRevenueController.php b/src/backend/app/Http/Controllers/MiniGridRevenueController.php index ae683213f..6f6f8df50 100644 --- a/src/backend/app/Http/Controllers/MiniGridRevenueController.php +++ b/src/backend/app/Http/Controllers/MiniGridRevenueController.php @@ -7,16 +7,13 @@ use App\Services\MiniGridRevenueService; use Illuminate\Http\Request; -class MiniGridRevenueController -{ +class MiniGridRevenueController { public function __construct( private MeterService $meterService, private MiniGridRevenueService $miniGridRevenueService, - ) { - } + ) {} - public function show($miniGridId, Request $request): ApiResource - { + public function show($miniGridId, Request $request): ApiResource { $startDate = $request->get('startDate'); $endDate = $request->get('endDate'); diff --git a/src/backend/app/Http/Controllers/MpmPluginController.php b/src/backend/app/Http/Controllers/MpmPluginController.php index 7581190d5..3a2d58258 100644 --- a/src/backend/app/Http/Controllers/MpmPluginController.php +++ b/src/backend/app/Http/Controllers/MpmPluginController.php @@ -6,14 +6,10 @@ use App\Services\MpmPluginService; use Illuminate\Http\Request; -class MpmPluginController extends Controller -{ - public function __construct(private MpmPluginService $mpmPluginService) - { - } +class MpmPluginController extends Controller { + public function __construct(private MpmPluginService $mpmPluginService) {} - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $limit = $request->get('limit'); return ApiResource::make($this->mpmPluginService->getAll($limit)); diff --git a/src/backend/app/Http/Controllers/OutstandingDebtsExportController.php b/src/backend/app/Http/Controllers/OutstandingDebtsExportController.php index 8191980f0..d2c92048c 100644 --- a/src/backend/app/Http/Controllers/OutstandingDebtsExportController.php +++ b/src/backend/app/Http/Controllers/OutstandingDebtsExportController.php @@ -8,15 +8,12 @@ use MPM\OutstandingDebts\OutstandingDebtsExportService; use Symfony\Component\HttpFoundation\BinaryFileResponse; -class OutstandingDebtsExportController -{ +class OutstandingDebtsExportController { public function __construct( private OutstandingDebtsExportService $outstandingDebtsExportService, - ) { - } + ) {} - public function download(): BinaryFileResponse - { + public function download(): BinaryFileResponse { $path = $this->outstandingDebtsExportService->createReport(CarbonImmutable::now()); return response()->download($path); diff --git a/src/backend/app/Http/Controllers/PaymentHistoryController.php b/src/backend/app/Http/Controllers/PaymentHistoryController.php index 6a857e832..6a6cd1910 100644 --- a/src/backend/app/Http/Controllers/PaymentHistoryController.php +++ b/src/backend/app/Http/Controllers/PaymentHistoryController.php @@ -14,8 +14,7 @@ * @group Payment-History * Class PaymentHistoryController */ -class PaymentHistoryController -{ +class PaymentHistoryController { /** * @var PaymentHistory */ @@ -23,11 +22,8 @@ class PaymentHistoryController /** * PaymentHistoryController constructor. - * - * @param PaymentHistory $history */ - public function __construct(PaymentHistory $history) - { + public function __construct(PaymentHistory $history) { $this->history = $history; } @@ -39,15 +35,12 @@ public function __construct(PaymentHistory $history) * @urlParam limit integer * @urlParam order string * - * @param int $payerId - * @param string $period * @param null $limit * @param string $order * * @return array */ - public function show(int $payerId, string $period, $limit = null, $order = 'ASC') - { + public function show(int $payerId, string $period, $limit = null, $order = 'ASC') { $period = strtoupper($period); switch ($period) { case 'D': @@ -85,8 +78,7 @@ public function show(int $payerId, string $period, $limit = null, $order = 'ASC' * * @throws \Exception */ - public function getPaymentPeriod(Person $person) - { + public function getPaymentPeriod(Person $person) { $payments = $person->payments()->latest()->take(10)->get(); $difference = 'no data available'; @@ -107,13 +99,9 @@ public function getPaymentPeriod(Person $person) * * @urlParam personId integer required * - * @param int $personId - * @param int|null $year * - * @return array **/ - public function byYear(int $personId, ?int $year = null): array - { + public function byYear(int $personId, ?int $year = null): array { $year = $year ?? (int) date('Y'); $payments = $this->history->getPaymentFlow('person', $personId, $year); $paymentFlow = array_fill(0, 11, 0); @@ -134,8 +122,7 @@ public function byYear(int $personId, ?int $year = null): array * * @return ApiResource */ - public function debts($personId) - { + public function debts($personId) { $accessRateDebt = 0; $meters = Device::query()->with('device') ->whereHasMorph( @@ -161,12 +148,9 @@ public function debts($personId) * @bodyParam begin string * @bodyParam end string * - * @return ApiResource - * * @throws \Exception */ - public function getPaymentRange(): ApiResource - { + public function getPaymentRange(): ApiResource { $begin = request('begin'); // Y-m-d $end = request('end'); // Y-m- d // create a sequence of dates @@ -192,8 +176,7 @@ public function getPaymentRange(): ApiResource * * @psalm-return array */ - public function preparePaymentFlow($payments): array - { + public function preparePaymentFlow($payments): array { $flowList = []; foreach ($payments as $payment) { $flowList[$payment['aperiod']][$payment['payment_type']] = $payment['amount']; diff --git a/src/backend/app/Http/Controllers/PersonAddressesController.php b/src/backend/app/Http/Controllers/PersonAddressesController.php index 6b4fef374..b8421f601 100644 --- a/src/backend/app/Http/Controllers/PersonAddressesController.php +++ b/src/backend/app/Http/Controllers/PersonAddressesController.php @@ -9,14 +9,12 @@ use App\Services\PersonAddressService; use App\Services\PersonService; -class PersonAddressesController extends Controller -{ +class PersonAddressesController extends Controller { public function __construct( private AddressesService $addressService, private PersonService $personService, private PersonAddressService $personAddressService, - ) { - } + ) {} /** * Addresses @@ -26,21 +24,15 @@ public function __construct( * * @responseFile responses/people/person.addresses.list.json * - * @param int $personId - * - * @return ApiResource - * * @apiResourceModel \App\Models\Person\Person */ - public function show(int $personId): ApiResource - { + public function show(int $personId): ApiResource { $person = $this->personService->getById($personId); return ApiResource::make($this->personAddressService->getPersonAddresses($person)); } - public function store(int $personId, CreateAddressRequest $request): ApiResource - { + public function store(int $personId, CreateAddressRequest $request): ApiResource { $person = $this->personService->getById($personId); $addressData = $this->addressService->createAddressDataFromRequest($request); $address = $this->addressService->make($addressData); @@ -57,8 +49,7 @@ public function store(int $personId, CreateAddressRequest $request): ApiResource return new ApiResource($this->addressService->getStoredAddressWithCityRelation($address->id)); } - public function update(int $personId, CreateAddressRequest $request): ApiResource - { + public function update(int $personId, CreateAddressRequest $request): ApiResource { $person = $this->personService->getById($personId); $address = $this->addressService->getById($request->input('id') ?? -1); $addressData = $this->addressService->createAddressDataFromRequest($request); diff --git a/src/backend/app/Http/Controllers/PersonController.php b/src/backend/app/Http/Controllers/PersonController.php index bc23d4603..07c8ce79b 100644 --- a/src/backend/app/Http/Controllers/PersonController.php +++ b/src/backend/app/Http/Controllers/PersonController.php @@ -19,16 +19,14 @@ * * @group People */ -class PersonController extends Controller -{ +class PersonController extends Controller { public function __construct( private AddressesService $addressService, private PersonService $personService, private PersonAddressService $personAddressService, private MaintenanceUserService $maintenanceUserService, private CountryService $countryService, - ) { - } + ) {} /** * List customer/other @@ -37,11 +35,8 @@ public function __construct( * @urlParam is_customer int optinal. To get a list of customers or non customer. Default : 1 * * @responseFile responses/people/people.list.json - * - * @return ApiResource */ - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $customerType = $request->input('is_customer', 1); $limit = $request->input('limit', config('settings.paginate')); @@ -56,28 +51,18 @@ public function index(Request $request): ApiResource * - Role * - Meter list. * - * @param int $personId - * - * @return ApiResource - * * @apiResourceModel App\Models\Person\Person * * @responseFile responses/people/people.detail.json */ - public function show(int $personId): ApiResource - { + public function show(int $personId): ApiResource { return ApiResource::make($this->personService->getDetails($personId, true)); } /** * Create. - * - * @param PersonRequest $request - * - * @return JsonResponse */ - public function store(PersonRequest $request): JsonResponse - { + public function store(PersonRequest $request): JsonResponse { try { $customerType = $request->input('customer_type'); $addressData = $this->addressService->createAddressDataFromRequest($request); @@ -127,10 +112,6 @@ public function store(PersonRequest $request): JsonResponse * @bodyParam sex string. The title of the person. Example: Dr. * @bodyParam education string. The title of the person. Example: Dr. * - * @param int $personId - * - * @return ApiResource - * * @apiResourceModel App\Models\Person\Person * * @responseFile responses/people/person.update.json @@ -150,10 +131,6 @@ public function update( * The list of all transactions(paginated) which belong to that person. * Each page contains 7 entries of the last transaction. * - * @param $personId - * - * @return ApiResource - * * @bodyParam person_id int required the ID of the person. Example: 2 * * @responseFile responses/people/person.transaction.list.json @@ -178,8 +155,6 @@ public function transactions( * @urlParam term The ID of the post. Example: John Doe * @urlParam paginage int The page number. Example:1 * - * @return ApiResource - * * @responseFile responses/people/people.search.json */ public function search( @@ -198,10 +173,6 @@ public function search( * * @urlParam person required The ID of the person. Example:1 * - * @param int $personId - * - * @return ApiResource - * * @throws \Exception * * @apiResourceModel App\Models\Person\Person diff --git a/src/backend/app/Http/Controllers/PersonDocumentController.php b/src/backend/app/Http/Controllers/PersonDocumentController.php index 3b029547a..7a8c8d23d 100644 --- a/src/backend/app/Http/Controllers/PersonDocumentController.php +++ b/src/backend/app/Http/Controllers/PersonDocumentController.php @@ -2,6 +2,4 @@ namespace App\Http\Controllers; -class PersonDocumentController extends Controller -{ -} +class PersonDocumentController extends Controller {} diff --git a/src/backend/app/Http/Controllers/PersonMeterController.php b/src/backend/app/Http/Controllers/PersonMeterController.php index 53f786164..ff2748258 100644 --- a/src/backend/app/Http/Controllers/PersonMeterController.php +++ b/src/backend/app/Http/Controllers/PersonMeterController.php @@ -5,28 +5,21 @@ use App\Http\Resources\ApiResource; use App\Services\PersonMeterService; -class PersonMeterController -{ +class PersonMeterController { public function __construct( private PersonMeterService $personMeterService, - ) { - } + ) {} /** * @group People * Person with Meters & Tariff * Person details with his/her owned meter(s) and its assigned tariff * - * @param int $personId - * * @urlParam person required The ID of the person * - * @return ApiResource - * * @responseFile responses/people/person.meter.tariff.json */ - public function show(int $personId): ApiResource - { + public function show(int $personId): ApiResource { return ApiResource::make($this->personMeterService->getPersonMeters($personId)); } } diff --git a/src/backend/app/Http/Controllers/PluginController.php b/src/backend/app/Http/Controllers/PluginController.php index d3ca01642..1c602b284 100644 --- a/src/backend/app/Http/Controllers/PluginController.php +++ b/src/backend/app/Http/Controllers/PluginController.php @@ -10,23 +10,19 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Artisan; -class PluginController extends Controller -{ +class PluginController extends Controller { public function __construct( private PluginsService $pluginsService, private MpmPluginService $mpmPluginService, private CompanyDatabaseService $companyDatabaseService, private RegistrationTailService $registrationTailService, - ) { - } + ) {} - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { return ApiResource::make($this->pluginsService->getAll()); } - public function update(Request $request, $mpmPluginId): ApiResource - { + public function update(Request $request, $mpmPluginId): ApiResource { $plugin = $this->pluginsService->getByMpmPluginId($mpmPluginId); $mpmPlugin = $this->mpmPluginService->getById($mpmPluginId); $registrationTail = $this->registrationTailService->getFirst(); diff --git a/src/backend/app/Http/Controllers/ProtectedPageController.php b/src/backend/app/Http/Controllers/ProtectedPageController.php index 750610d51..20ec8f6a3 100644 --- a/src/backend/app/Http/Controllers/ProtectedPageController.php +++ b/src/backend/app/Http/Controllers/ProtectedPageController.php @@ -5,10 +5,8 @@ use App\Http\Resources\ApiResource; use App\Models\ProtectedPage; -class ProtectedPageController -{ - public function index(): ApiResource - { +class ProtectedPageController { + public function index(): ApiResource { return ApiResource::make(ProtectedPage::query()->get()); } } diff --git a/src/backend/app/Http/Controllers/RegistrationTailController.php b/src/backend/app/Http/Controllers/RegistrationTailController.php index aa753aa42..3c66bc56f 100644 --- a/src/backend/app/Http/Controllers/RegistrationTailController.php +++ b/src/backend/app/Http/Controllers/RegistrationTailController.php @@ -7,19 +7,14 @@ use App\Services\RegistrationTailService; use Illuminate\Http\Request; -class RegistrationTailController extends Controller -{ - public function __construct(private RegistrationTailService $registrationTailService) - { - } +class RegistrationTailController extends Controller { + public function __construct(private RegistrationTailService $registrationTailService) {} - public function index(): ApiResource - { + public function index(): ApiResource { return ApiResource::make($this->registrationTailService->getAll()); } - public function update(RegistrationTail $registrationTail, Request $request): ApiResource - { + public function update(RegistrationTail $registrationTail, Request $request): ApiResource { $tail = $request->input('tail'); $registrationTailData = [ 'tail' => $tail, diff --git a/src/backend/app/Http/Controllers/ReportController.php b/src/backend/app/Http/Controllers/ReportController.php index 75ea04362..67959acb2 100644 --- a/src/backend/app/Http/Controllers/ReportController.php +++ b/src/backend/app/Http/Controllers/ReportController.php @@ -6,20 +6,17 @@ use App\Models\Report; use Illuminate\Http\Request; -class ReportController -{ +class ReportController { /** * @var Report */ private $report; - public function __construct(Report $report) - { + public function __construct(Report $report) { $this->report = $report; } - public function download($id) - { + public function download($id) { if (!$id) { return; } @@ -28,8 +25,7 @@ public function download($id) return response()->download(explode('*', $report->path)[0]); } - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $type = $request->get('type'); $startDate = $request->get('startDate'); $endDate = $request->get('endDate'); @@ -43,19 +39,16 @@ public function index(Request $request): ApiResource return new ApiResource($reports); } - private function getWeeklyReports($startDate, $endDate) - { + private function getWeeklyReports($startDate, $endDate) { return $this->report->where('type', 'weekly')->paginate(15); } - private function getMonthlyReports($startDate, $endDate) - { + private function getMonthlyReports($startDate, $endDate) { return $this->report->where('type', 'monthly') ->paginate(15); } - private function getAllReports($startDate, $endDate) - { + private function getAllReports($startDate, $endDate) { return $this->report->paginate(15); } } diff --git a/src/backend/app/Http/Controllers/Reports.php b/src/backend/app/Http/Controllers/Reports.php index 77726409d..b4dcd24da 100644 --- a/src/backend/app/Http/Controllers/Reports.php +++ b/src/backend/app/Http/Controllers/Reports.php @@ -30,11 +30,13 @@ * * @group Export */ -class Reports -{ +class Reports { private array $totalSold = []; + private array $connectionTypeCells = []; + private string|int $lastIndex; + private array $subConnectionRows; public function __construct( @@ -46,11 +48,9 @@ public function __construct( private City $city, private Target $target, private Report $report, - ) { - } + ) {} - private function monthlyTargetRibbon(Worksheet $sheet): void - { + private function monthlyTargetRibbon(Worksheet $sheet): void { $sheet->setCellValue('a5', 'Category'); $sheet->mergeCells('c5:e5'); $sheet->setCellValue('c5', 'No. of CUSTOMERS connected'); @@ -107,8 +107,7 @@ private function monthlyTargetRibbon(Worksheet $sheet): void } } - private function addTargetConnectionGroups(Worksheet $sheet): void - { + private function addTargetConnectionGroups(Worksheet $sheet): void { $column = 'A'; $subColumn = 'B'; $row = 7; @@ -137,14 +136,12 @@ private function addTargetConnectionGroups(Worksheet $sheet): void /** * Re-create the spreadsheet. */ - private function initSheet(): void - { + private function initSheet(): void { $this->spreadsheet = new Spreadsheet(); $this->totalSold = []; } - public function generateWithJob($startDate, $endDate, $reportType): void - { + public function generateWithJob($startDate, $endDate, $reportType): void { try { $cities = $this->city->newQuery()->get(); foreach ($cities as $city) { @@ -161,27 +158,16 @@ public function generateWithJob($startDate, $endDate, $reportType): void } /** - * @param Worksheet $sheet - * @param string $coordinate - * @param string $color - * * @throws \PhpOffice\PhpSpreadsheet\Exception */ - private function fillBackground(Worksheet $sheet, string $coordinate, string $color): void - { + private function fillBackground(Worksheet $sheet, string $coordinate, string $color): void { $sheet->getStyle($coordinate)->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color($color)); } /** - * @param Worksheet $sheet - * @param $column - * @param string|null $border - * @param string|null $color - * * @throws \PhpOffice\PhpSpreadsheet\Exception */ - private function styleSheet(Worksheet $sheet, string $column, ?string $border, ?string $color): void - { + private function styleSheet(Worksheet $sheet, string $column, ?string $border, ?string $color): void { $style = $sheet->getStyle($column); if ($border !== null) { @@ -193,15 +179,9 @@ private function styleSheet(Worksheet $sheet, string $column, ?string $border, ? } /** - * @param Worksheet $sheet - * @param $dateRange - * - * @return void - * * @throws \PhpOffice\PhpSpreadsheet\Exception */ - private function addStaticText(Worksheet $sheet, string $dateRange): void - { + private function addStaticText(Worksheet $sheet, string $dateRange): void { $this->styleSheet($sheet, 'A1:L4', Border::BORDER_THIN, null); $this->fillBackground($sheet, 'A1:A5', 'FFFABF8F'); $this->fillBackground($sheet, 'A3:L3', 'FFFABF8F'); @@ -247,8 +227,6 @@ private function addStaticText(Worksheet $sheet, string $dateRange): void } /** - * @param Worksheet $sheet - * @param string $dateRange * @param Builder[]|Collection $transactions * * @throws CustomerGroupNotFound @@ -278,14 +256,12 @@ public function generateXls( } /** - * @param Worksheet $sheet * @param bool $addPurchaseBreakDown * @param Builder[]|Collection $transactions * * @throws CustomerGroupNotFound */ - private function addTransactions(Worksheet $sheet, $transactions, $addPurchaseBreakDown = true): void - { + private function addTransactions(Worksheet $sheet, $transactions, $addPurchaseBreakDown = true): void { $sheetIndex = 0; $balance = 0; @@ -342,12 +318,6 @@ private function addTransactions(Worksheet $sheet, $transactions, $addPurchaseBr /** * Add the breakdown of the transaction amount into the right place on the spreadsheet. * - * @param Worksheet $sheet - * @param $paymentHistories - * @param int $index - * @param string $connectionGroupName - * @param $tariff - * * @throws CustomerGroupNotFound */ private function purchaseBreakDown( @@ -379,14 +349,9 @@ private function purchaseBreakDown( } /** - * @param string $connectionGroupName - * - * @return string - * * @throws CustomerGroupNotFound */ - private function getConnectionGroupColumn(string $connectionGroupName): string - { + private function getConnectionGroupColumn(string $connectionGroupName): string { if ( array_key_exists( $connectionGroupName, @@ -398,16 +363,11 @@ private function getConnectionGroupColumn(string $connectionGroupName): string throw new CustomerGroupNotFound($connectionGroupName.' not found'); } - private function storeConnectionGroupColumn(string $connectionGroup, string $column): void - { + private function storeConnectionGroupColumn(string $connectionGroup, string $column): void { $this->connectionTypeCells[$connectionGroup] = $column; } /** - * @param Worksheet $sheet - * @param $connectionGroups - * @param string $startingColumn - * @param int $startingRow * @param Builder[]|Collection $connectionGroups * * @throws \PhpOffice\PhpSpreadsheet\Exception @@ -450,8 +410,7 @@ private function addConnectionGroupsToXLS( } } - private function addSoldTotal(string $connectionGroupName, array $amount, $unit = null): void - { + private function addSoldTotal(string $connectionGroupName, array $amount, $unit = null): void { if (!array_key_exists($connectionGroupName, $this->totalSold)) { $this->totalSold[$connectionGroupName] = [ 'energy' => 0, @@ -469,13 +428,10 @@ private function addSoldTotal(string $connectionGroupName, array $amount, $unit } /** - * @param Worksheet $sheet - * * @throws CustomerGroupNotFound * @throws \PhpOffice\PhpSpreadsheet\Exception */ - private function addSoldSummary(Worksheet $sheet): void - { + private function addSoldSummary(Worksheet $sheet): void { // place total sold 1 row below the last transaction $index = $this->lastIndex + 1; if (\count($this->totalSold) === 0) { @@ -510,12 +466,9 @@ private function addSoldSummary(Worksheet $sheet): void } /** - * @return \Generator - * * @psalm-return Generator */ - private function excelColumnRange(string $lower, string $upper): \Generator - { + private function excelColumnRange(string $lower, string $upper): \Generator { ++$upper; for ($i = $lower; $i !== $upper; ++$i) { yield $i; @@ -526,12 +479,6 @@ private function excelColumnRange(string $lower, string $upper): \Generator private $monthlyTargetDatas = []; /** - * @param int $cityId - * @param $cityName - * @param $startDate - * @param $endDate - * @param $reportType - * * @throws CustomerGroupNotFound * @throws \PhpOffice\PhpSpreadsheet\Exception */ @@ -619,13 +566,8 @@ static function ($q) { /** * Total number of customer groups until given date. - * - * @param string $date - * - * @return void */ - private function getCustomerGroupCountPerMonth(string $date): void - { + private function getCustomerGroupCountPerMonth(string $date): void { $connectionGroupsCount = MeterParameter::query() ->selectRaw('Count(id) as total, connection_group_id') ->with('connectionGroup') @@ -643,8 +585,7 @@ private function getCustomerGroupCountPerMonth(string $date): void } } - private function getCustomerGroupEnergyUsagePerMonth(array $dates): void - { + private function getCustomerGroupEnergyUsagePerMonth(array $dates): void { foreach ($this->monthlyTargetDatas as $connectionName => $targetData) { $customerGroupRevenue = $this->sumOfTransactions($targetData['connection_id'], $dates); foreach ($customerGroupRevenue as $groupRevenue) { @@ -671,8 +612,7 @@ private function getCustomerGroupEnergyUsagePerMonth(array $dates): void } } - public function sumOfTransactions($connectionGroupId, array $dateRange): array - { + public function sumOfTransactions($connectionGroupId, array $dateRange): array { return Transaction::query() ->selectRaw(' meter_parameters.connection_group_id, @@ -698,8 +638,7 @@ static function ($q) { ->get()->toArray(); } - private function addTargetsToXls(Worksheet $sheet): void - { + private function addTargetsToXls(Worksheet $sheet): void { foreach ($this->monthlyTargetDatas as $subConnection => $monthlyTargetData) { $row = $this->subConnectionRows[$subConnection]; if (!$row) { @@ -712,8 +651,7 @@ private function addTargetsToXls(Worksheet $sheet): void } } - private function addStoredTargets(Worksheet $sheet, int $cityId, $endDate): void - { + private function addStoredTargets(Worksheet $sheet, int $cityId, $endDate): void { $targetData = $this->target::with('subTargets.connectionType') ->where('target_date', '>', $endDate) ->where('owner_type', 'mini-grid') diff --git a/src/backend/app/Http/Controllers/RestrictionController.php b/src/backend/app/Http/Controllers/RestrictionController.php index 74c9de4f3..77bb9b418 100644 --- a/src/backend/app/Http/Controllers/RestrictionController.php +++ b/src/backend/app/Http/Controllers/RestrictionController.php @@ -12,28 +12,23 @@ use Illuminate\Http\Response; use Illuminate\Support\Facades\Log; -class RestrictionController extends Controller -{ +class RestrictionController extends Controller { /** * @var Restriction */ private $restriction; + /** * @var Client */ private $httpClient; - public function __construct(Restriction $restriction, Client $httpClient) - { + public function __construct(Restriction $restriction, Client $httpClient) { $this->restriction = $restriction; $this->httpClient = $httpClient; } - /** - * @return Response - */ - public function store(Request $request, Response $response): Response - { + public function store(Request $request, Response $response): Response { $productId = $request->input('product_id'); $token = $request->input('token'); $type = $request->input('type'); @@ -102,15 +97,9 @@ public function store(Request $request, Response $response): Response } /** - * @param $target - * @param int $toAdd - * - * @return void - * * @throws PurchaseNotProcessable */ - private function updateRestriction(string $target, int $toAdd = 1): void - { + private function updateRestriction(string $target, int $toAdd = 1): void { try { $restriction = $this->restriction->where('target', $target)->firstOrFail(); $restriction->limit += $toAdd; diff --git a/src/backend/app/Http/Controllers/RevenueController.php b/src/backend/app/Http/Controllers/RevenueController.php index 0922fcad5..79bfb376f 100644 --- a/src/backend/app/Http/Controllers/RevenueController.php +++ b/src/backend/app/Http/Controllers/RevenueController.php @@ -17,8 +17,7 @@ use Inensus\Ticket\Models\Ticket; use Inensus\Ticket\Models\TicketCategory; -class RevenueController extends Controller -{ +class RevenueController extends Controller { public function __construct( private Ticket $ticket, private TicketCategory $label, @@ -27,11 +26,9 @@ public function __construct( private RevenueService $revenueService, private MeterRevenueService $meterRevenueService, private Target $target, - ) { - } + ) {} - public function ticketData($id): ApiResource - { + public function ticketData($id): ApiResource { $begin = date_create('2018-08-01'); $end = date_create(); $end->add(new \DateInterval('P1D')); @@ -68,8 +65,7 @@ public function ticketData($id): ApiResource return ApiResource::make($result); } - public function trending($id, Request $request): ApiResource - { + public function trending($id, Request $request): ApiResource { // the array which holds the final response $startDate = $request->input('startDate') ?? date('Y-01-01'); $end = $request->input('endDate') ?? date('Y-m-d'); @@ -117,12 +113,9 @@ public function trending($id, Request $request): ApiResource /** * Prepares the data for revenue dashboard. * - * @param Request $request - * * @return array|mixed */ - public function revenueData(Request $request): ApiResource - { + public function revenueData(Request $request): ApiResource { $startDate = date('Y-m-d', strtotime($request->get('start_date') ?? '2018-01-01')); $endDate = Carbon::parse(date('Y-m-d', strtotime($request->get('end_date') ?? '2018-12-31')))->endOfDay(); $targetTypeId = $request->get('target_type_id'); // cluster or mini-grid id @@ -240,8 +233,7 @@ public function revenueData(Request $request): ApiResource ); } - private function reformatPeriod($period): string - { + private function reformatPeriod($period): string { return substr_replace($period, '-', 4, 0); } } diff --git a/src/backend/app/Http/Controllers/SmsAndroidSettingController.php b/src/backend/app/Http/Controllers/SmsAndroidSettingController.php index cb106ed7a..e13674e2c 100644 --- a/src/backend/app/Http/Controllers/SmsAndroidSettingController.php +++ b/src/backend/app/Http/Controllers/SmsAndroidSettingController.php @@ -7,33 +7,27 @@ use App\Models\SmsAndroidSetting; use App\Services\SmsAndroidSettingService; -class SmsAndroidSettingController extends Controller -{ - public function __construct(private SmsAndroidSettingService $smsAndroidSettingService) - { +class SmsAndroidSettingController extends Controller { + public function __construct(private SmsAndroidSettingService $smsAndroidSettingService) { $this->smsAndroidSettingService = $smsAndroidSettingService; } - public function index(): ApiResource - { + public function index(): ApiResource { return ApiResource::make($this->smsAndroidSettingService->getSmsAndroidSetting()); } - public function store(SmsAndroidSettingRequest $request): ApiResource - { + public function store(SmsAndroidSettingRequest $request): ApiResource { return ApiResource::make($this->smsAndroidSettingService->createSmsAndroidSetting($request->input('token'))); } - public function update(SmsAndroidSetting $smsAndroidSetting, SmsAndroidSettingRequest $request): ApiResource - { + public function update(SmsAndroidSetting $smsAndroidSetting, SmsAndroidSettingRequest $request): ApiResource { return ApiResource::make($this->smsAndroidSettingService->updateSmsAndroidSetting( $smsAndroidSetting, $request->input('token') )); } - public function destroy(SmsAndroidSetting $smsAndroidSetting): ApiResource - { + public function destroy(SmsAndroidSetting $smsAndroidSetting): ApiResource { return ApiResource::make($this->smsAndroidSettingService->deleteSmsAndroidSetting($smsAndroidSetting)); } } diff --git a/src/backend/app/Http/Controllers/SmsApplianceRemindRateController.php b/src/backend/app/Http/Controllers/SmsApplianceRemindRateController.php index 197e58b8c..7180151ec 100644 --- a/src/backend/app/Http/Controllers/SmsApplianceRemindRateController.php +++ b/src/backend/app/Http/Controllers/SmsApplianceRemindRateController.php @@ -8,27 +8,22 @@ use App\Services\SmsApplianceRemindRateService; use Illuminate\Http\Request; -class SmsApplianceRemindRateController extends Controller -{ +class SmsApplianceRemindRateController extends Controller { private $smsApplianceRemindService; - public function __construct(SmsApplianceRemindRateService $smsApplianceRemindService) - { + public function __construct(SmsApplianceRemindRateService $smsApplianceRemindService) { $this->smsApplianceRemindService = $smsApplianceRemindService; } - public function index(): ApiResource - { + public function index(): ApiResource { return new ApiResource($this->smsApplianceRemindService->getApplianceRemindRatesWithAppliances()); } - public function store(SmsApplianceRemindRateRequest $request): ApiResource - { + public function store(SmsApplianceRemindRateRequest $request): ApiResource { return new ApiResource($this->smsApplianceRemindService->createApplianceRemindRate($request->all())); } - public function update(SmsApplianceRemindRate $smsApplianceRemindRate, Request $request): ApiResource - { + public function update(SmsApplianceRemindRate $smsApplianceRemindRate, Request $request): ApiResource { return new ApiResource($this->smsApplianceRemindService->updateApplianceRemindRate( $smsApplianceRemindRate, $request->all() diff --git a/src/backend/app/Http/Controllers/SmsBodyController.php b/src/backend/app/Http/Controllers/SmsBodyController.php index 6e423dd07..8d751d06d 100644 --- a/src/backend/app/Http/Controllers/SmsBodyController.php +++ b/src/backend/app/Http/Controllers/SmsBodyController.php @@ -6,22 +6,18 @@ use App\Services\SmsBodyService; use Illuminate\Http\Request; -class SmsBodyController extends Controller -{ +class SmsBodyController extends Controller { private $smsBodyService; - public function __construct(SmsBodyService $smsBodyService) - { + public function __construct(SmsBodyService $smsBodyService) { $this->smsBodyService = $smsBodyService; } - public function index(): ApiResource - { + public function index(): ApiResource { return new ApiResource($this->smsBodyService->getSmsBodies()); } - public function update(Request $request): ApiResource - { + public function update(Request $request): ApiResource { return new ApiResource($this->smsBodyService->updateSmsBodies($request->all())); } } diff --git a/src/backend/app/Http/Controllers/SmsController.php b/src/backend/app/Http/Controllers/SmsController.php index 49640f7aa..a480c7408 100644 --- a/src/backend/app/Http/Controllers/SmsController.php +++ b/src/backend/app/Http/Controllers/SmsController.php @@ -18,19 +18,16 @@ use Illuminate\Support\Facades\Log; use Inensus\Ticket\Services\TicketCommentService; -class SmsController extends Controller -{ +class SmsController extends Controller { public function __construct( private Sms $sms, private Person $person, private MeterParameter $meterParameter, private SmsService $smsService, private TicketCommentService $commentService, - ) { - } + ) {} - public function index(): ApiResource - { + public function index(): ApiResource { $list = $this->sms::with('address.owner') ->orderBy('id', 'DESC') ->select('receiver', DB::raw('count(*) as total')) @@ -43,8 +40,7 @@ public function index(): ApiResource /** * @return void */ - public function storeBulk(Request $request) - { + public function storeBulk(Request $request) { $type = $request->get('type'); $receivers = $request->get('receivers'); $message = $request->get('message'); @@ -159,8 +155,7 @@ function ($q) use ($receivers) { } } - public function store(StoreSmsRequest $request): ApiResource - { + public function store(StoreSmsRequest $request): ApiResource { $sender = $request->get('sender'); $message = $request->get('message'); $smsData = [ @@ -183,8 +178,7 @@ public function store(StoreSmsRequest $request): ApiResource return new ApiResource($sms); } - public function storeAndSend(SmsRequest $request): ApiResource - { + public function storeAndSend(SmsRequest $request): ApiResource { $personId = $request->get('person_id'); $message = $request->get('message'); $senderId = $request->get('senderId'); @@ -219,11 +213,8 @@ static function ($q) { * Marks the sms as sent. * * @param string $uuid - * - * @return void */ - public function updateForDelivered($uuid): void - { + public function updateForDelivered($uuid): void { try { Log::info('Sms has delivered successfully', ['uuid' => $uuid]); $sms = $this->sms->where('uuid', $uuid)->firstOrFail(); @@ -240,8 +231,7 @@ public function updateForDelivered($uuid): void } } - public function updateForFailed($uuid): void - { + public function updateForFailed($uuid): void { try { Log::warning('Sending Sms failed on AndroidGateway', ['uuid' => $uuid]); $sms = $this->sms->where('uuid', $uuid)->firstOrFail(); @@ -258,8 +248,7 @@ public function updateForFailed($uuid): void } } - public function updateForSent($uuid): void - { + public function updateForSent($uuid): void { try { Log::warning('Sms has sent successfully', ['uuid' => $uuid]); $sms = $this->sms->where('uuid', $uuid)->firstOrFail(); @@ -276,8 +265,7 @@ public function updateForSent($uuid): void } } - public function show($person_id): ApiResource - { + public function show($person_id): ApiResource { $personAddresses = $this->person::with( [ 'addresses' => function ($q) { @@ -293,15 +281,13 @@ public function show($person_id): ApiResource return new ApiResource($smses); } - public function byPhone($phone): ApiResource - { + public function byPhone($phone): ApiResource { $smses = $this->sms->where('receiver', $phone)->get(); return new ApiResource($smses); } - public function search($search) - { + public function search($search) { // search in people $list = $this->person::with('addresses') ->whereHas( diff --git a/src/backend/app/Http/Controllers/SmsResendInformationKeyController.php b/src/backend/app/Http/Controllers/SmsResendInformationKeyController.php index aa7fba348..1fc3f8f76 100644 --- a/src/backend/app/Http/Controllers/SmsResendInformationKeyController.php +++ b/src/backend/app/Http/Controllers/SmsResendInformationKeyController.php @@ -7,22 +7,18 @@ use App\Services\SmsResendInformationKeyService; use Illuminate\Http\Request; -class SmsResendInformationKeyController extends Controller -{ +class SmsResendInformationKeyController extends Controller { private $smsResendInformationKeyService; - public function __construct(SmsResendInformationKeyService $smsResendInformationKeyService) - { + public function __construct(SmsResendInformationKeyService $smsResendInformationKeyService) { $this->smsResendInformationKeyService = $smsResendInformationKeyService; } - public function index(): ApiResource - { + public function index(): ApiResource { return new ApiResource($this->smsResendInformationKeyService->getResendInformationKeys()); } - public function update(SmsResendInformationKey $smsResendInformationKey, Request $request): ApiResource - { + public function update(SmsResendInformationKey $smsResendInformationKey, Request $request): ApiResource { return new ApiResource($this->smsResendInformationKeyService->updateResendInformationKey( $smsResendInformationKey, $request->all() diff --git a/src/backend/app/Http/Controllers/SmsVariableDefaultValueController.php b/src/backend/app/Http/Controllers/SmsVariableDefaultValueController.php index 0dec1a448..e35dc0bb5 100644 --- a/src/backend/app/Http/Controllers/SmsVariableDefaultValueController.php +++ b/src/backend/app/Http/Controllers/SmsVariableDefaultValueController.php @@ -5,17 +5,14 @@ use App\Http\Resources\ApiResource; use App\Services\SmsVariableDefaultValueService; -class SmsVariableDefaultValueController extends Controller -{ +class SmsVariableDefaultValueController extends Controller { private $smsVariableDefaultSValueService; - public function __construct(SmsVariableDefaultValueService $smsVariableDefaultSValueService) - { + public function __construct(SmsVariableDefaultValueService $smsVariableDefaultSValueService) { $this->smsVariableDefaultSValueService = $smsVariableDefaultSValueService; } - public function index(): ApiResource - { + public function index(): ApiResource { return new ApiResource($this->smsVariableDefaultSValueService->getSmsVariableDefaultValues()); } } diff --git a/src/backend/app/Http/Controllers/SolarHomeSystemController.php b/src/backend/app/Http/Controllers/SolarHomeSystemController.php index fc09ce18a..7f9245781 100644 --- a/src/backend/app/Http/Controllers/SolarHomeSystemController.php +++ b/src/backend/app/Http/Controllers/SolarHomeSystemController.php @@ -9,24 +9,20 @@ use MPM\SolarHomeSystem\SolarHomeSystemDeviceService; use MPM\SolarHomeSystem\SolarHomeSystemService; -class SolarHomeSystemController extends Controller -{ +class SolarHomeSystemController extends Controller { public function __construct( private DeviceService $deviceService, private SolarHomeSystemService $solarHomeSystemService, private SolarHomeSystemDeviceService $solarHomeSystemDeviceService, - ) { - } + ) {} - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $limit = $request->input('per_page'); return ApiResource::make($this->solarHomeSystemService->getAll($limit)); } - public function store(StoreSolarHomeSystemRequest $request) - { + public function store(StoreSolarHomeSystemRequest $request) { $solarHomeSystemData = $request->all(); $deviceData = [ 'device_serial' => $solarHomeSystemData['serial_number'], @@ -43,8 +39,7 @@ public function store(StoreSolarHomeSystemRequest $request) return ApiResource::make($solarHomeSystem->load(['manufacturer', 'appliance', 'device.person'])); } - public function search(Request $request): ApiResource - { + public function search(Request $request): ApiResource { $term = $request->input('term'); $paginate = $request->input('paginate') ?? 1; diff --git a/src/backend/app/Http/Controllers/SubConnectionTypeController.php b/src/backend/app/Http/Controllers/SubConnectionTypeController.php index 7fb9f488f..5cfa14141 100644 --- a/src/backend/app/Http/Controllers/SubConnectionTypeController.php +++ b/src/backend/app/Http/Controllers/SubConnectionTypeController.php @@ -8,14 +8,10 @@ use App\Services\SubConnectionTypeService; use Illuminate\Http\Request; -class SubConnectionTypeController extends Controller -{ - public function __construct(private SubConnectionTypeService $subConnectionTypeService) - { - } +class SubConnectionTypeController extends Controller { + public function __construct(private SubConnectionTypeService $subConnectionTypeService) {} - public function index(Request $request, $connectionTypeId = null): ApiResource - { + public function index(Request $request, $connectionTypeId = null): ApiResource { $limit = $request->get('limit'); if ($connectionTypeId !== null) { @@ -27,13 +23,8 @@ public function index(Request $request, $connectionTypeId = null): ApiResource /** * Show the form for creating a new resource. - * - * @param SubConnectionTypeCreateRequest $request - * - * @return ApiResource */ - public function store(SubConnectionTypeCreateRequest $request): ApiResource - { + public function store(SubConnectionTypeCreateRequest $request): ApiResource { $subConnectionTypeData = $request->only(['name', 'connection_type_id', 'tariff_id']); return ApiResource::make($this->subConnectionTypeService->create($subConnectionTypeData)); @@ -43,11 +34,8 @@ public function store(SubConnectionTypeCreateRequest $request): ApiResource * Update the specified resource in storage. * * @param SubConnectionType $subConnectionType - * - * @return ApiResource */ - public function update(Request $request, $subConnectionTypeId): ApiResource - { + public function update(Request $request, $subConnectionTypeId): ApiResource { $subConnectionType = $this->subConnectionTypeService->getById($subConnectionTypeId); $subConnectionTypeData = $request->only(['name', 'tariff_id']); diff --git a/src/backend/app/Http/Controllers/TargetController.php b/src/backend/app/Http/Controllers/TargetController.php index e2210c432..956ff77a8 100644 --- a/src/backend/app/Http/Controllers/TargetController.php +++ b/src/backend/app/Http/Controllers/TargetController.php @@ -10,30 +10,25 @@ use App\Services\TargetService; use Illuminate\Http\Request; -class TargetController extends Controller -{ +class TargetController extends Controller { public function __construct( private TargetService $targetService, private ClusterService $clusterService, private MiniGridService $miniGridService, private SubTargetService $subTargetService, - ) { - } + ) {} - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $limit = $request->input('limit', 15); return ApiResource::make($this->targetService->getAll($limit)); } - public function show($targetId): ApiResource - { + public function show($targetId): ApiResource { return ApiResource::make($this->targetService->getById($targetId)); } - public function getSlotsForDate(Request $request): ApiResource - { + public function getSlotsForDate(Request $request): ApiResource { $date = $request->input('date'); $lastDayOfMonth = date('Y-m-t', strtotime($date)); $firstDayOfMonth = date('Y-m-1', strtotime($date)); @@ -42,8 +37,7 @@ public function getSlotsForDate(Request $request): ApiResource return ApiResource::make($this->targetService->getTakenSlots($targetData)); } - public function store(CreateTargetRequest $request): ApiResource - { + public function store(CreateTargetRequest $request): ApiResource { $targetData = [ 'period' => $request->getPeriod(), 'targetForType' => $request->getTargetForType(), diff --git a/src/backend/app/Http/Controllers/TicketSettingsController.php b/src/backend/app/Http/Controllers/TicketSettingsController.php index f39318abd..edb292d13 100644 --- a/src/backend/app/Http/Controllers/TicketSettingsController.php +++ b/src/backend/app/Http/Controllers/TicketSettingsController.php @@ -6,19 +6,14 @@ use App\Models\TicketSettings; use Illuminate\Http\Request; -class TicketSettingsController extends Controller -{ - public function __construct(private TicketSettings $ticketSettings) - { - } +class TicketSettingsController extends Controller { + public function __construct(private TicketSettings $ticketSettings) {} - public function index(): ApiResource - { + public function index(): ApiResource { return new ApiResource(TicketSettings::all()); } - public function update(Request $request): ApiResource - { + public function update(Request $request): ApiResource { $ticketSettings = $this->ticketSettings::query()->updateOrCreate( [ 'id' => $request->input('id'), diff --git a/src/backend/app/Http/Controllers/TimeOfUsageController.php b/src/backend/app/Http/Controllers/TimeOfUsageController.php index c86a30adc..d34a288af 100644 --- a/src/backend/app/Http/Controllers/TimeOfUsageController.php +++ b/src/backend/app/Http/Controllers/TimeOfUsageController.php @@ -5,16 +5,13 @@ use App\Services\MeterTariffService; use App\Services\TimeOfUsageService; -class TimeOfUsageController extends Controller -{ +class TimeOfUsageController extends Controller { public function __construct( private TimeOfUsageService $timeOfUsageService, private MeterTariffService $meterTariffService, - ) { - } + ) {} - public function destroy($timeOfUsageId): ?bool - { + public function destroy($timeOfUsageId): ?bool { $timeOfUsage = $this->timeOfUsageService->getById($timeOfUsageId); $result = $this->timeOfUsageService->delete($timeOfUsage); diff --git a/src/backend/app/Http/Controllers/TransactionAdvancedController.php b/src/backend/app/Http/Controllers/TransactionAdvancedController.php index 897c3da39..6f8e2fcf2 100644 --- a/src/backend/app/Http/Controllers/TransactionAdvancedController.php +++ b/src/backend/app/Http/Controllers/TransactionAdvancedController.php @@ -6,15 +6,12 @@ use Illuminate\Http\Request; use MPM\Transaction\TransactionService; -class TransactionAdvancedController extends Controller -{ +class TransactionAdvancedController extends Controller { public function __construct( private TransactionService $transactionService, - ) { - } + ) {} - public function searchAdvanced(Request $request): ApiResource - { + public function searchAdvanced(Request $request): ApiResource { $type = $request->input('deviceType') ?: 'meter'; $serialNumber = $request->input('serial_number'); $tariffId = $request->input('tariff'); @@ -36,8 +33,7 @@ public function searchAdvanced(Request $request): ApiResource )); } - public function compare($period): array - { + public function compare($period): array { $comparisonPeriod = $this->transactionService->determinePeriod($period); // get transactions for both current and previous periods $transactions = $this->transactionService->getByComparisonPeriod($comparisonPeriod); diff --git a/src/backend/app/Http/Controllers/TransactionController.php b/src/backend/app/Http/Controllers/TransactionController.php index cd966524f..9c6b9d12f 100644 --- a/src/backend/app/Http/Controllers/TransactionController.php +++ b/src/backend/app/Http/Controllers/TransactionController.php @@ -8,29 +8,24 @@ use MPM\Transaction\Provider\ITransactionProvider; use MPM\Transaction\TransactionService; -class TransactionController extends Controller -{ +class TransactionController extends Controller { public function __construct( private TransactionService $transactionService, - ) { - } + ) {} - public function index(): ApiResource - { + public function index(): ApiResource { $limit = \request()->get('per_page') ?? 15; return ApiResource::make($this->transactionService->getAll($limit)); } - public function show(int $id): ApiResource - { + public function show(int $id): ApiResource { $transaction = $this->transactionService->getById($id); return ApiResource::make($transaction); } - public function store(Request $request): void - { + public function store(Request $request): void { /** * @var ITransactionProvider $transactionProvider */ diff --git a/src/backend/app/Http/Controllers/TransactionExportController.php b/src/backend/app/Http/Controllers/TransactionExportController.php index 96576a19b..2694373de 100644 --- a/src/backend/app/Http/Controllers/TransactionExportController.php +++ b/src/backend/app/Http/Controllers/TransactionExportController.php @@ -7,13 +7,11 @@ use MPM\Transaction\TransactionService; use Symfony\Component\HttpFoundation\BinaryFileResponse; -class TransactionExportController -{ +class TransactionExportController { public function __construct( private TransactionService $transactionService, private TransactionExportService $transactionExportService, - ) { - } + ) {} public function download( Request $request, diff --git a/src/backend/app/Http/Controllers/TransactionProviderController.php b/src/backend/app/Http/Controllers/TransactionProviderController.php index f698a70e8..41f9eb739 100644 --- a/src/backend/app/Http/Controllers/TransactionProviderController.php +++ b/src/backend/app/Http/Controllers/TransactionProviderController.php @@ -5,17 +5,14 @@ use App\Http\Resources\ApiResource; use App\Services\TransactionProviderService; -class TransactionProviderController extends Controller -{ +class TransactionProviderController extends Controller { private $transactionProviderService; - public function __construct(TransactionProviderService $transactionProviderService) - { + public function __construct(TransactionProviderService $transactionProviderService) { $this->transactionProviderService = $transactionProviderService; } - public function index(): ApiResource - { + public function index(): ApiResource { return new ApiResource($this->transactionProviderService->getTransactionProviders()); } } diff --git a/src/backend/app/Http/Controllers/UsageTypeController.php b/src/backend/app/Http/Controllers/UsageTypeController.php index c1381c68f..0925534ee 100644 --- a/src/backend/app/Http/Controllers/UsageTypeController.php +++ b/src/backend/app/Http/Controllers/UsageTypeController.php @@ -6,14 +6,10 @@ use App\Services\UsageTypeService; use Illuminate\Http\Request; -class UsageTypeController extends Controller -{ - public function __construct(private UsageTypeService $usageTypeService) - { - } +class UsageTypeController extends Controller { + public function __construct(private UsageTypeService $usageTypeService) {} - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { return ApiResource::make($this->usageTypeService->getAll()); } } diff --git a/src/backend/app/Http/Controllers/UserAddressController.php b/src/backend/app/Http/Controllers/UserAddressController.php index 5c307f398..d1f6c6c3a 100644 --- a/src/backend/app/Http/Controllers/UserAddressController.php +++ b/src/backend/app/Http/Controllers/UserAddressController.php @@ -8,29 +8,24 @@ use App\Services\UserAddressService; use Illuminate\Http\Request; -class UserAddressController extends Controller -{ +class UserAddressController extends Controller { private $userAddressService; - public function __construct(UserAddressService $userAddressService) - { + public function __construct(UserAddressService $userAddressService) { $this->userAddressService = $userAddressService; } - public function store(User $user, CreateAddressRequest $request): ApiResource - { + public function store(User $user, CreateAddressRequest $request): ApiResource { return new ApiResource($this->userAddressService->update($user, $request->all())); } - public function admin(User $user, Request $request) - { + public function admin(User $user, Request $request) { $address = $user->addressDetails()->first(); return new ApiResource($address); } - public function update(User $user, CreateAddressRequest $request) - { + public function update(User $user, CreateAddressRequest $request) { return new ApiResource($this->userAddressService->update($user, $request->all())); } } diff --git a/src/backend/app/Http/Controllers/UserController.php b/src/backend/app/Http/Controllers/UserController.php index ac6d13a98..837f6daac 100644 --- a/src/backend/app/Http/Controllers/UserController.php +++ b/src/backend/app/Http/Controllers/UserController.php @@ -10,24 +10,20 @@ use App\Services\UserService; use Illuminate\Http\Request; -class UserController extends Controller -{ +class UserController extends Controller { public function __construct( private UserService $userService, private DatabaseProxyService $databaseProxyService, private CompanyDatabaseService $companyDatabaseService, - ) { - } + ) {} - public function index(Request $request): ApiResource - { + public function index(Request $request): ApiResource { $users = $this->userService->list(); return new ApiResource($users); } - public function store(CreateAdminRequest $request) - { + public function store(CreateAdminRequest $request) { $user = $this->userService->create($request->only(['name', 'password', 'email'])); $companyDatabase = $this->companyDatabaseService->findByCompanyId($user->getCompanyId()); $databaseProxyData = [ @@ -40,13 +36,11 @@ public function store(CreateAdminRequest $request) return ApiResource::make($user->toArray()); } - public function show(User $user) - { + public function show(User $user) { return new ApiResource($this->userService->get($user->id)); } - public function update(User $user, Request $request): ApiResource - { + public function update(User $user, Request $request): ApiResource { $this->userService->update($user, $request->all()); return new ApiResource($user->fresh()); diff --git a/src/backend/app/Http/Controllers/UserPasswordController.php b/src/backend/app/Http/Controllers/UserPasswordController.php index 960b86cb6..04c4b9622 100644 --- a/src/backend/app/Http/Controllers/UserPasswordController.php +++ b/src/backend/app/Http/Controllers/UserPasswordController.php @@ -9,17 +9,14 @@ use App\Services\UserService; use Illuminate\Http\Response; -class UserPasswordController extends Controller -{ +class UserPasswordController extends Controller { private $userService; - public function __construct(UserService $userService) - { + public function __construct(UserService $userService) { $this->userService = $userService; } - public function forgotPassword(AdminResetPasswordRequest $request, Response $response): Response - { + public function forgotPassword(AdminResetPasswordRequest $request, Response $response): Response { if (!$this->userService->resetPassword($request->input('email'))) { return $response->setStatusCode(422)->setContent( [ @@ -41,8 +38,7 @@ public function forgotPassword(AdminResetPasswordRequest $request, Response $res ); } - public function update(User $user, UserChangePasswordRequest $changePasswordRequest) - { + public function update(User $user, UserChangePasswordRequest $changePasswordRequest) { return new ApiResource($this->userService->update($user, $changePasswordRequest->all())); } } diff --git a/src/backend/app/Http/Controllers/VodacomTransactionController.php b/src/backend/app/Http/Controllers/VodacomTransactionController.php index a8603d2a2..7e4935b60 100644 --- a/src/backend/app/Http/Controllers/VodacomTransactionController.php +++ b/src/backend/app/Http/Controllers/VodacomTransactionController.php @@ -5,17 +5,11 @@ use App\Models\Transaction\VodacomTransaction; use Illuminate\Http\Request; -class VodacomTransactionController extends Controller -{ +class VodacomTransactionController extends Controller { /** * Store a newly created resource in storage. - * - * @param Request $request - * - * @return void */ - public function store(Request $request): void - { + public function store(Request $request): void { // get Transaction object $transactionData = request('transaction')->transaction; diff --git a/src/backend/app/Http/Kernel.php b/src/backend/app/Http/Kernel.php index d1dae17bc..f9f458f33 100644 --- a/src/backend/app/Http/Kernel.php +++ b/src/backend/app/Http/Kernel.php @@ -30,8 +30,7 @@ use Illuminate\Session\Middleware\StartSession; use Illuminate\View\Middleware\ShareErrorsFromSession; -class Kernel extends HttpKernel -{ +class Kernel extends HttpKernel { /** * The application's global HTTP middleware stack. * diff --git a/src/backend/app/Http/Middleware/AdminJWT.php b/src/backend/app/Http/Middleware/AdminJWT.php index 0ceac6d63..becefc19f 100644 --- a/src/backend/app/Http/Middleware/AdminJWT.php +++ b/src/backend/app/Http/Middleware/AdminJWT.php @@ -4,10 +4,8 @@ use Illuminate\Http\Request; -class AdminJWT -{ - public function handle(Request $request, \Closure $next) - { +class AdminJWT { + public function handle(Request $request, \Closure $next) { return $next($request); } } diff --git a/src/backend/app/Http/Middleware/AgentBalanceMiddleware.php b/src/backend/app/Http/Middleware/AgentBalanceMiddleware.php index bbc5cdbd8..e99da167d 100644 --- a/src/backend/app/Http/Middleware/AgentBalanceMiddleware.php +++ b/src/backend/app/Http/Middleware/AgentBalanceMiddleware.php @@ -11,25 +11,21 @@ use App\Services\AgentTransactionService; use Illuminate\Database\Eloquent\ModelNotFoundException; -class AgentBalanceMiddleware -{ +class AgentBalanceMiddleware { public function __construct( private AgentService $agentService, private AgentAssignedApplianceService $agentAssignedApplianceService, private AgentTransactionService $agentTransactionService, - ) { - } + ) {} /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request - * @param \Closure $next * * @return mixed */ - public function handle($request, \Closure $next) - { + public function handle($request, \Closure $next) { $routeName = request()->route()->getName(); $agent = $this->agentService->getByAuthenticatedUser(); $commission = $agent->commission()->first(); diff --git a/src/backend/app/Http/Middleware/CorsMiddleware.php b/src/backend/app/Http/Middleware/CorsMiddleware.php index b3135fe27..a5a48f695 100644 --- a/src/backend/app/Http/Middleware/CorsMiddleware.php +++ b/src/backend/app/Http/Middleware/CorsMiddleware.php @@ -4,10 +4,8 @@ use Illuminate\Http\Request; -class CorsMiddleware -{ - public function handle(Request $request, \Closure $next) - { +class CorsMiddleware { + public function handle(Request $request, \Closure $next) { $accessControlRequestMethod = $request->header('access-control-request-method'); $accessControlRequestHeaders = $request->header('access-control-request-headers'); diff --git a/src/backend/app/Http/Middleware/EncryptCookies.php b/src/backend/app/Http/Middleware/EncryptCookies.php index 50d0fe796..5768e90e2 100644 --- a/src/backend/app/Http/Middleware/EncryptCookies.php +++ b/src/backend/app/Http/Middleware/EncryptCookies.php @@ -4,8 +4,7 @@ use Illuminate\Cookie\Middleware\EncryptCookies as Middleware; -class EncryptCookies extends Middleware -{ +class EncryptCookies extends Middleware { /** * The names of the cookies that should not be encrypted. * diff --git a/src/backend/app/Http/Middleware/JwtMiddleware.php b/src/backend/app/Http/Middleware/JwtMiddleware.php index a7cb48e0d..ea3063c4b 100644 --- a/src/backend/app/Http/Middleware/JwtMiddleware.php +++ b/src/backend/app/Http/Middleware/JwtMiddleware.php @@ -13,19 +13,11 @@ use Tymon\JWTAuth\Facades\JWTAuth; use Tymon\JWTAuth\Http\Middleware\BaseMiddleware; -class JwtMiddleware extends BaseMiddleware -{ +class JwtMiddleware extends BaseMiddleware { /** * Handle an incoming request. - * - * @param Request $request - * @param \Closure $next - * @param string $type - * - * @return mixed */ - public function handle(Request $request, \Closure $next, string $type = 'user'): mixed - { + public function handle(Request $request, \Closure $next, string $type = 'user'): mixed { try { // @phpstan-ignore-next-line as no methods are defined on the facade its failing to resolve the function $id = JWTAuth::parseToken()->getPayload()->get('sub'); @@ -59,8 +51,7 @@ public function handle(Request $request, \Closure $next, string $type = 'user'): return $next($request); } - private function generateResponse(string $message, $status = 400): JsonResponse - { + private function generateResponse(string $message, $status = 400): JsonResponse { return response()->json(['data' => ['message' => $message, 'status' => $status]]); } } diff --git a/src/backend/app/Http/Middleware/RedirectIfAuthenticated.php b/src/backend/app/Http/Middleware/RedirectIfAuthenticated.php index 4d55e11ec..b4fb94931 100644 --- a/src/backend/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/src/backend/app/Http/Middleware/RedirectIfAuthenticated.php @@ -5,19 +5,16 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; -class RedirectIfAuthenticated -{ +class RedirectIfAuthenticated { /** * Handle an incoming request. * * @param Request $request - * @param \Closure $next * @param string|null $guard * * @return mixed */ - public function handle($request, \Closure $next, $guard = null) - { + public function handle($request, \Closure $next, $guard = null) { if (Auth::guard($guard)->check()) { return redirect('/home'); } diff --git a/src/backend/app/Http/Middleware/RestrictionMiddleware.php b/src/backend/app/Http/Middleware/RestrictionMiddleware.php index bf16953c1..7c2013ea8 100644 --- a/src/backend/app/Http/Middleware/RestrictionMiddleware.php +++ b/src/backend/app/Http/Middleware/RestrictionMiddleware.php @@ -12,26 +12,22 @@ /** * Class RestrictionMiddleware. */ -class RestrictionMiddleware -{ +class RestrictionMiddleware { public function __construct( private RestrictionService $restrictionService, private MaintenanceUserService $maintenanceUserService, private MiniGridService $miniGridService, - ) { - } + ) {} /** * Handle an incoming request. * - * @param Request $request - * @param \Closure $next - * @param $type + * @param Request $request + * @param $type * * @return mixed */ - public function handle($request, \Closure $next, $target) - { + public function handle($request, \Closure $next, $target) { try { $restriction = $this->restrictionService->getRestrictionForTarget($target); $restrictionResult = $this->handleRestriction($restriction->limit, $target, $request); @@ -56,8 +52,7 @@ public function handle($request, \Closure $next, $target) return $next($request); } - private function handleRestriction(int $limit, $target, Request $request): bool - { + private function handleRestriction(int $limit, $target, Request $request): bool { if ($target === 'maintenance-user') { if ($this->maintenanceUserService->getMaintenanceUsersCount() >= $limit) { return false; diff --git a/src/backend/app/Http/Middleware/Transaction.php b/src/backend/app/Http/Middleware/Transaction.php index cd954e78d..4e46449a4 100644 --- a/src/backend/app/Http/Middleware/Transaction.php +++ b/src/backend/app/Http/Middleware/Transaction.php @@ -8,10 +8,8 @@ use Illuminate\Support\Facades\Log; use MPM\Transaction\Provider\ITransactionProvider; -class Transaction -{ - public function handle(Request $request, \Closure $next): mixed - { +class Transaction { + public function handle(Request $request, \Closure $next): mixed { try { $request->attributes->add(['transactionProcessor' => $this->determineSender($request)]); } catch (PaymentProviderNotIdentified $e) { @@ -21,8 +19,7 @@ public function handle(Request $request, \Closure $next): mixed return $next($request); } - private function determineSender(Request $request): ITransactionProvider - { + private function determineSender(Request $request): ITransactionProvider { if ( preg_match('/\/vodacom/', $request->url()) && \in_array($request->ip(), Config::get('services.vodacom.ips')) diff --git a/src/backend/app/Http/Middleware/TransactionRequest.php b/src/backend/app/Http/Middleware/TransactionRequest.php index 43369e79d..b7e43cc23 100644 --- a/src/backend/app/Http/Middleware/TransactionRequest.php +++ b/src/backend/app/Http/Middleware/TransactionRequest.php @@ -6,18 +6,15 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; -class TransactionRequest -{ +class TransactionRequest { /** * Handle an incoming request. * - * @param Request $request - * @param \Closure $next + * @param Request $request * * @return mixed */ - public function handle($request, \Closure $next) - { + public function handle($request, \Closure $next) { $transactionProvider = $request->attributes->get('transactionProcessor'); try { $transactionProvider->validateRequest($request->getContent()); diff --git a/src/backend/app/Http/Middleware/TrimStrings.php b/src/backend/app/Http/Middleware/TrimStrings.php index 5a50e7b5c..da8416469 100644 --- a/src/backend/app/Http/Middleware/TrimStrings.php +++ b/src/backend/app/Http/Middleware/TrimStrings.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware; -class TrimStrings extends Middleware -{ +class TrimStrings extends Middleware { /** * The names of the attributes that should not be trimmed. * diff --git a/src/backend/app/Http/Middleware/TrustProxies.php b/src/backend/app/Http/Middleware/TrustProxies.php index fc0fa6e36..dd7bd8369 100644 --- a/src/backend/app/Http/Middleware/TrustProxies.php +++ b/src/backend/app/Http/Middleware/TrustProxies.php @@ -5,8 +5,7 @@ use Illuminate\Http\Middleware\TrustProxies as Middleware; use Illuminate\Http\Request; -class TrustProxies extends Middleware -{ +class TrustProxies extends Middleware { /** * The trusted proxies for this application. * diff --git a/src/backend/app/Http/Middleware/UserDefaultDatabaseConnectionMiddleware.php b/src/backend/app/Http/Middleware/UserDefaultDatabaseConnectionMiddleware.php index 7a8216a46..09cf672df 100644 --- a/src/backend/app/Http/Middleware/UserDefaultDatabaseConnectionMiddleware.php +++ b/src/backend/app/Http/Middleware/UserDefaultDatabaseConnectionMiddleware.php @@ -15,25 +15,21 @@ * The goal is to have the database connection on each incomming http request. * This will save querying in each model the correct database connection string. */ -class UserDefaultDatabaseConnectionMiddleware -{ +class UserDefaultDatabaseConnectionMiddleware { public function __construct( private DatabaseProxyManagerService $databaseProxyManager, private ApiCompanyResolverService $apiCompanyResolverService, private ApiResolverMap $apiResolverMap, - ) { - } + ) {} - public function handle($request, \Closure $next) - { + public function handle($request, \Closure $next) { if ($request instanceof Request) { return $this->handleApiRequest($request, $next); } throw new ValidationException('was not able to handle the request'); } - private function handleApiRequest(Request $request, \Closure $next) - { + private function handleApiRequest(Request $request, \Closure $next) { // REMOVE THIS WHEN THE TESTS ARE FIXED if ($request->path() === 'api/micro-star-meters/test' && $request->isMethod('get')) { return $next($request); @@ -97,8 +93,7 @@ private function handleApiRequest(Request $request, \Closure $next) }); } - private function resolveThirdPartyApi(string $requestPath): bool - { + private function resolveThirdPartyApi(string $requestPath): bool { foreach ($this->apiResolverMap->getResolvableApis() as $apiPath) { if (Str::startsWith(Str::lower($requestPath), Str::lower($apiPath))) { return true; @@ -108,8 +103,7 @@ private function resolveThirdPartyApi(string $requestPath): bool return false; } - private function isAgentApp(string $path): bool - { + private function isAgentApp(string $path): bool { return Str::startsWith($path, 'api/app/'); } } diff --git a/src/backend/app/Http/Middleware/VerifyCsrfToken.php b/src/backend/app/Http/Middleware/VerifyCsrfToken.php index 4c029cf39..fd2a511ed 100644 --- a/src/backend/app/Http/Middleware/VerifyCsrfToken.php +++ b/src/backend/app/Http/Middleware/VerifyCsrfToken.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware; -class VerifyCsrfToken extends Middleware -{ +class VerifyCsrfToken extends Middleware { /** * The URIs that should be excluded from CSRF verification. * diff --git a/src/backend/app/Http/Requests/AdminResetPasswordRequest.php b/src/backend/app/Http/Requests/AdminResetPasswordRequest.php index 03e6e18a8..51a3cf18b 100644 --- a/src/backend/app/Http/Requests/AdminResetPasswordRequest.php +++ b/src/backend/app/Http/Requests/AdminResetPasswordRequest.php @@ -4,25 +4,20 @@ use Illuminate\Foundation\Http\FormRequest; -class AdminResetPasswordRequest extends FormRequest -{ +class AdminResetPasswordRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } /** * Get the validation rules that apply to the request. - * - * @return array */ - public function rules(): array - { + public function rules(): array { return [ 'email' => 'required', ]; diff --git a/src/backend/app/Http/Requests/AndroidAppRequest.php b/src/backend/app/Http/Requests/AndroidAppRequest.php index 51c0111c1..1da1c92b3 100644 --- a/src/backend/app/Http/Requests/AndroidAppRequest.php +++ b/src/backend/app/Http/Requests/AndroidAppRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class AndroidAppRequest extends FormRequest -{ +class AndroidAppRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'name' => 'required|min:3', 'surname' => 'required|min:3', diff --git a/src/backend/app/Http/Requests/AssetTypeCreateRequest.php b/src/backend/app/Http/Requests/AssetTypeCreateRequest.php index 79cf11f11..7575bfea7 100644 --- a/src/backend/app/Http/Requests/AssetTypeCreateRequest.php +++ b/src/backend/app/Http/Requests/AssetTypeCreateRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class AssetTypeCreateRequest extends FormRequest -{ +class AssetTypeCreateRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'name' => 'required|min:3', ]; diff --git a/src/backend/app/Http/Requests/AssetTypeUpdateRequest.php b/src/backend/app/Http/Requests/AssetTypeUpdateRequest.php index 89e1c328b..698412f95 100644 --- a/src/backend/app/Http/Requests/AssetTypeUpdateRequest.php +++ b/src/backend/app/Http/Requests/AssetTypeUpdateRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class AssetTypeUpdateRequest extends FormRequest -{ +class AssetTypeUpdateRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'name' => 'sometimes|min:4', ]; diff --git a/src/backend/app/Http/Requests/CityRequest.php b/src/backend/app/Http/Requests/CityRequest.php index 7cd8a3dce..a72d859f3 100644 --- a/src/backend/app/Http/Requests/CityRequest.php +++ b/src/backend/app/Http/Requests/CityRequest.php @@ -5,38 +5,33 @@ use App\Models\City; use Illuminate\Foundation\Http\FormRequest; -class CityRequest extends FormRequest -{ +class CityRequest extends FormRequest { private const PARAM_NAME = 'name'; + private const PARAM_MINI_GRID = 'mini_grid_id'; + private const PARAM_CLUSTER_ID = 'cluster_id'; + private const PARAM_COUNTRY_ID = 'country_id'; /** * Determine if the user is authorized to make this request. - * - * @return bool */ - public function authorize(): bool - { + public function authorize(): bool { return true; } /** * Get the validation rules that apply to the request. - * - * @return array */ - public function rules(): array - { + public function rules(): array { return [ 'name' => 'required', 'mini_grid_id' => 'required', ]; } - public function getCity(): City - { + public function getCity(): City { $city = new City(); $city->setName($this->input(self::PARAM_NAME)); $city->setCountryId($this->input(self::PARAM_COUNTRY_ID, 0)); diff --git a/src/backend/app/Http/Requests/ClusterRequest.php b/src/backend/app/Http/Requests/ClusterRequest.php index de9467fb0..06a69d5a8 100644 --- a/src/backend/app/Http/Requests/ClusterRequest.php +++ b/src/backend/app/Http/Requests/ClusterRequest.php @@ -14,25 +14,18 @@ * @bodyParam cities array[int] required. The id's of the cities which belong to the cluster. * @bodyParam manager_id int required. The id of the user who is responsible for the cluster. */ -class ClusterRequest extends FormRequest -{ +class ClusterRequest extends FormRequest { /** * Determine if the user is authorized to make this request. - * - * @return bool */ - public function authorize(): bool - { + public function authorize(): bool { return true; } /** * Get the validation rules that apply to the request. - * - * @return array */ - public function rules(): array - { + public function rules(): array { return [ 'name' => 'required', 'geo_type' => 'required', diff --git a/src/backend/app/Http/Requests/CompanyRegistrationRequest.php b/src/backend/app/Http/Requests/CompanyRegistrationRequest.php index ce3a72f87..c7b673405 100644 --- a/src/backend/app/Http/Requests/CompanyRegistrationRequest.php +++ b/src/backend/app/Http/Requests/CompanyRegistrationRequest.php @@ -4,15 +4,11 @@ use Illuminate\Foundation\Http\FormRequest; -class CompanyRegistrationRequest extends FormRequest -{ +class CompanyRegistrationRequest extends FormRequest { /** * Get the validation rules that apply to the request. - * - * @return array */ - public function rules(): array - { + public function rules(): array { return [ 'name' => 'required', 'address' => 'required', diff --git a/src/backend/app/Http/Requests/CountryRequest.php b/src/backend/app/Http/Requests/CountryRequest.php index 10fc06b54..a75db722a 100644 --- a/src/backend/app/Http/Requests/CountryRequest.php +++ b/src/backend/app/Http/Requests/CountryRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class CountryRequest extends FormRequest -{ +class CountryRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'country_name' => 'required', 'country_code' => 'required|min:2', diff --git a/src/backend/app/Http/Requests/CreateAddressRequest.php b/src/backend/app/Http/Requests/CreateAddressRequest.php index 43bcadb33..2545a38d7 100644 --- a/src/backend/app/Http/Requests/CreateAddressRequest.php +++ b/src/backend/app/Http/Requests/CreateAddressRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class CreateAddressRequest extends FormRequest -{ +class CreateAddressRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -23,8 +21,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'city_id' => 'required', ]; diff --git a/src/backend/app/Http/Requests/CreateAdminRequest.php b/src/backend/app/Http/Requests/CreateAdminRequest.php index 667f1a508..a327037ce 100644 --- a/src/backend/app/Http/Requests/CreateAdminRequest.php +++ b/src/backend/app/Http/Requests/CreateAdminRequest.php @@ -7,15 +7,13 @@ /** * Class CreateUserRequest. */ -class CreateAdminRequest extends FormRequest -{ +class CreateAdminRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -24,8 +22,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'email' => 'required', 'name' => 'required|min:3', diff --git a/src/backend/app/Http/Requests/CreateAgentAssignedApplianceRequest.php b/src/backend/app/Http/Requests/CreateAgentAssignedApplianceRequest.php index 392835105..8c24ec848 100644 --- a/src/backend/app/Http/Requests/CreateAgentAssignedApplianceRequest.php +++ b/src/backend/app/Http/Requests/CreateAgentAssignedApplianceRequest.php @@ -5,15 +5,13 @@ use App\Services\SessionService; use Illuminate\Foundation\Http\FormRequest; -class CreateAgentAssignedApplianceRequest extends FormRequest -{ +class CreateAgentAssignedApplianceRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -22,8 +20,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { $sessionService = app()->make(SessionService::class); $database = $sessionService->getAuthenticatedUserDatabaseName(); diff --git a/src/backend/app/Http/Requests/CreateAgentBalanceHistoryRequest.php b/src/backend/app/Http/Requests/CreateAgentBalanceHistoryRequest.php index 336ae2def..2b33ac65f 100644 --- a/src/backend/app/Http/Requests/CreateAgentBalanceHistoryRequest.php +++ b/src/backend/app/Http/Requests/CreateAgentBalanceHistoryRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class CreateAgentBalanceHistoryRequest extends FormRequest -{ +class CreateAgentBalanceHistoryRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'amount' => 'required|regex:/^\d*(\.\d{1,2})?$/', ]; diff --git a/src/backend/app/Http/Requests/CreateAgentChargeRequest.php b/src/backend/app/Http/Requests/CreateAgentChargeRequest.php index 42cc83112..2b2d884e6 100644 --- a/src/backend/app/Http/Requests/CreateAgentChargeRequest.php +++ b/src/backend/app/Http/Requests/CreateAgentChargeRequest.php @@ -5,15 +5,13 @@ use App\Services\SessionService; use Illuminate\Foundation\Http\FormRequest; -class CreateAgentChargeRequest extends FormRequest -{ +class CreateAgentChargeRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -22,8 +20,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { // TODO: Change on UI. user_id is not required. $sessionService = app()->make(SessionService::class); $database = $sessionService->getAuthenticatedUserDatabaseName(); diff --git a/src/backend/app/Http/Requests/CreateAgentCommissionRequest.php b/src/backend/app/Http/Requests/CreateAgentCommissionRequest.php index 5ddcc15bb..726a6c8e6 100644 --- a/src/backend/app/Http/Requests/CreateAgentCommissionRequest.php +++ b/src/backend/app/Http/Requests/CreateAgentCommissionRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class CreateAgentCommissionRequest extends FormRequest -{ +class CreateAgentCommissionRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'name' => 'required', 'energy_commission' => 'required|numeric', diff --git a/src/backend/app/Http/Requests/CreateAgentReceiptRequest.php b/src/backend/app/Http/Requests/CreateAgentReceiptRequest.php index dbf38fbe4..d6d29434b 100644 --- a/src/backend/app/Http/Requests/CreateAgentReceiptRequest.php +++ b/src/backend/app/Http/Requests/CreateAgentReceiptRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class CreateAgentReceiptRequest extends FormRequest -{ +class CreateAgentReceiptRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'agent_id' => 'required', 'amount' => 'required', diff --git a/src/backend/app/Http/Requests/CreateAgentRequest.php b/src/backend/app/Http/Requests/CreateAgentRequest.php index 949d62fd0..e62fd4f80 100644 --- a/src/backend/app/Http/Requests/CreateAgentRequest.php +++ b/src/backend/app/Http/Requests/CreateAgentRequest.php @@ -7,15 +7,13 @@ /** * Class CreateUserRequest. */ -class CreateAgentRequest extends FormRequest -{ +class CreateAgentRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -24,8 +22,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'email' => 'required', 'name' => 'required|min:3', diff --git a/src/backend/app/Http/Requests/CreateAgentSoldApplianceRequest.php b/src/backend/app/Http/Requests/CreateAgentSoldApplianceRequest.php index 771577c50..2b035155f 100644 --- a/src/backend/app/Http/Requests/CreateAgentSoldApplianceRequest.php +++ b/src/backend/app/Http/Requests/CreateAgentSoldApplianceRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class CreateAgentSoldApplianceRequest extends FormRequest -{ +class CreateAgentSoldApplianceRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'person_id' => 'required', 'down_payment' => 'required|numeric', diff --git a/src/backend/app/Http/Requests/CreateAgentTicketRequest.php b/src/backend/app/Http/Requests/CreateAgentTicketRequest.php index 1a3f8f5f7..63ce0e8f7 100644 --- a/src/backend/app/Http/Requests/CreateAgentTicketRequest.php +++ b/src/backend/app/Http/Requests/CreateAgentTicketRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class CreateAgentTicketRequest extends FormRequest -{ +class CreateAgentTicketRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'owner_id' => 'required', 'title' => 'required', diff --git a/src/backend/app/Http/Requests/CreateAssetRequest.php b/src/backend/app/Http/Requests/CreateAssetRequest.php index 6e2dd8980..fd73ccdeb 100644 --- a/src/backend/app/Http/Requests/CreateAssetRequest.php +++ b/src/backend/app/Http/Requests/CreateAssetRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class CreateAssetRequest extends FormRequest -{ +class CreateAssetRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'asset_type_id' => 'required', 'name' => 'required|min:3', diff --git a/src/backend/app/Http/Requests/CreateConnectionGroupRequest.php b/src/backend/app/Http/Requests/CreateConnectionGroupRequest.php index ec17857a4..a7752eaf6 100644 --- a/src/backend/app/Http/Requests/CreateConnectionGroupRequest.php +++ b/src/backend/app/Http/Requests/CreateConnectionGroupRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class CreateConnectionGroupRequest extends FormRequest -{ +class CreateConnectionGroupRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'name' => 'required|string', ]; diff --git a/src/backend/app/Http/Requests/CreateTargetRequest.php b/src/backend/app/Http/Requests/CreateTargetRequest.php index 64f47a0ef..44e687123 100644 --- a/src/backend/app/Http/Requests/CreateTargetRequest.php +++ b/src/backend/app/Http/Requests/CreateTargetRequest.php @@ -5,15 +5,13 @@ use Carbon\CarbonImmutable; use Illuminate\Foundation\Http\FormRequest; -class CreateTargetRequest extends FormRequest -{ +class CreateTargetRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'data' => 'required', 'period' => 'required', @@ -22,23 +20,19 @@ public function rules() ]; } - public function getTargetForType(): string - { + public function getTargetForType(): string { return $this->input('targetForType'); } - public function getTargetForId(): int - { + public function getTargetForId(): int { return $this->input('targetForId'); } - public function getData(): array - { + public function getData(): array { return $this->input('data'); } - public function getPeriod(): CarbonImmutable - { + public function getPeriod(): CarbonImmutable { return CarbonImmutable::parse($this->input('period')); } } diff --git a/src/backend/app/Http/Requests/MailSettingsRequest.php b/src/backend/app/Http/Requests/MailSettingsRequest.php index 52beefa29..e61088711 100644 --- a/src/backend/app/Http/Requests/MailSettingsRequest.php +++ b/src/backend/app/Http/Requests/MailSettingsRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class MailSettingsRequest extends FormRequest -{ +class MailSettingsRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'mail_host' => 'required|min:5', 'mail_port' => 'required|numeric', diff --git a/src/backend/app/Http/Requests/MaintenanceRequest.php b/src/backend/app/Http/Requests/MaintenanceRequest.php index 2246d187f..d6b3a9892 100644 --- a/src/backend/app/Http/Requests/MaintenanceRequest.php +++ b/src/backend/app/Http/Requests/MaintenanceRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class MaintenanceRequest extends FormRequest -{ +class MaintenanceRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array# */ - public function rules() - { + public function rules() { return [ 'title' => 'sometimes|string', 'name' => 'required|min:3', @@ -38,23 +35,19 @@ public function rules() ]; } - public function getCityId(): int - { + public function getCityId(): int { return $this->input('city_id'); } - public function getPhone(): ?string - { + public function getPhone(): ?string { return $this->input('phone'); } - public function getStreet(): ?string - { + public function getStreet(): ?string { return $this->input('street'); } - public function getEmail(): ?string - { + public function getEmail(): ?string { return $this->input('email'); } } diff --git a/src/backend/app/Http/Requests/ManufacturerRequest.php b/src/backend/app/Http/Requests/ManufacturerRequest.php index 91fb06a7d..18dc98425 100644 --- a/src/backend/app/Http/Requests/ManufacturerRequest.php +++ b/src/backend/app/Http/Requests/ManufacturerRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class ManufacturerRequest extends FormRequest -{ +class ManufacturerRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'name' => 'required|string', 'phone' => 'sometimes|string', diff --git a/src/backend/app/Http/Requests/MeterParameterRequest.php b/src/backend/app/Http/Requests/MeterParameterRequest.php index 317b17459..4e98a4900 100644 --- a/src/backend/app/Http/Requests/MeterParameterRequest.php +++ b/src/backend/app/Http/Requests/MeterParameterRequest.php @@ -12,15 +12,13 @@ * @bodyParam customer_id int required * @bodyParam geo_points string required */ -class MeterParameterRequest extends FormRequest -{ +class MeterParameterRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -29,8 +27,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'meter_id' => 'required', 'tariff_id' => 'required', diff --git a/src/backend/app/Http/Requests/MeterRequest.php b/src/backend/app/Http/Requests/MeterRequest.php index a30012173..dd74aa141 100644 --- a/src/backend/app/Http/Requests/MeterRequest.php +++ b/src/backend/app/Http/Requests/MeterRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class MeterRequest extends FormRequest -{ +class MeterRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'serial_number' => 'required|string', 'manufacturer_id' => 'required', diff --git a/src/backend/app/Http/Requests/MeterTypeCreateRequest.php b/src/backend/app/Http/Requests/MeterTypeCreateRequest.php index 04a87c5cc..edcc21304 100644 --- a/src/backend/app/Http/Requests/MeterTypeCreateRequest.php +++ b/src/backend/app/Http/Requests/MeterTypeCreateRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class MeterTypeCreateRequest extends FormRequest -{ +class MeterTypeCreateRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'max_current' => 'required|numeric|min:1', 'phase' => 'required|numeric|min:1', diff --git a/src/backend/app/Http/Requests/MeterTypeUpdateRequest.php b/src/backend/app/Http/Requests/MeterTypeUpdateRequest.php index 67db6466b..9370fd5e7 100644 --- a/src/backend/app/Http/Requests/MeterTypeUpdateRequest.php +++ b/src/backend/app/Http/Requests/MeterTypeUpdateRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class MeterTypeUpdateRequest extends FormRequest -{ +class MeterTypeUpdateRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'max_current' => 'required|numeric|min:1', 'phase' => 'required|numeric|min:1', diff --git a/src/backend/app/Http/Requests/PersonRequest.php b/src/backend/app/Http/Requests/PersonRequest.php index dd97fdd6f..b17556a4c 100644 --- a/src/backend/app/Http/Requests/PersonRequest.php +++ b/src/backend/app/Http/Requests/PersonRequest.php @@ -17,15 +17,13 @@ * @bodyParam phone string. Example: +1111 * @bodyParam nationality string. Example: Earth Citizen */ -class PersonRequest extends FormRequest -{ +class PersonRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -34,8 +32,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'title' => 'sometimes|string', 'name' => 'required|min:3', diff --git a/src/backend/app/Http/Requests/SmsAndroidSettingRequest.php b/src/backend/app/Http/Requests/SmsAndroidSettingRequest.php index 946bbe39d..b5c2244e3 100644 --- a/src/backend/app/Http/Requests/SmsAndroidSettingRequest.php +++ b/src/backend/app/Http/Requests/SmsAndroidSettingRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class SmsAndroidSettingRequest extends FormRequest -{ +class SmsAndroidSettingRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'token' => 'required', ]; diff --git a/src/backend/app/Http/Requests/SmsApplianceRemindRateRequest.php b/src/backend/app/Http/Requests/SmsApplianceRemindRateRequest.php index f7ac4c5ab..e694b5595 100644 --- a/src/backend/app/Http/Requests/SmsApplianceRemindRateRequest.php +++ b/src/backend/app/Http/Requests/SmsApplianceRemindRateRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class SmsApplianceRemindRateRequest extends FormRequest -{ +class SmsApplianceRemindRateRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'appliance_type_id' => 'required', 'overdue_remind_rate' => 'required', diff --git a/src/backend/app/Http/Requests/SmsRequest.php b/src/backend/app/Http/Requests/SmsRequest.php index 18c4bc7e2..96098e5bf 100644 --- a/src/backend/app/Http/Requests/SmsRequest.php +++ b/src/backend/app/Http/Requests/SmsRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class SmsRequest extends FormRequest -{ +class SmsRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'message' => 'required', 'person_id' => 'required_without_all:phone', diff --git a/src/backend/app/Http/Requests/StoreDeviceRequest.php b/src/backend/app/Http/Requests/StoreDeviceRequest.php index 0d4becedf..955852107 100644 --- a/src/backend/app/Http/Requests/StoreDeviceRequest.php +++ b/src/backend/app/Http/Requests/StoreDeviceRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class StoreDeviceRequest extends FormRequest -{ +class StoreDeviceRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ ]; } diff --git a/src/backend/app/Http/Requests/StoreEBikeRequest.php b/src/backend/app/Http/Requests/StoreEBikeRequest.php index 7b8f0257a..b71e1eeff 100644 --- a/src/backend/app/Http/Requests/StoreEBikeRequest.php +++ b/src/backend/app/Http/Requests/StoreEBikeRequest.php @@ -4,15 +4,11 @@ use Illuminate\Foundation\Http\FormRequest; -class StoreEBikeRequest extends FormRequest -{ +class StoreEBikeRequest extends FormRequest { /** * Determine if the user is authorized to make this request. - * - * @return bool */ - public function authorize(): bool - { + public function authorize(): bool { return true; } @@ -21,8 +17,7 @@ public function authorize(): bool * * @return array */ - public function rules() - { + public function rules() { return [ 'serial_number' => 'required|min:8|max:15|unique:shard.devices,device_serial', 'manufacturer_id' => 'required|exists:shard.manufacturers,id', diff --git a/src/backend/app/Http/Requests/StoreMiniGridRequest.php b/src/backend/app/Http/Requests/StoreMiniGridRequest.php index 5e0eabfee..77fcbea56 100644 --- a/src/backend/app/Http/Requests/StoreMiniGridRequest.php +++ b/src/backend/app/Http/Requests/StoreMiniGridRequest.php @@ -5,9 +5,9 @@ use App\Models\MiniGrid; use Illuminate\Foundation\Http\FormRequest; -class StoreMiniGridRequest extends FormRequest -{ +class StoreMiniGridRequest extends FormRequest { public const PARAM_CLUSTER_ID = 'cluster_id'; + public const PARAM_NAME = 'name'; /** @@ -15,8 +15,7 @@ class StoreMiniGridRequest extends FormRequest * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -25,8 +24,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'name' => 'required|min:3', 'cluster_id' => 'required', @@ -34,8 +32,7 @@ public function rules() ]; } - public function getMiniGrid(): MiniGrid - { + public function getMiniGrid(): MiniGrid { $miniGrid = new MiniGrid(); $miniGrid->setClusterId($this->input(self::PARAM_CLUSTER_ID)); $miniGrid->setName($this->input(self::PARAM_NAME)); diff --git a/src/backend/app/Http/Requests/StoreSmsRequest.php b/src/backend/app/Http/Requests/StoreSmsRequest.php index 8dd149640..53f946063 100644 --- a/src/backend/app/Http/Requests/StoreSmsRequest.php +++ b/src/backend/app/Http/Requests/StoreSmsRequest.php @@ -4,15 +4,12 @@ use Illuminate\Foundation\Http\FormRequest; -class StoreSmsRequest extends FormRequest -{ - public function authorize(): bool - { +class StoreSmsRequest extends FormRequest { + public function authorize(): bool { return true; } - public function rules(): array - { + public function rules(): array { return [ 'sender' => 'required', 'message' => 'required', diff --git a/src/backend/app/Http/Requests/StoreSolarHomeSystemRequest.php b/src/backend/app/Http/Requests/StoreSolarHomeSystemRequest.php index 3be928a58..b8383b35a 100644 --- a/src/backend/app/Http/Requests/StoreSolarHomeSystemRequest.php +++ b/src/backend/app/Http/Requests/StoreSolarHomeSystemRequest.php @@ -4,15 +4,11 @@ use Illuminate\Foundation\Http\FormRequest; -class StoreSolarHomeSystemRequest extends FormRequest -{ +class StoreSolarHomeSystemRequest extends FormRequest { /** * Determine if the user is authorized to make this request. - * - * @return bool */ - public function authorize(): bool - { + public function authorize(): bool { return true; } @@ -21,8 +17,7 @@ public function authorize(): bool * * @return array */ - public function rules() - { + public function rules() { return [ 'serial_number' => 'required|min:8|max:11|unique:shard.devices,device_serial', 'manufacturer_id' => 'required|exists:shard.manufacturers,id', diff --git a/src/backend/app/Http/Requests/SubConnectionTypeCreateRequest.php b/src/backend/app/Http/Requests/SubConnectionTypeCreateRequest.php index 3155ae65c..798ba94d2 100644 --- a/src/backend/app/Http/Requests/SubConnectionTypeCreateRequest.php +++ b/src/backend/app/Http/Requests/SubConnectionTypeCreateRequest.php @@ -4,25 +4,18 @@ use Illuminate\Foundation\Http\FormRequest; -class SubConnectionTypeCreateRequest extends FormRequest -{ +class SubConnectionTypeCreateRequest extends FormRequest { /** * Determine if the user is authorized to make this request. - * - * @return bool */ - public function authorize(): bool - { + public function authorize(): bool { return true; } /** * Get the validation rules that apply to the request. - * - * @return array */ - public function rules(): array - { + public function rules(): array { return [ 'name' => 'required|min:3', 'connection_type_id' => 'required|numeric', diff --git a/src/backend/app/Http/Requests/TariffCreateRequest.php b/src/backend/app/Http/Requests/TariffCreateRequest.php index 463688322..8ac415b98 100644 --- a/src/backend/app/Http/Requests/TariffCreateRequest.php +++ b/src/backend/app/Http/Requests/TariffCreateRequest.php @@ -7,15 +7,13 @@ use Illuminate\Http\JsonResponse; use Illuminate\Validation\ValidationException; -class TariffCreateRequest extends FormRequest -{ +class TariffCreateRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -24,8 +22,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'name' => 'required', 'price' => 'required|numeric', // 100 times of original price to support 2 decimal numbers. @@ -40,8 +37,7 @@ public function rules() ]; } - protected function failedValidation(Validator $validator) - { + protected function failedValidation(Validator $validator) { $response = new JsonResponse( [ 'data' => [], diff --git a/src/backend/app/Http/Requests/UpdateAssetRequest.php b/src/backend/app/Http/Requests/UpdateAssetRequest.php index f09eebdac..84a6da0a7 100644 --- a/src/backend/app/Http/Requests/UpdateAssetRequest.php +++ b/src/backend/app/Http/Requests/UpdateAssetRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class UpdateAssetRequest extends FormRequest -{ +class UpdateAssetRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'asset_type_id' => 'sometimes', 'name' => 'sometimes|min:4', diff --git a/src/backend/app/Http/Requests/UpdateDeviceRequest.php b/src/backend/app/Http/Requests/UpdateDeviceRequest.php index 94da0486a..7801d3532 100644 --- a/src/backend/app/Http/Requests/UpdateDeviceRequest.php +++ b/src/backend/app/Http/Requests/UpdateDeviceRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class UpdateDeviceRequest extends FormRequest -{ +class UpdateDeviceRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'id' => 'required|numeric', 'person_id' => 'required|numeric', diff --git a/src/backend/app/Http/Requests/UpdateMeterRequest.php b/src/backend/app/Http/Requests/UpdateMeterRequest.php index 26f40d0c3..400d5c292 100644 --- a/src/backend/app/Http/Requests/UpdateMeterRequest.php +++ b/src/backend/app/Http/Requests/UpdateMeterRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class UpdateMeterRequest extends FormRequest -{ +class UpdateMeterRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'id' => 'required|numeric', 'serial_number' => 'sometimes|string', diff --git a/src/backend/app/Http/Requests/UpdateMiniGridRequest.php b/src/backend/app/Http/Requests/UpdateMiniGridRequest.php index d628382d8..ea754791a 100644 --- a/src/backend/app/Http/Requests/UpdateMiniGridRequest.php +++ b/src/backend/app/Http/Requests/UpdateMiniGridRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class UpdateMiniGridRequest extends FormRequest -{ +class UpdateMiniGridRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } } diff --git a/src/backend/app/Http/Requests/UserChangePasswordRequest.php b/src/backend/app/Http/Requests/UserChangePasswordRequest.php index 491f1dc84..5c14a63a3 100644 --- a/src/backend/app/Http/Requests/UserChangePasswordRequest.php +++ b/src/backend/app/Http/Requests/UserChangePasswordRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class UserChangePasswordRequest extends FormRequest -{ +class UserChangePasswordRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'password' => 'required|min:5|max:15', 'confirm_password' => 'required|same:password', diff --git a/src/backend/app/Http/Resources/ApiResource.php b/src/backend/app/Http/Resources/ApiResource.php index 5016dea38..3a651eb44 100644 --- a/src/backend/app/Http/Resources/ApiResource.php +++ b/src/backend/app/Http/Resources/ApiResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class ApiResource extends JsonResource -{ +class ApiResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class ApiResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/app/Http/Resources/MeterResource.php b/src/backend/app/Http/Resources/MeterResource.php index 4eba9a77d..0b1202044 100644 --- a/src/backend/app/Http/Resources/MeterResource.php +++ b/src/backend/app/Http/Resources/MeterResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class MeterResource extends JsonResource -{ +class MeterResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class MeterResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/app/Http/Resources/MeterTypeResource.php b/src/backend/app/Http/Resources/MeterTypeResource.php index 0f79f0186..51cd2eea4 100644 --- a/src/backend/app/Http/Resources/MeterTypeResource.php +++ b/src/backend/app/Http/Resources/MeterTypeResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class MeterTypeResource extends JsonResource -{ +class MeterTypeResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class MeterTypeResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/app/Http/Resources/SmsSearchResultResource.php b/src/backend/app/Http/Resources/SmsSearchResultResource.php index ab9722154..cc773bbc2 100644 --- a/src/backend/app/Http/Resources/SmsSearchResultResource.php +++ b/src/backend/app/Http/Resources/SmsSearchResultResource.php @@ -12,17 +12,13 @@ * @property string $surname * @property Collection $addresses */ -class SmsSearchResultResource extends JsonResource -{ +class SmsSearchResultResource extends JsonResource { /** * Transform the resource into an array. * * @param Request $request - * - * @return array */ - public function toArray($request): array - { + public function toArray($request): array { return [ 'id' => $this->id, 'display' => $this->name.' '.$this->surname, diff --git a/src/backend/app/Http/Resources/UserResource.php b/src/backend/app/Http/Resources/UserResource.php index 9aa7c241a..22155bb3d 100644 --- a/src/backend/app/Http/Resources/UserResource.php +++ b/src/backend/app/Http/Resources/UserResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class UserResource extends JsonResource -{ +class UserResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class UserResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/app/Jobs/AbstractJob.php b/src/backend/app/Jobs/AbstractJob.php index 10762ee3f..7e33ba799 100644 --- a/src/backend/app/Jobs/AbstractJob.php +++ b/src/backend/app/Jobs/AbstractJob.php @@ -11,22 +11,21 @@ use Illuminate\Queue\SerializesModels; use MPM\DatabaseProxy\DatabaseProxyManagerService; -abstract class AbstractJob implements ShouldQueue -{ +abstract class AbstractJob implements ShouldQueue { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; protected int $companyId; + protected CompanyJob $companyJob; public ?string $parentId = null; abstract public function executeJob(); - public function __construct($jobName) - { + public function __construct($jobName) { $this->afterCommit = true; $this->companyId = app()->make(UserService::class)->getCompanyId(); @@ -40,8 +39,7 @@ public function __construct($jobName) ); } - public function handle() - { + public function handle() { $this->setJobUuid($this->job->uuid()); $databaseProxyManager = app()->make(DatabaseProxyManagerService::class); $databaseProxyManager->runForCompany($this->companyId, function () { @@ -51,20 +49,17 @@ public function handle() $this->setJobStatus(CompanyJob::STATUS_SUCCESS); } - public function failed(?\Throwable $t = null) - { + public function failed(?\Throwable $t = null) { $trace = $t !== null ? explode('#15', $t->getTraceAsString(), 1000)[0] : null; $this->setJobStatus(CompanyJob::STATUS_FAILED, $t?->getMessage(), $trace); } - protected function setJobUuid($jobUuid) - { + protected function setJobUuid($jobUuid) { $this->companyJob->job_uuid = $jobUuid; $this->companyJob->save(); } - protected function setJobStatus($status, ?string $message = null, ?string $trace = null) - { + protected function setJobStatus($status, ?string $message = null, ?string $trace = null) { $this->companyJob->status = $status; $this->companyJob->message = $message; $this->companyJob->trace = $trace; diff --git a/src/backend/app/Jobs/ApplianceTransactionProcessor.php b/src/backend/app/Jobs/ApplianceTransactionProcessor.php index 9a175e938..ce8b483bd 100644 --- a/src/backend/app/Jobs/ApplianceTransactionProcessor.php +++ b/src/backend/app/Jobs/ApplianceTransactionProcessor.php @@ -8,13 +8,12 @@ use App\Models\Transaction\Transaction; use Illuminate\Support\Facades\Log; -class ApplianceTransactionProcessor extends AbstractJob -{ +class ApplianceTransactionProcessor extends AbstractJob { private Transaction $transaction; + protected const TYPE = 'deferred_payment'; - public function __construct(private int $transactionId) - { + public function __construct(private int $transactionId) { $this->afterCommit = true; parent::__construct(get_class($this)); } @@ -22,8 +21,7 @@ public function __construct(private int $transactionId) /** * @throws TransactionNotInitializedException */ - public function executeJob() - { + public function executeJob() { $this->initializeTransaction(); $container = $this->initializeTransactionDataContainer(); @@ -37,15 +35,13 @@ public function executeJob() } } - private function initializeTransaction() - { + private function initializeTransaction() { $this->transaction = Transaction::query()->find($this->transactionId); $this->transaction->type = 'deferred_payment'; $this->transaction->save(); } - private function initializeTransactionDataContainer(): TransactionDataContainer - { + private function initializeTransactionDataContainer(): TransactionDataContainer { try { return TransactionDataContainer::initialize($this->transaction); } catch (\Exception $e) { @@ -54,16 +50,14 @@ private function initializeTransactionDataContainer(): TransactionDataContainer } } - private function checkForMinimumPurchaseAmount(TransactionDataContainer $container): void - { + private function checkForMinimumPurchaseAmount(TransactionDataContainer $container): void { $minimumPurchaseAmount = $container->installmentCost; if ($container->amount < $minimumPurchaseAmount) { throw new TransactionAmountNotEnoughException("Minimum purchase amount not reached for {$container->device->device_serial}"); } } - private function payApplianceInstallments(TransactionDataContainer $container): TransactionDataContainer - { + private function payApplianceInstallments(TransactionDataContainer $container): TransactionDataContainer { $applianceInstallmentPayer = resolve('ApplianceInstallmentPayer'); $applianceInstallmentPayer->initialize($container); $applianceInstallmentPayer->payInstallmentsForDevice($container); @@ -72,8 +66,7 @@ private function payApplianceInstallments(TransactionDataContainer $container): return $container; } - private function processToken(TransactionDataContainer $transactionData): void - { + private function processToken(TransactionDataContainer $transactionData): void { $kWhToBeCharged = 0.0; $transactionData->chargedEnergy = round($kWhToBeCharged, 1); diff --git a/src/backend/app/Jobs/CreatePiggyBankEntry.php b/src/backend/app/Jobs/CreatePiggyBankEntry.php index 7cdb3d95e..5b93be0fa 100644 --- a/src/backend/app/Jobs/CreatePiggyBankEntry.php +++ b/src/backend/app/Jobs/CreatePiggyBankEntry.php @@ -4,15 +4,12 @@ use App\Models\Meter\MeterParameter; -class CreatePiggyBankEntry extends AbstractJob -{ - public function __construct(private MeterParameter $meterParameter) - { +class CreatePiggyBankEntry extends AbstractJob { + public function __construct(private MeterParameter $meterParameter) { parent::__construct(get_class($this)); } - public function executeJob() - { + public function executeJob() { if ($socialTariff = $this->meterParameter->tariff()->first()->socialTariff) { $this->meterParameter->socialTariffPiggyBank()->create( [ diff --git a/src/backend/app/Jobs/EnergyTransactionProcessor.php b/src/backend/app/Jobs/EnergyTransactionProcessor.php index 82d4fa139..020213ce4 100644 --- a/src/backend/app/Jobs/EnergyTransactionProcessor.php +++ b/src/backend/app/Jobs/EnergyTransactionProcessor.php @@ -8,13 +8,12 @@ use App\Models\Transaction\Transaction; use Illuminate\Support\Facades\Log; -class EnergyTransactionProcessor extends AbstractJob -{ +class EnergyTransactionProcessor extends AbstractJob { private Transaction $transaction; + protected const TYPE = 'energy'; - public function __construct(private $transactionId) - { + public function __construct(private $transactionId) { $this->afterCommit = true; parent::__construct(get_class($this)); } @@ -26,8 +25,7 @@ public function __construct(private $transactionId) * * @throws TransactionNotInitializedException */ - public function executeJob() - { + public function executeJob() { $this->initializeTransaction(); $container = $this->initializeTransactionDataContainer(); @@ -47,15 +45,13 @@ public function executeJob() } } - private function initializeTransaction() - { + private function initializeTransaction() { $this->transaction = Transaction::query()->find($this->transactionId); $this->transaction->type = 'energy'; $this->transaction->save(); } - private function initializeTransactionDataContainer(): TransactionDataContainer - { + private function initializeTransactionDataContainer(): TransactionDataContainer { try { return TransactionDataContainer::initialize($this->transaction); } catch (\Exception $e) { @@ -64,8 +60,7 @@ private function initializeTransactionDataContainer(): TransactionDataContainer } } - private function checkForMinimumPurchaseAmount(TransactionDataContainer $transactionData): void - { + private function checkForMinimumPurchaseAmount(TransactionDataContainer $transactionData): void { $minimumPurchaseAmount = $this->getTariffMinimumPurchaseAmount($transactionData); if ($minimumPurchaseAmount > 0) { @@ -80,8 +75,7 @@ private function checkForMinimumPurchaseAmount(TransactionDataContainer $transac } } - private function payApplianceInstallments(TransactionDataContainer $container): TransactionDataContainer - { + private function payApplianceInstallments(TransactionDataContainer $container): TransactionDataContainer { $applianceInstallmentPayer = resolve('ApplianceInstallmentPayer'); $applianceInstallmentPayer->initialize($container); $container->transaction->amount = $applianceInstallmentPayer->payInstallments(); @@ -91,8 +85,7 @@ private function payApplianceInstallments(TransactionDataContainer $container): return $container; } - private function payAccessRateIfExists(TransactionDataContainer $transactionData): TransactionDataContainer - { + private function payAccessRateIfExists(TransactionDataContainer $transactionData): TransactionDataContainer { if ($transactionData->transaction->amount > 0) { // pay if necessary access rate $accessRatePayer = resolve('AccessRatePayer'); @@ -103,13 +96,11 @@ private function payAccessRateIfExists(TransactionDataContainer $transactionData return $transactionData; } - private function completeTransactionWithNotification(TransactionDataContainer $transactionData): void - { + private function completeTransactionWithNotification(TransactionDataContainer $transactionData): void { event('transaction.successful', [$transactionData->transaction]); } - private function processToken(TransactionDataContainer $transactionData): void - { + private function processToken(TransactionDataContainer $transactionData): void { $kWhToBeCharged = 0.0; $transactionData->chargedEnergy = round($kWhToBeCharged, 1); @@ -118,8 +109,7 @@ private function processToken(TransactionDataContainer $transactionData): void ->onQueue(config('services.queues.token')); } - private function getTariffMinimumPurchaseAmount($transactionData) - { + private function getTariffMinimumPurchaseAmount($transactionData) { return $transactionData->tariff->minimum_purchase_amount; } } diff --git a/src/backend/app/Jobs/HearthBeat.php b/src/backend/app/Jobs/HearthBeat.php index fae5b6fd3..74d7f71a8 100644 --- a/src/backend/app/Jobs/HearthBeat.php +++ b/src/backend/app/Jobs/HearthBeat.php @@ -9,8 +9,7 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Log; -class HearthBeat implements ShouldQueue -{ +class HearthBeat implements ShouldQueue { use Dispatchable; use InteractsWithQueue; use Queueable; @@ -21,17 +20,14 @@ class HearthBeat implements ShouldQueue * * @return void */ - public function __construct() - { - } + public function __construct() {} /** * Execute the job. * * @return void */ - public function handle() - { + public function handle() { Log::critical('I\'m alive'); } } diff --git a/src/backend/app/Jobs/MeterReader.php b/src/backend/app/Jobs/MeterReader.php index 26dcf3ce0..1f6935b54 100644 --- a/src/backend/app/Jobs/MeterReader.php +++ b/src/backend/app/Jobs/MeterReader.php @@ -9,8 +9,7 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -class MeterReader extends AbstractJob -{ +class MeterReader extends AbstractJob { use Dispatchable; use InteractsWithQueue; use Queueable; @@ -20,6 +19,7 @@ class MeterReader extends AbstractJob * @var CalinReadMeter */ public $meterReader; + /** * @var Meter */ @@ -27,12 +27,8 @@ class MeterReader extends AbstractJob /** * Create a new job instance. - * - * @param CalinReadMeter $meterReader - * @param Meter $meters */ - public function __construct(CalinReadMeter $meterReader, Meter $meters) - { + public function __construct(CalinReadMeter $meterReader, Meter $meters) { $this->meterReader = $meterReader; $this->meters = $meters; parent::__construct(get_class($this)); @@ -40,11 +36,8 @@ public function __construct(CalinReadMeter $meterReader, Meter $meters) /** * Execute the job. - * - * @return void */ - public function executeJob(): void - { + public function executeJob(): void { $this->meterReader->readBatch($this->meters->get(), $this->meterReader::READ_DAILY, ['date' => date('Y-m-d')]); } } diff --git a/src/backend/app/Jobs/ProcessPayment.php b/src/backend/app/Jobs/ProcessPayment.php index d25708605..14b252407 100644 --- a/src/backend/app/Jobs/ProcessPayment.php +++ b/src/backend/app/Jobs/ProcessPayment.php @@ -9,8 +9,7 @@ use Illuminate\Queue\SerializesModels; use MPM\Transaction\TransactionPaymentProcessor; -class ProcessPayment extends AbstractJob -{ +class ProcessPayment extends AbstractJob { use Dispatchable; use InteractsWithQueue; use Queueable; @@ -26,8 +25,7 @@ class ProcessPayment extends AbstractJob * * @param int $transaction_id */ - public function __construct(int $transactionId) - { + public function __construct(int $transactionId) { $this->transactionId = $transactionId; parent::__construct(get_class($this)); @@ -35,11 +33,8 @@ public function __construct(int $transactionId) /** * Execute the job. - * - * @return void */ - public function executeJob(): void - { + public function executeJob(): void { TransactionPaymentProcessor::process($this->transactionId); } } diff --git a/src/backend/app/Jobs/SmsLoadBalancer.php b/src/backend/app/Jobs/SmsLoadBalancer.php index b80920a6a..8cb1cdb7a 100644 --- a/src/backend/app/Jobs/SmsLoadBalancer.php +++ b/src/backend/app/Jobs/SmsLoadBalancer.php @@ -10,27 +10,26 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Redis; -class SmsLoadBalancer extends AbstractJob -{ +class SmsLoadBalancer extends AbstractJob { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; public $timeout = 600; + public $tries = 250; + public $gateways; public $smsBody; - public function __construct($smsBody) - { + public function __construct($smsBody) { $this->smsBody = $smsBody; parent::__construct(get_class($this)); } - public function executeJob(): void - { + public function executeJob(): void { Redis::throttle('smsgateway')->allow(10)->every(1)->block(1)->then( function () { $fireBaseResult = $this->sendSms($this->smsBody); @@ -42,8 +41,7 @@ function () { ); } - private function sendSms($data): string - { + private function sendSms($data): string { $smsCollection = collect($data); $smsCollection = $smsCollection->chunk(3); $httpClient = new Client(); diff --git a/src/backend/app/Jobs/SmsProcessor.php b/src/backend/app/Jobs/SmsProcessor.php index 17c1f848d..cc93c8c1f 100644 --- a/src/backend/app/Jobs/SmsProcessor.php +++ b/src/backend/app/Jobs/SmsProcessor.php @@ -12,8 +12,7 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Log; -class SmsProcessor extends AbstractJob -{ +class SmsProcessor extends AbstractJob { use Dispatchable; use InteractsWithQueue; use Queueable; @@ -26,8 +25,7 @@ class SmsProcessor extends AbstractJob * @param int $smsType * @param $smsConfigs */ - public function __construct(private SmsSender $smsSender) - { + public function __construct(private SmsSender $smsSender) { parent::__construct(get_class($this)); } @@ -36,8 +34,7 @@ public function __construct(private SmsSender $smsSender) * * @return void */ - public function executeJob() - { + public function executeJob() { try { $this->smsSender->sendSms(); } catch (SmsTypeNotFoundException|SmsAndroidSettingNotExistingException|SmsBodyParserNotExtendedException $exception) { diff --git a/src/backend/app/Jobs/SocialTariffPiggyBankManager.php b/src/backend/app/Jobs/SocialTariffPiggyBankManager.php index 6f45c7fd4..fe0215d91 100644 --- a/src/backend/app/Jobs/SocialTariffPiggyBankManager.php +++ b/src/backend/app/Jobs/SocialTariffPiggyBankManager.php @@ -9,8 +9,7 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -class SocialTariffPiggyBankManager extends AbstractJob -{ +class SocialTariffPiggyBankManager extends AbstractJob { use Dispatchable; use InteractsWithQueue; use Queueable; @@ -21,8 +20,7 @@ class SocialTariffPiggyBankManager extends AbstractJob * * @return void */ - public function __construct() - { + public function __construct() { parent::__construct(get_class($this)); } @@ -31,8 +29,7 @@ public function __construct() * * @return void */ - public function executeJob() - { + public function executeJob() { // get all social tariffs $socialTariffs = SocialTariff::all(); @@ -41,8 +38,7 @@ public function executeJob() } } - private function chargeClients(SocialTariff $socialTariff): void - { + private function chargeClients(SocialTariff $socialTariff): void { SocialTariffPiggyBank::query()-> where('social_tariff_id', $socialTariff->id) ->where('savings', '<=', $socialTariff->maximum_stacked_energy) diff --git a/src/backend/app/Jobs/TokenProcessor.php b/src/backend/app/Jobs/TokenProcessor.php index 9f4cceccc..7eb9c2958 100644 --- a/src/backend/app/Jobs/TokenProcessor.php +++ b/src/backend/app/Jobs/TokenProcessor.php @@ -11,16 +11,18 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Log; -class TokenProcessor extends AbstractJob -{ +class TokenProcessor extends AbstractJob { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; private TransactionDataContainer $transactionContainer; + private bool $reCreate; + private int $counter; + private const MAX_TRIES = 3; public function __construct( @@ -34,8 +36,7 @@ public function __construct( parent::__construct(static::class); } - public function executeJob(): void - { + public function executeJob(): void { try { $api = resolve($this->transactionContainer->manufacturer->api_name); } catch (\Exception $e) { @@ -54,8 +55,7 @@ public function executeJob(): void } } - private function handleApiException(\Exception $e): void - { + private function handleApiException(\Exception $e): void { Log::critical( 'No Api is registered for '.$this->transactionContainer->manufacturer->name, ['message' => $e->getMessage()] @@ -63,8 +63,7 @@ private function handleApiException(\Exception $e): void event('transaction.failed', [$this->transactionContainer->transaction, $e->getMessage()]); } - private function handleExistingToken() - { + private function handleExistingToken() { $token = $this->transactionContainer->transaction->token()->first(); if ($token !== null && $this->reCreate === true) { @@ -75,8 +74,7 @@ private function handleExistingToken() return $token; } - private function generateToken($api): void - { + private function generateToken($api): void { try { $tokenData = $api->chargeDevice($this->transactionContainer); } catch (\Exception $e) { @@ -88,9 +86,8 @@ private function generateToken($api): void $this->saveToken($tokenData); } - private function handleTokenGenerationFailure(\Exception $e): void - { - if (self::MAX_TRIES > $this->counter) { + private function handleTokenGenerationFailure(\Exception $e): void { + if ($this->counter < self::MAX_TRIES) { $this->retryTokenGeneration(); return; @@ -109,8 +106,7 @@ private function handleTokenGenerationFailure(\Exception $e): void ]); } - private function retryTokenGeneration(): void - { + private function retryTokenGeneration(): void { ++$this->counter; self::dispatch( $this->transactionContainer, @@ -119,8 +115,7 @@ private function retryTokenGeneration(): void )->allOnConnection('redis')->onQueue(config('services.queues.token'))->delay(5); } - private function saveToken(array $tokenData): void - { + private function saveToken(array $tokenData): void { $token = Token::query()->make(['token' => $tokenData['token'], 'load' => $tokenData['load']]); $token->transaction()->associate($this->transactionContainer->transaction); $token->save(); @@ -128,8 +123,7 @@ private function saveToken(array $tokenData): void $this->handlePaymentEvents($token); } - private function handlePaymentEvents($token): void - { + private function handlePaymentEvents($token): void { $owner = $this->transactionContainer->device->person; event('payment.successful', [ @@ -145,8 +139,7 @@ private function handlePaymentEvents($token): void event('transaction.successful', [$this->transactionContainer->transaction]); } - private function handleRollbackInFailure() - { + private function handleRollbackInFailure() { $paidRates = $this->transactionContainer->paidRates; collect($paidRates)->map(function ($paidRate) { $assetRate = AssetRate::query()->find($paidRate['asset_rate_id']); diff --git a/src/backend/app/Jobs/UpdatePiggyBankEntry.php b/src/backend/app/Jobs/UpdatePiggyBankEntry.php index 2365c996a..2fa17662a 100644 --- a/src/backend/app/Jobs/UpdatePiggyBankEntry.php +++ b/src/backend/app/Jobs/UpdatePiggyBankEntry.php @@ -8,8 +8,7 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -class UpdatePiggyBankEntry extends AbstractJob -{ +class UpdatePiggyBankEntry extends AbstractJob { use Dispatchable; use InteractsWithQueue; use Queueable; @@ -25,8 +24,7 @@ class UpdatePiggyBankEntry extends AbstractJob * * @return void */ - public function __construct(MeterParameter $meterParameter) - { + public function __construct(MeterParameter $meterParameter) { $this->meterParameter = $meterParameter; parent::__construct(get_class($this)); } @@ -36,8 +34,7 @@ public function __construct(MeterParameter $meterParameter) * * @return void */ - public function executeJob() - { + public function executeJob() { $socialTariff = $this->meterParameter->tariff()->first()->socialTariff; if (!$socialTariff) { echo "meter has no social tariff should be deleted \n"; diff --git a/src/backend/app/Lib/IManufacturerAPI.php b/src/backend/app/Lib/IManufacturerAPI.php index 870b9e8e9..4dd77c5e6 100644 --- a/src/backend/app/Lib/IManufacturerAPI.php +++ b/src/backend/app/Lib/IManufacturerAPI.php @@ -5,13 +5,7 @@ use App\Misc\TransactionDataContainer; use App\Models\Device; -interface IManufacturerAPI -{ - /** - * @param TransactionDataContainer $transactionContainer - * - * @return array - */ +interface IManufacturerAPI { public function chargeDevice(TransactionDataContainer $transactionContainer): array; public function clearDevice(Device $device); diff --git a/src/backend/app/Lib/IMeterReader.php b/src/backend/app/Lib/IMeterReader.php index 6fd9939bd..43f526af2 100644 --- a/src/backend/app/Lib/IMeterReader.php +++ b/src/backend/app/Lib/IMeterReader.php @@ -2,13 +2,11 @@ namespace App\Lib; -interface IMeterReader -{ +interface IMeterReader { /** * Reads the data for a single meter. * - * @param $meterIdentifier - * @param int $type defines what to read from the remote api + * @param int $type defines what to read from the remote api * * @return mixed */ @@ -17,9 +15,8 @@ public function readMeter($meterIdentifier, $type); /** * Reads the data for a given meter list. * - * @param $meterList - * @param int $type defines what to read from the remote api - * * @param array $options + * @param int $type defines what to read from the remote api + * * @param array $options * * @return mixed */ diff --git a/src/backend/app/Lib/ISmsProvider.php b/src/backend/app/Lib/ISmsProvider.php index db2aac738..909b69dca 100644 --- a/src/backend/app/Lib/ISmsProvider.php +++ b/src/backend/app/Lib/ISmsProvider.php @@ -4,16 +4,10 @@ use App\Models\SmsAndroidSetting; -interface ISmsProvider -{ +interface ISmsProvider { /** * Sends the sms to the sms provider. * - * @param string $number - * @param string $body - * @param string $callback - * @param SmsAndroidSetting $smsAndroidSetting - * * @return mixed */ public function sendSms(string $number, string $body, string $callback, SmsAndroidSetting $smsAndroidSetting); diff --git a/src/backend/app/Lib/ITransaction.php b/src/backend/app/Lib/ITransaction.php index 7359ddca2..c985765a2 100644 --- a/src/backend/app/Lib/ITransaction.php +++ b/src/backend/app/Lib/ITransaction.php @@ -2,8 +2,7 @@ namespace App\Lib; -interface ITransaction -{ +interface ITransaction { public function getAmount(); public function getSender(); diff --git a/src/backend/app/Listeners/AccessRateListener.php b/src/backend/app/Listeners/AccessRateListener.php index e417d5534..4bd85edf8 100644 --- a/src/backend/app/Listeners/AccessRateListener.php +++ b/src/backend/app/Listeners/AccessRateListener.php @@ -9,10 +9,8 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Log; -class AccessRateListener -{ - public function initializeAccessRatePayment(Meter $meter): void - { +class AccessRateListener { + public function initializeAccessRatePayment(Meter $meter): void { try { $accessRate = $meter->tariff()->first()->accessRate; if (!$accessRate) { @@ -29,8 +27,7 @@ public function initializeAccessRatePayment(Meter $meter): void } } - public function subscribe(Dispatcher $events): void - { + public function subscribe(Dispatcher $events): void { $events->listen( 'accessRatePayment.initialize', '\App\Listeners\AccessRateListener@initializeAccessRatePayment' diff --git a/src/backend/app/Listeners/ClusterGeoListener.php b/src/backend/app/Listeners/ClusterGeoListener.php index 059b0acda..c659aeca5 100644 --- a/src/backend/app/Listeners/ClusterGeoListener.php +++ b/src/backend/app/Listeners/ClusterGeoListener.php @@ -9,17 +9,11 @@ use Illuminate\Support\Facades\Storage; use Mockery\Exception; -class ClusterGeoListener -{ +class ClusterGeoListener { /** * Handle the event. - * - * @param ClusterEvent $event - * - * @return void */ - public function handle(ClusterEvent $event): void - { + public function handle(ClusterEvent $event): void { $cluster = $event->cluster; $type = $event->type; if ($type === 'external') { @@ -48,28 +42,21 @@ public function handle(ClusterEvent $event): void /** * Creates a json file which has the same name as the cluster. - * - * @param Cluster $cluster - * @param $data */ - private function storeData(Cluster $cluster, $data): void - { + private function storeData(Cluster $cluster, $data): void { Storage::disk('local')->put($cluster->name.'.json', json_encode($data)); } /** * External geojson resource has lon,lat format. Change order to lat,lon. * - * @param $data - * * @return array[] * * @throws GeoFormatException * * @psalm-return list */ - public function reformatExternalData($data): array - { + public function reformatExternalData($data): array { $formatted = []; if (is_array($data) && !array_key_exists('geojson', $data)) { $data = $data[0]; diff --git a/src/backend/app/Listeners/HistoryListener.php b/src/backend/app/Listeners/HistoryListener.php index c197d67ed..47e011f95 100644 --- a/src/backend/app/Listeners/HistoryListener.php +++ b/src/backend/app/Listeners/HistoryListener.php @@ -7,8 +7,7 @@ use Illuminate\Events\Dispatcher; use Illuminate\Support\Facades\Log; -class HistoryListener -{ +class HistoryListener { /** * @var History */ @@ -16,24 +15,18 @@ class HistoryListener /** * Create the event listener. - * - * @param $historyModel */ - public function __construct(History $historyModel) - { + public function __construct(History $historyModel) { $this->historyModel = $historyModel; } /** * Saves a new event in to the histories table. * - * @param mixed $data is an object which should be stored on the histories table - * @param string $content the stringified message about the entry - * @param string $type - * @param string|null $field + * @param mixed $data is an object which should be stored on the histories table + * @param string $content the stringified message about the entry */ - public function save($data, string $content, string $type, ?string $field): void - { + public function save($data, string $content, string $type, ?string $field): void { $this->historyModel->target()->associate($data); $this->historyModel->content = $content; $this->historyModel->action = $type; @@ -43,8 +36,7 @@ public function save($data, string $content, string $type, ?string $field): void broadcast(new HistoryEvent($this->historyModel)); } - public function subscribe(Dispatcher $events): void - { + public function subscribe(Dispatcher $events): void { $events->listen('history.create', 'App\Listeners\HistoryListener@save'); $events->listen( 'history.hearth.beat', diff --git a/src/backend/app/Listeners/LogListener.php b/src/backend/app/Listeners/LogListener.php index 1bb19bdb1..8f740c986 100644 --- a/src/backend/app/Listeners/LogListener.php +++ b/src/backend/app/Listeners/LogListener.php @@ -5,20 +5,17 @@ use App\Models\Log; use Illuminate\Events\Dispatcher; -class LogListener -{ +class LogListener { /** * @var Log */ private $log; - public function __construct(Log $log) - { + public function __construct(Log $log) { $this->log = $log; } - public function storeLog($logData): void - { + public function storeLog($logData): void { $this->log->user_id = $logData['user_id']; $this->log->affected()->associate($logData['affected']); $this->log->action = $logData['action']; @@ -26,8 +23,7 @@ public function storeLog($logData): void $this->log->save(); } - public function subscribe(Dispatcher $event): void - { + public function subscribe(Dispatcher $event): void { $event->listen('new.log', '\App\Listeners\LogListener@storeLog'); } } diff --git a/src/backend/app/Listeners/MeterListener.php b/src/backend/app/Listeners/MeterListener.php index bb814a45f..a1ed969d6 100644 --- a/src/backend/app/Listeners/MeterListener.php +++ b/src/backend/app/Listeners/MeterListener.php @@ -5,22 +5,15 @@ use Illuminate\Events\Dispatcher; use Illuminate\Support\Facades\Log; -class MeterListener -{ +class MeterListener { /** * Sets the in_use to true. - * - * @param int $meter_id - * - * @return void */ - public function onParameterSaved(int $meter_id): void - { + public function onParameterSaved(int $meter_id): void { Log::debug('listener Core', []); } - public function subscribe(Dispatcher $events): void - { + public function subscribe(Dispatcher $events): void { $events->listen('meterparameter.saved', 'App\Listeners\MeterListener@onParameterSaved'); } } diff --git a/src/backend/app/Listeners/PaymentListener.php b/src/backend/app/Listeners/PaymentListener.php index 190f2646a..df9325e55 100644 --- a/src/backend/app/Listeners/PaymentListener.php +++ b/src/backend/app/Listeners/PaymentListener.php @@ -17,19 +17,16 @@ use Illuminate\Support\Facades\Log; use MPM\Transaction\Provider\ITransactionProvider; -class PaymentListener -{ +class PaymentListener { public function __construct( private PaymentHistoryService $paymentHistoryService, private PersonPaymentHistoryService $personPaymentHistoryService, private ApplianceRatePaymentHistoryService $applianceRatePaymentHistoryService, private AccessRatePaymentHistoryService $accessRatePaymentHistoryService, private TransactionPaymentHistoryService $transactionPaymentHistoryService, - ) { - } + ) {} - public function onEnergyPayment(ITransactionProvider $transactionProvider): void - { + public function onEnergyPayment(ITransactionProvider $transactionProvider): void { $transaction = $transactionProvider->getTransaction(); // get meter preferences try { @@ -40,23 +37,17 @@ public function onEnergyPayment(ITransactionProvider $transactionProvider): void } } - public function onLoanPayment(string $customer_id, int $amount): void - { - } + public function onLoanPayment(string $customer_id, int $amount): void {} - public function onPaymentFailed(): void - { + public function onPaymentFailed(): void { Log::debug('payment failed event'); } /** * @param int $amount * @param string $paymentService the name of the Payment gateway - * @param $paymentType * @param mixed $sender : The number or person who sent the money * @param mixed $paidFor the identifier for the payment. Ex; { LoanID, TokenID } - * @param $payer - * @param $transaction */ public function onPaymentSuccess( $amount, @@ -107,8 +98,7 @@ public function onPaymentSuccess( $this->paymentHistoryService->save($paymentHistory); } - public function subscribe(Dispatcher $events): void - { + public function subscribe(Dispatcher $events): void { $events->listen('payment.energy', 'App\Listeners\PaymentListener@onEnergyPayment'); $events->listen('payment.failed', 'App\Listeners\PaymentListener@onPaymentFailed'); $events->listen('payment.successful', 'App\Listeners\PaymentListener@onPaymentSuccess'); diff --git a/src/backend/app/Listeners/PaymentPeriodListener.php b/src/backend/app/Listeners/PaymentPeriodListener.php index c760b9f17..e2d69cd54 100644 --- a/src/backend/app/Listeners/PaymentPeriodListener.php +++ b/src/backend/app/Listeners/PaymentPeriodListener.php @@ -9,12 +9,12 @@ use Illuminate\Events\Dispatcher; use Illuminate\Support\Facades\Log; -class PaymentPeriodListener -{ +class PaymentPeriodListener { /** * @var PaymentProfile */ public $paymentProfile; + /** * @var PaymentHistory */ @@ -22,25 +22,20 @@ class PaymentPeriodListener /** * Create the event listener. - * - * @param PaymentProfile $paymentProfile - * @param PaymentHistory $history */ - public function __construct(PaymentProfile $paymentProfile, PaymentHistory $history) - { + public function __construct(PaymentProfile $paymentProfile, PaymentHistory $history) { $this->paymentProfile = $paymentProfile; $this->history = $history; } - public function recalculate(Person $person): void - { + public function recalculate(Person $person): void { $transactions = $person->payments() ->with('transaction') ->latest()->take(10) ->groupBy('transaction_id')->get(); $totalAmount = 0; $difference = (new Carbon($transactions[0]->created_at)) - ->diffInDays(new Carbon($transactions[\count($transactions) - 1]->created_at)) / \count($transactions); + ->diffInDays(new Carbon($transactions[\count($transactions) - 1]->created_at)) / \count($transactions); foreach ($transactions as $transaction) { $totalAmount += $transaction->amount; } @@ -52,8 +47,7 @@ public function recalculate(Person $person): void // $this->history-> } - public function subscribe(Dispatcher $events): void - { + public function subscribe(Dispatcher $events): void { $events->listen('payment.period.recalculate', '\App\Listeners\PaymentPeriodListener@recalculate'); } } diff --git a/src/backend/app/Listeners/SmsListener.php b/src/backend/app/Listeners/SmsListener.php index d62d09cc5..4ef9bda51 100644 --- a/src/backend/app/Listeners/SmsListener.php +++ b/src/backend/app/Listeners/SmsListener.php @@ -10,10 +10,11 @@ use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Events\Dispatcher; -class SmsListener -{ +class SmsListener { private $smsResendInformationKeyService; + private $transaction; + private $smsService; public function __construct( @@ -26,8 +27,7 @@ public function __construct( $this->smsService = $smsService; } - public function onSmsStored($sender, $message) - { + public function onSmsStored($sender, $message) { $resendInformationKey = $this->smsResendInformationKeyService->getResendInformationKeys()->first(); if (!$resendInformationKey) { return; @@ -51,8 +51,7 @@ public function onSmsStored($sender, $message) } } - public function subscribe(Dispatcher $events) - { + public function subscribe(Dispatcher $events) { $events->listen('sms.stored', 'App\Listeners\SmsListener@onSmsStored'); } } diff --git a/src/backend/app/Listeners/SoldApplianceListener.php b/src/backend/app/Listeners/SoldApplianceListener.php index 3d2b619dd..5343b8195 100644 --- a/src/backend/app/Listeners/SoldApplianceListener.php +++ b/src/backend/app/Listeners/SoldApplianceListener.php @@ -7,16 +7,13 @@ use App\Services\PersonService; use Illuminate\Events\Dispatcher; -class SoldApplianceListener -{ +class SoldApplianceListener { public function __construct( private ApplianceRateService $applianceRateService, private PersonService $personService, - ) { - } + ) {} - public function initializeApplianceRates(SoldApplianceDataContainer $soldAppliance): void - { + public function initializeApplianceRates(SoldApplianceDataContainer $soldAppliance): void { $assetPerson = $soldAppliance->getAssetPerson(); $assetType = $soldAppliance->getAssetType(); $transaction = $soldAppliance->getTransaction(); @@ -42,8 +39,7 @@ public function initializeApplianceRates(SoldApplianceDataContainer $soldApplian } } - public function subscribe(Dispatcher $events): void - { + public function subscribe(Dispatcher $events): void { $events->listen('appliance.sold', 'App\Listeners\SoldApplianceListener@initializeApplianceRates'); } } diff --git a/src/backend/app/Listeners/TokenListener.php b/src/backend/app/Listeners/TokenListener.php index cd5c221b1..0663852ef 100644 --- a/src/backend/app/Listeners/TokenListener.php +++ b/src/backend/app/Listeners/TokenListener.php @@ -10,9 +10,9 @@ use Illuminate\Events\Dispatcher; use Illuminate\Support\Facades\Log; -class TokenListener -{ +class TokenListener { private $token; + protected $tokenData; /** @@ -20,16 +20,11 @@ class TokenListener * * @return void */ - public function __construct(MeterToken $token) - { + public function __construct(MeterToken $token) { $this->token = $token; } - /** - * @param TransactionDataContainer $transactionContainer - */ - public function generateToken(TransactionDataContainer $transactionContainer): void - { + public function generateToken(TransactionDataContainer $transactionContainer): void { $api = null; // get Manufacturer APi try { @@ -89,8 +84,7 @@ public function generateToken(TransactionDataContainer $transactionContainer): v ); } - public function subscribe(Dispatcher $events): void - { + public function subscribe(Dispatcher $events): void { $events->listen('token.generate', '\App\Listeners\TokenListener@generateToken'); } } diff --git a/src/backend/app/Listeners/TransactionListener.php b/src/backend/app/Listeners/TransactionListener.php index 398745fb4..05db61309 100644 --- a/src/backend/app/Listeners/TransactionListener.php +++ b/src/backend/app/Listeners/TransactionListener.php @@ -7,29 +7,24 @@ use MPM\Transaction\Provider\ITransactionProvider; use MPM\Transaction\Provider\TransactionAdapter; -class TransactionListener -{ - public function onTransactionSaved(ITransactionProvider $transactionProvider): void - { +class TransactionListener { + public function onTransactionSaved(ITransactionProvider $transactionProvider): void { // echos the confirmation output $transactionProvider->confirm(); } - public function onTransactionFailed(Transaction $transaction, $message = null): void - { + public function onTransactionFailed(Transaction $transaction, $message = null): void { $baseTransaction = TransactionAdapter::getTransaction($transaction->originalTransaction()->first()); $baseTransaction->addConflict($message); $baseTransaction->sendResult(false, $transaction); } - public function onTransactionSuccess(Transaction $transaction): void - { + public function onTransactionSuccess(Transaction $transaction): void { $baseTransaction = TransactionAdapter::getTransaction($transaction->originalTransaction()->first()); $baseTransaction->sendResult(true, $transaction); } - public function subscribe(Dispatcher $events): void - { + public function subscribe(Dispatcher $events): void { $events->listen('transaction.saved', 'App\Listeners\TransactionListener@onTransactionSaved'); $events->listen('transaction.successful', 'App\Listeners\TransactionListener@onTransactionSuccess'); $events->listen('transaction.failed', 'App\Listeners\TransactionListener@onTransactionFailed'); diff --git a/src/backend/app/ManufacturerApi/CalinReadMeter.php b/src/backend/app/ManufacturerApi/CalinReadMeter.php index db0d34a15..3213eeb23 100644 --- a/src/backend/app/ManufacturerApi/CalinReadMeter.php +++ b/src/backend/app/ManufacturerApi/CalinReadMeter.php @@ -8,13 +8,14 @@ use Carbon\Exceptions\InvalidDateException; use Illuminate\Support\Facades\Log; -class CalinReadMeter implements IMeterReader -{ +class CalinReadMeter implements IMeterReader { public const READ_DAILY = 1; + /** * @var \SoapClient */ private $api; + /** * @var MeterConsumption */ @@ -23,12 +24,9 @@ class CalinReadMeter implements IMeterReader /** * CalinReadMeter constructor. * - * @param MeterConsumption $consumption - * * @throws \SoapFault */ - public function __construct(MeterConsumption $consumption) - { + public function __construct(MeterConsumption $consumption) { try { $this->api = new \SoapClient(\config('services.calin.meter.api'), ['keep_alive' => false]); } catch (\Exception $exception) { @@ -42,8 +40,7 @@ public function __construct(MeterConsumption $consumption) * * @return mixed */ - public function readDailyData($meterId, $date) - { + public function readDailyData($meterId, $date) { if ($this->api === null) { return; } @@ -59,26 +56,19 @@ public function readDailyData($meterId, $date) /** * Reads the total consumption of a meter. * - * @param $meterId - * @param $type - * * @return void */ - public function readMeter($meterId, $type) - { - } + public function readMeter($meterId, $type) {} /** * Reads the data for a given meter list. * - * @param $meterList - * @param int $type defines what to read from the remote api + * @param int $type defines what to read from the remote api * @param array $options * * @return void */ - public function readBatch($meterList, $type, $options) - { + public function readBatch($meterList, $type, $options) { if ($type === self::READ_DAILY) { if (!isset($options['date'])) { throw new InvalidDateException('Date', 'date is not set. Send date within the options array'); @@ -96,6 +86,7 @@ public function readBatch($meterList, $type, $options) 'Meter Reading, negative consumption ', ['meter_id' => $meter->id, 'consumption' => $meterData[0]] ); + continue; } @@ -118,13 +109,8 @@ public function readBatch($meterList, $type, $options) /** * Calculates the difference of usages with the prev. reading. - * - * @param MeterConsumption $consumption - * - * @return MeterConsumption */ - private function calculateDifference(MeterConsumption $consumption): MeterConsumption - { + private function calculateDifference(MeterConsumption $consumption): MeterConsumption { $prevReading = $this->consumption->where('meter_id', $consumption->meter_id)->latest()->first(); if ($prevReading !== null) { $consumption->consumption = $consumption->total_consumption - $prevReading->total_consumption; @@ -136,16 +122,13 @@ private function calculateDifference(MeterConsumption $consumption): MeterConsum } /** - * @param $data - * * @return string[] * * @throws MeterIsNotReadable * * @psalm-return non-empty-list */ - private function fetchResponseData($data): array - { + private function fetchResponseData($data): array { $out = []; /*fetch information out of the response. successful response : 00^total_power,rest_energy @@ -159,16 +142,11 @@ private function fetchResponseData($data): array } /** - * @param string $meterId - * @param string $year - * @param string $month - * @param string $day * @param string $action * * @return array (\Illuminate\Config\Repository|float|mixed)[] */ - private function prepareDailyReq(string $meterId, string $year, string $month, string $day, $action = 'Read'): array - { + private function prepareDailyReq(string $meterId, string $year, string $month, string $day, $action = 'Read'): array { [$t1, $t2] = explode(' ', microtime()); $timestamp = (float) sprintf('%.0f', ((float) $t1 + (float) $t2) * 1000); @@ -186,8 +164,7 @@ private function prepareDailyReq(string $meterId, string $year, string $month, s return $params; } - private function generateCipher($meterId, float $timestamp, $dataWay): string - { + private function generateCipher($meterId, float $timestamp, $dataWay): string { return md5( sprintf( '%s%s%s%s%s', diff --git a/src/backend/app/Misc/LoanDataContainer.php b/src/backend/app/Misc/LoanDataContainer.php index b982cfc4d..e4967d223 100644 --- a/src/backend/app/Misc/LoanDataContainer.php +++ b/src/backend/app/Misc/LoanDataContainer.php @@ -14,20 +14,18 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\ModelNotFoundException; -class LoanDataContainer -{ +class LoanDataContainer { private ?Person $meterOwner; + private Transaction $transaction; public array $paid_rates = []; - public function initialize(Transaction $transaction): void - { + public function initialize(Transaction $transaction): void { $this->meterOwner = $this->getMeterOwner($transaction->message); } - public function loanCost() - { + public function loanCost() { if (!$this->meterOwner) { throw new MeterParameterNotFound('loan data container'); } @@ -87,14 +85,11 @@ public function loanCost() } /** - * @param $owner - * * @return Builder[]|Collection * * @psalm-return Collection|array */ - private function getCustomerDueRates($owner): Collection - { + private function getCustomerDueRates($owner): Collection { $loans = AssetPerson::query()->where('person_id', $owner->id)->pluck('id'); return AssetRate::with('assetPerson.assetType') @@ -105,15 +100,12 @@ private function getCustomerDueRates($owner): Collection } /** - * @param string $serialNumber - * * @return mixed * * @throws MeterIsNotInUse * @throws MeterIsNotAssignedToCustomer */ - private function getMeterOwner(string $serialNumber): ?Person - { + private function getMeterOwner(string $serialNumber): ?Person { try { /** @var Meter $meter */ $meter = Meter::with('meterParameter.owner') diff --git a/src/backend/app/Misc/SoldApplianceDataContainer.php b/src/backend/app/Misc/SoldApplianceDataContainer.php index 64374b393..80eb0c781 100644 --- a/src/backend/app/Misc/SoldApplianceDataContainer.php +++ b/src/backend/app/Misc/SoldApplianceDataContainer.php @@ -7,33 +7,27 @@ use App\Models\AssetType; use App\Models\Transaction\Transaction; -class SoldApplianceDataContainer -{ +class SoldApplianceDataContainer { public function __construct( private Asset $asset, private AssetType $assetType, private AssetPerson $assetPerson, private ?Transaction $transaction = null, - ) { - } + ) {} - public function getAsset() - { + public function getAsset() { return $this->asset; } - public function getAssetType() - { + public function getAssetType() { return $this->assetType; } - public function getAssetPerson() - { + public function getAssetPerson() { return $this->assetPerson; } - public function getTransaction() - { + public function getTransaction() { return $this->transaction; } } diff --git a/src/backend/app/Misc/TransactionDataContainer.php b/src/backend/app/Misc/TransactionDataContainer.php index 1f2b182b7..0e9f52fb5 100644 --- a/src/backend/app/Misc/TransactionDataContainer.php +++ b/src/backend/app/Misc/TransactionDataContainer.php @@ -12,25 +12,36 @@ use Illuminate\Database\Eloquent\ModelNotFoundException; use MPM\Device\DeviceService; -class TransactionDataContainer -{ +class TransactionDataContainer { public int $accessRateDebt; + public Transaction $transaction; + public Device $device; + public ?MeterTariff $tariff; + public Manufacturer $manufacturer; + public Token $token; + public array $paidRates; + public float $chargedEnergy; + public float $amount; + public float $totalAmount; + public float $rawAmount; + public ?AssetPerson $appliancePerson; + public float $installmentCost; + public string $dayDifferenceBetweenTwoInstallments; - public static function initialize(Transaction $transaction): TransactionDataContainer - { + public static function initialize(Transaction $transaction): TransactionDataContainer { $container = app()->make(TransactionDataContainer::class); $deviceService = app()->make(DeviceService::class); $container->chargedEnergy = 0; diff --git a/src/backend/app/Models/AccessRate/AccessRate.php b/src/backend/app/Models/AccessRate/AccessRate.php index ffd95ec41..cc830fe4a 100644 --- a/src/backend/app/Models/AccessRate/AccessRate.php +++ b/src/backend/app/Models/AccessRate/AccessRate.php @@ -18,29 +18,24 @@ * @property int tariff_id * @property int period when the payment repeats itself */ -class AccessRate extends BaseModel -{ +class AccessRate extends BaseModel { use HasFactory; public const RELATION_NAME = 'access_rate'; - public function tariff(): BelongsTo - { + public function tariff(): BelongsTo { return $this->belongsTo(MeterTariff::class, 'tariff_id', 'id'); } - public function accessRatePayments(): HasMany - { + public function accessRatePayments(): HasMany { return $this->hasMany(AccessRatePayment::class); } - public function __toString() - { + public function __toString() { return sprintf('For tariff : %s', $this->tariff()->first()->name); } - public function paymentHistories(): MorphMany - { + public function paymentHistories(): MorphMany { return $this->morphMany(PaymentHistory::class, 'paid_for'); } } diff --git a/src/backend/app/Models/AccessRate/AccessRatePayment.php b/src/backend/app/Models/AccessRate/AccessRatePayment.php index 52552b9b1..705e3be91 100644 --- a/src/backend/app/Models/AccessRate/AccessRatePayment.php +++ b/src/backend/app/Models/AccessRate/AccessRatePayment.php @@ -14,15 +14,12 @@ * @property \DateTime due_date * @property int debt */ -class AccessRatePayment extends BaseModel -{ - public function meter(): BelongsTo - { +class AccessRatePayment extends BaseModel { + public function meter(): BelongsTo { return $this->belongsTo(Meter::class); } - public function accessRate(): BelongsTo - { + public function accessRate(): BelongsTo { return $this->belongsTo(AccessRate::class); } } diff --git a/src/backend/app/Models/Address/Address.php b/src/backend/app/Models/Address/Address.php index e2de67a16..b66d94d0a 100644 --- a/src/backend/app/Models/Address/Address.php +++ b/src/backend/app/Models/Address/Address.php @@ -21,60 +21,52 @@ * @property int $owner_id * @property string $owner_type */ -class Address extends BaseModel -{ +class Address extends BaseModel { use HasFactory; public const RELATION_NAME = 'address'; + protected $hidden = ['owner_id', 'owner_type']; + public static $rules = [ 'city_id' => 'required|exists:cities,id', ]; - public function city(): BelongsTo - { + public function city(): BelongsTo { return $this->belongsTo(City::class); } // client & company - public function owner(): MorphTo - { + public function owner(): MorphTo { return $this->morphTo(); } - public function geo(): MorphOne - { + public function geo(): MorphOne { return $this->morphOne(GeographicalInformation::class, 'owner'); } - public function setOwner(int $ownerId, string $ownerType): void - { + public function setOwner(int $ownerId, string $ownerType): void { $this->owner_id = $ownerId; $this->owner_type = $ownerType; } - public function setCityId(int $cityId): void - { + public function setCityId(int $cityId): void { $this->city_id = $cityId; } - public function setPhone(?string $phone): void - { + public function setPhone(?string $phone): void { $this->phone = $phone; } - public function setEmail(?string $email): void - { + public function setEmail(?string $email): void { $this->email = $email; } - public function setIsPrimary(bool $isPrimary): void - { + public function setIsPrimary(bool $isPrimary): void { $this->is_primary = $isPrimary; } - public function setStreet(?string $street): void - { + public function setStreet(?string $street): void { $this->street = $street; } } diff --git a/src/backend/app/Models/Address/HasAddressesInterface.php b/src/backend/app/Models/Address/HasAddressesInterface.php index 6ae680e53..425b1785e 100644 --- a/src/backend/app/Models/Address/HasAddressesInterface.php +++ b/src/backend/app/Models/Address/HasAddressesInterface.php @@ -4,7 +4,6 @@ use Illuminate\Database\Eloquent\Relations\HasOneOrMany; -interface HasAddressesInterface -{ +interface HasAddressesInterface { public function addresses(): HasOneOrMany; } diff --git a/src/backend/app/Models/Admin.php b/src/backend/app/Models/Admin.php index 3a3bbba45..2cf81e2be 100644 --- a/src/backend/app/Models/Admin.php +++ b/src/backend/app/Models/Admin.php @@ -2,6 +2,4 @@ namespace App\Models; -class Admin extends BaseModel -{ -} +class Admin extends BaseModel {} diff --git a/src/backend/app/Models/Agent.php b/src/backend/app/Models/Agent.php index 49dcbf3ee..12a6a6161 100644 --- a/src/backend/app/Models/Agent.php +++ b/src/backend/app/Models/Agent.php @@ -32,20 +32,17 @@ * @property string $remember_token * @property int $company_id */ -class Agent extends Authenticatable implements JWTSubject -{ +class Agent extends Authenticatable implements JWTSubject { use HasFactory; public const RELATION_NAME = 'agent'; - public function __construct(array $attributes = []) - { + public function __construct(array $attributes = []) { $this->setConnection('shard'); parent::__construct($attributes); } - public function setPasswordAttribute($password): void - { + public function setPasswordAttribute($password): void { $this->attributes['password'] = Hash::make($password); } @@ -62,8 +59,7 @@ public function setPasswordAttribute($password): void 'device_id', ]; - public function miniGrid(): BelongsTo - { + public function miniGrid(): BelongsTo { return $this->belongsTo(MiniGrid::class); } @@ -72,8 +68,7 @@ public function miniGrid(): BelongsTo * * @return mixed */ - public function getJWTIdentifier() - { + public function getJWTIdentifier() { return $this->getKey(); } @@ -84,70 +79,57 @@ public function getJWTIdentifier() * * @psalm-return array */ - public function getJWTCustomClaims() - { + public function getJWTCustomClaims() { return [ 'companyId' => User::query()->select(User::COL_COMPANY_ID)->first()[User::COL_COMPANY_ID], ]; } - public function address(): MorphOne - { + public function address(): MorphOne { return $this->morphOne(Address::class, 'owner'); } - public function tickets(): MorphMany - { + public function tickets(): MorphMany { return $this->morphMany(Ticket::class, 'creator'); } - public function transaction(): HasMany - { + public function transaction(): HasMany { return $this->hasMany(Transaction::class); } - public function balanceHistory(): HasMany - { + public function balanceHistory(): HasMany { return $this->hasMany(AgentBalanceHistory::class); } - public function assignedAppliance(): HasMany - { + public function assignedAppliance(): HasMany { return $this->hasMany(AgentAssignedAppliances::class); } - public function addressDetails() - { + public function addressDetails() { return $this->addresses()->with('city'); } - public function person(): BelongsTo - { + public function person(): BelongsTo { return $this->belongsTo(Person::class); } - public function commission(): BelongsTo - { + public function commission(): BelongsTo { return $this->belongsTo(AgentCommission::class, 'agent_commission_id'); } - public function soldAppliances(): MorphMany - { + public function soldAppliances(): MorphMany { return $this->morphMany(AssetPerson::class, 'creator'); } - public function agentCharges(): HasMany - { + public function agentCharges(): HasMany { return $this->hasMany(AgentCharge::class); } - public function addresses(): MorphMany - { + public function addresses(): MorphMany { return $this->morphMany(Address::class, 'owner'); } - public function receipt(): HasMany - { + public function receipt(): HasMany { return $this->hasMany(AgentReceipt::class, 'agent_id', 'id'); } } diff --git a/src/backend/app/Models/AgentAssignedAppliances.php b/src/backend/app/Models/AgentAssignedAppliances.php index 5af37cfaf..b8f97d158 100644 --- a/src/backend/app/Models/AgentAssignedAppliances.php +++ b/src/backend/app/Models/AgentAssignedAppliances.php @@ -6,28 +6,24 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; -class AgentAssignedAppliances extends BaseModel -{ +class AgentAssignedAppliances extends BaseModel { public const RELATION_NAME = 'agent_appliance'; + protected $guarded = []; - public function agent(): BelongsTo - { + public function agent(): BelongsTo { return $this->belongsTo(Agent::class); } - public function user(): BelongsTo - { + public function user(): BelongsTo { return $this->belongsTo(User::class); } - public function appliance(): BelongsTo - { + public function appliance(): BelongsTo { return $this->belongsTo(Asset::class, 'appliance_id', 'id'); } - public function soldAppliance(): HasMany - { + public function soldAppliance(): HasMany { return $this->hasMany(AgentSoldAppliance::class); } } diff --git a/src/backend/app/Models/AgentBalanceHistory.php b/src/backend/app/Models/AgentBalanceHistory.php index ccd56168e..b788ade83 100644 --- a/src/backend/app/Models/AgentBalanceHistory.php +++ b/src/backend/app/Models/AgentBalanceHistory.php @@ -7,22 +7,18 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphTo; -class AgentBalanceHistory extends BaseModel -{ +class AgentBalanceHistory extends BaseModel { protected $guarded = []; - public function agent(): void - { + public function agent(): void { $this->belongsTo(Agent::class); } - public function trigger(): MorphTo - { + public function trigger(): MorphTo { return $this->morphTo(); } - public function transaction(): BelongsTo - { + public function transaction(): BelongsTo { return $this->belongsTo(Transaction::class); } } diff --git a/src/backend/app/Models/AgentCharge.php b/src/backend/app/Models/AgentCharge.php index c8b51f70a..23930a668 100644 --- a/src/backend/app/Models/AgentCharge.php +++ b/src/backend/app/Models/AgentCharge.php @@ -7,24 +7,20 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphOne; -class AgentCharge extends BaseModel -{ +class AgentCharge extends BaseModel { use HasFactory; public const RELATION_NAME = 'agent_charge'; - public function agent(): BelongsTo - { + public function agent(): BelongsTo { return $this->belongsTo(Agent::class); } - public function user(): BelongsTo - { + public function user(): BelongsTo { return $this->belongsTo(User::class); } - public function history(): MorphOne - { + public function history(): MorphOne { return $this->morphOne(AgentBalanceHistory::class, 'trigger'); } } diff --git a/src/backend/app/Models/AgentCommission.php b/src/backend/app/Models/AgentCommission.php index bf5c3e75d..b006d9f39 100644 --- a/src/backend/app/Models/AgentCommission.php +++ b/src/backend/app/Models/AgentCommission.php @@ -15,19 +15,16 @@ * @property float $appliance_commission * @property float $risk_balance */ -class AgentCommission extends BaseModel -{ +class AgentCommission extends BaseModel { use HasFactory; public const RELATION_NAME = 'agent_commission'; - public function agent(): HasMany - { + public function agent(): HasMany { return $this->hasMany(Agent::class); } - public function history(): MorphOne - { + public function history(): MorphOne { return $this->morphOne(AgentBalanceHistory::class, 'trigger'); } } diff --git a/src/backend/app/Models/AgentReceipt.php b/src/backend/app/Models/AgentReceipt.php index d9c682b90..3f41744de 100644 --- a/src/backend/app/Models/AgentReceipt.php +++ b/src/backend/app/Models/AgentReceipt.php @@ -6,27 +6,22 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; -class AgentReceipt extends BaseModel -{ +class AgentReceipt extends BaseModel { public const RELATION_NAME = 'agent_receipt'; - public function history(): BelongsTo - { + public function history(): BelongsTo { return $this->belongsTo(AgentBalanceHistory::class, 'last_controlled_balance_history_id', 'id'); } - public function agent(): BelongsTo - { + public function agent(): BelongsTo { return $this->belongsTo(Agent::class); } - public function user(): BelongsTo - { + public function user(): BelongsTo { return $this->belongsTo(User::class); } - public function detail(): HasMany - { + public function detail(): HasMany { return $this->hasMany(AgentReceiptDetail::class); } } diff --git a/src/backend/app/Models/AgentReceiptDetail.php b/src/backend/app/Models/AgentReceiptDetail.php index 9e06d5d66..acfed7130 100644 --- a/src/backend/app/Models/AgentReceiptDetail.php +++ b/src/backend/app/Models/AgentReceiptDetail.php @@ -5,10 +5,8 @@ use App\Models\Base\BaseModel; use Illuminate\Database\Eloquent\Relations\BelongsTo; -class AgentReceiptDetail extends BaseModel -{ - public function receipt(): BelongsTo - { +class AgentReceiptDetail extends BaseModel { + public function receipt(): BelongsTo { return $this->belongsTo(AgentReceipt::class, 'agent_receipt_id'); } } diff --git a/src/backend/app/Models/AgentSoldAppliance.php b/src/backend/app/Models/AgentSoldAppliance.php index 428c08d44..33e58b7c4 100644 --- a/src/backend/app/Models/AgentSoldAppliance.php +++ b/src/backend/app/Models/AgentSoldAppliance.php @@ -6,17 +6,14 @@ use App\Models\Person\Person; use Illuminate\Database\Eloquent\Relations\BelongsTo; -class AgentSoldAppliance extends BaseModel -{ +class AgentSoldAppliance extends BaseModel { protected $guarded = []; - public function assignedAppliance(): BelongsTo - { + public function assignedAppliance(): BelongsTo { return $this->belongsTo(AgentAssignedAppliances::class, 'agent_assigned_appliance_id', 'id'); } - public function person(): BelongsTo - { + public function person(): BelongsTo { return $this->belongsTo(Person::class); } } diff --git a/src/backend/app/Models/Asset.php b/src/backend/app/Models/Asset.php index 2224a9966..9ec760a15 100644 --- a/src/backend/app/Models/Asset.php +++ b/src/backend/app/Models/Asset.php @@ -8,30 +8,26 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; -class Asset extends BaseModel -{ +class Asset extends BaseModel { use HasFactory; public const RELATION_NAME = 'appliance'; + protected $table = 'assets'; - public function assetType(): BelongsTo - { + public function assetType(): BelongsTo { return $this->belongsTo(AssetType::class); } - public function agentAssignedAppliance(): HasMany - { + public function agentAssignedAppliance(): HasMany { return $this->hasMany(AgentAssignedAppliances::class, 'appliance_type_id', 'id'); } - public function rates(): HasMany - { + public function rates(): HasMany { return $this->hasMany(AssetPerson::class); } - public function smsReminderRate(): HasOne - { + public function smsReminderRate(): HasOne { return $this->hasOne(SmsApplianceRemindRate::class, 'appliance_id', 'id'); } } diff --git a/src/backend/app/Models/AssetPerson.php b/src/backend/app/Models/AssetPerson.php index 563b6a290..098b7595b 100644 --- a/src/backend/app/Models/AssetPerson.php +++ b/src/backend/app/Models/AssetPerson.php @@ -19,39 +19,32 @@ * @property int $down_payment * @property int $rate_count */ -class AssetPerson extends BaseModel -{ +class AssetPerson extends BaseModel { protected $dispatchesEvents = [ 'created' => AssetPersonCreated::class, ]; - public function person(): BelongsTo - { + public function person(): BelongsTo { return $this->belongsTo(Person::class); } - public function logs(): MorphMany - { + public function logs(): MorphMany { return $this->morphMany(Log::class, 'affected'); } - public function asset(): BelongsTo - { + public function asset(): BelongsTo { return $this->belongsTo(Asset::class, 'asset_id'); } - public function rates(): HasMany - { + public function rates(): HasMany { return $this->hasMany(AssetRate::class); } - public function creator(): MorphTo - { + public function creator(): MorphTo { return $this->morphTo(); } - public function device(): BelongsTo - { + public function device(): BelongsTo { return $this->belongsTo(Device::class); } } diff --git a/src/backend/app/Models/AssetRate.php b/src/backend/app/Models/AssetRate.php index fb7eb22ae..b1322f6a0 100644 --- a/src/backend/app/Models/AssetRate.php +++ b/src/backend/app/Models/AssetRate.php @@ -17,8 +17,7 @@ * @property string $due_date * @property AssetPerson assetPerson */ -class AssetRate extends BaseModel -{ +class AssetRate extends BaseModel { public const RELATION_NAME = 'asset_rate'; protected $fillable = [ @@ -29,23 +28,19 @@ class AssetRate extends BaseModel 'remind', ]; - public function assetPerson(): BelongsTo - { + public function assetPerson(): BelongsTo { return $this->belongsTo(AssetPerson::class); } - public function logs(): MorphMany - { + public function logs(): MorphMany { return $this->morphMany(Log::class, 'affected'); } - public function paymentHistory(): MorphOne - { + public function paymentHistory(): MorphOne { return $this->morphOne(PaymentHistory::class, 'paid_for'); } - public function asset(): HasOneThrough - { + public function asset(): HasOneThrough { return $this->HasOneThrough(AssetType::class, AssetPerson::class, 'asset_type_id', 'id'); } } diff --git a/src/backend/app/Models/AssetType.php b/src/backend/app/Models/AssetType.php index d6bc98b77..6ed715d7a 100644 --- a/src/backend/app/Models/AssetType.php +++ b/src/backend/app/Models/AssetType.php @@ -5,12 +5,10 @@ use App\Models\Base\BaseModel; use Illuminate\Database\Eloquent\Relations\HasMany; -class AssetType extends BaseModel -{ +class AssetType extends BaseModel { public const APPLIANCE_TYPE_SHS = 1; - public function asset(): HasMany - { + public function asset(): HasMany { return $this->hasMany(Asset::class); } } diff --git a/src/backend/app/Models/Base/BaseModel.php b/src/backend/app/Models/Base/BaseModel.php index 635661df6..8fdc10894 100644 --- a/src/backend/app/Models/Base/BaseModel.php +++ b/src/backend/app/Models/Base/BaseModel.php @@ -11,13 +11,12 @@ * logic and define interaction between entities. * "Most" models will extend this base model. */ -abstract class BaseModel extends Model -{ +abstract class BaseModel extends Model { protected $guarded = ['id']; + public static $rules = []; - public function __construct(array $attributes = []) - { + public function __construct(array $attributes = []) { parent::__construct($attributes); $this->setConnection('shard'); } diff --git a/src/backend/app/Models/Base/BaseModelCore.php b/src/backend/app/Models/Base/BaseModelCore.php index 6d43ebc05..1553abaa6 100644 --- a/src/backend/app/Models/Base/BaseModelCore.php +++ b/src/backend/app/Models/Base/BaseModelCore.php @@ -10,13 +10,12 @@ * Only applies to very few common, high-level configuration entities in * the entire MPM-instance like database and plugin configuration. */ -abstract class BaseModelCore extends Model -{ +abstract class BaseModelCore extends Model { protected $guarded = ['id']; + public static $rules = []; - public function __construct(array $attributes = []) - { + public function __construct(array $attributes = []) { $this->setConnection('micro_power_manager'); parent::__construct($attributes); } diff --git a/src/backend/app/Models/City.php b/src/backend/app/Models/City.php index 696945aa0..fd84932b1 100644 --- a/src/backend/app/Models/City.php +++ b/src/backend/app/Models/City.php @@ -18,69 +18,56 @@ * @property int $cluster_id * @property int $mini_grid_id */ -class City extends BaseModel -{ +class City extends BaseModel { use HasFactory; public const RELATION_NAME = 'city'; - public function targets(): HasMany - { + public function targets(): HasMany { return $this->hasMany(Target::class); } - public function addresses(): HasMany - { + public function addresses(): HasMany { return $this->hasMany(Address::class); } - public function country(): BelongsTo - { + public function country(): BelongsTo { return $this->belongsTo(Country::class); } - public function miniGrid(): BelongsTo - { + public function miniGrid(): BelongsTo { return $this->belongsTo(MiniGrid::class); } - public function cluster(): BelongsTo - { + public function cluster(): BelongsTo { return $this->belongsTo(Cluster::class); } - public function location(): MorphOne - { + public function location(): MorphOne { return $this->morphOne(GeographicalInformation::class, 'owner'); } - public function setName(string $name): void - { + public function setName(string $name): void { $this->name = $name; } - public function setCountryId(int $countryId): void - { + public function setCountryId(int $countryId): void { $this->country_id = $countryId; } - public function setClusterId(int $clusterId): void - { + public function setClusterId(int $clusterId): void { $this->cluster_id = $clusterId; } - public function setMiniGridId(int $miniGridId): void - { + public function setMiniGridId(int $miniGridId): void { $this->mini_grid_id = $miniGridId; } - public function getMiniGridId(): int - { + public function getMiniGridId(): int { return $this->mini_grid_id; } - public function geo(): MorphOne - { + public function geo(): MorphOne { return $this->morphOne(GeographicalInformation::class, 'owner'); } } diff --git a/src/backend/app/Models/Cluster.php b/src/backend/app/Models/Cluster.php index acf8bfaf2..f04a7d647 100644 --- a/src/backend/app/Models/Cluster.php +++ b/src/backend/app/Models/Cluster.php @@ -18,8 +18,7 @@ * @property string $updated_at * @property string $created_at */ -class Cluster extends BaseModel implements TargetAssignable -{ +class Cluster extends BaseModel implements TargetAssignable { use HasFactory; public const RELATION_NAME = 'cluster'; @@ -28,18 +27,15 @@ class Cluster extends BaseModel implements TargetAssignable 'geo_data' => 'array', ]; - public function manager(): BelongsTo - { + public function manager(): BelongsTo { return $this->belongsTo(User::class); } - public function cities(): HasMany - { + public function cities(): HasMany { return $this->hasMany(City::class); } - public function miniGrids(): HasMany - { + public function miniGrids(): HasMany { return $this->hasMany(MiniGrid::class); } } diff --git a/src/backend/app/Models/Company.php b/src/backend/app/Models/Company.php index 584247dca..0e08e49d7 100644 --- a/src/backend/app/Models/Company.php +++ b/src/backend/app/Models/Company.php @@ -11,8 +11,7 @@ * @property int $id * @property string $name; */ -class Company extends BaseModelCore -{ +class Company extends BaseModelCore { use HasFactory; public const COL_ID = 'id'; @@ -23,28 +22,23 @@ class Company extends BaseModelCore // return $this->hasMany(User::class); // } - public function database(): HasOne - { + public function database(): HasOne { return $this->hasOne(CompanyDatabase::class); } - public function databaseProxies(): HasMany - { + public function databaseProxies(): HasMany { return $this->hasMany(DatabaseProxy::class); } - public function getId(): int - { + public function getId(): int { return $this->id; } - public function getName(): string - { + public function getName(): string { return $this->name; } - public function jobs() - { + public function jobs() { return $this->hasMany(CompanyJob::class); } } diff --git a/src/backend/app/Models/CompanyDatabase.php b/src/backend/app/Models/CompanyDatabase.php index 7a21fbb58..1a159f498 100644 --- a/src/backend/app/Models/CompanyDatabase.php +++ b/src/backend/app/Models/CompanyDatabase.php @@ -12,26 +12,24 @@ * @property int $database_name; * @property int $company_id; */ -class CompanyDatabase extends BaseModelCore -{ +class CompanyDatabase extends BaseModelCore { use HasFactory; public const TABLE_NAME = 'company_databases'; + public const COL_DATABASE_NAME = 'database_name'; + public const COL_COMPANY_ID = 'company_id'; - public function company(): BelongsTo - { + public function company(): BelongsTo { return $this->belongsTo(Company::class); } - public function databaseProxies(): HasMany - { + public function databaseProxies(): HasMany { return $this->hasMany(DatabaseProxy::class); } - public function findByCompanyId(int $companyId): CompanyDatabase - { + public function findByCompanyId(int $companyId): CompanyDatabase { /** @var CompanyDatabase $result */ $result = $this->newQuery() ->select(self::COL_DATABASE_NAME) @@ -41,18 +39,15 @@ public function findByCompanyId(int $companyId): CompanyDatabase return $result; } - public function getDatabaseName(): string - { + public function getDatabaseName(): string { return $this->database_name; } - public function getId(): int - { + public function getId(): int { return $this->id; } - public function getCompanyId(): int - { + public function getCompanyId(): int { return $this->company_id; } } diff --git a/src/backend/app/Models/CompanyJob.php b/src/backend/app/Models/CompanyJob.php index ce9c9089d..b7d8dabbc 100644 --- a/src/backend/app/Models/CompanyJob.php +++ b/src/backend/app/Models/CompanyJob.php @@ -4,15 +4,15 @@ use App\Models\Base\BaseModelCore; -class CompanyJob extends BaseModelCore -{ +class CompanyJob extends BaseModelCore { public const STATUS_PENDING = 0; + public const STATUS_SUCCESS = 1; + public const STATUS_FAILED = -1; // has one company - public function company() - { + public function company() { return $this->belongsTo(Company::class); } } diff --git a/src/backend/app/Models/ConnectionGroup.php b/src/backend/app/Models/ConnectionGroup.php index ebf0ed231..4a01a3744 100644 --- a/src/backend/app/Models/ConnectionGroup.php +++ b/src/backend/app/Models/ConnectionGroup.php @@ -9,15 +9,12 @@ /** * Class ConnectionGroup. */ -class ConnectionGroup extends BaseModel -{ - public function meterParameters(): HasMany - { +class ConnectionGroup extends BaseModel { + public function meterParameters(): HasMany { return $this->hasMany(MeterParameter::class); } - public function meterParametersCount($till) - { + public function meterParametersCount($till) { return $this->meterParameters() ->selectRaw('connection_group_id, count(*) as aggregate') ->where('created_at', '<=', $till) diff --git a/src/backend/app/Models/ConnectionType.php b/src/backend/app/Models/ConnectionType.php index 0ff6aea12..c051b2a02 100644 --- a/src/backend/app/Models/ConnectionType.php +++ b/src/backend/app/Models/ConnectionType.php @@ -13,36 +13,30 @@ * * @property string $name */ -class ConnectionType extends BaseModel -{ - public function subTargets(): HasMany - { +class ConnectionType extends BaseModel { + public function subTargets(): HasMany { return $this->hasMany(SubTarget::class); } - public function meterParameters(): HasMany - { + public function meterParameters(): HasMany { return $this->hasMany(MeterParameter::class); } - public function meterParametersCount($till) - { + public function meterParametersCount($till) { return $this->meterParameters() ->selectRaw('connection_type_id, count(*) as aggregate') ->where('created_at', '<=', $till) ->groupBy('connection_type_id'); } - public function numberOfConnections(): Collection - { + public function numberOfConnections(): Collection { return DB::connection('shard')->table('meter_parameters') ->select(DB::connection('shard')->raw('connection_type_id, count(id) as total')) ->groupBy('connection_type_id') ->get(); } - public function subConnections(): HasMany - { + public function subConnections(): HasMany { return $this->hasMany(SubConnectionType::class); } } diff --git a/src/backend/app/Models/Country.php b/src/backend/app/Models/Country.php index 4f3fa2088..fd00e7f0d 100644 --- a/src/backend/app/Models/Country.php +++ b/src/backend/app/Models/Country.php @@ -5,18 +5,12 @@ use App\Models\Base\BaseModel; use Illuminate\Database\Eloquent\Relations\HasMany; -class Country extends BaseModel -{ - /** - * @return string - */ - public function getRouteKeyName(): string - { +class Country extends BaseModel { + public function getRouteKeyName(): string { return 'country_code'; } - public function cities(): HasMany - { + public function cities(): HasMany { return $this->hasMany(City::class); } } diff --git a/src/backend/app/Models/CustomerGroup.php b/src/backend/app/Models/CustomerGroup.php index a0fa71081..878a36de1 100644 --- a/src/backend/app/Models/CustomerGroup.php +++ b/src/backend/app/Models/CustomerGroup.php @@ -8,15 +8,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; -class CustomerGroup extends BaseModel -{ - public function tariff(): BelongsTo - { +class CustomerGroup extends BaseModel { + public function tariff(): BelongsTo { return $this->belongsTo(MeterTariff::class); } - public function customers(): HasMany - { + public function customers(): HasMany { return $this->hasMany(Person::class); } } diff --git a/src/backend/app/Models/DatabaseProxy.php b/src/backend/app/Models/DatabaseProxy.php index ddfd19060..d47f08282 100644 --- a/src/backend/app/Models/DatabaseProxy.php +++ b/src/backend/app/Models/DatabaseProxy.php @@ -11,14 +11,14 @@ /** * @property int $fk_company_id */ -class DatabaseProxy extends BaseModelCore -{ +class DatabaseProxy extends BaseModelCore { public const COL_DATABASE_CONNECTION = 'database_connection'; + public const COL_COMPANY_ID = 'fk_company_id'; + public const COL_EMAIL = 'email'; - private function buildQuery(?int $companyId = null): Builder - { + private function buildQuery(?int $companyId = null): Builder { $query = $this->newQuery(); if ($companyId) { @@ -28,8 +28,7 @@ private function buildQuery(?int $companyId = null): Builder return $query; } - public function findByEmail(string $email): DatabaseProxy - { + public function findByEmail(string $email): DatabaseProxy { /** @var DatabaseProxy $result */ $result = $this->buildQuery() ->join(CompanyDatabase::TABLE_NAME, CompanyDatabase::COL_COMPANY_ID, '=', self::COL_COMPANY_ID) @@ -39,8 +38,7 @@ public function findByEmail(string $email): DatabaseProxy return $result; } - public function findByCompanyId(int $companyId): DatabaseProxy - { + public function findByCompanyId(int $companyId): DatabaseProxy { /** @var DatabaseProxy $result */ $result = $this->buildQuery($companyId) ->select(CompanyDatabase::COL_DATABASE_NAME) @@ -49,18 +47,15 @@ public function findByCompanyId(int $companyId): DatabaseProxy return $result; } - public function getCompanyId(): int - { + public function getCompanyId(): int { return $this->fk_company_id; } - public function company(): BelongsTo - { + public function company(): BelongsTo { return $this->belongsTo(Company::class, 'fk_company_id'); } - public function companyDatabase(): BelongsTo - { + public function companyDatabase(): BelongsTo { return $this->belongsTo(CompanyDatabase::class, 'fk_company_database_id'); } } diff --git a/src/backend/app/Models/Device.php b/src/backend/app/Models/Device.php index 0c356560d..4aedeae21 100644 --- a/src/backend/app/Models/Device.php +++ b/src/backend/app/Models/Device.php @@ -11,8 +11,7 @@ use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphTo; -class Device extends BaseModel -{ +class Device extends BaseModel { use HasFactory; public const RELATION_NAME = 'device'; @@ -22,23 +21,19 @@ class Device extends BaseModel // but they are completely different things. // `id` is this device's... well... id, which it can be references with in the `device` table // `device_id` is the `id` in the target table depending on type. For example `meter` or `solar_home_system`. - public function device(): MorphTo - { + public function device(): MorphTo { return $this->morphTo(); } - public function person(): BelongsTo - { + public function person(): BelongsTo { return $this->belongsTo(Person::class); } - public function address(): MorphOne - { + public function address(): MorphOne { return $this->morphOne(Address::class, 'owner'); } - public function appliance(): HasOne - { + public function appliance(): HasOne { return $this->hasOne(Asset::class, 'device_serial', 'device_serial'); } } diff --git a/src/backend/app/Models/EBike.php b/src/backend/app/Models/EBike.php index 0b3839223..b0c9769fc 100644 --- a/src/backend/app/Models/EBike.php +++ b/src/backend/app/Models/EBike.php @@ -6,23 +6,20 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphOne; -class EBike extends BaseModel -{ +class EBike extends BaseModel { public const RELATION_NAME = 'e_bike'; + protected $table = 'e_bikes'; - public function device(): MorphOne - { + public function device(): MorphOne { return $this->morphOne(Device::class, 'device'); } - public function manufacturer(): BelongsTo - { + public function manufacturer(): BelongsTo { return $this->belongsTo(Manufacturer::class); } - public function appliance(): BelongsTo - { + public function appliance(): BelongsTo { return $this->belongsTo(Asset::class, 'asset_id', 'id'); } } diff --git a/src/backend/app/Models/GeographicalInformation.php b/src/backend/app/Models/GeographicalInformation.php index 759693f75..15a2f64c4 100644 --- a/src/backend/app/Models/GeographicalInformation.php +++ b/src/backend/app/Models/GeographicalInformation.php @@ -11,14 +11,12 @@ * * @property string $points */ -class GeographicalInformation extends BaseModel -{ +class GeographicalInformation extends BaseModel { use HasFactory; protected $table = 'geographical_informations'; - public function owner(): MorphTo - { + public function owner(): MorphTo { return $this->morphTo(); } } diff --git a/src/backend/app/Models/History.php b/src/backend/app/Models/History.php index 85ff55636..feaafe331 100644 --- a/src/backend/app/Models/History.php +++ b/src/backend/app/Models/History.php @@ -13,14 +13,14 @@ * @property string $field the affected field. Only required for the update action * @property string $content; */ -class History extends BaseModel -{ +class History extends BaseModel { public const ACTION_CREATED = 'create'; + public const ACTION_UPDATE = 'update'; + public const ACTION_DELETE = 'delete'; - public function target(): MorphTo - { + public function target(): MorphTo { return $this->morphTo(); } } diff --git a/src/backend/app/Models/Loan/Loan.php b/src/backend/app/Models/Loan/Loan.php index e163857fd..12610572d 100644 --- a/src/backend/app/Models/Loan/Loan.php +++ b/src/backend/app/Models/Loan/Loan.php @@ -6,11 +6,9 @@ use App\Models\PaymentHistory; use Illuminate\Database\Eloquent\Relations\HasMany; -class Loan extends BaseModel -{ +class Loan extends BaseModel { // related payment histories which are made for that loan - public function paymentHistories(): HasMany - { + public function paymentHistories(): HasMany { return $this->hasMany(PaymentHistory::class); } } diff --git a/src/backend/app/Models/Loan/LoanableInterface.php b/src/backend/app/Models/Loan/LoanableInterface.php index 916425d39..2a5551322 100644 --- a/src/backend/app/Models/Loan/LoanableInterface.php +++ b/src/backend/app/Models/Loan/LoanableInterface.php @@ -2,7 +2,6 @@ namespace App\Models\Loan; -interface LoanableInterface -{ +interface LoanableInterface { public function loans(); } diff --git a/src/backend/app/Models/Log.php b/src/backend/app/Models/Log.php index 287ab2326..49718eb34 100644 --- a/src/backend/app/Models/Log.php +++ b/src/backend/app/Models/Log.php @@ -6,15 +6,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphTo; -class Log extends BaseModel -{ - public function owner(): BelongsTo - { +class Log extends BaseModel { + public function owner(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } - public function affected(): MorphTo - { + public function affected(): MorphTo { return $this->morphTo(); } } diff --git a/src/backend/app/Models/MailSettings.php b/src/backend/app/Models/MailSettings.php index 7168b56bd..e3e6a16a7 100644 --- a/src/backend/app/Models/MailSettings.php +++ b/src/backend/app/Models/MailSettings.php @@ -7,6 +7,4 @@ /** * Class MailSettings. */ -class MailSettings extends BaseModel -{ -} +class MailSettings extends BaseModel {} diff --git a/src/backend/app/Models/MainSettings.php b/src/backend/app/Models/MainSettings.php index d64c2a842..6557fc307 100644 --- a/src/backend/app/Models/MainSettings.php +++ b/src/backend/app/Models/MainSettings.php @@ -16,6 +16,4 @@ * @property float $vat_energy * @property float $vat_appliance * */ -class MainSettings extends BaseModel -{ -} +class MainSettings extends BaseModel {} diff --git a/src/backend/app/Models/MaintenanceUsers.php b/src/backend/app/Models/MaintenanceUsers.php index 6177e9aa8..9385ad110 100644 --- a/src/backend/app/Models/MaintenanceUsers.php +++ b/src/backend/app/Models/MaintenanceUsers.php @@ -8,22 +8,18 @@ use Illuminate\Database\Eloquent\Relations\MorphMany; use Inensus\Ticket\Models\Ticket; -class MaintenanceUsers extends BaseModel -{ +class MaintenanceUsers extends BaseModel { public const RELATION_NAME = 'maintenance_user'; - public function person(): BelongsTo - { + public function person(): BelongsTo { return $this->belongsTo(Person::class); } - public function miniGrid(): BelongsTo - { + public function miniGrid(): BelongsTo { return $this->belongsTo(MiniGrid::class, 'mini_grid_id', 'id'); } - public function tickets(): MorphMany - { + public function tickets(): MorphMany { return $this->morphMany(Ticket::class, 'owner'); } } diff --git a/src/backend/app/Models/Manufacturer.php b/src/backend/app/Models/Manufacturer.php index 412739b6b..89150c828 100644 --- a/src/backend/app/Models/Manufacturer.php +++ b/src/backend/app/Models/Manufacturer.php @@ -7,17 +7,16 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\MorphMany; -class Manufacturer extends BaseModel -{ +class Manufacturer extends BaseModel { use HasFactory; public const RELATION_NAME = 'manufacturer'; protected $hidden = ['api_name']; + protected $guarded = []; - public function address(): MorphMany - { + public function address(): MorphMany { return $this->morphMany(Address::class, 'owner'); } } diff --git a/src/backend/app/Models/MapSettings.php b/src/backend/app/Models/MapSettings.php index dbb4ea829..3bac61711 100644 --- a/src/backend/app/Models/MapSettings.php +++ b/src/backend/app/Models/MapSettings.php @@ -12,6 +12,4 @@ * @property float $latitude * @property float $longitude */ -class MapSettings extends BaseModel -{ -} +class MapSettings extends BaseModel {} diff --git a/src/backend/app/Models/Meter/Meter.php b/src/backend/app/Models/Meter/Meter.php index 1443b008c..306573fa8 100644 --- a/src/backend/app/Models/Meter/Meter.php +++ b/src/backend/app/Models/Meter/Meter.php @@ -21,83 +21,71 @@ * @property MeterTariff $tariff * @property bool $in_use */ -class Meter extends BaseModel -{ +class Meter extends BaseModel { use HasFactory; public const RELATION_NAME = 'meter'; + protected $guarded = []; + public static $rules = [ 'serial_number' => 'required|min:1|unique:meters', 'meter_type_id' => 'exists:shard.meter_types,id', 'manufacturer_id' => 'exists:shard.manufacturers,id', ]; - public function meterType(): BelongsTo - { + public function meterType(): BelongsTo { return $this->belongsTo(MeterType::class); } - public function device(): MorphOne - { + public function device(): MorphOne { return $this->morphOne(Device::class, 'device'); } - public function manufacturer(): BelongsTo - { + public function manufacturer(): BelongsTo { return $this->belongsTo(Manufacturer::class); } - public function tariff(): BelongsTo - { + public function tariff(): BelongsTo { return $this->belongsTo(MeterTariff::class); } - public function connectionType(): BelongsTo - { + public function connectionType(): BelongsTo { return $this->belongsTo(ConnectionType::class, 'connection_type_id', 'id'); } - public function connectionGroup(): BelongsTo - { + public function connectionGroup(): BelongsTo { return $this->belongsTo(ConnectionGroup::class); } - public function accessRatePayment(): HasOne - { + public function accessRatePayment(): HasOne { return $this->hasOne(AccessRatePayment::class); } - public function accessRate(): AccessRate - { + public function accessRate(): AccessRate { return $this->tariff->accessRate; } - public function tokens(): HasMany - { + public function tokens(): HasMany { return $this->hasMany(MeterToken::class); } - public function consumptions(): HasMany - { + public function consumptions(): HasMany { return $this->hasMany(MeterConsumption::class); } - public function transactions(): HasMany - { + public function transactions(): HasMany { return $this->hasMany(Transaction::class, 'message', 'serial_number'); } - public function findBySerialNumber(string $meterSerialNumber): ?self - { + public function findBySerialNumber(string $meterSerialNumber): ?self { /** @var Meter|null $result */ $result = $this->newQuery()->where('serial_number', '=', $meterSerialNumber)->first(); return $result; } - public function getId(): int - { + public function getId(): int { return $this->id; } } diff --git a/src/backend/app/Models/Meter/MeterConsumption.php b/src/backend/app/Models/Meter/MeterConsumption.php index d922b5bd8..ddf09869f 100644 --- a/src/backend/app/Models/Meter/MeterConsumption.php +++ b/src/backend/app/Models/Meter/MeterConsumption.php @@ -15,17 +15,14 @@ * @property float $credit_on_meter * @property string $reading_date */ -class MeterConsumption extends BaseModel -{ +class MeterConsumption extends BaseModel { protected $table = 'meter_consumptions'; - public function meter(): BelongsTo - { + public function meter(): BelongsTo { return $this->belongsTo(Meter::class); } - public function __toString() - { + public function __toString() { return 'Meter : '.$this->meter_id.' consumption : '.$this->total_consumption. ' credit :'.$this->credit_on_meter; } diff --git a/src/backend/app/Models/Meter/MeterParameter.php b/src/backend/app/Models/Meter/MeterParameter.php index f4076bbf6..e698ec857 100644 --- a/src/backend/app/Models/Meter/MeterParameter.php +++ b/src/backend/app/Models/Meter/MeterParameter.php @@ -27,39 +27,34 @@ * @property int tariff_access_rate_id * @property MeterTariff $tariff */ -class MeterParameter extends BaseModel -{ +class MeterParameter extends BaseModel { public const RELATION_NAME = 'meter_parameter'; + protected $hidden = ['owner_id', 'owner_type', 'meter_id', 'tariff_id']; + protected $guarded = []; - public function connectionType(): BelongsTo - { + public function connectionType(): BelongsTo { return $this->belongsTo(ConnectionType::class, 'connection_type_id', 'id'); } - public function tariff(): BelongsTo - { + public function tariff(): BelongsTo { return $this->belongsTo(MeterTariff::class); } - public function tariffAccessRate(): ?AccessRate - { + public function tariffAccessRate(): ?AccessRate { return $this->tariff->accessRate; } - public function meter(): BelongsTo - { + public function meter(): BelongsTo { return $this->belongsTo(Meter::class); } - public function owner(): MorphTo - { + public function owner(): MorphTo { return $this->morphTo(); } - public function geo(): MorphOne - { + public function geo(): MorphOne { return $this->morphOne(GeographicalInformation::class, 'owner'); } @@ -68,24 +63,20 @@ public function geo(): MorphOne * * @psalm-return non-empty-list */ - public function latLon(): array - { + public function latLon(): array { return explode(',', $this->geo()->first()->points ?? '0.0,0.0'); } // the address where the meter is placed - public function address(): MorphOne - { + public function address(): MorphOne { return $this->morphOne(Address::class, 'owner'); } - public function connectionGroup(): BelongsTo - { + public function connectionGroup(): BelongsTo { return $this->belongsTo(ConnectionGroup::class); } - public function socialTariffPiggyBank(): HasOne - { + public function socialTariffPiggyBank(): HasOne { return $this->hasOne(SocialTariffPiggyBank::class); } } diff --git a/src/backend/app/Models/Meter/MeterTariff.php b/src/backend/app/Models/Meter/MeterTariff.php index a1a986a4b..8db28565e 100644 --- a/src/backend/app/Models/Meter/MeterTariff.php +++ b/src/backend/app/Models/Meter/MeterTariff.php @@ -24,52 +24,47 @@ * @property int|null $factor * @property AccessRate $accessRate */ -class MeterTariff extends BaseModel -{ - use SoftDeletes; +class MeterTariff extends BaseModel { use HasFactory; + use SoftDeletes; public const RELATION_NAME = 'meter_tariff'; + public const DEFAULT_FACTOR = 1; // for energy usage + public const SHS_FACTOR = 2; // for shs usage protected $table = 'meter_tariffs'; + protected $guarded = []; - public function meterParameter(): HasMany - { + public function meterParameter(): HasMany { return $this->hasMany(MeterParameter::class, 'tariff_id'); } - public function meterParametersCount() - { + public function meterParametersCount() { return $this->meterParameter() ->selectRaw('tariff_id, count(*) as aggregate') ->groupBy('tariff_id'); } - public function customerGroups(): HasMany - { + public function customerGroups(): HasMany { return $this->hasMany(CustomerGroup::class, 'tariff_id'); } - public function accessRate(): HasOne - { + public function accessRate(): HasOne { return $this->hasOne(AccessRate::class, 'tariff_id'); } - public function pricingComponent(): MorphMany - { + public function pricingComponent(): MorphMany { return $this->morphMany(TariffPricingComponent::class, 'owner'); } - public function socialTariff(): HasOne - { + public function socialTariff(): HasOne { return $this->hasOne(SocialTariff::class, 'tariff_id'); } - public function tou(): HasMany - { + public function tou(): HasMany { return $this->hasMany(TimeOfUsage::class, 'tariff_id'); } } diff --git a/src/backend/app/Models/Meter/MeterToken.php b/src/backend/app/Models/Meter/MeterToken.php index 1a0fc809d..bd9307b0e 100644 --- a/src/backend/app/Models/Meter/MeterToken.php +++ b/src/backend/app/Models/Meter/MeterToken.php @@ -16,34 +16,28 @@ * @property string $token * @property float $energy */ -class MeterToken extends BaseModel -{ +class MeterToken extends BaseModel { public const RELATION_NAME = 'meter_token'; - public function transaction(): BelongsTo - { + public function transaction(): BelongsTo { return $this->belongsTo(Transaction::class); } - public function meter(): BelongsTo - { + public function meter(): BelongsTo { return $this->belongsTo(Meter::class); } - public function __toString(): string - { + public function __toString(): string { return 'Token: '.$this->token.' for '.$this->energy.'kWh'; } - public function paymentHistories(): MorphOne - { + public function paymentHistories(): MorphOne { return $this->morphOne(PaymentHistory::class, 'paid_for'); } - public function soldEnergyPerPeriod($startDate, $endDate): Builder - { + public function soldEnergyPerPeriod($startDate, $endDate): Builder { return $this::query() - ->select(DB::raw(' SUM( energy) as sold,YEARWEEK(created_at,3) as period')) + ->select(DB::raw(' SUM( energy) as sold,YEARWEEK(created_at,3) as period')) ->whereBetween('created_at', [$startDate, $endDate]) ->groupBy(DB::raw('YEARWEEK(created_at,3)')); } diff --git a/src/backend/app/Models/Meter/MeterType.php b/src/backend/app/Models/Meter/MeterType.php index 4393e3b3d..495f2d865 100644 --- a/src/backend/app/Models/Meter/MeterType.php +++ b/src/backend/app/Models/Meter/MeterType.php @@ -12,8 +12,7 @@ * @property string $phase * @property int $max_current */ -class MeterType extends BaseModel -{ +class MeterType extends BaseModel { use HasFactory; public static $rules = [ @@ -22,13 +21,11 @@ class MeterType extends BaseModel 'max_current' => 'required', ]; - public function meters(): HasMany - { + public function meters(): HasMany { return $this->hasMany(Meter::class); } - public function __toString() - { + public function __toString() { return sprintf( '%s Phase, %s Amper, Online: %s', $this->phase, diff --git a/src/backend/app/Models/MiniGrid.php b/src/backend/app/Models/MiniGrid.php index e4347b37c..e3d28d590 100644 --- a/src/backend/app/Models/MiniGrid.php +++ b/src/backend/app/Models/MiniGrid.php @@ -19,45 +19,38 @@ * @property int $cluster_id * @property Collection $cities */ -class MiniGrid extends BaseModel implements TargetAssignable -{ +class MiniGrid extends BaseModel implements TargetAssignable { use HasFactory; public const RELATION_NAME = 'mini-grid'; + protected $guarded = []; - public function cities(): HasMany - { + public function cities(): HasMany { return $this->hasMany(City::class); } - public function cluster(): BelongsTo - { + public function cluster(): BelongsTo { return $this->belongsTo(Cluster::class); } - public function location(): MorphOne - { + public function location(): MorphOne { return $this->morphOne(GeographicalInformation::class, 'owner'); } - public function agent(): HasOne - { + public function agent(): HasOne { return $this->hasOne(Agent::class); } - public function setClusterId(int $clusterId): void - { + public function setClusterId(int $clusterId): void { $this->cluster_id = $clusterId; } - public function setName(string $name): void - { + public function setName(string $name): void { $this->name = $name; } - public function getClusterId(): int - { + public function getClusterId(): int { return $this->cluster_id; } } diff --git a/src/backend/app/Models/MpmPlugin.php b/src/backend/app/Models/MpmPlugin.php index 8e4104b72..4bd219597 100644 --- a/src/backend/app/Models/MpmPlugin.php +++ b/src/backend/app/Models/MpmPlugin.php @@ -9,32 +9,46 @@ * @property string|null $tail_tag * @property string|null $installation_command */ -class MpmPlugin extends BaseModelCore -{ +class MpmPlugin extends BaseModelCore { use HasFactory; public const SPARK_METER = 1; + public const STEAMACO_METER = 2; + public const CALIN_METER = 3; + public const CALIN_SMART_METER = 4; + public const KELIN_METER = 5; + public const STRON_METER = 6; + public const SWIFTA_PAYMENT_PROVIDER = 7; + public const MESOMB_PAYMENT_PROVIDER = 8; + public const BULK_REGISTRATION = 9; + public const VIBER_MESSAGING = 10; + public const WAVE_MONEY_PAYMENT_PROVIDER = 11; + public const MICRO_STAR_METERS = 12; + public const SUN_KING_SHS = 13; + public const GOME_LONG_METERS = 14; + public const WAVECOM_PAYMENT_PROVIDER = 15; + public const DALY_BMS = 16; + public const AGAZA_SHS = 17; protected $table = 'mpm_plugins'; - public function plugins() - { + public function plugins() { return $this->hasMany(Plugins::class); } } diff --git a/src/backend/app/Models/Payment/PaymentProfile.php b/src/backend/app/Models/Payment/PaymentProfile.php index a236f88d4..dc2b491fa 100644 --- a/src/backend/app/Models/Payment/PaymentProfile.php +++ b/src/backend/app/Models/Payment/PaymentProfile.php @@ -4,6 +4,4 @@ use App\Models\Base\BaseModel; -class PaymentProfile extends BaseModel -{ -} +class PaymentProfile extends BaseModel {} diff --git a/src/backend/app/Models/PaymentHistory.php b/src/backend/app/Models/PaymentHistory.php index 6601fa629..7db95fdfb 100644 --- a/src/backend/app/Models/PaymentHistory.php +++ b/src/backend/app/Models/PaymentHistory.php @@ -20,25 +20,20 @@ * @property string payment_type * @property int transaction_id */ -class PaymentHistory extends BaseModel -{ - public function paidFor(): MorphTo - { +class PaymentHistory extends BaseModel { + public function paidFor(): MorphTo { return $this->morphTo(); } - public function payer(): MorphTo - { + public function payer(): MorphTo { return $this->morphTo(); } - public function transaction(): BelongsTo - { + public function transaction(): BelongsTo { return $this->belongsTo(Transaction::class); } - public function getFlow(string $payer_type, int $payer_id, string $period, $limit = null, string $order = 'ASC') - { + public function getFlow(string $payer_type, int $payer_id, string $period, $limit = null, string $order = 'ASC') { $sql = 'SELECT sum(amount) as amount, payment_type, CONCAT_WS("/", '.$period.') as aperiod from'. ' payment_histories where payer_id=:payer_id and payer_type=:payer_type '. 'GROUP by concat( '.$period.'), payment_type ORDER BY created_at '.$order; @@ -50,8 +45,7 @@ public function getFlow(string $payer_type, int $payer_id, string $period, $limi return $this->executeSqlCommand($sql, $payer_id, null, $payer_type); } - public function getAgentCustomersFlow(string $payer_type, $agent_id, string $period, $limit = null, $order = 'ASC') - { + public function getAgentCustomersFlow(string $payer_type, $agent_id, string $period, $limit = null, $order = 'ASC') { $sql = 'SELECT sum(amount) as amount, payment_type, CONCAT_WS("/", '.$period.') as aperiod '. 'from payment_histories inner join addresses on payment_histories.payer_id = addresses.owner_id '. 'inner JOIN cities on addresses.city_id=cities.id inner JOIN mini_grids on '. @@ -67,8 +61,7 @@ public function getAgentCustomersFlow(string $payer_type, $agent_id, string $per return $this->executeSqlCommand($sql, null, $agent_id, $payer_type); } - public function getPaymentFlow(string $payer_type, int $payer_id, int $year) - { + public function getPaymentFlow(string $payer_type, int $payer_id, int $year) { $sql = 'SELECT sum(amount) as amount, MONTH(created_at) as month from payment_histories where'. ' payer_id=:payer_id and payer_type=:payer_type and '. 'YEAR(created_at)=:year group by MONTH(created_at) order by MONTH(created_at) '; @@ -87,8 +80,7 @@ public function getPaymentFlow(string $payer_type, int $payer_id, int $year) * @param Request|array|string $begin * @param Request|array|string $end */ - public function getOverview($begin, $end) - { + public function getOverview($begin, $end) { $sql = 'SELECT sum(amount) as total, DATE_FORMAT(created_at, "%Y-%m-%d")'. ' as dato from payment_histories where DATE(created_at) >= DATE(\''.$begin.'\') '. 'and DATE(created_at)<= DATE(\''.$end.'\') group by dato'; @@ -99,8 +91,7 @@ public function getOverview($begin, $end) return $results; } - private function executeSqlCommand(string $sql, $payer_id, $agent_id, $payer_type) - { + private function executeSqlCommand(string $sql, $payer_id, $agent_id, $payer_type) { $sth = DB::connection('shard')->getPdo()->prepare($sql); if ($payer_id) { $sth->bindValue(':payer_id', $payer_id, \PDO::PARAM_INT); diff --git a/src/backend/app/Models/Person/Person.php b/src/backend/app/Models/Person/Person.php index 92840e38d..5b2b39e18 100644 --- a/src/backend/app/Models/Person/Person.php +++ b/src/backend/app/Models/Person/Person.php @@ -38,10 +38,9 @@ * @property int $nationality * @property int $is_customer */ -class Person extends BaseModel implements HasAddressesInterface, RoleInterface -{ - use SoftDeletes; +class Person extends BaseModel implements HasAddressesInterface, RoleInterface { use HasFactory; + use SoftDeletes; public const RELATION_NAME = 'person'; @@ -55,69 +54,57 @@ class Person extends BaseModel implements HasAddressesInterface, RoleInterface 'deleting' => PersonDeleting::class, ]; - public function tickets(): MorphMany - { + public function tickets(): MorphMany { return $this->morphMany(Ticket::class, 'owner'); } - public function saveAddress(Address $address): void - { + public function saveAddress(Address $address): void { $this->addresses()->save($address); } /** * @return MorphMany */ - public function addresses(): HasOneOrMany - { + public function addresses(): HasOneOrMany { return $this->morphMany(Address::class, 'owner'); } - public function citizenship(): BelongsTo - { + public function citizenship(): BelongsTo { return $this->belongsTo(Country::class, 'nationality', 'id'); } - public function devices(): HasMany - { + public function devices(): HasMany { return $this->hasMany(Device::class); } /** * @return MorphMany */ - public function roleOwner(): HasOneOrMany - { + public function roleOwner(): HasOneOrMany { return $this->morphMany(Roles::class, 'role_owner'); } - public function payments(): MorphMany - { + public function payments(): MorphMany { return $this->morphMany(PaymentHistory::class, 'payer'); } - public function customerGroup(): BelongsTo - { + public function customerGroup(): BelongsTo { return $this->belongsTo(CustomerGroup::class); } - public function agent(): HasOne - { + public function agent(): HasOne { return $this->hasOne(Agent::class); } - public function agentSoldAppliance(): HasOne - { + public function agentSoldAppliance(): HasOne { return $this->hasOne(AgentSoldAppliance::class); } - public function __toString() - { + public function __toString() { return sprintf('%s %s', $this->name, $this->surname); } - public function livingInClusterQuery(int $clusterId) - { + public function livingInClusterQuery(int $clusterId) { return DB::table($this->getTable()) ->select('people.id') ->leftJoin('addresses', function (JoinClause $q) { @@ -135,8 +122,7 @@ public function livingInClusterQuery(int $clusterId) ->orderBy('cities.id'); } - public function getId(): int - { + public function getId(): int { return $this->id; } } diff --git a/src/backend/app/Models/PersonDocument.php b/src/backend/app/Models/PersonDocument.php index aa80760a9..3cc302ed0 100644 --- a/src/backend/app/Models/PersonDocument.php +++ b/src/backend/app/Models/PersonDocument.php @@ -5,10 +5,8 @@ use App\Models\Base\BaseModel; use App\Models\Person\Person; -class PersonDocument extends BaseModel -{ - public function person() - { +class PersonDocument extends BaseModel { + public function person() { return $this->belongsTo(Person::class); } } diff --git a/src/backend/app/Models/Plugins.php b/src/backend/app/Models/Plugins.php index bec300114..fbe32de69 100644 --- a/src/backend/app/Models/Plugins.php +++ b/src/backend/app/Models/Plugins.php @@ -4,8 +4,8 @@ use App\Models\Base\BaseModel; -class Plugins extends BaseModel -{ +class Plugins extends BaseModel { public const ACTIVE = 1; + public const INACTIVE = 0; } diff --git a/src/backend/app/Models/ProtectedPage.php b/src/backend/app/Models/ProtectedPage.php index 317acb440..7a23ce048 100644 --- a/src/backend/app/Models/ProtectedPage.php +++ b/src/backend/app/Models/ProtectedPage.php @@ -5,8 +5,7 @@ use App\Models\Base\BaseModelCore; use Illuminate\Database\Eloquent\Factories\HasFactory; -class ProtectedPage extends BaseModelCore -{ +class ProtectedPage extends BaseModelCore { use HasFactory; protected $table = 'protected_pages'; diff --git a/src/backend/app/Models/RegistrationTail.php b/src/backend/app/Models/RegistrationTail.php index 9bfab53ef..b0ce0438c 100644 --- a/src/backend/app/Models/RegistrationTail.php +++ b/src/backend/app/Models/RegistrationTail.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class RegistrationTail extends BaseModel -{ +class RegistrationTail extends BaseModel { protected $table = 'registration_tail'; } diff --git a/src/backend/app/Models/Report.php b/src/backend/app/Models/Report.php index 2b4d2e9a2..b8a0d225b 100644 --- a/src/backend/app/Models/Report.php +++ b/src/backend/app/Models/Report.php @@ -13,6 +13,4 @@ * @property string $path * @property string $type */ -class Report extends BaseModel -{ -} +class Report extends BaseModel {} diff --git a/src/backend/app/Models/Restriction.php b/src/backend/app/Models/Restriction.php index 98bd99ed2..bbe78d6b0 100644 --- a/src/backend/app/Models/Restriction.php +++ b/src/backend/app/Models/Restriction.php @@ -13,10 +13,8 @@ * @property int $default * @property int $limit */ -class Restriction extends BaseModel -{ - public function upgrades(): HasMany - { +class Restriction extends BaseModel { + public function upgrades(): HasMany { return $this->hasMany(Upgrade::class); } } diff --git a/src/backend/app/Models/Revenue.php b/src/backend/app/Models/Revenue.php index c4a57af0f..661250b29 100644 --- a/src/backend/app/Models/Revenue.php +++ b/src/backend/app/Models/Revenue.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class Revenue extends BaseModel -{ +class Revenue extends BaseModel { protected $table = 'revenues'; } diff --git a/src/backend/app/Models/Role/RoleDefinition.php b/src/backend/app/Models/Role/RoleDefinition.php index fcfd9d8e2..c05dcf8e9 100644 --- a/src/backend/app/Models/Role/RoleDefinition.php +++ b/src/backend/app/Models/Role/RoleDefinition.php @@ -4,13 +4,12 @@ use App\Models\Base\BaseModel; -class RoleDefinition extends BaseModel -{ +class RoleDefinition extends BaseModel { public $timestamps = false; + protected $connection = 'micro_power_manager'; - public function roles(): void - { + public function roles(): void { $this->hasMany(Roles::class); } } diff --git a/src/backend/app/Models/Role/RoleInterface.php b/src/backend/app/Models/Role/RoleInterface.php index 010b7f713..6ac7537d1 100644 --- a/src/backend/app/Models/Role/RoleInterface.php +++ b/src/backend/app/Models/Role/RoleInterface.php @@ -4,7 +4,6 @@ use Illuminate\Database\Eloquent\Relations\HasOneOrMany; -interface RoleInterface -{ +interface RoleInterface { public function roleOwner(): HasOneOrMany; } diff --git a/src/backend/app/Models/Role/Roles.php b/src/backend/app/Models/Role/Roles.php index 534e542e5..bb3514bc7 100644 --- a/src/backend/app/Models/Role/Roles.php +++ b/src/backend/app/Models/Role/Roles.php @@ -6,20 +6,14 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphTo; -class Roles extends BaseModel -{ +class Roles extends BaseModel { protected $connection = 'micro_power_manager'; - /** - * @return BelongsTo - */ - public function definitions(): BelongsTo - { + public function definitions(): BelongsTo { return $this->belongsTo(RoleDefinition::class, 'role_definition_id'); } - public function roleOwner(): MorphTo - { + public function roleOwner(): MorphTo { return $this->morphTo(); } } diff --git a/src/backend/app/Models/Sms.php b/src/backend/app/Models/Sms.php index 36cbdbf81..f3947ad0a 100644 --- a/src/backend/app/Models/Sms.php +++ b/src/backend/app/Models/Sms.php @@ -20,15 +20,12 @@ * @property int $direction * @property int $sender_id */ -class Sms extends BaseModel -{ - public function trigger(): MorphTo - { +class Sms extends BaseModel { + public function trigger(): MorphTo { return $this->morphTo(); } - public function address(): BelongsTo - { + public function address(): BelongsTo { return $this->belongsTo(Address::class, 'receiver', 'phone'); } } diff --git a/src/backend/app/Models/SmsAndroidSetting.php b/src/backend/app/Models/SmsAndroidSetting.php index bae1bea8a..cb25957a0 100644 --- a/src/backend/app/Models/SmsAndroidSetting.php +++ b/src/backend/app/Models/SmsAndroidSetting.php @@ -9,12 +9,10 @@ /** * @property int $id */ -class SmsAndroidSetting extends BaseModel -{ +class SmsAndroidSetting extends BaseModel { protected $table = 'sms_android_settings'; - public static function getResponsible() - { + public static function getResponsible() { $smsAndroidSettings = SmsAndroidSetting::all(); if ($smsAndroidSettings->count()) { try { @@ -30,8 +28,7 @@ public static function getResponsible() } } - public function getId(): int - { + public function getId(): int { return $this->id; } } diff --git a/src/backend/app/Models/SmsApplianceRemindRate.php b/src/backend/app/Models/SmsApplianceRemindRate.php index eb2227c75..86de310fb 100644 --- a/src/backend/app/Models/SmsApplianceRemindRate.php +++ b/src/backend/app/Models/SmsApplianceRemindRate.php @@ -5,12 +5,10 @@ use App\Models\Base\BaseModel; use Illuminate\Database\Eloquent\Relations\BelongsTo; -class SmsApplianceRemindRate extends BaseModel -{ +class SmsApplianceRemindRate extends BaseModel { protected $table = 'sms_appliance_remind_rates'; - public function appliance(): BelongsTo - { + public function appliance(): BelongsTo { return $this->belongsTo(Asset::class, 'appliance_id', 'id'); } } diff --git a/src/backend/app/Models/SmsBody.php b/src/backend/app/Models/SmsBody.php index aa9192723..f3bb6840f 100644 --- a/src/backend/app/Models/SmsBody.php +++ b/src/backend/app/Models/SmsBody.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class SmsBody extends BaseModel -{ +class SmsBody extends BaseModel { protected $table = 'sms_bodies'; } diff --git a/src/backend/app/Models/SmsResendInformationKey.php b/src/backend/app/Models/SmsResendInformationKey.php index 2145b3672..a8cc4794c 100644 --- a/src/backend/app/Models/SmsResendInformationKey.php +++ b/src/backend/app/Models/SmsResendInformationKey.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class SmsResendInformationKey extends BaseModel -{ +class SmsResendInformationKey extends BaseModel { protected $table = 'sms_resend_information_keys'; } diff --git a/src/backend/app/Models/SmsVariableDefaultValue.php b/src/backend/app/Models/SmsVariableDefaultValue.php index 5fb11f64d..c406e7788 100644 --- a/src/backend/app/Models/SmsVariableDefaultValue.php +++ b/src/backend/app/Models/SmsVariableDefaultValue.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class SmsVariableDefaultValue extends BaseModel -{ +class SmsVariableDefaultValue extends BaseModel { protected $table = 'sms_variable_default_values'; } diff --git a/src/backend/app/Models/SocialTariff.php b/src/backend/app/Models/SocialTariff.php index 6fcb471fc..fcad1e190 100644 --- a/src/backend/app/Models/SocialTariff.php +++ b/src/backend/app/Models/SocialTariff.php @@ -14,7 +14,6 @@ * @property int $initial_energy_budget * @property int $maximum_stacked_energy */ -class SocialTariff extends BaseModel -{ +class SocialTariff extends BaseModel { protected $guarded = []; } diff --git a/src/backend/app/Models/SocialTariffPiggyBank.php b/src/backend/app/Models/SocialTariffPiggyBank.php index 3deb05a7a..db1454857 100644 --- a/src/backend/app/Models/SocialTariffPiggyBank.php +++ b/src/backend/app/Models/SocialTariffPiggyBank.php @@ -13,17 +13,14 @@ * @property string $owner_type * @property int $savings */ -class SocialTariffPiggyBank extends BaseModel -{ +class SocialTariffPiggyBank extends BaseModel { protected $guarded = []; - public function meter(): BelongsTo - { + public function meter(): BelongsTo { return $this->belongsTo(MeterParameter::class); } - public function socialTariff(): BelongsTo - { + public function socialTariff(): BelongsTo { return $this->belongsTo(SocialTariff::class); } } diff --git a/src/backend/app/Models/SolarHomeSystem.php b/src/backend/app/Models/SolarHomeSystem.php index da5f3de96..a4828773b 100644 --- a/src/backend/app/Models/SolarHomeSystem.php +++ b/src/backend/app/Models/SolarHomeSystem.php @@ -7,25 +7,22 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphOne; -class SolarHomeSystem extends BaseModel -{ +class SolarHomeSystem extends BaseModel { use HasFactory; public const RELATION_NAME = 'solar_home_system'; + protected $table = 'solar_home_systems'; - public function device(): MorphOne - { + public function device(): MorphOne { return $this->morphOne(Device::class, 'device'); } - public function manufacturer(): BelongsTo - { + public function manufacturer(): BelongsTo { return $this->belongsTo(Manufacturer::class); } - public function appliance(): BelongsTo - { + public function appliance(): BelongsTo { return $this->belongsTo(Asset::class, 'asset_id', 'id'); } } diff --git a/src/backend/app/Models/SubConnectionType.php b/src/backend/app/Models/SubConnectionType.php index 79b07263a..607188e4f 100644 --- a/src/backend/app/Models/SubConnectionType.php +++ b/src/backend/app/Models/SubConnectionType.php @@ -8,20 +8,16 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; -class SubConnectionType extends BaseModel -{ - public function connectionType(): BelongsTo - { +class SubConnectionType extends BaseModel { + public function connectionType(): BelongsTo { return $this->belongsTo(ConnectionType::class); } - public function meterParameters(): HasMany - { + public function meterParameters(): HasMany { return $this->hasMany(MeterParameter::class, 'connection_type_id'); } - public function tariff(): BelongsTo - { + public function tariff(): BelongsTo { return $this->belongsTo(MeterTariff::class, 'tariff_id', 'id'); } } diff --git a/src/backend/app/Models/SubTarget.php b/src/backend/app/Models/SubTarget.php index 3db49a4a5..92dfc70ce 100644 --- a/src/backend/app/Models/SubTarget.php +++ b/src/backend/app/Models/SubTarget.php @@ -14,21 +14,12 @@ * @property int $revenue * @property int new_connections */ -class SubTarget extends BaseModel -{ - /** - * @return BelongsTo - */ - public function target(): BelongsTo - { +class SubTarget extends BaseModel { + public function target(): BelongsTo { return $this->belongsTo(Target::class); } - /** - * @return BelongsTo - */ - public function connectionType(): BelongsTo - { + public function connectionType(): BelongsTo { return $this->belongsTo(ConnectionGroup::class, 'connection_id'); } } diff --git a/src/backend/app/Models/Subscription.php b/src/backend/app/Models/Subscription.php index bbc1d7bd2..b2e42f62c 100644 --- a/src/backend/app/Models/Subscription.php +++ b/src/backend/app/Models/Subscription.php @@ -13,10 +13,8 @@ * @property string $expires * @property string $transaction_id */ -class Subscription extends BaseModel -{ - public function upgrade(): BelongsTo - { +class Subscription extends BaseModel { + public function upgrade(): BelongsTo { return $this->belongsTo(Upgrade::class); } } diff --git a/src/backend/app/Models/Target.php b/src/backend/app/Models/Target.php index aa3371560..cedea66ee 100644 --- a/src/backend/app/Models/Target.php +++ b/src/backend/app/Models/Target.php @@ -17,26 +17,16 @@ * @property string $end_date * @property int $city_id */ -class Target extends BaseModel -{ - public function city(): BelongsTo - { +class Target extends BaseModel { + public function city(): BelongsTo { return $this->belongsTo(City::class); } - public function subTargets(): HasMany - { + public function subTargets(): HasMany { return $this->hasMany(SubTarget::class); } - /** - * @param $cityId - * @param string $endDate - * - * @return Builder - */ - public function targetForMiniGrid($cityId, string $endDate): Builder - { + public function targetForMiniGrid($cityId, string $endDate): Builder { return $this::with('subTargets.connectionType', 'city') ->where('owner_id', $cityId) ->where('owner_type', 'mini-grid') @@ -45,8 +35,7 @@ public function targetForMiniGrid($cityId, string $endDate): Builder ->limit(1); } - public function targetForCluster($miniGridIds, string $endDate): Builder - { + public function targetForCluster($miniGridIds, string $endDate): Builder { return $this::query() ->select(DB::raw('*, YEARWEEK(target_date,3) as period')) ->with('subTargets.connectionType', 'city') @@ -56,13 +45,11 @@ public function targetForCluster($miniGridIds, string $endDate): Builder ->orderBy('target_date', 'asc'); } - public function owner(): MorphTo - { + public function owner(): MorphTo { return $this->morphTo(); } - public function periodTargetAlternative($cityId, $startDate): Builder - { + public function periodTargetAlternative($cityId, $startDate): Builder { return $this::query() ->select(DB::raw('*, YEARWEEK(target_date,3) as period'))->with( 'subTargets.connectionType', diff --git a/src/backend/app/Models/TariffPricingComponent.php b/src/backend/app/Models/TariffPricingComponent.php index 73422b6e0..f0ffdee88 100644 --- a/src/backend/app/Models/TariffPricingComponent.php +++ b/src/backend/app/Models/TariffPricingComponent.php @@ -14,12 +14,10 @@ * @property int $owner_id * @property string $owner_type */ -class TariffPricingComponent extends BaseModel -{ +class TariffPricingComponent extends BaseModel { protected $guarded = []; - public function owner(): MorphTo - { + public function owner(): MorphTo { return $this->morphTo(); } } diff --git a/src/backend/app/Models/TicketSettings.php b/src/backend/app/Models/TicketSettings.php index 081c3f385..bbfe4fc1d 100644 --- a/src/backend/app/Models/TicketSettings.php +++ b/src/backend/app/Models/TicketSettings.php @@ -13,6 +13,4 @@ * @property string $api_url * @property string $api_key * */ -class TicketSettings extends BaseModel -{ -} +class TicketSettings extends BaseModel {} diff --git a/src/backend/app/Models/TimeOfUsage.php b/src/backend/app/Models/TimeOfUsage.php index 2227c2c5c..c5d98f62e 100644 --- a/src/backend/app/Models/TimeOfUsage.php +++ b/src/backend/app/Models/TimeOfUsage.php @@ -6,10 +6,8 @@ use App\Models\Meter\MeterTariff; use Illuminate\Database\Eloquent\Relations\BelongsTo; -class TimeOfUsage extends BaseModel -{ - public function tariff(): BelongsTo - { +class TimeOfUsage extends BaseModel { + public function tariff(): BelongsTo { return $this->belongsTo(MeterTariff::class); } } diff --git a/src/backend/app/Models/Token.php b/src/backend/app/Models/Token.php index 52f839fce..4382fcc7d 100644 --- a/src/backend/app/Models/Token.php +++ b/src/backend/app/Models/Token.php @@ -7,17 +7,14 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphOne; -class Token extends BaseModel -{ +class Token extends BaseModel { public const RELATION_NAME = 'token'; - public function transaction(): BelongsTo - { + public function transaction(): BelongsTo { return $this->belongsTo(Transaction::class); } - public function paymentHistories(): MorphOne - { + public function paymentHistories(): MorphOne { return $this->morphOne(PaymentHistory::class, 'paid_for'); } } diff --git a/src/backend/app/Models/Transaction/AgentTransaction.php b/src/backend/app/Models/Transaction/AgentTransaction.php index ac93657bf..8f7255ee6 100644 --- a/src/backend/app/Models/Transaction/AgentTransaction.php +++ b/src/backend/app/Models/Transaction/AgentTransaction.php @@ -16,32 +16,26 @@ * @property int status * @property string sender */ -class AgentTransaction extends BaseModel implements IRawTransaction, FullySupportedTransactionInterface -{ +class AgentTransaction extends BaseModel implements FullySupportedTransactionInterface, IRawTransaction { public const RELATION_NAME = 'agent_transaction'; - public function transaction(): MorphOne - { + public function transaction(): MorphOne { return $this->morphOne(Transaction::class, 'original_transaction'); } - public function manufacturerTransaction(): MorphTo - { + public function manufacturerTransaction(): MorphTo { return $this->morphTo(); } - public function agent(): BelongsTo - { + public function agent(): BelongsTo { return $this->belongsTo(Agent::class); } - public function conflicts(): MorphMany - { + public function conflicts(): MorphMany { return $this->morphMany(TransactionConflicts::class, 'transaction'); } - public static function getTransactionName(): string - { + public static function getTransactionName(): string { return self::RELATION_NAME; } } diff --git a/src/backend/app/Models/Transaction/AirtelTransaction.php b/src/backend/app/Models/Transaction/AirtelTransaction.php index f0c397a80..f541ac289 100644 --- a/src/backend/app/Models/Transaction/AirtelTransaction.php +++ b/src/backend/app/Models/Transaction/AirtelTransaction.php @@ -18,30 +18,22 @@ * @property int $status * @property string $tr_id */ -class AirtelTransaction extends BaseModel implements IRawTransaction, FullySupportedTransactionInterface -{ +class AirtelTransaction extends BaseModel implements FullySupportedTransactionInterface, IRawTransaction { public const RELATION_NAME = 'airtel_transaction'; - /** - * @return MorphOne - */ - public function transaction(): MorphOne - { + public function transaction(): MorphOne { return $this->morphOne(Transaction::class, 'original_transaction'); } - public function manufacturerTransaction(): MorphTo - { + public function manufacturerTransaction(): MorphTo { return $this->morphTo(); } - public function conflicts(): MorphMany - { + public function conflicts(): MorphMany { return $this->morphMany(TransactionConflicts::class, 'transaction'); } - public static function getTransactionName(): string - { + public static function getTransactionName(): string { return self::RELATION_NAME; } } diff --git a/src/backend/app/Models/Transaction/CashTransaction.php b/src/backend/app/Models/Transaction/CashTransaction.php index a0e511809..d095aaa01 100644 --- a/src/backend/app/Models/Transaction/CashTransaction.php +++ b/src/backend/app/Models/Transaction/CashTransaction.php @@ -15,27 +15,22 @@ * @property int manufacturer_transaction_id * @property string manufacturer_transaction_type */ -class CashTransaction extends BaseModel implements IRawTransaction -{ +class CashTransaction extends BaseModel implements IRawTransaction { public const RELATION_NAME = 'cash_transaction'; - public function user(): BelongsTo - { + public function user(): BelongsTo { return $this->belongsTo(User::class); } - public function transaction(): MorphOne - { + public function transaction(): MorphOne { return $this->morphOne(Transaction::class, 'original_transaction'); } - public function manufacturerTransaction(): MorphTo - { + public function manufacturerTransaction(): MorphTo { return $this->morphTo(); } - public function conflicts(): MorphMany - { + public function conflicts(): MorphMany { return $this->morphMany(TransactionConflicts::class, 'transaction'); } } diff --git a/src/backend/app/Models/Transaction/IRawTransaction.php b/src/backend/app/Models/Transaction/IRawTransaction.php index efd619135..4a675fee4 100644 --- a/src/backend/app/Models/Transaction/IRawTransaction.php +++ b/src/backend/app/Models/Transaction/IRawTransaction.php @@ -2,8 +2,7 @@ namespace App\Models\Transaction; -interface IRawTransaction -{ +interface IRawTransaction { // returns the filtered transaction // which is been used by the system // to process the payment diff --git a/src/backend/app/Models/Transaction/ISubTransaction.php b/src/backend/app/Models/Transaction/ISubTransaction.php index 42e3957ae..34e5cf778 100644 --- a/src/backend/app/Models/Transaction/ISubTransaction.php +++ b/src/backend/app/Models/Transaction/ISubTransaction.php @@ -2,8 +2,7 @@ namespace App\Models\Transaction; -interface ISubTransaction -{ +interface ISubTransaction { public function vodacomTransaction(); public function airtelTransaction(); diff --git a/src/backend/app/Models/Transaction/ThirdPartyTransaction.php b/src/backend/app/Models/Transaction/ThirdPartyTransaction.php index 28b7bddd3..284acb34d 100644 --- a/src/backend/app/Models/Transaction/ThirdPartyTransaction.php +++ b/src/backend/app/Models/Transaction/ThirdPartyTransaction.php @@ -7,22 +7,18 @@ use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphTo; -class ThirdPartyTransaction extends BaseModel implements IRawTransaction -{ +class ThirdPartyTransaction extends BaseModel implements IRawTransaction { public const RELATION_NAME = 'third_party_transaction'; - public function transaction(): MorphOne - { + public function transaction(): MorphOne { return $this->morphOne(Transaction::class, 'original_transaction'); } - public function manufacturerTransaction(): MorphTo - { + public function manufacturerTransaction(): MorphTo { return $this->morphTo(); } - public function conflicts(): MorphMany - { + public function conflicts(): MorphMany { return $this->morphMany(TransactionConflicts::class, 'transaction'); } } diff --git a/src/backend/app/Models/Transaction/Transaction.php b/src/backend/app/Models/Transaction/Transaction.php index e13e91df2..c4f456f76 100644 --- a/src/backend/app/Models/Transaction/Transaction.php +++ b/src/backend/app/Models/Transaction/Transaction.php @@ -27,45 +27,38 @@ * @property string $message * @property string $original_transaction_type */ -class Transaction extends BaseModel -{ +class Transaction extends BaseModel { use RelationsManager; public const RELATION_NAME = 'transaction'; + public const TYPE_IMPORTED = 'imported'; - public function originalTransaction(): MorphTo - { + public function originalTransaction(): MorphTo { return $this->morphTo(); } - public function token(): HasOne - { + public function token(): HasOne { return $this->hasOne(Token::class); } - public function sms(): MorphOne - { + public function sms(): MorphOne { return $this->morphOne(Sms::class, 'trigger'); } - public function paymentHistories(): HasMany - { + public function paymentHistories(): HasMany { return $this->hasMany(PaymentHistory::class); } - public function device(): HasOne - { + public function device(): HasOne { return $this->hasOne(Device::class, 'device_serial', 'message'); } - public function appliance(): HasOne - { + public function appliance(): HasOne { return $this->hasOne(AssetPerson::class, 'device_serial', 'message'); } - public function periodTargetAlternative($cityId, $startDate, $endDate) - { + public function periodTargetAlternative($cityId, $startDate, $endDate) { $sql = 'SELECT sum(transactions.amount) as revenue,'. ' count(transactions.id) as total,'. ' AVG(transactions.amount) as average,'. @@ -99,68 +92,55 @@ public function periodTargetAlternative($cityId, $startDate, $endDate) return $sth->fetchAll(\PDO::FETCH_ASSOC); } - public function getAmount(): int - { + public function getAmount(): int { return $this->amount; } - public function getOriginalTransactionType(): string - { + public function getOriginalTransactionType(): string { return $this->original_transaction_type; } - public function getSender(): string - { + public function getSender(): string { return $this->sender; } - public function setAmount(int $amount): void - { + public function setAmount(int $amount): void { $this->amount = $amount; } - public function setSender(string $sender): void - { + public function setSender(string $sender): void { $this->sender = $sender; } - public function setMessage(string $message): void - { + public function setMessage(string $message): void { $this->message = $message; } - public function setOriginalTransactionType(string $originalTransaction): void - { + public function setOriginalTransactionType(string $originalTransaction): void { $this->original_transaction_type = $originalTransaction; } - public function getId(): int - { + public function getId(): int { return $this->id; } - public function setType(string $type) - { + public function setType(string $type) { $this->type = $type; } - public function getMessage(): string - { + public function getMessage(): string { return $this->message; } - public function originalAgent(): BelongsToMorph - { + public function originalAgent(): BelongsToMorph { return BelongsToMorph::build($this, AgentTransaction::class, 'originalTransaction'); } - public function originalCash(): BelongsToMorph - { + public function originalCash(): BelongsToMorph { return BelongsToMorph::build($this, CashTransaction::class, 'originalTransaction'); } - public function originalWaveMoney(): BelongsToMorph - { + public function originalWaveMoney(): BelongsToMorph { return BelongsToMorph::build($this, WaveMoneyTransaction::class, 'originalTransaction'); } } diff --git a/src/backend/app/Models/Transaction/TransactionConflicts.php b/src/backend/app/Models/Transaction/TransactionConflicts.php index 997c03d18..2213f1f1c 100644 --- a/src/backend/app/Models/Transaction/TransactionConflicts.php +++ b/src/backend/app/Models/Transaction/TransactionConflicts.php @@ -11,10 +11,8 @@ * @property int id * @property string state */ -class TransactionConflicts extends BaseModel -{ - public function transaction(): MorphTo - { +class TransactionConflicts extends BaseModel { + public function transaction(): MorphTo { return $this->morphTo(); } } diff --git a/src/backend/app/Models/Transaction/VodacomTransaction.php b/src/backend/app/Models/Transaction/VodacomTransaction.php index 180c15651..b890e0872 100644 --- a/src/backend/app/Models/Transaction/VodacomTransaction.php +++ b/src/backend/app/Models/Transaction/VodacomTransaction.php @@ -17,30 +17,25 @@ * @property string transaction_date * @property int status */ -class VodacomTransaction extends BaseModel implements IRawTransaction, FullySupportedTransactionInterface -{ +class VodacomTransaction extends BaseModel implements FullySupportedTransactionInterface, IRawTransaction { public const RELATION_NAME = 'vodacom_transaction'; /** * @return MorphOne */ - public function transaction() - { + public function transaction() { return $this->morphOne(Transaction::class, 'original_transaction'); } - public function manufacturerTransaction(): MorphTo - { + public function manufacturerTransaction(): MorphTo { return $this->morphTo(); } - public function conflicts(): MorphMany - { + public function conflicts(): MorphMany { return $this->morphMany(TransactionConflicts::class, 'transaction'); } - public static function getTransactionName(): string - { + public static function getTransactionName(): string { return self::RELATION_NAME; } } diff --git a/src/backend/app/Models/Upgrade.php b/src/backend/app/Models/Upgrade.php index dcdf08189..dd0b0a78e 100644 --- a/src/backend/app/Models/Upgrade.php +++ b/src/backend/app/Models/Upgrade.php @@ -13,10 +13,8 @@ * @property int $cost * @property int $period_in_months */ -class Upgrade extends BaseModel -{ - public function restriction(): BelongsTo - { +class Upgrade extends BaseModel { + public function restriction(): BelongsTo { return $this->belongsTo(Restriction::class); } } diff --git a/src/backend/app/Models/UsageType.php b/src/backend/app/Models/UsageType.php index 9b6f99281..48f9dce6f 100644 --- a/src/backend/app/Models/UsageType.php +++ b/src/backend/app/Models/UsageType.php @@ -5,8 +5,7 @@ use App\Models\Base\BaseModelCore; use Illuminate\Database\Eloquent\Factories\HasFactory; -class UsageType extends BaseModelCore -{ +class UsageType extends BaseModelCore { use HasFactory; protected $table = 'usage_types'; diff --git a/src/backend/app/Models/User.php b/src/backend/app/Models/User.php index 200706f66..5a6ca8022 100644 --- a/src/backend/app/Models/User.php +++ b/src/backend/app/Models/User.php @@ -22,24 +22,23 @@ * @property string $name * @property string|null $email */ -class User extends Authenticatable implements JWTSubject -{ - use Notifiable; +class User extends Authenticatable implements JWTSubject { use HasFactory; + use Notifiable; public const RELATION_NAME = 'admin'; + public const COL_ID = 'id'; + public const COL_COMPANY_ID = 'company_id'; - public function __construct(array $attributes = []) - { + public function __construct(array $attributes = []) { $this->setConnection('shard'); parent::__construct($attributes); } - public function setPasswordAttribute($password): void - { + public function setPasswordAttribute($password): void { $this->attributes['password'] = Hash::make($password); } @@ -70,67 +69,55 @@ public function setPasswordAttribute($password): void * * @return mixed */ - public function getJWTIdentifier() - { + public function getJWTIdentifier() { return $this->getKey(); } // we need to provide the company id in the token to encode and find the right database when an authenticated requests hits the api - public function getJWTCustomClaims(): array - { + public function getJWTCustomClaims(): array { return [ 'companyId' => $this->getCompanyId(), ]; } - public function address(): MorphOne - { + public function address(): MorphOne { return $this->morphOne(Address::class, 'owner'); } - public function addressDetails(): MorphOne - { + public function addressDetails(): MorphOne { return $this->address()->with('city'); } - public function balanceHistory(): HasMany - { + public function balanceHistory(): HasMany { return $this->hasMany(AgentBalanceHistory::class); } - public function assignedAppliance(): HasMany - { + public function assignedAppliance(): HasMany { return $this->hasMany(AgentAssignedAppliances::class); } // belongsTo company - public function company(): BelongsTo - { + public function company(): BelongsTo { return $this->BelongsTo(Company::class, 'company_id'); } - public function getCompanyId(): int - { + public function getCompanyId(): int { return $this->company_id; } - public function getId(): int - { + public function getId(): int { return $this->id; } - public function getName(): string - { + public function getName(): string { return $this->name; } - public function getEmail(): string - { + public function getEmail(): string { return $this->email; } - public function relationTicketUser(): HasOne - { + public function relationTicketUser(): HasOne { return $this->hasOne(TicketUser::class, TicketUser::COL_USER_ID, User::COL_ID); } } diff --git a/src/backend/app/Observers/AddressesObserver.php b/src/backend/app/Observers/AddressesObserver.php index b44fbba3b..d09caecb5 100644 --- a/src/backend/app/Observers/AddressesObserver.php +++ b/src/backend/app/Observers/AddressesObserver.php @@ -4,17 +4,11 @@ use App\Models\Address\Address; -class AddressesObserver -{ +class AddressesObserver { /** * Handles 'deleted' event of Address. - * - * @param Address $address - * - * @return void */ - public function deleted(Address $address): void - { + public function deleted(Address $address): void { // delete the geographic information for that address // $address->geo()->delete(); } diff --git a/src/backend/app/Observers/AgentBalanceHistoryObserver.php b/src/backend/app/Observers/AgentBalanceHistoryObserver.php index 2e7097188..b51627eb4 100644 --- a/src/backend/app/Observers/AgentBalanceHistoryObserver.php +++ b/src/backend/app/Observers/AgentBalanceHistoryObserver.php @@ -10,22 +10,17 @@ use App\Models\Transaction\AgentTransaction; use App\Services\AgentService; -class AgentBalanceHistoryObserver -{ +class AgentBalanceHistoryObserver { public function __construct( private AgentService $agentService, - ) { - } + ) {} /** * Handle the asset person "updated" event. * - * @param AgentBalanceHistory $agentBalanceHistory - * * @return void */ - public function created(AgentBalanceHistory $agentBalanceHistory) - { + public function created(AgentBalanceHistory $agentBalanceHistory) { $trigger = $agentBalanceHistory->trigger()->first(); $agent = $this->agentService->getById($agentBalanceHistory->agent_id); diff --git a/src/backend/app/Observers/AgentChargeObserver.php b/src/backend/app/Observers/AgentChargeObserver.php index fa9d39e67..509397724 100644 --- a/src/backend/app/Observers/AgentChargeObserver.php +++ b/src/backend/app/Observers/AgentChargeObserver.php @@ -7,17 +7,14 @@ use App\Services\AgentChargeHistoryBalanceService; use App\Services\AgentService; -class AgentChargeObserver -{ +class AgentChargeObserver { public function __construct( private AgentChargeHistoryBalanceService $agentChargeHistoryBalanceService, private AgentBalanceHistoryService $agentBalanceHistoryService, private AgentService $agentService, - ) { - } + ) {} - public function created(AgentCharge $agentCharge): void - { + public function created(AgentCharge $agentCharge): void { $agent = $this->agentService->getById($agentCharge->agent_id); $agentBalanceHistoryData = [ 'agent_id' => $agent->id, diff --git a/src/backend/app/Observers/AgentObserver.php b/src/backend/app/Observers/AgentObserver.php index d7f4d5b4f..67e955e24 100644 --- a/src/backend/app/Observers/AgentObserver.php +++ b/src/backend/app/Observers/AgentObserver.php @@ -6,19 +6,14 @@ use App\Models\Person\Person; use Illuminate\Support\Facades\Log; -class AgentObserver -{ - public function created(Agent $agent): void - { - } +class AgentObserver { + public function created(Agent $agent): void {} - public function updated(Agent $agent): void - { + public function updated(Agent $agent): void { Log::debug($agent->id.'updated'); } - public function deleted(Agent $agent): void - { + public function deleted(Agent $agent): void { $person = Person::find($agent->person_id); $person->delete(); foreach ($agent->addresses()->get() as $address) { diff --git a/src/backend/app/Observers/AgentReceiptObserver.php b/src/backend/app/Observers/AgentReceiptObserver.php index 59c46f608..fc0394de4 100644 --- a/src/backend/app/Observers/AgentReceiptObserver.php +++ b/src/backend/app/Observers/AgentReceiptObserver.php @@ -10,19 +10,16 @@ use App\Services\AgentService; use Illuminate\Database\Eloquent\ModelNotFoundException; -class AgentReceiptObserver -{ +class AgentReceiptObserver { public function __construct( private AgentBalanceHistoryService $agentBalanceHistoryService, private AgentService $agentService, private AgentReceiptService $agentReceiptService, private AgentReceiptDetailService $agentReceiptDetailService, private AgentReceiptHistoryBalanceService $agentReceiptHistoryBalanceService, - ) { - } + ) {} - public function created(AgentReceipt $receipt): void - { + public function created(AgentReceipt $receipt): void { $agentId = $receipt->agent_id; $agent = $this->agentService->getById($agentId); $due = $agent->due_to_energy_supplier; diff --git a/src/backend/app/Observers/AgentSoldApplianceObserver.php b/src/backend/app/Observers/AgentSoldApplianceObserver.php index 6da696d97..66cd33ae0 100644 --- a/src/backend/app/Observers/AgentSoldApplianceObserver.php +++ b/src/backend/app/Observers/AgentSoldApplianceObserver.php @@ -15,8 +15,7 @@ use App\Services\AppliancePersonService; use MPM\Transaction\TransactionService; -class AgentSoldApplianceObserver -{ +class AgentSoldApplianceObserver { public function __construct( private AgentBalanceHistoryService $agentBalanceHistoryService, private AgentAssignedApplianceService $agentAssignedApplianceService, @@ -29,18 +28,15 @@ public function __construct( private AgentAssignedApplianceHistoryBalanceService $agentAssignedApplianceHistoryBalanceService, private AgentCommissionService $agentCommissionService, private AgentCommissionHistoryBalanceService $agentCommissionHistoryBalanceService, - ) { - } + ) {} - public function created(AgentSoldAppliance $agentSoldAppliance): void - { + public function created(AgentSoldAppliance $agentSoldAppliance): void { if (request()->all()) { $this->processSaleIfIsNotCreatedByFactory($agentSoldAppliance); } } - private function processSaleIfIsNotCreatedByFactory($agentSoldAppliance) - { + private function processSaleIfIsNotCreatedByFactory($agentSoldAppliance) { $assignedApplianceId = $agentSoldAppliance->agent_assigned_appliance_id; $assignedAppliance = $this->agentAssignedApplianceService->getById($assignedApplianceId); $appliance = $assignedAppliance->applianceType()->first(); diff --git a/src/backend/app/Observers/MeterParameterObserver.php b/src/backend/app/Observers/MeterParameterObserver.php index c928cc40d..2a652ff3d 100644 --- a/src/backend/app/Observers/MeterParameterObserver.php +++ b/src/backend/app/Observers/MeterParameterObserver.php @@ -8,29 +8,20 @@ use App\Models\Meter\MeterParameter; use App\Services\MeterParameterService; -class MeterParameterObserver -{ - public function __construct(private MeterParameterService $meterParameterService) - { - } +class MeterParameterObserver { + public function __construct(private MeterParameterService $meterParameterService) {} /** * Handle "deleted" event. - * - * @param MeterParameter $meterParameter - * - * @return void */ - public function deleted(MeterParameter $meterParameter): void - { + public function deleted(MeterParameter $meterParameter): void { // set the meter free $meter = $meterParameter->meter()->first(); $meter->in_use = 0; $meter->save(); } - public function created(MeterParameter $meterParameter): void - { + public function created(MeterParameter $meterParameter): void { /* CreatePiggyBankEntry::dispatchSync( $meterParameter,$this->meterParameterService);*/ @@ -39,8 +30,7 @@ public function created(MeterParameter $meterParameter): void $meter->save(); } - public function updated(MeterParameter $meterParameter): void - { + public function updated(MeterParameter $meterParameter): void { // UpdatePiggyBankEntry::dispatchSync($meterParameter); } } diff --git a/src/backend/app/Observers/PersonObserver.php b/src/backend/app/Observers/PersonObserver.php index 72526f50d..fbcc9ed4b 100644 --- a/src/backend/app/Observers/PersonObserver.php +++ b/src/backend/app/Observers/PersonObserver.php @@ -5,29 +5,18 @@ use App\Models\Person\Person; use Illuminate\Support\Facades\Log; -class PersonObserver -{ +class PersonObserver { /** * Handle the Person "updated" event. - * - * @param Person $person - * - * @return void */ - public function updated(Person $person): void - { + public function updated(Person $person): void { Log::debug($person->id.'updated'); } /** * Handle the User "deleted" event. - * - * @param Person $person - * - * @return void */ - public function deleted(Person $person): void - { + public function deleted(Person $person): void { // delete all associated roles $person->roleOwner()->get(); diff --git a/src/backend/app/PaymentHandler/AccessRate.php b/src/backend/app/PaymentHandler/AccessRate.php index 7323f5d96..946b76127 100644 --- a/src/backend/app/PaymentHandler/AccessRate.php +++ b/src/backend/app/PaymentHandler/AccessRate.php @@ -9,12 +9,12 @@ use App\Models\Meter\MeterParameter; use Carbon\Carbon; -class AccessRate -{ +class AccessRate { /** * @var AccessRate */ private $accessRate; + /** * @var MeterParameter */ @@ -25,19 +25,12 @@ class AccessRate * * @param AccessRate $accessRate */ - public function __construct() - { - } + public function __construct() {} /** - * @param MeterParameter $meterParameter - * - * @return AccessRate - * * @throws NoAccessRateFound */ - public static function withMeterParameters(MeterParameter $meterParameter): AccessRate - { + public static function withMeterParameters(MeterParameter $meterParameter): AccessRate { if ($meterParameter->tariffAccessRate() === null) { throw new NoAccessRateFound('Tariff '.$meterParameter->tariff()->first()->name.' has no access rate'); } @@ -48,18 +41,14 @@ public static function withMeterParameters(MeterParameter $meterParameter): Acce return $accessRate; } - private function setMeterParameter(MeterParameter $meterParameter): void - { + private function setMeterParameter(MeterParameter $meterParameter): void { $this->meterParameter = $meterParameter; } /** - * @return AccessRatePayment - * * @throws NoAccessRateFound */ - public function initializeAccessRatePayment(): AccessRatePayment - { + public function initializeAccessRatePayment(): AccessRatePayment { if ($this->accessRate === null || $this->meterParameter === null) { throw new NoAccessRateFound(sprintf('%s %s', $this->accessRate === null ? 'Access Rate is not set' : '', $this->meterParameter === null ? 'Meter Parameter is not set' : '')); } @@ -76,12 +65,9 @@ public function initializeAccessRatePayment(): AccessRatePayment } /** - * @return int - * * @throws NoAccessRateFound */ - private function getDebt(Meter $meter): int - { + private function getDebt(Meter $meter): int { $accessRate = $meter->accessRatePayment()->first(); if ($accessRate === null) { throw new NoAccessRateFound('no access rate is defined'); @@ -91,14 +77,11 @@ private function getDebt(Meter $meter): int } /** - * @param TransactionDataContainer $transactionData - * * @return int * * @deprecated */ - public static function payAccessRate(TransactionDataContainer $transactionData): TransactionDataContainer - { + public static function payAccessRate(TransactionDataContainer $transactionData): TransactionDataContainer { $nonStaticGateway = new self(); // get accessRatePayment $accessRatePayment = $nonStaticGateway->getAccessRatePayment($transactionData->meter); @@ -137,14 +120,12 @@ public static function payAccessRate(TransactionDataContainer $transactionData): return $transactionData; } - public function updatePayment($accessRatePayment, int $paidAmount, bool $satisfied = false): void - { + public function updatePayment($accessRatePayment, int $paidAmount, bool $satisfied = false): void { $accessRatePayment->debt = $satisfied === true ? 0 : $accessRatePayment->debt - $paidAmount; $accessRatePayment->save(); } - private function getAccessRatePayment(Meter $meter): ?object - { + private function getAccessRatePayment(Meter $meter): ?object { return $meter->accessRatePayment()->first(); } } diff --git a/src/backend/app/PaymentHandler/EnergyPayment.php b/src/backend/app/PaymentHandler/EnergyPayment.php index bc17ecacd..de76192f4 100644 --- a/src/backend/app/PaymentHandler/EnergyPayment.php +++ b/src/backend/app/PaymentHandler/EnergyPayment.php @@ -2,6 +2,4 @@ namespace App\PaymentHandler; -class EnergyPayment -{ -} +class EnergyPayment {} diff --git a/src/backend/app/Providers/AppServiceProvider.php b/src/backend/app/Providers/AppServiceProvider.php index 4554acc28..24a61d74c 100644 --- a/src/backend/app/Providers/AppServiceProvider.php +++ b/src/backend/app/Providers/AppServiceProvider.php @@ -48,15 +48,13 @@ use MPM\Transaction\Provider\AirtelVoltTerraProvider; use MPM\Transaction\Provider\VodacomTransactionProvider; -class AppServiceProvider extends ServiceProvider -{ +class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ - public function boot() - { + public function boot() { // Maria DB work-around Schema::defaultStringLength(191); @@ -99,11 +97,8 @@ public function boot() /** * Register any application services. - * - * @return void */ - public function register(): void - { + public function register(): void { if ($this->app->environment('development') || $this->app->environment('local')) { $this->app->singleton(MailHelperInterface::class, MailHelperMock::class); } else { diff --git a/src/backend/app/Providers/AuthServiceProvider.php b/src/backend/app/Providers/AuthServiceProvider.php index 84c04286a..de96aa8b4 100644 --- a/src/backend/app/Providers/AuthServiceProvider.php +++ b/src/backend/app/Providers/AuthServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; -class AuthServiceProvider extends ServiceProvider -{ +class AuthServiceProvider extends ServiceProvider { /** * The policy mappings for the application. * @@ -20,8 +19,7 @@ class AuthServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { $this->registerPolicies(); } } diff --git a/src/backend/app/Providers/BroadcastServiceProvider.php b/src/backend/app/Providers/BroadcastServiceProvider.php index 9529056e6..b254637d9 100644 --- a/src/backend/app/Providers/BroadcastServiceProvider.php +++ b/src/backend/app/Providers/BroadcastServiceProvider.php @@ -5,15 +5,13 @@ use Illuminate\Support\Facades\Broadcast; use Illuminate\Support\ServiceProvider; -class BroadcastServiceProvider extends ServiceProvider -{ +class BroadcastServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ - public function boot() - { + public function boot() { Broadcast::routes(); include base_path('routes/channels.php'); diff --git a/src/backend/app/Providers/EventServiceProvider.php b/src/backend/app/Providers/EventServiceProvider.php index 96f555224..3c2f4f080 100644 --- a/src/backend/app/Providers/EventServiceProvider.php +++ b/src/backend/app/Providers/EventServiceProvider.php @@ -15,8 +15,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use MPM\User\UserEventSubscriber; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { /** * The event listener mappings for the application. * @@ -45,8 +44,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/app/Providers/HorizonServiceProvider.php b/src/backend/app/Providers/HorizonServiceProvider.php index c72d99ca6..829903db9 100644 --- a/src/backend/app/Providers/HorizonServiceProvider.php +++ b/src/backend/app/Providers/HorizonServiceProvider.php @@ -6,15 +6,13 @@ use Laravel\Horizon\Horizon; use Laravel\Horizon\HorizonApplicationServiceProvider; -class HorizonServiceProvider extends HorizonApplicationServiceProvider -{ +class HorizonServiceProvider extends HorizonApplicationServiceProvider { /** * Bootstrap any application services. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); // Horizon::routeSmsNotificationsTo('15556667777'); @@ -31,8 +29,7 @@ public function boot() * * @return void */ - protected function gate() - { + protected function gate() { Gate::define( 'viewHorizon', function ($user) { diff --git a/src/backend/app/Providers/RouteServiceProvider.php b/src/backend/app/Providers/RouteServiceProvider.php index 4c0493cf0..aee4ccf4e 100644 --- a/src/backend/app/Providers/RouteServiceProvider.php +++ b/src/backend/app/Providers/RouteServiceProvider.php @@ -5,8 +5,7 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { /** * This namespace is applied to your controller routes. * @@ -21,8 +20,7 @@ class RouteServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } @@ -31,8 +29,7 @@ public function boot() * * @return void */ - public function map() - { + public function map() { $this->mapApiRoutes(); $this->mapWebRoutes(); @@ -45,8 +42,7 @@ public function map() * * @return void */ - protected function mapWebRoutes() - { + protected function mapWebRoutes() { Route::middleware('web') ->namespace($this->namespace) ->group(base_path('routes/web.php')); @@ -59,8 +55,7 @@ protected function mapWebRoutes() * * @return void */ - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/app/Providers/ServicesProvider.php b/src/backend/app/Providers/ServicesProvider.php index 538756ce2..4137f8c78 100644 --- a/src/backend/app/Providers/ServicesProvider.php +++ b/src/backend/app/Providers/ServicesProvider.php @@ -26,15 +26,11 @@ use Illuminate\Support\ServiceProvider; use Laravel\Horizon\Horizon; -class ServicesProvider extends ServiceProvider -{ +class ServicesProvider extends ServiceProvider { /** * Bootstrap services. - * - * @return void */ - public function boot(): void - { + public function boot(): void { Person::observe(PersonObserver::class); Address::observe(AddressesObserver::class); MeterParameter::observe(MeterParameterObserver::class); @@ -52,11 +48,8 @@ static function ($request) { /** * Register services. - * - * @return void */ - public function register(): void - { + public function register(): void { $this->app->bind( RolesService::class, function ($app) { diff --git a/src/backend/app/Providers/VodacomServiceProvider.php b/src/backend/app/Providers/VodacomServiceProvider.php index 32bee4568..a00aca511 100644 --- a/src/backend/app/Providers/VodacomServiceProvider.php +++ b/src/backend/app/Providers/VodacomServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Support\ServiceProvider; -class VodacomServiceProvider extends ServiceProvider -{ +class VodacomServiceProvider extends ServiceProvider { protected $defer = true; /** @@ -13,16 +12,12 @@ class VodacomServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { - } + public function boot() {} /** * Register services. * * @return void */ - public function register() - { - } + public function register() {} } diff --git a/src/backend/app/Relations/BelongsToMorph.php b/src/backend/app/Relations/BelongsToMorph.php index 652792acd..ab8724441 100644 --- a/src/backend/app/Relations/BelongsToMorph.php +++ b/src/backend/app/Relations/BelongsToMorph.php @@ -9,14 +9,14 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; -class BelongsToMorph extends BelongsTo -{ +class BelongsToMorph extends BelongsTo { /** * The name of the polymorphic relation. * * @var string */ protected $morphName; + /** * The type of the polymorphic relation. * @@ -24,8 +24,7 @@ class BelongsToMorph extends BelongsTo */ protected $morphType; - public function __construct(Builder $query, Model $parent, $name, $type, $id, $otherKey, $relation) - { + public function __construct(Builder $query, Model $parent, $name, $type, $id, $otherKey, $relation) { $this->morphName = $name; $this->morphType = $type; parent::__construct($query, $parent, $id, $otherKey, $relation); @@ -52,8 +51,7 @@ public function __construct(Builder $query, Model $parent, $name, $type, $id, $o * * @return mixed */ - public function getResults() - { + public function getResults() { if ($this->getParent()->{$this->morphType} === $this->morphName) { return $this->query->first(); } @@ -67,11 +65,8 @@ public function getResults() * @param string $name * @param string $type * @param string $id - * - * @return array */ - protected static function getMorphs($name, $type, $id): array - { + protected static function getMorphs($name, $type, $id): array { $type = $type ?: $name.'_type'; $id = $id ?: $name.'_id'; @@ -81,15 +76,12 @@ protected static function getMorphs($name, $type, $id): array /** * Define an inverse morph relationship. * - * @param Model $parent * @param string $related * @param string $name * @param null $type * @param null $id * @param null $otherKey * @param null $relation - * - * @return BelongsToMorph */ public static function build( Model $parent, @@ -104,11 +96,11 @@ public static function build( // the calling method's name and use that as the relationship name as most // of the time this will be what we desire to use for the relationships. if (is_null($relation)) { - list($current, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + [$current, $caller] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $relation = $caller['function']; } $morphName = Arr::get(array_flip(Relation::morphMap()), $related, $related); - list($type, $id) = self::getMorphs(Str::snake($name), $type, $id); + [$type, $id] = self::getMorphs(Str::snake($name), $type, $id); $instance = new $related(); // Once we have the foreign key names, we'll just create a new Eloquent query // for the related models and returns the relationship instance which will diff --git a/src/backend/app/Services/AbstractDashboardCacheDataService.php b/src/backend/app/Services/AbstractDashboardCacheDataService.php index 162bdb04e..d3e370291 100644 --- a/src/backend/app/Services/AbstractDashboardCacheDataService.php +++ b/src/backend/app/Services/AbstractDashboardCacheDataService.php @@ -6,8 +6,7 @@ use App\Models\User; use Illuminate\Support\Facades\Cache; -abstract class AbstractDashboardCacheDataService -{ +abstract class AbstractDashboardCacheDataService { protected string $cacheDataKey; public function __construct( @@ -18,13 +17,11 @@ public function __construct( abstract public function setData($dateRange = []); - public function getData() - { + public function getData() { return Cache::get(self::cacheKeyGenerator()) ? Cache::get(self::cacheKeyGenerator())->toArray() : []; } - public function getDataById($id) - { + public function getDataById($id) { $cachedData = Cache::get(self::cacheKeyGenerator()); return $cachedData ? collect($cachedData)->filter(function ($data) use ($id) { @@ -32,8 +29,7 @@ public function getDataById($id) })->first() : []; } - protected function cacheKeyGenerator(): string - { + protected function cacheKeyGenerator(): string { $user = User::query()->first(); $databaseProxy = app()->make(DatabaseProxy::class); $companyId = $databaseProxy->findByEmail($user->email)->getCompanyId(); @@ -41,8 +37,7 @@ protected function cacheKeyGenerator(): string return $this->cacheDataKey.'-'.$companyId; } - protected function reformatPeriod($period): string - { + protected function reformatPeriod($period): string { return substr_replace($period, '-', 4, 0); } } diff --git a/src/backend/app/Services/AbstractExportService.php b/src/backend/app/Services/AbstractExportService.php index 07a836c0d..efec54ff1 100644 --- a/src/backend/app/Services/AbstractExportService.php +++ b/src/backend/app/Services/AbstractExportService.php @@ -14,14 +14,19 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use Webpatser\Uuid\Uuid; -abstract class AbstractExportService -{ +abstract class AbstractExportService { protected IReader $reader; + protected Worksheet $worksheet; + protected Spreadsheet $spreadsheet; + protected Collection $exportingData; + protected string $currency; + protected string $timeZone; + protected string $recentlyCreatedSpreadSheetId; abstract public function setExportingData(); @@ -30,8 +35,7 @@ abstract public function getTemplatePath(); abstract public function getPrefix(); - public function createSpreadSheetFromTemplate(string $path): Spreadsheet - { + public function createSpreadSheetFromTemplate(string $path): Spreadsheet { try { $this->reader = IOFactory::createReader('Xlsx'); $this->spreadsheet = @@ -47,18 +51,15 @@ public function createSpreadSheetFromTemplate(string $path): Spreadsheet } } - public function setCurrency($currency) - { + public function setCurrency($currency) { $this->currency = $currency; } - public function setTimeZone($timeZone) - { + public function setTimeZone($timeZone) { $this->timeZone = $timeZone; } - public function readable($amount, $separator = ',') - { + public function readable($amount, $separator = ',') { // Check for null or undefined amount and return '0' if ($amount === null || $amount === 'undefined') { return '0'; @@ -83,8 +84,7 @@ public function readable($amount, $separator = ',') return $decimal ? "$whole.$decimal" : $whole; } - public function convertUtcDateToTimezone($utcDate): string - { + public function convertUtcDateToTimezone($utcDate): string { // Create a DateTime object with the UTC-based date $dateTimeUtc = Carbon::parse($utcDate)->setTimezone('UTC'); @@ -95,13 +95,11 @@ public function convertUtcDateToTimezone($utcDate): string return $dateTimeUtc->format('Y-m-d H:i:s'); } - public function setRecentlyCreatedSpreadSheetId(string $id): void - { + public function setRecentlyCreatedSpreadSheetId(string $id): void { $this->recentlyCreatedSpreadSheetId = $id; } - public function setActivatedSheet($sheetName): void - { + public function setActivatedSheet($sheetName): void { try { $this->worksheet = $this->spreadsheet->setActiveSheetIndexByName($sheetName); } catch (\Exception $e) { @@ -112,8 +110,7 @@ public function setActivatedSheet($sheetName): void } } - public function saveSpreadSheet(): string - { + public function saveSpreadSheet(): string { try { $uuid = (string) Uuid::generate(4); $fileName = storage_path('appliance').'/'.$this->getPrefix().'-'.$uuid.'.xlsx'; diff --git a/src/backend/app/Services/AbstractPaymentAggregatorTransactionService.php b/src/backend/app/Services/AbstractPaymentAggregatorTransactionService.php index de1f7c7bf..c5073dfcf 100644 --- a/src/backend/app/Services/AbstractPaymentAggregatorTransactionService.php +++ b/src/backend/app/Services/AbstractPaymentAggregatorTransactionService.php @@ -13,13 +13,17 @@ use App\Models\Transaction\Transaction; use Inensus\SteamaMeter\Exceptions\ModelNotFoundException; -abstract class AbstractPaymentAggregatorTransactionService -{ +abstract class AbstractPaymentAggregatorTransactionService { private const MINIMUM_TRANSACTION_AMOUNT = 0; + protected string $payerPhoneNumber; + protected string $meterSerialNumber; + protected float $minimumPurchaseAmount; + protected int $customerId; + protected float $amount; public function __construct( @@ -28,11 +32,9 @@ public function __construct( private Transaction $transaction, private MeterParameter $meterParameter, private IRawTransaction $paymentAggregatorTransaction, - ) { - } + ) {} - public function validatePaymentOwner(string $meterSerialNumber, float $amount): void - { + public function validatePaymentOwner(string $meterSerialNumber, float $amount): void { if (!$meter = $this->meter->findBySerialNumber($meterSerialNumber)) { throw new ModelNotFoundException('Meter not found with serial number you entered'); } @@ -63,8 +65,7 @@ public function validatePaymentOwner(string $meterSerialNumber, float $amount): * @throws TransactionIsInvalidForProcessingIncomingRequestException * @throws TransactionAmountNotEnoughException */ - public function imitateTransactionForValidation(array $transactionData) - { + public function imitateTransactionForValidation(array $transactionData) { $this->paymentAggregatorTransaction = $this->paymentAggregatorTransaction->newQuery()->make($transactionData); $this->transaction = $this->transaction->newQuery()->make([ 'amount' => $transactionData['amount'], @@ -77,14 +78,12 @@ public function imitateTransactionForValidation(array $transactionData) $this->isImitationTransactionValid($this->transaction); } - public function saveTransaction() - { + public function saveTransaction() { $this->paymentAggregatorTransaction->save(); $this->transaction->originalTransaction()->associate($this->paymentAggregatorTransaction)->save(); } - private function isImitationTransactionValid($transaction) - { + private function isImitationTransactionValid($transaction) { try { $transactionData = TransactionDataContainer::initialize($transaction); } catch (\Exception $e) { @@ -104,8 +103,7 @@ private function isImitationTransactionValid($transaction) } } - private function getTransactionSender($meterSerialNumber) - { + private function getTransactionSender($meterSerialNumber) { $meterParameter = $this->meterParameter->newQuery() ->whereHas( 'meter', @@ -131,28 +129,23 @@ function ($q) use ($personId) { } } - public function getCustomerId(): int - { + public function getCustomerId(): int { return $this->customerId; } - public function getMeterSerialNumber() - { + public function getMeterSerialNumber() { return $this->meterSerialNumber; } - public function getAmount() - { + public function getAmount() { return $this->amount; } - public function getMinimumPurchaseAmount() - { + public function getMinimumPurchaseAmount() { return $this->minimumPurchaseAmount; } - public function getPaymentAggregatorTransaction(): IRawTransaction - { + public function getPaymentAggregatorTransaction(): IRawTransaction { return $this->paymentAggregatorTransaction; } } diff --git a/src/backend/app/Services/AccessRatePaymentHistoryService.php b/src/backend/app/Services/AccessRatePaymentHistoryService.php index f072a3a88..d06263608 100644 --- a/src/backend/app/Services/AccessRatePaymentHistoryService.php +++ b/src/backend/app/Services/AccessRatePaymentHistoryService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class AccessRatePaymentHistoryService implements IAssignationService -{ +class AccessRatePaymentHistoryService implements IAssignationService { private PaymentHistory $paymentHistory; + private AccessRate $accessRate; - public function setAssigned($paymentHistory): void - { + public function setAssigned($paymentHistory): void { $this->paymentHistory = $paymentHistory; } - public function setAssignee($accessRate): void - { + public function setAssignee($accessRate): void { $this->accessRate = $accessRate; } - public function assign(): PaymentHistory - { + public function assign(): PaymentHistory { $this->paymentHistory->paidFor()->associate($this->accessRate); return $this->paymentHistory; diff --git a/src/backend/app/Services/AccessRatePaymentService.php b/src/backend/app/Services/AccessRatePaymentService.php index 395257da0..9722f69ab 100644 --- a/src/backend/app/Services/AccessRatePaymentService.php +++ b/src/backend/app/Services/AccessRatePaymentService.php @@ -10,38 +10,31 @@ /** * @implements IBaseService */ -class AccessRatePaymentService implements IBaseService -{ +class AccessRatePaymentService implements IBaseService { public function __construct( private AccessRatePayment $accessRatePayment, - ) { - } + ) {} - public function getById(int $id): AccessRatePayment - { + public function getById(int $id): AccessRatePayment { return $this->accessRatePayment->newQuery()->find($id); } - public function create(array $accessRatePaymentData): AccessRatePayment - { + public function create(array $accessRatePaymentData): AccessRatePayment { return $this->accessRatePayment->newQuery()->create($accessRatePaymentData); } - public function update($accessRatePayment, array $accessRatePaymentData): AccessRatePayment - { + public function update($accessRatePayment, array $accessRatePaymentData): AccessRatePayment { $accessRatePayment->update($accessRatePaymentData); $accessRatePayment->fresh(); return $accessRatePayment; } - public function delete($accessRatePayment): ?bool - { + public function delete($accessRatePayment): ?bool { return $accessRatePayment->delete(); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { $query = $this->accessRatePayment->newQuery(); if ($limit) { @@ -51,8 +44,7 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->accessRatePayment->newQuery()->get(); } - public function getAccessRatePaymentByMeter($meter) - { + public function getAccessRatePaymentByMeter($meter) { return $meter->accessRatePayment()->first(); } } diff --git a/src/backend/app/Services/AccessRateService.php b/src/backend/app/Services/AccessRateService.php index a28e5bc55..21d6cdb03 100644 --- a/src/backend/app/Services/AccessRateService.php +++ b/src/backend/app/Services/AccessRateService.php @@ -9,43 +9,35 @@ /** * @implements IBaseService */ -class AccessRateService implements IBaseService -{ +class AccessRateService implements IBaseService { public function __construct( private AccessRate $accessRate, - ) { - } + ) {} - public function getById(int $accessRateId): AccessRate - { + public function getById(int $accessRateId): AccessRate { return $this->accessRate->newQuery()->find($accessRateId); } - public function create(array $accessRateData): AccessRate - { + public function create(array $accessRateData): AccessRate { return $this->accessRate->newQuery()->create($accessRateData); } - public function update($accessRate, $acessRateData): AccessRate - { + public function update($accessRate, $acessRateData): AccessRate { $accessRate->update($acessRateData); $accessRate->fresh(); return $accessRate; } - public function deleteByTariffId($meterTariffId) - { + public function deleteByTariffId($meterTariffId) { $this->accessRate->newQuery()->where('tariff_id', $meterTariffId)->delete(); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } } diff --git a/src/backend/app/Services/AddressGeographicalInformationService.php b/src/backend/app/Services/AddressGeographicalInformationService.php index 7bb67513a..74e925d20 100644 --- a/src/backend/app/Services/AddressGeographicalInformationService.php +++ b/src/backend/app/Services/AddressGeographicalInformationService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class AddressGeographicalInformationService implements IAssignationService -{ +class AddressGeographicalInformationService implements IAssignationService { private GeographicalInformation $geographicInformation; + private Address $address; - public function setAssigned($assigned): void - { + public function setAssigned($assigned): void { $this->geographicInformation = $assigned; } - public function setAssignee($assignee): void - { + public function setAssignee($assignee): void { $this->address = $assignee; } - public function assign(): GeographicalInformation - { + public function assign(): GeographicalInformation { $this->geographicInformation->owner()->associate($this->address); return $this->geographicInformation; diff --git a/src/backend/app/Services/AddressesService.php b/src/backend/app/Services/AddressesService.php index 45c128d74..00d262457 100644 --- a/src/backend/app/Services/AddressesService.php +++ b/src/backend/app/Services/AddressesService.php @@ -14,16 +14,13 @@ * @implements IBaseService
* @implements IAssociative
*/ -class AddressesService implements IBaseService, IAssociative -{ +class AddressesService implements IAssociative, IBaseService { public function __construct( private Address $address, - ) { - } + ) {} // fills the object and returns it without saving. - public function instantiate(array $params): Address - { + public function instantiate(array $params): Address { return $this->address->fill([ 'city_id' => $params['city_id'] ?? null, 'email' => $params['email'] ?? null, @@ -33,18 +30,15 @@ public function instantiate(array $params): Address ]); } - public function assignAddressToOwner(HasAddressesInterface $owner, Address $address) - { + public function assignAddressToOwner(HasAddressesInterface $owner, Address $address) { return $owner->addresses()->save($address); } - public function getStoredAddressWithCityRelation(int $id): Address - { + public function getStoredAddressWithCityRelation(int $id): Address { return $this->address::with('city')->findOrFail($id); } - public function createAddressDataFromRequest(Request $request): array - { + public function createAddressDataFromRequest(Request $request): array { return [ 'email' => $request->get('email') ?? '', 'phone' => $request->get('phone') ?? '', @@ -54,13 +48,11 @@ public function createAddressDataFromRequest(Request $request): array ]; } - public function getById(int $id): Address - { + public function getById(int $id): Address { return $this->address->newQuery()->findOrFail($id); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->address->newQuery()->paginate($limit); } @@ -68,25 +60,21 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->address->newQuery()->get(); } - public function create(array $data): Address - { + public function create(array $data): Address { throw new \Exception('Method create() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function update($address, array $addressData): Address - { + public function update($address, array $addressData): Address { $address->update($addressData); return $address; } - public function make($addressData): Address - { + public function make($addressData): Address { return $this->address->newQuery()->make([ 'email' => $addressData['email'] ?? null, 'phone' => $addressData['phone'] ?? null, @@ -97,8 +85,7 @@ public function make($addressData): Address ]); } - public function save($address): bool - { + public function save($address): bool { return $address->save(); } } diff --git a/src/backend/app/Services/AgentAppliancePersonService.php b/src/backend/app/Services/AgentAppliancePersonService.php index 1c2d8edc2..f6a154947 100644 --- a/src/backend/app/Services/AgentAppliancePersonService.php +++ b/src/backend/app/Services/AgentAppliancePersonService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class AgentAppliancePersonService implements IAssignationService -{ +class AgentAppliancePersonService implements IAssignationService { private AssetPerson $appliancePerson; + private Agent $agent; - public function setAssigned($appliancePerson): void - { + public function setAssigned($appliancePerson): void { $this->appliancePerson = $appliancePerson; } - public function setAssignee($agent): void - { + public function setAssignee($agent): void { $this->agent = $agent; } - public function assign(): AssetPerson - { + public function assign(): AssetPerson { $this->appliancePerson->creator()->associate($this->agent); return $this->appliancePerson; diff --git a/src/backend/app/Services/AgentAssignedApplianceHistoryBalanceService.php b/src/backend/app/Services/AgentAssignedApplianceHistoryBalanceService.php index 23c18ac4d..cbb77b9f1 100644 --- a/src/backend/app/Services/AgentAssignedApplianceHistoryBalanceService.php +++ b/src/backend/app/Services/AgentAssignedApplianceHistoryBalanceService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class AgentAssignedApplianceHistoryBalanceService implements IAssignationService -{ +class AgentAssignedApplianceHistoryBalanceService implements IAssignationService { private AgentBalanceHistory $agentBalanceHistory; + private AgentAssignedAppliances $agentAssignedAppliance; - public function setAssigned($agentBalanceHistory): void - { + public function setAssigned($agentBalanceHistory): void { $this->agentBalanceHistory = $agentBalanceHistory; } - public function setAssignee($agentAssignedAppliance): void - { + public function setAssignee($agentAssignedAppliance): void { $this->agentAssignedAppliance = $agentAssignedAppliance; } - public function assign(): AgentBalanceHistory - { + public function assign(): AgentBalanceHistory { $this->agentBalanceHistory->trigger()->associate($this->agentAssignedAppliance); return $this->agentBalanceHistory; diff --git a/src/backend/app/Services/AgentAssignedApplianceService.php b/src/backend/app/Services/AgentAssignedApplianceService.php index b5b4756ec..837502e67 100644 --- a/src/backend/app/Services/AgentAssignedApplianceService.php +++ b/src/backend/app/Services/AgentAssignedApplianceService.php @@ -10,15 +10,12 @@ /** * @implements IBaseService */ -class AgentAssignedApplianceService implements IBaseService -{ +class AgentAssignedApplianceService implements IBaseService { public function __construct( private AgentAssignedAppliances $agentAssignedAppliance, - ) { - } + ) {} - public function create(array $applianceData): AgentAssignedAppliances - { + public function create(array $applianceData): AgentAssignedAppliances { return $this->agentAssignedAppliance->newQuery()->create([ 'agent_id' => $applianceData['agent_id'], 'user_id' => $applianceData['user_id'], @@ -27,23 +24,19 @@ public function create(array $applianceData): AgentAssignedAppliances ]); } - public function getById(int $id): AgentAssignedAppliances - { + public function getById(int $id): AgentAssignedAppliances { return $this->agentAssignedAppliance->newQuery()->with('applianceType')->find($id); } - public function update($model, array $data): AgentAssignedAppliances - { + public function update($model, array $data): AgentAssignedAppliances { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null, ?int $agentId = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null, ?int $agentId = null): Collection|LengthAwarePaginator { $query = $this->agentAssignedAppliance->newQuery(); if ($agentId) { diff --git a/src/backend/app/Services/AgentBalanceHistoryService.php b/src/backend/app/Services/AgentBalanceHistoryService.php index 68bc2ce97..1b75fc343 100644 --- a/src/backend/app/Services/AgentBalanceHistoryService.php +++ b/src/backend/app/Services/AgentBalanceHistoryService.php @@ -13,16 +13,13 @@ * @implements IBaseService * @implements IAssociative */ -class AgentBalanceHistoryService implements IBaseService, IAssociative -{ +class AgentBalanceHistoryService implements IAssociative, IBaseService { public function __construct( private AgentBalanceHistory $agentBalanceHistory, private PeriodService $periodService, - ) { - } + ) {} - public function getAll(?int $limit = null, ?int $agentId = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null, ?int $agentId = null): Collection|LengthAwarePaginator { $query = $this->agentBalanceHistory->newQuery() ->whereHasMorph( 'trigger', @@ -38,36 +35,30 @@ public function getAll(?int $limit = null, ?int $agentId = null): Collection|Len return $query->latest()->get(); } - public function create(array $agentBalanceHistoryData): AgentBalanceHistory - { + public function create(array $agentBalanceHistoryData): AgentBalanceHistory { return $this->agentBalanceHistory->newQuery()->create($agentBalanceHistoryData); } - public function make(array $agentBalanceHistoryData): AgentBalanceHistory - { + public function make(array $agentBalanceHistoryData): AgentBalanceHistory { return $this->agentBalanceHistory->newQuery()->make($agentBalanceHistoryData); } - public function save($agentBalanceHistory): bool - { + public function save($agentBalanceHistory): bool { return $agentBalanceHistory->save(); } - public function getLastAgentBalanceHistory($agentId) - { + public function getLastAgentBalanceHistory($agentId) { return $this->agentBalanceHistory->newQuery()->where('agent_id', $agentId)->get()->last(); } - public function getTotalAmountSinceLastVisit($agentBalanceHistoryId, $agentId) - { + public function getTotalAmountSinceLastVisit($agentBalanceHistoryId, $agentId) { return $this->agentBalanceHistory->newQuery()->where('agent_id', $agentId) ->where('id', '>', $agentBalanceHistoryId) ->whereIn('trigger_type', ['agent_appliance', 'agent_transaction']) ->sum('amount'); } - public function getTransactionAverage($agent, $lastReceipt) - { + public function getTransactionAverage($agent, $lastReceipt) { if ($lastReceipt) { $averageTransactionAmounts = $this->agentBalanceHistory->newQuery() ->where('agent_id', $agent->id) @@ -86,8 +77,7 @@ public function getTransactionAverage($agent, $lastReceipt) return -1 * $averageTransactionAmounts; } - public function getGraphValues($agent, $lastReceiptDate) - { + public function getGraphValues($agent, $lastReceiptDate) { $periodDate = $lastReceiptDate; $period = $this->getPeriod($agent, $periodDate); $history = $this->agentBalanceHistory->newQuery() @@ -142,8 +132,7 @@ public function getGraphValues($agent, $lastReceiptDate) return $period; } - public function getPeriod($agent, $date): array - { + public function getPeriod($agent, $date): array { $days = $this->agentBalanceHistory->newQuery()->selectRaw('DATE_FORMAT(created_at,\'%Y-%m-%d\') as day') ->where('agent_id', $agent->id) ->where( @@ -151,7 +140,7 @@ public function getPeriod($agent, $date): array '>=', $date )->groupBy(DB::connection($this->agentBalanceHistory->getConnectionName()) - ->raw('DATE_FORMAT(created_at,\'%Y-%m-%d\')')) + ->raw('DATE_FORMAT(created_at,\'%Y-%m-%d\')')) ->get(); $period = []; foreach ($days as $key => $item) { @@ -164,8 +153,7 @@ public function getPeriod($agent, $date): array return $period; } - public function getAgentRevenuesWeekly($agent): array - { + public function getAgentRevenuesWeekly($agent): array { $startDate = date('Y-m-d', strtotime('-3 months')); $endDate = date('Y-m-d'); $Revenues = $this->agentBalanceHistory->newQuery() @@ -184,18 +172,15 @@ public function getAgentRevenuesWeekly($agent): array return $p; } - public function getById($id): AgentBalanceHistory - { + public function getById($id): AgentBalanceHistory { throw new \Exception('Method getById() not yet implemented.'); } - public function update($model, $data): AgentBalanceHistory - { + public function update($model, $data): AgentBalanceHistory { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } } diff --git a/src/backend/app/Services/AgentChargeHistoryBalanceService.php b/src/backend/app/Services/AgentChargeHistoryBalanceService.php index e5d6fc27d..a759053c3 100644 --- a/src/backend/app/Services/AgentChargeHistoryBalanceService.php +++ b/src/backend/app/Services/AgentChargeHistoryBalanceService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class AgentChargeHistoryBalanceService implements IAssignationService -{ +class AgentChargeHistoryBalanceService implements IAssignationService { private AgentBalanceHistory $agentBalanceHistory; + private AgentCharge $agentCharge; - public function setAssigned($agentBalanceHistory): void - { + public function setAssigned($agentBalanceHistory): void { $this->agentBalanceHistory = $agentBalanceHistory; } - public function setAssignee($agentCharge): void - { + public function setAssignee($agentCharge): void { $this->agentCharge = $agentCharge; } - public function assign(): AgentBalanceHistory - { + public function assign(): AgentBalanceHistory { $this->agentBalanceHistory->trigger()->associate($this->agentCharge); return $this->agentBalanceHistory; diff --git a/src/backend/app/Services/AgentChargeService.php b/src/backend/app/Services/AgentChargeService.php index e05307ee8..992bb8ac5 100644 --- a/src/backend/app/Services/AgentChargeService.php +++ b/src/backend/app/Services/AgentChargeService.php @@ -9,35 +9,28 @@ /** * @implements IBaseService */ -class AgentChargeService implements IBaseService -{ +class AgentChargeService implements IBaseService { public function __construct( private AgentCharge $agentCharge, - ) { - } + ) {} - public function create(array $agentChargeData): AgentCharge - { + public function create(array $agentChargeData): AgentCharge { return $this->agentCharge->newQuery()->create($agentChargeData); } - public function getById(int $id): AgentCharge - { + public function getById(int $id): AgentCharge { throw new \Exception('Method getById() not yet implemented.'); } - public function update($model, array $data): AgentCharge - { + public function update($model, array $data): AgentCharge { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } } diff --git a/src/backend/app/Services/AgentCommissionHistoryBalanceService.php b/src/backend/app/Services/AgentCommissionHistoryBalanceService.php index 57507f394..3002d7891 100644 --- a/src/backend/app/Services/AgentCommissionHistoryBalanceService.php +++ b/src/backend/app/Services/AgentCommissionHistoryBalanceService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class AgentCommissionHistoryBalanceService implements IAssignationService -{ +class AgentCommissionHistoryBalanceService implements IAssignationService { private AgentBalanceHistory $agentBalanceHistory; + private AgentCommission $agentCommission; - public function setAssigned($agentBalanceHistory): void - { + public function setAssigned($agentBalanceHistory): void { $this->agentBalanceHistory = $agentBalanceHistory; } - public function setAssignee($agentCommission): void - { + public function setAssignee($agentCommission): void { $this->agentCommission = $agentCommission; } - public function assign(): AgentBalanceHistory - { + public function assign(): AgentBalanceHistory { $this->agentBalanceHistory->trigger()->associate($this->agentCommission); return $this->agentBalanceHistory; diff --git a/src/backend/app/Services/AgentCommissionService.php b/src/backend/app/Services/AgentCommissionService.php index 9c1e5d1af..1085e12d5 100644 --- a/src/backend/app/Services/AgentCommissionService.php +++ b/src/backend/app/Services/AgentCommissionService.php @@ -10,38 +10,31 @@ /** * @implements IBaseService */ -class AgentCommissionService implements IBaseService -{ +class AgentCommissionService implements IBaseService { public function __construct( private AgentCommission $agentCommission, - ) { - } + ) {} - public function create(array $agentCommissiondata): AgentCommission - { + public function create(array $agentCommissiondata): AgentCommission { return $this->agentCommission->newQuery()->create($agentCommissiondata); } - public function update($agentCommission, array $agentCommissiondata): AgentCommission - { + public function update($agentCommission, array $agentCommissiondata): AgentCommission { $agentCommission->update($agentCommissiondata); $agentCommission->fresh(); return $agentCommission; } - public function delete($agentCommission): ?bool - { + public function delete($agentCommission): ?bool { return $agentCommission->delete(); } - public function getById(int $id): AgentCommission - { + public function getById(int $id): AgentCommission { return $this->agentCommission->newQuery()->find($id); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->agentCommission->newQuery()->paginate($limit); } diff --git a/src/backend/app/Services/AgentCustomerService.php b/src/backend/app/Services/AgentCustomerService.php index 07c79211b..d66ef83a1 100644 --- a/src/backend/app/Services/AgentCustomerService.php +++ b/src/backend/app/Services/AgentCustomerService.php @@ -6,14 +6,10 @@ use App\Models\Person\Person; use Illuminate\Contracts\Pagination\LengthAwarePaginator; -class AgentCustomerService -{ - public function __construct(private Agent $agent, private Person $person) - { - } +class AgentCustomerService { + public function __construct(private Agent $agent, private Person $person) {} - public function list(Agent $agent): LengthAwarePaginator - { + public function list(Agent $agent): LengthAwarePaginator { $miniGridId = $agent->mini_grid_id; return $this->person->newQuery()->with([ @@ -28,8 +24,7 @@ public function list(Agent $agent): LengthAwarePaginator ->paginate(config('settings.paginate')); } - public function search($searchTerm, $limit, $agent) - { + public function search($searchTerm, $limit, $agent) { return $this->person->newQuery()->with(['addresses.city', 'devices'])->whereHas( 'addresses', fn ($q) => $q->where('phone', 'LIKE', '%'.$searchTerm.'%') diff --git a/src/backend/app/Services/AgentCustomersPaymentHistoryService.php b/src/backend/app/Services/AgentCustomersPaymentHistoryService.php index 6982f3169..78ca0cc99 100644 --- a/src/backend/app/Services/AgentCustomersPaymentHistoryService.php +++ b/src/backend/app/Services/AgentCustomersPaymentHistoryService.php @@ -5,15 +5,12 @@ use App\Models\PaymentHistory; use Illuminate\Support\Facades\DB; -class AgentCustomersPaymentHistoryService -{ +class AgentCustomersPaymentHistoryService { public function __construct( private PaymentHistory $paymentHistory, - ) { - } + ) {} - public function getPaymentFlowByCustomerId($period, $customerId, $limit, $order = 'ASC') - { + public function getPaymentFlowByCustomerId($period, $customerId, $limit, $order = 'ASC') { $periodParam = strtoupper($period); $period = strtoupper($period); @@ -52,8 +49,7 @@ public function getPaymentFlowByCustomerId($period, $customerId, $limit, $order return $this->preparePaymentFlow($payments); } - public function getPaymentFlows($period, $agentId, $limit, $order = 'ASC') - { + public function getPaymentFlows($period, $agentId, $limit, $order = 'ASC') { $periodParam = strtoupper($period); $period = strtoupper($period); @@ -96,8 +92,7 @@ public function getPaymentFlows($period, $agentId, $limit, $order = 'ASC') return $this->preparePaymentFlow($payments); } - private function preparePaymentFlow($payments): array - { + private function preparePaymentFlow($payments): array { $flowList = []; foreach ($payments as $payment) { $flowList[$payment['period']][$payment['payment_type']] = $payment['amount']; @@ -106,8 +101,7 @@ private function preparePaymentFlow($payments): array return $flowList; } - private function executeSqlCommand(string $sql, $payerId, $agentId, $payerType) - { + private function executeSqlCommand(string $sql, $payerId, $agentId, $payerType) { $sth = DB::connection($this->paymentHistory->getConnectionName())->getPdo()->prepare($sql); if ($payerId) { diff --git a/src/backend/app/Services/AgentReceiptDetailService.php b/src/backend/app/Services/AgentReceiptDetailService.php index 8612d91b4..d164f5c42 100644 --- a/src/backend/app/Services/AgentReceiptDetailService.php +++ b/src/backend/app/Services/AgentReceiptDetailService.php @@ -9,15 +9,12 @@ /** * @implements IBaseService */ -class AgentReceiptDetailService implements IBaseService -{ +class AgentReceiptDetailService implements IBaseService { public function __construct( private AgentReceiptDetail $agentReceiptDetail, - ) { - } + ) {} - public function getSummary($agentId) - { + public function getSummary($agentId) { return $this->agentReceiptDetail->newQuery()->select('summary') ->whereHas( 'receipt', @@ -27,28 +24,23 @@ static function ($q) use ($agentId) { )->latest()->firstOrFail()->summary; } - public function getById(int $id): AgentReceiptDetail - { + public function getById(int $id): AgentReceiptDetail { throw new \Exception('Method getById() not yet implemented.'); } - public function create(array $agentReceiptDetailData): AgentReceiptDetail - { + public function create(array $agentReceiptDetailData): AgentReceiptDetail { return $this->agentReceiptDetail->create($agentReceiptDetailData); } - public function update($model, array $data): AgentReceiptDetail - { + public function update($model, array $data): AgentReceiptDetail { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } } diff --git a/src/backend/app/Services/AgentReceiptHistoryBalanceService.php b/src/backend/app/Services/AgentReceiptHistoryBalanceService.php index 8eeb63041..4e42d76dd 100644 --- a/src/backend/app/Services/AgentReceiptHistoryBalanceService.php +++ b/src/backend/app/Services/AgentReceiptHistoryBalanceService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class AgentReceiptHistoryBalanceService implements IAssignationService -{ +class AgentReceiptHistoryBalanceService implements IAssignationService { private AgentBalanceHistory $agentBalanceHistory; + private AgentReceipt $agentReceipt; - public function setAssigned($agentBalanceHistory): void - { + public function setAssigned($agentBalanceHistory): void { $this->agentBalanceHistory = $agentBalanceHistory; } - public function setAssignee($agentReceipt): void - { + public function setAssignee($agentReceipt): void { $this->agentReceipt = $agentReceipt; } - public function assign(): AgentBalanceHistory - { + public function assign(): AgentBalanceHistory { $this->agentBalanceHistory->trigger()->associate($this->agentReceipt); return $this->agentBalanceHistory; diff --git a/src/backend/app/Services/AgentReceiptService.php b/src/backend/app/Services/AgentReceiptService.php index 1d86579c3..fdacf7647 100644 --- a/src/backend/app/Services/AgentReceiptService.php +++ b/src/backend/app/Services/AgentReceiptService.php @@ -10,15 +10,12 @@ /** * @implements IBaseService */ -class AgentReceiptService implements IBaseService -{ +class AgentReceiptService implements IBaseService { public function __construct( private AgentReceipt $agentReceipt, - ) { - } + ) {} - public function getAll(?int $limit = null, ?int $agentId = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null, ?int $agentId = null): Collection|LengthAwarePaginator { $query = $this->agentReceipt->newQuery() ->with(['user', 'agent', 'history']); @@ -37,34 +34,28 @@ function ($q) use ($agentId) { } } - public function create(array $receiptData): AgentReceipt - { + public function create(array $receiptData): AgentReceipt { return $this->agentReceipt->newQuery()->create($receiptData); } - public function getById(int $id): AgentReceipt - { + public function getById(int $id): AgentReceipt { throw new \Exception('Method getById() not yet implemented.'); } - public function update($model, array $data): AgentReceipt - { + public function update($model, array $data): AgentReceipt { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getLastReceipt($agentId) - { + public function getLastReceipt($agentId) { return $this->agentReceipt->newQuery()->where('agent_id', $agentId) ->latest('id')->first(); } - public function getLastReceiptDate($agent) - { + public function getLastReceiptDate($agent) { $lastReceiptDate = $this->agentReceipt->newQuery()->where('agent_id', $agent->id)->get()->last(); if ($lastReceiptDate) { diff --git a/src/backend/app/Services/AgentService.php b/src/backend/app/Services/AgentService.php index 67426c1c8..53fbaafc4 100644 --- a/src/backend/app/Services/AgentService.php +++ b/src/backend/app/Services/AgentService.php @@ -15,19 +15,16 @@ /** * @implements IBaseService */ -class AgentService implements IBaseService -{ +class AgentService implements IBaseService { public function __construct( private Agent $agent, private AgentReceipt $agentReceipt, private AgentBalanceHistory $agentBalanceHistory, private PeriodService $periodService, private PersonService $personService, - ) { - } + ) {} - public function resetPassword(string $email) - { + public function resetPassword(string $email) { try { $newPassword = PasswordGenerator::generatePassword(); } catch (Exception $exception) { @@ -48,28 +45,24 @@ public function resetPassword(string $email) return $newPassword; } - public function updateDevice($agent, $deviceId): void - { + public function updateDevice($agent, $deviceId): void { $agent->device_id = $deviceId; $agent->update(); $agent->fresh(); } - public function setFirebaseToken($agent, $firebaseToken) - { + public function setFirebaseToken($agent, $firebaseToken) { $agent->fire_base_token = $firebaseToken; $agent->update(); return $agent->fresh(); } - public function getAgentBalance($agent) - { + public function getAgentBalance($agent) { return $agent->balance; } - public function searchAgent($searchTerm, $paginate) - { + public function searchAgent($searchTerm, $paginate) { if ($paginate === 1) { return $this->agent->newQuery()->with('miniGrid')->WhereHas( 'miniGrid', @@ -89,25 +82,21 @@ function ($q) use ($searchTerm) { ->orWhere('email', 'LIKE', '%'.$searchTerm.'%')->get(); } - public function getByAuthenticatedUser() - { + public function getByAuthenticatedUser() { return $this->agent->newQuery()->find(auth('agent_api')->user()->id); } - public function getById(int $id): Agent - { + public function getById(int $id): Agent { return $this->agent->newQuery() ->with(['person', 'person.addresses', 'miniGrid', 'commission']) ->where('id', $id)->firstOrFail(); } - public function delete($agent): ?bool - { + public function delete($agent): ?bool { return $agent->delete(); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->agent->newQuery() ->with(['person', 'person.addresses', 'miniGrid', 'commission']) @@ -146,8 +135,7 @@ public function create( return $this->agent->newQuery()->create($agentData); } - public function update($agent, array $agentData): Agent - { + public function update($agent, array $agentData): Agent { $person = $this->personService->getById($agentData['personId']); $personData = [ 'name' => $agentData['name'], diff --git a/src/backend/app/Services/AgentSoldApplianceService.php b/src/backend/app/Services/AgentSoldApplianceService.php index 12f5f0f5e..1662010bf 100644 --- a/src/backend/app/Services/AgentSoldApplianceService.php +++ b/src/backend/app/Services/AgentSoldApplianceService.php @@ -12,21 +12,17 @@ /** * @implements IBaseService */ -class AgentSoldApplianceService implements IBaseService -{ +class AgentSoldApplianceService implements IBaseService { public function __construct( private AgentSoldAppliance $agentSoldAppliance, private AssetPerson $assetPerson, - ) { - } + ) {} - public function create($applianceData): AgentSoldAppliance - { + public function create($applianceData): AgentSoldAppliance { return $this->agentSoldAppliance->newQuery()->create($applianceData); } - public function getById(int $agentId, ?int $customerId = null): AgentSoldAppliance - { + public function getById(int $agentId, ?int $customerId = null): AgentSoldAppliance { return $this->assetPerson->newQuery()->with(['person', 'assetType', 'rates']) ->whereHasMorph( 'creator', @@ -43,13 +39,11 @@ function ($q) use ($agentId) { ->first(); } - public function update($model, array $data): AgentSoldAppliance - { + public function update($model, array $data): AgentSoldAppliance { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } @@ -92,8 +86,7 @@ function ($q) use ($agentId) { } } - public function list($agentId) - { + public function list($agentId) { return $this->assetPerson->newQuery()->with(['person', 'assetType', 'rates']) ->whereHasMorph( 'creator', diff --git a/src/backend/app/Services/AgentTicketService.php b/src/backend/app/Services/AgentTicketService.php index 769ac940e..d994eca25 100644 --- a/src/backend/app/Services/AgentTicketService.php +++ b/src/backend/app/Services/AgentTicketService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class AgentTicketService implements IAssignationService -{ +class AgentTicketService implements IAssignationService { private Ticket $ticket; + private Agent $agent; - public function setAssigned($ticket): void - { + public function setAssigned($ticket): void { $this->ticket = $ticket; } - public function setAssignee($agent): void - { + public function setAssignee($agent): void { $this->agent = $agent; } - public function assign(): Ticket - { + public function assign(): Ticket { $this->ticket->creator()->associate($this->agent); return $this->ticket; diff --git a/src/backend/app/Services/AgentTransactionHistoryBalanceService.php b/src/backend/app/Services/AgentTransactionHistoryBalanceService.php index 0fa694703..bb371b58d 100644 --- a/src/backend/app/Services/AgentTransactionHistoryBalanceService.php +++ b/src/backend/app/Services/AgentTransactionHistoryBalanceService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class AgentTransactionHistoryBalanceService implements IAssignationService -{ +class AgentTransactionHistoryBalanceService implements IAssignationService { private AgentBalanceHistory $agentBalanceHistory; + private AgentTransaction $agentTransaction; - public function setAssigned($agentBalanceHistory): void - { + public function setAssigned($agentBalanceHistory): void { $this->agentBalanceHistory = $agentBalanceHistory; } - public function setAssignee($agentTransaction): void - { + public function setAssignee($agentTransaction): void { $this->agentTransaction = $agentTransaction; } - public function assign(): AgentBalanceHistory - { + public function assign(): AgentBalanceHistory { $this->agentBalanceHistory->trigger()->associate($this->agentTransaction); return $this->agentBalanceHistory; diff --git a/src/backend/app/Services/AgentTransactionService.php b/src/backend/app/Services/AgentTransactionService.php index 7d75e37cf..9eaf29781 100644 --- a/src/backend/app/Services/AgentTransactionService.php +++ b/src/backend/app/Services/AgentTransactionService.php @@ -12,14 +12,12 @@ /** * @implements IBaseService */ -class AgentTransactionService implements IBaseService -{ +class AgentTransactionService implements IBaseService { public function __construct( private AgentTransaction $agentTransaction, private Transaction $transaction, private Device $device, - ) { - } + ) {} public function getAll( ?int $limit = null, @@ -49,8 +47,7 @@ static function ($q) use ($agentId) { return $query->get(); } - public function getById(int $agentId, ?int $customerId = null): AgentTransaction - { + public function getById(int $agentId, ?int $customerId = null): AgentTransaction { $customerDeviceSerials = $this->device->newQuery()->where('person_id', $customerId) ->get()->pluck('device_serial'); @@ -73,18 +70,15 @@ public function getById(int $agentId, ?int $customerId = null): AgentTransaction ->first(); } - public function create(array $transactionData): AgentTransaction - { + public function create(array $transactionData): AgentTransaction { return $this->agentTransaction->newQuery()->create($transactionData); } - public function update($model, array $data): AgentTransaction - { + public function update($model, array $data): AgentTransaction { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } } diff --git a/src/backend/app/Services/AgentTransactionTransactionService.php b/src/backend/app/Services/AgentTransactionTransactionService.php index a2901f2a3..1693971ef 100644 --- a/src/backend/app/Services/AgentTransactionTransactionService.php +++ b/src/backend/app/Services/AgentTransactionTransactionService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class AgentTransactionTransactionService implements IAssignationService -{ +class AgentTransactionTransactionService implements IAssignationService { private Transaction $transaction; + private AgentTransaction $agentTransaction; - public function setAssigned($transaction): void - { + public function setAssigned($transaction): void { $this->transaction = $transaction; } - public function setAssignee($agentTransaction): void - { + public function setAssignee($agentTransaction): void { $this->agentTransaction = $agentTransaction; } - public function assign(): Transaction - { + public function assign(): Transaction { $this->transaction->originalTransaction()->associate($this->agentTransaction); return $this->transaction; diff --git a/src/backend/app/Services/AppliancePaymentService.php b/src/backend/app/Services/AppliancePaymentService.php index 73d5ef8f4..a82b32ab1 100644 --- a/src/backend/app/Services/AppliancePaymentService.php +++ b/src/backend/app/Services/AppliancePaymentService.php @@ -12,8 +12,7 @@ use Illuminate\Support\Carbon; use MPM\Device\DeviceService; -class AppliancePaymentService -{ +class AppliancePaymentService { private float $paymentAmount; public function __construct( @@ -21,11 +20,9 @@ public function __construct( private MainSettings $mainSettings, private AppliancePersonService $appliancePersonService, private DeviceService $deviceService, - ) { - } + ) {} - public function getPaymentForAppliance($request, $appliancePerson) - { + public function getPaymentForAppliance($request, $appliancePerson) { $creatorId = auth('api')->user()->id; $this->paymentAmount = $amount = (float) $request->input('amount'); $applianceDetail = $this->appliancePersonService->getApplianceDetails($appliancePerson->id); @@ -50,8 +47,7 @@ public function getPaymentForAppliance($request, $appliancePerson) return $appliancePerson; } - public function updateRateRemaining($id, $amount): AssetRate - { + public function updateRateRemaining($id, $amount): AssetRate { /** @var AssetRate $applianceRate */ $applianceRate = AssetRate::query()->findOrFail($id); $applianceRate->remaining -= $amount; @@ -61,8 +57,7 @@ public function updateRateRemaining($id, $amount): AssetRate return $applianceRate; } - public function createPaymentLog($appliancePerson, $amount, $creatorId): void - { + public function createPaymentLog($appliancePerson, $amount, $creatorId): void { /** @var MainSettings $mainSettings */ $mainSettings = $this->mainSettings->newQuery()->first(); $currency = $mainSettings ? $mainSettings->currency : '€'; @@ -78,8 +73,7 @@ public function createPaymentLog($appliancePerson, $amount, $creatorId): void ); } - public function createPaymentHistory($amount, $buyer, $applianceRate, $transaction) - { + public function createPaymentHistory($amount, $buyer, $applianceRate, $transaction) { event( 'payment.successful', [ @@ -94,8 +88,7 @@ public function createPaymentHistory($amount, $buyer, $applianceRate, $transacti ); } - private function validateAmount($applianceDetail, $amount) - { + private function validateAmount($applianceDetail, $amount) { $totalRemainingAmount = $applianceDetail->rates->sum('remaining'); $installmentCost = $applianceDetail->rates[1]['rate_cost']; @@ -112,8 +105,7 @@ private function validateAmount($applianceDetail, $amount) } } - public function payInstallment($installment, $applianceOwner, $transaction) - { + public function payInstallment($installment, $applianceOwner, $transaction) { if ($installment['remaining'] > 0 && $this->paymentAmount > 0) { if ($installment['remaining'] <= $this->paymentAmount) { $this->paymentAmount -= $installment['remaining']; @@ -127,8 +119,7 @@ public function payInstallment($installment, $applianceOwner, $transaction) } } - private function processPaymentForDevice($deviceSerial, $transaction, $applianceDetail) - { + private function processPaymentForDevice($deviceSerial, $transaction, $applianceDetail) { $device = $this->deviceService->getBySerialNumber($deviceSerial); if (!$device) { @@ -156,8 +147,7 @@ private function processPaymentForDevice($deviceSerial, $transaction, $appliance $token->save(); } - public function getDayDifferenceBetweenTwoInstallments($installments) - { + public function getDayDifferenceBetweenTwoInstallments($installments) { try { $secondInstallment = $installments[1]; $thirdInstallment = $installments[2]; @@ -170,8 +160,7 @@ public function getDayDifferenceBetweenTwoInstallments($installments) } } - public function setPaymentAmount($amount): void - { + public function setPaymentAmount($amount): void { $this->paymentAmount = $amount; } } diff --git a/src/backend/app/Services/AppliancePersonService.php b/src/backend/app/Services/AppliancePersonService.php index bb6222603..8d4b67ec9 100644 --- a/src/backend/app/Services/AppliancePersonService.php +++ b/src/backend/app/Services/AppliancePersonService.php @@ -16,34 +16,28 @@ * @implements IBaseService * @implements IAssociative */ -class AppliancePersonService implements IBaseService, IAssociative -{ +class AppliancePersonService implements IAssociative, IBaseService { public function __construct( private MainSettings $mainSettings, private AssetPerson $assetPerson, private CashTransactionService $cashTransactionService, - ) { - } + ) {} - public function make(array $data): AssetPerson - { + public function make(array $data): AssetPerson { return $this->assetPerson->newQuery()->make($data); } - public function save($appliancePerson): bool - { + public function save($appliancePerson): bool { return $appliancePerson->save(); } - private function checkDownPaymentIsBigger($downPayment, $cost) - { + private function checkDownPaymentIsBigger($downPayment, $cost) { if ($downPayment > $cost) { throw new DownPaymentBiggerThanAppliancePriceException('Down payment is not bigger than appliance sold cost '); } } - public function createFromRequest($request, $person, $asset) - { + public function createFromRequest($request, $person, $asset) { $this->checkDownPaymentIsBigger($request->input('down_payment'), $request->input('cost')); $assetPerson = $this->assetPerson::query()->make( [ @@ -102,8 +96,7 @@ static function ($q) { return $assetPerson; } - public function initSoldApplianceDataContainer($asset, $assetPerson, $transaction) - { + public function initSoldApplianceDataContainer($asset, $assetPerson, $transaction) { $soldApplianceDataContainer = app()->makeWith( SoldApplianceDataContainer::class, [ @@ -116,8 +109,7 @@ public function initSoldApplianceDataContainer($asset, $assetPerson, $transactio event('appliance.sold', $soldApplianceDataContainer); } - public function createLogForSoldAppliance($assetPerson, $cost, $preferredPrice) - { + public function createLogForSoldAppliance($assetPerson, $cost, $preferredPrice) { $currency = $this->getCurrencyFromMainSettings(); event( @@ -133,15 +125,13 @@ public function createLogForSoldAppliance($assetPerson, $cost, $preferredPrice) ); } - public function getCurrencyFromMainSettings() - { + public function getCurrencyFromMainSettings() { $mainSettings = $this->mainSettings->newQuery()->first(); return $mainSettings === null ? '€' : $mainSettings->currency; } - public function getApplianceDetails($applianceId) - { + public function getApplianceDetails($applianceId) { $appliance = $this->assetPerson::with('asset', 'rates.logs', 'logs.owner') ->where('id', '=', $applianceId) ->first(); @@ -149,8 +139,7 @@ public function getApplianceDetails($applianceId) return $this->sumTotalPaymentsAndTotalRemainingAmount($appliance); } - private function sumTotalPaymentsAndTotalRemainingAmount($appliance) - { + private function sumTotalPaymentsAndTotalRemainingAmount($appliance) { $rates = Collect($appliance->rates); $appliance['totalRemainingAmount'] = 0; $appliance['totalPayments'] = 0; @@ -165,33 +154,27 @@ private function sumTotalPaymentsAndTotalRemainingAmount($appliance) return $appliance; } - public function getLoansForCustomerId($customerId) - { + public function getLoansForCustomerId($customerId) { return $this->assetPerson->newQuery()->where('person_id', $customerId); } - public function getById(int $id): AssetPerson - { + public function getById(int $id): AssetPerson { throw new \Exception('Method getById() not yet implemented.'); } - public function create(array $data): AssetPerson - { + public function create(array $data): AssetPerson { throw new \Exception('Method create() not yet implemented.'); } - public function update($model, array $data): AssetPerson - { + public function update($model, array $data): AssetPerson { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->assetPerson->newQuery()->with(['person.devices'])->paginate($limit); } @@ -199,16 +182,14 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->assetPerson->newQuery()->with(['person.devices'])->get(); } - public function getLoanIdsForCustomerId($customerId) - { + public function getLoanIdsForCustomerId($customerId) { return $this->assetPerson->newQuery() ->where('person_id', $customerId) ->where('device_serial', null) ->orWhere('device_serial', '')->pluck('id'); } - public function getBySerialNumber($serialNumber) - { + public function getBySerialNumber($serialNumber) { return $this->assetPerson->newQuery()->where('device_serial', $serialNumber)->first(); } } diff --git a/src/backend/app/Services/ApplianceRatePaymentHistoryService.php b/src/backend/app/Services/ApplianceRatePaymentHistoryService.php index a532e78e4..79f7f7c26 100644 --- a/src/backend/app/Services/ApplianceRatePaymentHistoryService.php +++ b/src/backend/app/Services/ApplianceRatePaymentHistoryService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class ApplianceRatePaymentHistoryService implements IAssignationService -{ +class ApplianceRatePaymentHistoryService implements IAssignationService { private PaymentHistory $paymentHistory; + private AssetRate $assetRate; - public function setAssigned($paymentHistory): void - { + public function setAssigned($paymentHistory): void { $this->paymentHistory = $paymentHistory; } - public function setAssignee($assetRate): void - { + public function setAssignee($assetRate): void { $this->assetRate = $assetRate; } - public function assign(): PaymentHistory - { + public function assign(): PaymentHistory { $this->paymentHistory->paidFor()->associate($this->assetRate); return $this->paymentHistory; diff --git a/src/backend/app/Services/ApplianceRateService.php b/src/backend/app/Services/ApplianceRateService.php index 7f5fa6820..195bbece9 100644 --- a/src/backend/app/Services/ApplianceRateService.php +++ b/src/backend/app/Services/ApplianceRateService.php @@ -11,24 +11,20 @@ // FIXME: // class ApplianceRateService implements IBaseService -class ApplianceRateService -{ +class ApplianceRateService { public function __construct( private AssetRate $applianceRate, private MainSettings $mainSettings, - ) { - } + ) {} - public function getCurrencyFromMainSettings(): string - { + public function getCurrencyFromMainSettings(): string { /** @var MainSettings $mainSettings */ $mainSettings = $this->mainSettings->newQuery()->first(); return $mainSettings === null ? '€' : $mainSettings->currency; } - public function updateApplianceRateCost(AssetRate $applianceRate, $creatorId, $cost, $newCost): AssetRate - { + public function updateApplianceRateCost(AssetRate $applianceRate, $creatorId, $cost, $newCost): AssetRate { $currency = $this->getCurrencyFromMainSettings(); event( 'new.log', @@ -52,8 +48,7 @@ public function updateApplianceRateCost(AssetRate $applianceRate, $creatorId, $c return $applianceRate->refresh(); } - public function deleteUpdatedApplianceRateIfCostZero(AssetRate $applianceRate, $creatorId, $cost, $newCost): void - { + public function deleteUpdatedApplianceRateIfCostZero(AssetRate $applianceRate, $creatorId, $cost, $newCost): void { $currency = $this->getCurrencyFromMainSettings(); $appliancePerson = $applianceRate->assetPerson; $applianceRate->delete(); @@ -73,8 +68,7 @@ public function deleteUpdatedApplianceRateIfCostZero(AssetRate $applianceRate, $ ); } - public function getByLoanIdsForDueDate($loanIds): Collection - { + public function getByLoanIdsForDueDate($loanIds): Collection { return $this->applianceRate->newQuery()->with('assetPerson.asset') ->whereIn('asset_person_id', $loanIds) ->where('remaining', '>', 0) @@ -82,20 +76,17 @@ public function getByLoanIdsForDueDate($loanIds): Collection ->get(); } - public function getAllByLoanId($loanId): Collection - { + public function getAllByLoanId($loanId): Collection { return $this->applianceRate->newQuery()->with('assetPerson.asset') ->where('asset_person_id', $loanId) ->get(); } - public function getById(int $id): AssetRate - { + public function getById(int $id): AssetRate { throw new \Exception('Method getById() not yet implemented.'); } - public function create($assetPerson, $installmentType = 'monthly'): void - { + public function create($assetPerson, $installmentType = 'monthly'): void { $baseTime = $assetPerson->first_payment_date ?? date('Y-m-d'); $installment = $installmentType === 'monthly' ? 'month' : 'week'; if ($assetPerson->down_payment > 0) { @@ -134,23 +125,19 @@ public function create($assetPerson, $installmentType = 'monthly'): void } } - public function update($model, array $data): AssetRate - { + public function update($model, array $data): AssetRate { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } - public function getDownPaymentAsAssetRate($assetPerson): ?AssetRate - { + public function getDownPaymentAsAssetRate($assetPerson): ?AssetRate { /** @var ?AssetRate $result */ $result = $this->applianceRate->newQuery() ->where('asset_person_id', $assetPerson->id) @@ -161,8 +148,7 @@ public function getDownPaymentAsAssetRate($assetPerson): ?AssetRate return $result; } - public function queryOutstandingDebtsByApplianceRates(CarbonImmutable $toDate): Builder - { + public function queryOutstandingDebtsByApplianceRates(CarbonImmutable $toDate): Builder { return $this->applianceRate->newQuery() ->with(['assetPerson.asset', 'assetPerson.person']) ->where('due_date', '<', $toDate->format('Y-m-d')) diff --git a/src/backend/app/Services/ApplianceTypeService.php b/src/backend/app/Services/ApplianceTypeService.php index 1feb0bb8a..d83b6c39d 100644 --- a/src/backend/app/Services/ApplianceTypeService.php +++ b/src/backend/app/Services/ApplianceTypeService.php @@ -4,17 +4,14 @@ use App\Models\AssetType; -class ApplianceTypeService -{ +class ApplianceTypeService { private $assetType; - public function __construct(AssetType $assetType) - { + public function __construct(AssetType $assetType) { $this->assetType = $assetType; } - public function getApplianceTypes($request) - { + public function getApplianceTypes($request) { $perPage = $request->get('per_page'); if ($perPage) { return $this->assetType->newQuery()->paginate($perPage); @@ -23,24 +20,21 @@ public function getApplianceTypes($request) return $this->assetType->newQuery()->get(); } - public function createApplianceType($request) - { + public function createApplianceType($request) { return $this->assetType::query() ->create( $request->only(['name', 'price']) ); } - public function updateApplianceType($request, $appliance) - { + public function updateApplianceType($request, $appliance) { $appliance->update($request->only(['name', 'price'])); $appliance->fresh(); return $appliance; } - public function deleteApplianceType($applianceType) - { + public function deleteApplianceType($applianceType) { $applianceType->delete(); } } diff --git a/src/backend/app/Services/AssetService.php b/src/backend/app/Services/AssetService.php index d4a4c71e1..2b0000d55 100644 --- a/src/backend/app/Services/AssetService.php +++ b/src/backend/app/Services/AssetService.php @@ -4,14 +4,10 @@ use App\Models\Asset; -class AssetService -{ - public function __construct(private Asset $asset) - { - } +class AssetService { + public function __construct(private Asset $asset) {} - public function getAssets($request) - { + public function getAssets($request) { $perPage = $request->get('per_page'); if ($perPage) { return $this->asset->newQuery()->with(['assetType'])->paginate($perPage); @@ -20,29 +16,25 @@ public function getAssets($request) return $this->asset->newQuery()->with(['assetType'])->get(); } - public function createAsset($request) - { + public function createAsset($request) { return $this->asset::query() ->create( $request->only(['asset_type_id', 'name', 'price']) ); } - public function updateAsset($request, $asset) - { + public function updateAsset($request, $asset) { $asset->update($request->only(['name', 'asset_type_id', 'price'])); $asset->fresh(); return $asset; } - public function deleteAsset($asset) - { + public function deleteAsset($asset) { $asset->delete(); } - public function getById($id) - { + public function getById($id) { return $this->asset->newQuery()->with(['assetType'])->find($id); } } diff --git a/src/backend/app/Services/BingMapApiService.php b/src/backend/app/Services/BingMapApiService.php index c79367e1b..b850b9505 100644 --- a/src/backend/app/Services/BingMapApiService.php +++ b/src/backend/app/Services/BingMapApiService.php @@ -6,20 +6,17 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; -class BingMapApiService -{ +class BingMapApiService { private $httpClient; - public function __construct(Client $httpClient) - { + public function __construct(Client $httpClient) { $this->httpClient = $httpClient; } /** * @throws InvalidBingApiKeyException */ - public function checkAuthenticationKey($key): bool - { + public function checkAuthenticationKey($key): bool { try { $response = $this->httpClient->get(config('services.bingMapApi.url').$key)->getBody()->getContents(); } catch (GuzzleException $e) { @@ -29,8 +26,7 @@ public function checkAuthenticationKey($key): bool return $this->isRequestAuthenticated($response); } - private function isRequestAuthenticated($body): bool - { + private function isRequestAuthenticated($body): bool { try { $jsonBody = json_decode($body, true, 512, JSON_THROW_ON_ERROR); $authenticated = $jsonBody['statusDescription'] === 'OK'; diff --git a/src/backend/app/Services/CashTransactionService.php b/src/backend/app/Services/CashTransactionService.php index b62535b75..9b4a3e1da 100644 --- a/src/backend/app/Services/CashTransactionService.php +++ b/src/backend/app/Services/CashTransactionService.php @@ -5,19 +5,17 @@ use App\Models\Transaction\CashTransaction; use App\Models\Transaction\Transaction; -class CashTransactionService -{ +class CashTransactionService { private $cashTransaction; + private $transaction; - public function __construct(CashTransaction $cashTransaction, Transaction $transaction) - { + public function __construct(CashTransaction $cashTransaction, Transaction $transaction) { $this->transaction = $transaction; $this->cashTransaction = $cashTransaction; } - public function createCashTransaction($creatorId, $amount, $sender, $deviceSerial = null) - { + public function createCashTransaction($creatorId, $amount, $sender, $deviceSerial = null) { $cashTransaction = $this->cashTransaction->newQuery()->create( [ 'user_id' => $creatorId, diff --git a/src/backend/app/Services/CityGeographicalInformationService.php b/src/backend/app/Services/CityGeographicalInformationService.php index 06b0d3bdc..351b15daa 100644 --- a/src/backend/app/Services/CityGeographicalInformationService.php +++ b/src/backend/app/Services/CityGeographicalInformationService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class CityGeographicalInformationService implements IAssignationService -{ +class CityGeographicalInformationService implements IAssignationService { private GeographicalInformation $geographicInformation; + private City $city; - public function setAssigned($assigned): void - { + public function setAssigned($assigned): void { $this->geographicInformation = $assigned; } - public function setAssignee($assignee): void - { + public function setAssignee($assignee): void { $this->city = $assignee; } - public function assign(): GeographicalInformation - { + public function assign(): GeographicalInformation { $this->geographicInformation->owner()->associate($this->city); return $this->geographicInformation; diff --git a/src/backend/app/Services/CityService.php b/src/backend/app/Services/CityService.php index 4690699ce..b5250239f 100644 --- a/src/backend/app/Services/CityService.php +++ b/src/backend/app/Services/CityService.php @@ -10,30 +10,24 @@ /** * @implements IBaseService */ -class CityService implements IBaseService -{ +class CityService implements IBaseService { public function __construct( private City $city, - ) { - } + ) {} - public function getCityIdsByMiniGridId($miniGridId): array - { + public function getCityIdsByMiniGridId($miniGridId): array { return $this->city->newQuery()->select('id')->where('mini_grid_id', $miniGridId)->get()->pluck('id')->toArray(); } - public function getByIdWithRelation($cityId, $relation) - { + public function getByIdWithRelation($cityId, $relation) { return $this->city->newQuery()->with($relation)->find($cityId); } - public function getById($cityId): City - { + public function getById($cityId): City { return $this->city->newQuery()->find($cityId); } - public function update($city, array $cityData): City - { + public function update($city, array $cityData): City { $city->update([ 'name' => $cityData['name'] ?? $city->name, 'mini_grid_id' => $cityData['mini_grid_id'] ?? $city->mini_grid_id, @@ -45,13 +39,11 @@ public function update($city, array $cityData): City return $city; } - public function create(array $data): City - { + public function create(array $data): City { return $this->city->newQuery()->create($data); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->city->newQuery()->with('location')->paginate($limit); } @@ -59,8 +51,7 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->city->newQuery()->with('location')->get(); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('not implemented'); } } diff --git a/src/backend/app/Services/ClusterManagerService.php b/src/backend/app/Services/ClusterManagerService.php index d6433b6a3..4d511c9d7 100644 --- a/src/backend/app/Services/ClusterManagerService.php +++ b/src/backend/app/Services/ClusterManagerService.php @@ -4,17 +4,14 @@ use App\Models\User; -class ClusterManagerService -{ +class ClusterManagerService { private User $user; - public function __construct(User $user) - { + public function __construct(User $user) { $this->user = $user; } - public function findManagerById(int $managerId): User - { + public function findManagerById(int $managerId): User { return $this->user->find($managerId); } } diff --git a/src/backend/app/Services/ClusterMeterService.php b/src/backend/app/Services/ClusterMeterService.php index 6929a8091..41a9f69d9 100644 --- a/src/backend/app/Services/ClusterMeterService.php +++ b/src/backend/app/Services/ClusterMeterService.php @@ -5,14 +5,10 @@ use App\Models\Cluster; use App\Models\Meter\Meter; -class ClusterMeterService -{ - public function __construct(private Cluster $cluster, private Meter $meter) - { - } +class ClusterMeterService { + public function __construct(private Cluster $cluster, private Meter $meter) {} - public function getCountById($clusterId): int - { + public function getCountById($clusterId): int { return $this->meter->newQuery()->whereHas( 'meterParameter', function ($q) use ($clusterId) { diff --git a/src/backend/app/Services/ClusterMiniGridService.php b/src/backend/app/Services/ClusterMiniGridService.php index 896357a6d..ff7788327 100644 --- a/src/backend/app/Services/ClusterMiniGridService.php +++ b/src/backend/app/Services/ClusterMiniGridService.php @@ -5,14 +5,10 @@ use App\Models\Cluster; use App\Models\MiniGrid; -class ClusterMiniGridService -{ - public function __construct(private Cluster $cluster, private MiniGrid $miniGrid) - { - } +class ClusterMiniGridService { + public function __construct(private Cluster $cluster, private MiniGrid $miniGrid) {} - public function getClustersWithMiniGrids() - { + public function getClustersWithMiniGrids() { return $this->cluster->newQuery()->with('miniGrids')->get(); } } diff --git a/src/backend/app/Services/ClusterPopulationService.php b/src/backend/app/Services/ClusterPopulationService.php index b686b3a7a..f90fcae16 100644 --- a/src/backend/app/Services/ClusterPopulationService.php +++ b/src/backend/app/Services/ClusterPopulationService.php @@ -5,14 +5,10 @@ use App\Models\Cluster; use App\Models\Person\Person; -class ClusterPopulationService -{ - public function __construct(private Person $person, private Cluster $cluster) - { - } +class ClusterPopulationService { + public function __construct(private Person $person, private Cluster $cluster) {} - public function getById($clusterId, $onlyCustomers = true): int - { + public function getById($clusterId, $onlyCustomers = true): int { if ($onlyCustomers) { $population = $this->person->newQuery() ->where('is_customer', 1) diff --git a/src/backend/app/Services/ClusterRevenueService.php b/src/backend/app/Services/ClusterRevenueService.php index 1c8169f03..feb2b6b3e 100644 --- a/src/backend/app/Services/ClusterRevenueService.php +++ b/src/backend/app/Services/ClusterRevenueService.php @@ -8,14 +8,12 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Facades\DB; -class ClusterRevenueService -{ +class ClusterRevenueService { public function __construct( private PeriodService $periodService, private Cluster $cluster, private Transaction $transaction, - ) { - } + ) {} public function getTransactionsForMonthlyPeriodById( $clusterId, @@ -63,8 +61,7 @@ static function ($q) { ->groupBy(DB::raw('DATE_FORMAT(created_at,\'%Y-%m\')'))->get(); } - public function getTransactionsForWeeklyPeriod($clusterId, $period, $connectionType = null) - { + public function getTransactionsForWeeklyPeriod($clusterId, $period, $connectionType = null) { return $this->transaction->newQuery() ->selectRaw('DATE_FORMAT(created_at,\'%Y-%m\') as period , SUM(amount) as revenue') ->whereHas( @@ -240,8 +237,7 @@ public function getMonthlyRevenueAnalysisForConnectionTypesById( /** * @throws \Exception */ - public function getMonthlyMiniGridBasedRevenueById($clusterId) - { + public function getMonthlyMiniGridBasedRevenueById($clusterId) { $startDate = date('Y-01-01'); $endDate = date('Y-m-t'); $period = 'monthly'; @@ -309,8 +305,7 @@ public function getMiniGridBasedRevenueById( return $miniGrids; } - public function setDatesForRequest($startDate, $endDate): array - { + public function setDatesForRequest($startDate, $endDate): array { if (!$startDate) { $start = new \DateTime(); $start->setDate($start->format('Y'), $start->format('n'), 1); // Normalize the day to 1 @@ -323,8 +318,7 @@ public function setDatesForRequest($startDate, $endDate): array return ['startDate' => $startDate, 'endDate' => $endDate]; } - public function setDateRangeForRequest($startDate, $endDate): array - { + public function setDateRangeForRequest($startDate, $endDate): array { $dateRange = []; if ($startDate !== null && $endDate !== null) { $dateRange[0] = $startDate; diff --git a/src/backend/app/Services/ClusterService.php b/src/backend/app/Services/ClusterService.php index 7288bbb2b..4c0306d4a 100644 --- a/src/backend/app/Services/ClusterService.php +++ b/src/backend/app/Services/ClusterService.php @@ -10,25 +10,20 @@ /** * @implements IBaseService */ -class ClusterService implements IBaseService -{ +class ClusterService implements IBaseService { public function __construct( private Cluster $cluster, - ) { - } + ) {} - protected function setClusterMeterCount(Cluster $cluster, int $meterCount) - { + protected function setClusterMeterCount(Cluster $cluster, int $meterCount) { $cluster->meterCount = $meterCount; } - protected function setRevenue(Cluster $cluster, int $totalTransactionsAmount) - { + protected function setRevenue(Cluster $cluster, int $totalTransactionsAmount) { $cluster->revenue = $totalTransactionsAmount; } - protected function setPopulation(Cluster $cluster, int $populationCount) - { + protected function setPopulation(Cluster $cluster, int $populationCount) { $cluster->population = $populationCount; } @@ -45,23 +40,19 @@ public function getCluster( return $cluster; } - public function getClusterCities($clusterId) - { + public function getClusterCities($clusterId) { return Cluster::query()->with('cities')->find($clusterId); } - public function getClusterMiniGrids($clusterId) - { + public function getClusterMiniGrids($clusterId) { return Cluster::query()->with('miniGrids')->find($clusterId); } - public function getGeoLocationById($clusterId) - { + public function getGeoLocationById($clusterId) { return $this->cluster->newQuery()->select('geo_data')->find($clusterId)->geo_data; } - public function getDateRangeFromRequest($startDate, $endDate): array - { + public function getDateRangeFromRequest($startDate, $endDate): array { $dateRange = []; if ($startDate !== null && $endDate !== null) { @@ -75,18 +66,15 @@ public function getDateRangeFromRequest($startDate, $endDate): array return $dateRange; } - public function getById($clusterId): Cluster - { + public function getById($clusterId): Cluster { return $this->cluster->newQuery()->with(['miniGrids.location', 'cities'])->find($clusterId); } - public function create(array $clusterData): Cluster - { + public function create(array $clusterData): Cluster { return $this->cluster->newQuery()->create($clusterData); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit !== null) { return $this->cluster->newQuery()->with('miniGrids')->limit($limit)->get(); } @@ -94,15 +82,13 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->cluster->newQuery()->with('miniGrids')->get(); } - public function update($model, array $data): Cluster - { + public function update($model, array $data): Cluster { throw new \Exception('Method update() not yet implemented.'); return new Cluster(); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } } diff --git a/src/backend/app/Services/ClusterTransactionService.php b/src/backend/app/Services/ClusterTransactionService.php index b64c1cfc0..bea5180f5 100644 --- a/src/backend/app/Services/ClusterTransactionService.php +++ b/src/backend/app/Services/ClusterTransactionService.php @@ -5,14 +5,10 @@ use App\Models\Cluster; use App\Models\Transaction\Transaction; -class ClusterTransactionService -{ - public function __construct(private Cluster $cluster, private Transaction $transaction) - { - } +class ClusterTransactionService { + public function __construct(private Cluster $cluster, private Transaction $transaction) {} - public function getById($clusterId, array $range) - { + public function getById($clusterId, array $range) { return $this->transaction->newQuery()->whereHas( 'device', function ($q) use ($clusterId) { diff --git a/src/backend/app/Services/ClustersDashboardCacheDataService.php b/src/backend/app/Services/ClustersDashboardCacheDataService.php index a02bb6d2f..f0f90e22d 100644 --- a/src/backend/app/Services/ClustersDashboardCacheDataService.php +++ b/src/backend/app/Services/ClustersDashboardCacheDataService.php @@ -6,8 +6,7 @@ use MPM\Device\ClusterDeviceService; use Nette\Utils\DateTime; -class ClustersDashboardCacheDataService extends AbstractDashboardCacheDataService -{ +class ClustersDashboardCacheDataService extends AbstractDashboardCacheDataService { private const CACHE_KEY_CLUSTERS_DATA = 'ClustersData'; public function __construct( @@ -23,15 +22,14 @@ public function __construct( parent::__construct(self::CACHE_KEY_CLUSTERS_DATA); } - public function setData($dateRange = []) - { + public function setData($dateRange = []) { if (empty($dateRange)) { $startDate = date('Y-01-01'); // first day of the year $endDate = date('Y-m-d H:i:s', strtotime('today')); $dateRange[0] = $startDate; $dateRange[1] = $endDate; } else { - list($startDate, $endDate) = $dateRange; + [$startDate, $endDate] = $dateRange; } $monthlyPeriods = $this->periodService->generatePeriodicList($startDate, $endDate, 'monthly', [ diff --git a/src/backend/app/Services/CompanyDatabaseService.php b/src/backend/app/Services/CompanyDatabaseService.php index fae0c3f1e..d055ac71d 100644 --- a/src/backend/app/Services/CompanyDatabaseService.php +++ b/src/backend/app/Services/CompanyDatabaseService.php @@ -12,23 +12,19 @@ /** * @implements IBaseService */ -class CompanyDatabaseService implements IBaseService -{ +class CompanyDatabaseService implements IBaseService { public function __construct( private CompanyDatabase $companyDatabase, private DatabaseProxyManagerService $databaseProxyManagerService, - ) { - } + ) {} - public function getById(int $id): CompanyDatabase - { + public function getById(int $id): CompanyDatabase { $result = $this->companyDatabase->newQuery()->find($id); return $result; } - public function create(array $data): CompanyDatabase - { + public function create(array $data): CompanyDatabase { /** @var CompanyDatabase $result */ $company_database = $this->companyDatabase->newQuery()->create($data); $database_name = $company_database->database_name; @@ -55,23 +51,19 @@ function () { return $company_database; } - public function update($model, array $data): CompanyDatabase - { + public function update($model, array $data): CompanyDatabase { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method update() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } - public function findByCompanyId(int $companyId): CompanyDatabase - { + public function findByCompanyId(int $companyId): CompanyDatabase { /** @var CompanyDatabase $result */ $result = $this->companyDatabase->newQuery() ->where(CompanyDatabase::COL_COMPANY_ID, '=', $companyId) diff --git a/src/backend/app/Services/CompanyService.php b/src/backend/app/Services/CompanyService.php index 5f978ca7e..4f67dac71 100644 --- a/src/backend/app/Services/CompanyService.php +++ b/src/backend/app/Services/CompanyService.php @@ -9,49 +9,40 @@ /** * @implements IBaseService */ -class CompanyService implements IBaseService -{ +class CompanyService implements IBaseService { public function __construct( private Company $company, - ) { - } + ) {} - public function getByName($name): Company - { + public function getByName($name): Company { return $this->company->where('name', $name)->firstOrFail(); } - public function getByDatabaseProxy($databaseProxy): Company - { + public function getByDatabaseProxy($databaseProxy): Company { return $this->getById($databaseProxy->getCompanyId()); } - public function getById($id): Company - { + public function getById($id): Company { $result = $this->company->newQuery()->findOrFail($id); return $result; } - public function create($data): Company - { + public function create($data): Company { $company = $this->company->newQuery()->create($data); return $company; } - public function update($model, array $data): Company - { + public function update($model, array $data): Company { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { return $this->company->newQuery()->get(); } } diff --git a/src/backend/app/Services/ConnectionGroupService.php b/src/backend/app/Services/ConnectionGroupService.php index c29f1060e..60f9cd016 100644 --- a/src/backend/app/Services/ConnectionGroupService.php +++ b/src/backend/app/Services/ConnectionGroupService.php @@ -9,33 +9,27 @@ /** * @implements IBaseService - */ class ConnectionGroupService implements IBaseService -{ + */ class ConnectionGroupService implements IBaseService { public function __construct( private ConnectionGroup $connectionGroup, - ) { - } + ) {} - public function create(array $connectionGroupData): ConnectionGroup - { + public function create(array $connectionGroupData): ConnectionGroup { return $this->connectionGroup->newQuery()->create($connectionGroupData); } - public function getById(int $connectionGroupId): ConnectionGroup - { + public function getById(int $connectionGroupId): ConnectionGroup { return $this->connectionGroup->newQuery()->findOrFail($connectionGroupId); } - public function update($connectionGroup, array $connectionGroupData): ConnectionGroup - { + public function update($connectionGroup, array $connectionGroupData): ConnectionGroup { $connectionGroup->update($connectionGroupData); $connectionGroup->fresh(); return $connectionGroup; } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->connectionGroup->newQuery()->paginate($limit); } @@ -43,8 +37,7 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->connectionGroup->newQuery()->get(); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } } diff --git a/src/backend/app/Services/ConnectionTypeService.php b/src/backend/app/Services/ConnectionTypeService.php index f8c8bcd5f..c61f31d21 100644 --- a/src/backend/app/Services/ConnectionTypeService.php +++ b/src/backend/app/Services/ConnectionTypeService.php @@ -12,39 +12,32 @@ /** * @implements IBaseService */ -class ConnectionTypeService implements IBaseService -{ +class ConnectionTypeService implements IBaseService { public function __construct( private ConnectionType $connectionType, - ) { - } + ) {} - public function getByIdWithMeterCountRelation($connectionTypeId): Model|Builder - { + public function getByIdWithMeterCountRelation($connectionTypeId): Model|Builder { return $this->connectionType->newQuery()->withCount('meterParameters')->where('id', $connectionTypeId) ->firstOrFail(); } - public function getById(int $connectionTypeId): ConnectionType - { + public function getById(int $connectionTypeId): ConnectionType { return $this->connectionType->newQuery()->findOrFail($connectionTypeId); } - public function create(array $connectionServiceData): ConnectionType - { + public function create(array $connectionServiceData): ConnectionType { return $this->connectionType->newQuery()->create($connectionServiceData); } - public function update($connectionType, array $connectionTypeData): ConnectionType - { + public function update($connectionType, array $connectionTypeData): ConnectionType { $connectionType->update($connectionTypeData); $connectionType->fresh(); return $connectionType; } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->connectionType->newQuery()->paginate($limit); } @@ -52,8 +45,7 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->connectionType->newQuery()->get(); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } } diff --git a/src/backend/app/Services/CountryService.php b/src/backend/app/Services/CountryService.php index 7be1f06d1..e40dd85ed 100644 --- a/src/backend/app/Services/CountryService.php +++ b/src/backend/app/Services/CountryService.php @@ -9,40 +9,32 @@ /** * @implements IBaseService */ -class CountryService implements IBaseService -{ +class CountryService implements IBaseService { public function __construct( private Country $country, - ) { - } + ) {} - public function getByCode(?string $countryCode) - { + public function getByCode(?string $countryCode) { return $countryCode !== null ? $this->country->where('country_code', $countryCode)->first() : $countryCode; } - public function getById(int $id): Country - { + public function getById(int $id): Country { throw new \Exception('Method getById() not yet implemented.'); } - public function create(array $data): Country - { + public function create(array $data): Country { throw new \Exception('Method create() not yet implemented.'); } - public function update($model, array $data): Country - { + public function update($model, array $data): Country { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } } diff --git a/src/backend/app/Services/DatabaseProxyService.php b/src/backend/app/Services/DatabaseProxyService.php index d0d6b558c..9968e85be 100644 --- a/src/backend/app/Services/DatabaseProxyService.php +++ b/src/backend/app/Services/DatabaseProxyService.php @@ -9,36 +9,28 @@ /** * @implements IBaseService */ -class DatabaseProxyService implements IBaseService -{ - public function __construct(private DatabaseProxy $databaseProxy) - { - } +class DatabaseProxyService implements IBaseService { + public function __construct(private DatabaseProxy $databaseProxy) {} - public function getById($id): DatabaseProxy - { + public function getById($id): DatabaseProxy { throw new \Exception('Method getById() not yet implemented.'); return new DatabaseProxy(); } - public function create(array $databaseProxyData): DatabaseProxy - { + public function create(array $databaseProxyData): DatabaseProxy { return $this->databaseProxy->newQuery()->create($databaseProxyData); } - public function update($model, array $data): DatabaseProxy - { + public function update($model, array $data): DatabaseProxy { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } } diff --git a/src/backend/app/Services/FirebaseService.php b/src/backend/app/Services/FirebaseService.php index 22ba42fec..63080a4c5 100644 --- a/src/backend/app/Services/FirebaseService.php +++ b/src/backend/app/Services/FirebaseService.php @@ -6,10 +6,8 @@ use GuzzleHttp\Client; use Illuminate\Support\Facades\Log; -class FirebaseService -{ - public function sendNotify($firebaseToken, $body): string - { +class FirebaseService { + public function sendNotify($firebaseToken, $body): string { try { $httpClient = new Client(); $request = $httpClient->post( diff --git a/src/backend/app/Services/GeographicalInformationService.php b/src/backend/app/Services/GeographicalInformationService.php index 7b76b9d49..6598f385c 100644 --- a/src/backend/app/Services/GeographicalInformationService.php +++ b/src/backend/app/Services/GeographicalInformationService.php @@ -12,16 +12,13 @@ * @implements IBaseService * @implements IAssociative */ -class GeographicalInformationService implements IBaseService, IAssociative -{ +class GeographicalInformationService implements IAssociative, IBaseService { public function __construct( private GeographicalInformation $geographicalInformation, - ) { - } + ) {} // This function will be removed until devices feature migration is done - public function changeOwnerWithAddress($meterParameter, $addressId) - { + public function changeOwnerWithAddress($meterParameter, $addressId) { $geoInfo = $this->geographicalInformation->newQuery()->where('owner_type', 'meter_parameter')->where('owner_id', $meterParameter->id)->first(); if ($geoInfo) { $geoInfo->owner_type = 'address'; @@ -30,43 +27,36 @@ public function changeOwnerWithAddress($meterParameter, $addressId) } } - public function getById(int $id): GeographicalInformation - { + public function getById(int $id): GeographicalInformation { return $this->geographicalInformation->newQuery()->find($id); } - public function delete($model): ?bool - { + public function delete($model): ?bool { return $model->delete(); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { return $this->geographicalInformation->newQuery()->get(); } - public function create(array $data): GeographicalInformation - { + public function create(array $data): GeographicalInformation { throw new \Exception('Method create() not yet implemented.'); } - public function update($model, array $data): GeographicalInformation - { + public function update($model, array $data): GeographicalInformation { $model->update($data); $model->fresh(); return $model; } - public function make($geographicalInformationData): GeographicalInformation - { + public function make($geographicalInformationData): GeographicalInformation { return $this->geographicalInformation->newQuery()->make([ 'points' => $geographicalInformationData['points'], ]); } - public function save($geographicalInformation): bool - { + public function save($geographicalInformation): bool { return $geographicalInformation->save(); } } diff --git a/src/backend/app/Services/Interfaces/IAssignationService.php b/src/backend/app/Services/Interfaces/IAssignationService.php index aa16f18da..d240a495f 100644 --- a/src/backend/app/Services/Interfaces/IAssignationService.php +++ b/src/backend/app/Services/Interfaces/IAssignationService.php @@ -10,8 +10,7 @@ * @template TAssigned of Model * @template TAssignee of Model */ -interface IAssignationService -{ +interface IAssignationService { /** @param TAssigned $assigned */ public function setAssigned($assigned): void; diff --git a/src/backend/app/Services/Interfaces/IAssociative.php b/src/backend/app/Services/Interfaces/IAssociative.php index 12859bb1f..c77a4e4d9 100644 --- a/src/backend/app/Services/Interfaces/IAssociative.php +++ b/src/backend/app/Services/Interfaces/IAssociative.php @@ -9,8 +9,7 @@ * * @template T of Model */ -interface IAssociative -{ +interface IAssociative { public function make(array $data): Model; /** diff --git a/src/backend/app/Services/Interfaces/IBaseService.php b/src/backend/app/Services/Interfaces/IBaseService.php index 90651b23e..322698360 100644 --- a/src/backend/app/Services/Interfaces/IBaseService.php +++ b/src/backend/app/Services/Interfaces/IBaseService.php @@ -11,8 +11,7 @@ * * @template T of Model */ -interface IBaseService -{ +interface IBaseService { /** @return T|null */ public function getById(int $id): ?Model; diff --git a/src/backend/app/Services/Interfaces/ISettingsService.php b/src/backend/app/Services/Interfaces/ISettingsService.php index 37a6f47a3..dabc62855 100644 --- a/src/backend/app/Services/Interfaces/ISettingsService.php +++ b/src/backend/app/Services/Interfaces/ISettingsService.php @@ -9,8 +9,7 @@ * * @template T of Model */ -interface ISettingsService -{ +interface ISettingsService { /** @return T|null */ public function get(): ?Model; diff --git a/src/backend/app/Services/MailService.php b/src/backend/app/Services/MailService.php index 9c506cdaf..3650d0947 100644 --- a/src/backend/app/Services/MailService.php +++ b/src/backend/app/Services/MailService.php @@ -5,17 +5,14 @@ use Illuminate\Mail\MailManager; use Illuminate\Mail\Message; -class MailService -{ +class MailService { private MailManager $mailManager; - public function __construct(MailManager $mailManager) - { + public function __construct(MailManager $mailManager) { $this->mailManager = $mailManager; } - public function sendWithAttachment(string $view, array $viewData, array $mailMeta, array $attachments) - { + public function sendWithAttachment(string $view, array $viewData, array $mailMeta, array $attachments) { $this->mailManager->send($view, $viewData, function (Message $message) use ($attachments, $mailMeta) { $message->to($mailMeta['to']) ->from($mailMeta['from']) diff --git a/src/backend/app/Services/MailSettingsService.php b/src/backend/app/Services/MailSettingsService.php index 33735bd01..3472edfbf 100644 --- a/src/backend/app/Services/MailSettingsService.php +++ b/src/backend/app/Services/MailSettingsService.php @@ -4,22 +4,18 @@ use App\Models\MailSettings; -class MailSettingsService -{ +class MailSettingsService { private $mailSettings; - public function __construct(MailSettings $mailSettings) - { + public function __construct(MailSettings $mailSettings) { $this->mailSettings = $mailSettings; } - public function list() - { + public function list() { return $this->mailSettings->newQuery()->get()->first(); } - public function create($request) - { + public function create($request) { $mailSettings = $this->mailSettings->newQuery()->create( ['mail_host' => $request->get('mail_host'), 'mail_port' => $request->get('mail_port'), @@ -32,8 +28,7 @@ public function create($request) return $mailSettings; } - public function update($request, $mailSettings) - { + public function update($request, $mailSettings) { $mailSettings->update( ['mail_host' => $request->get('mail_host'), 'mail_port' => $request->get('mail_port'), diff --git a/src/backend/app/Services/MainSettingsService.php b/src/backend/app/Services/MainSettingsService.php index ed83749b0..f8e700b5b 100644 --- a/src/backend/app/Services/MainSettingsService.php +++ b/src/backend/app/Services/MainSettingsService.php @@ -11,42 +11,35 @@ * @implements IBaseService */ // FIXME: Should this not be a ISettingsService? -class MainSettingsService implements IBaseService -{ +class MainSettingsService implements IBaseService { public function __construct( private MainSettings $mainSettings, - ) { - } + ) {} - public function getById(int $id): MainSettings - { + public function getById(int $id): MainSettings { throw new \Exception('Method getById() not yet implemented.'); return new MainSettings(); } - public function create(array $data): MainSettings - { + public function create(array $data): MainSettings { throw new \Exception('Method create() not yet implemented.'); return new MainSettings(); } - public function update($mainSettings, $mainSettingsData): MainSettings - { + public function update($mainSettings, $mainSettingsData): MainSettings { $mainSettings->update($mainSettingsData); $mainSettings->fresh(); return $mainSettings; } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method getById() not yet implemented.'); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { return $this->mainSettings->newQuery()->get(); } } diff --git a/src/backend/app/Services/MaintenanceUserService.php b/src/backend/app/Services/MaintenanceUserService.php index b2d4700a1..bb4095862 100644 --- a/src/backend/app/Services/MaintenanceUserService.php +++ b/src/backend/app/Services/MaintenanceUserService.php @@ -9,40 +9,32 @@ /** * @implements IBaseService */ -class MaintenanceUserService implements IBaseService -{ +class MaintenanceUserService implements IBaseService { public function __construct( private MaintenanceUsers $maintenanceUser, - ) { - } + ) {} - public function getMaintenanceUsersCount() - { + public function getMaintenanceUsersCount() { return $this->maintenanceUser->newQuery()->count(); } - public function create(array $maintenanceUserData): MaintenanceUsers - { + public function create(array $maintenanceUserData): MaintenanceUsers { return $this->maintenanceUser->newQuery()->create($maintenanceUserData); } - public function getById(int $id): MaintenanceUsers - { + public function getById(int $id): MaintenanceUsers { return $this->maintenanceUser->newQuery()->find($id); } - public function update($model, array $data): MaintenanceUsers - { + public function update($model, array $data): MaintenanceUsers { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } } diff --git a/src/backend/app/Services/MaintenanceUserTicketService.php b/src/backend/app/Services/MaintenanceUserTicketService.php index 4544f06f3..bda3e8408 100644 --- a/src/backend/app/Services/MaintenanceUserTicketService.php +++ b/src/backend/app/Services/MaintenanceUserTicketService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class MaintenanceUserTicketService implements IAssignationService -{ +class MaintenanceUserTicketService implements IAssignationService { private Ticket $ticket; + private MaintenanceUsers $maintenanceUser; - public function setAssigned($ticket): void - { + public function setAssigned($ticket): void { $this->ticket = $ticket; } - public function setAssignee($maintenanceUser): void - { + public function setAssignee($maintenanceUser): void { $this->maintenanceUser = $maintenanceUser; } - public function assign(): Ticket - { + public function assign(): Ticket { $this->ticket->owner()->associate($this->maintenanceUser); return $this->ticket; diff --git a/src/backend/app/Services/ManufacturerAddressService.php b/src/backend/app/Services/ManufacturerAddressService.php index 8397a7eb6..df50e2d44 100644 --- a/src/backend/app/Services/ManufacturerAddressService.php +++ b/src/backend/app/Services/ManufacturerAddressService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class ManufacturerAddressService implements IAssignationService -{ +class ManufacturerAddressService implements IAssignationService { private Address $address; + private Manufacturer $manufacturer; - public function setAssigned($address): void - { + public function setAssigned($address): void { $this->address = $address; } - public function setAssignee($manufacturer): void - { + public function setAssignee($manufacturer): void { $this->manufacturer = $manufacturer; } - public function assign(): Address - { + public function assign(): Address { $this->address->owner()->associate($this->manufacturer); return $this->address; diff --git a/src/backend/app/Services/ManufacturerService.php b/src/backend/app/Services/ManufacturerService.php index 3f936b697..8a90ccb90 100644 --- a/src/backend/app/Services/ManufacturerService.php +++ b/src/backend/app/Services/ManufacturerService.php @@ -11,15 +11,12 @@ /** * @implements IBaseService */ -class ManufacturerService implements IBaseService -{ +class ManufacturerService implements IBaseService { public function __construct( private Manufacturer $manufacturer, - ) { - } + ) {} - public function createManufacturerDataFromRequest(Request $request): array - { + public function createManufacturerDataFromRequest(Request $request): array { return [ 'name' => $request->get('name'), 'contact_person' => $request->get('contact_person'), @@ -28,18 +25,15 @@ public function createManufacturerDataFromRequest(Request $request): array ]; } - public function getById(int $manufacturerId): Manufacturer - { + public function getById(int $manufacturerId): Manufacturer { return $this->manufacturer->newQuery()->with(['address.city.country'])->findOrFail($manufacturerId); } - public function create(array $manufacturerData): Manufacturer - { + public function create(array $manufacturerData): Manufacturer { return $this->manufacturer->newQuery()->create($manufacturerData); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->manufacturer->newQuery()->paginate($limit); } @@ -47,18 +41,15 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->manufacturer->newQuery()->get(); } - public function getByName($manufacturerName) - { + public function getByName($manufacturerName) { return $this->manufacturer->newQuery()->where('name', $manufacturerName)->first(); } - public function update($model, array $data): Manufacturer - { + public function update($model, array $data): Manufacturer { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } } diff --git a/src/backend/app/Services/MeterConsumptionService.php b/src/backend/app/Services/MeterConsumptionService.php index 3605922d0..af28ab39e 100644 --- a/src/backend/app/Services/MeterConsumptionService.php +++ b/src/backend/app/Services/MeterConsumptionService.php @@ -10,15 +10,12 @@ /** * @implements IBaseService */ -class MeterConsumptionService implements IBaseService -{ +class MeterConsumptionService implements IBaseService { public function __construct( private MeterConsumption $meterConsumption, - ) { - } + ) {} - public function getByMeter(Meter $meter, $start, $end): Collection|array - { + public function getByMeter(Meter $meter, $start, $end): Collection|array { return $this->meterConsumption->newQuery() ->where('meter_id', $meter->id)->whereBetween( 'reading_date', @@ -26,28 +23,23 @@ public function getByMeter(Meter $meter, $start, $end): Collection|array )->orderBy('reading_date')->get(); } - public function getById(int $id): MeterConsumption - { + public function getById(int $id): MeterConsumption { throw new \Exception('Method getById() not yet implemented.'); } - public function create(array $data): MeterConsumption - { + public function create(array $data): MeterConsumption { throw new \Exception('Method create() not yet implemented.'); } - public function update($model, array $data): MeterConsumption - { + public function update($model, array $data): MeterConsumption { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } } diff --git a/src/backend/app/Services/MeterGeographicalInformationService.php b/src/backend/app/Services/MeterGeographicalInformationService.php index aa1c741db..648b0a81f 100644 --- a/src/backend/app/Services/MeterGeographicalInformationService.php +++ b/src/backend/app/Services/MeterGeographicalInformationService.php @@ -5,16 +5,13 @@ use App\Models\GeographicalInformation; use App\Models\Meter\Meter; -class MeterGeographicalInformationService -{ +class MeterGeographicalInformationService { public function __construct( private GeographicalInformation $geographicalInformation, private Meter $meter, - ) { - } + ) {} - public function updateGeographicalInformation(array $meters): array - { + public function updateGeographicalInformation(array $meters): array { collect($meters)->each(function ($meter) { $points = [ $meter['lat'], diff --git a/src/backend/app/Services/MeterParameterAddressService.php b/src/backend/app/Services/MeterParameterAddressService.php index 8948c9259..548c0be25 100644 --- a/src/backend/app/Services/MeterParameterAddressService.php +++ b/src/backend/app/Services/MeterParameterAddressService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class MeterParameterAddressService implements IAssignationService -{ +class MeterParameterAddressService implements IAssignationService { private MeterParameter $meterParameter; + private Address $address; - public function setAssignee($meterParameter): void - { + public function setAssignee($meterParameter): void { $this->meterParameter = $meterParameter; } - public function setAssigned($address): void - { + public function setAssigned($address): void { $this->address = $address; } - public function assign(): Address - { + public function assign(): Address { $this->address->owner()->associate($this->meterParameter); return $this->address; diff --git a/src/backend/app/Services/MeterParameterService.php b/src/backend/app/Services/MeterParameterService.php index a724be0c2..cf5ff6de7 100644 --- a/src/backend/app/Services/MeterParameterService.php +++ b/src/backend/app/Services/MeterParameterService.php @@ -6,12 +6,10 @@ use App\Models\Meter\MeterParameter; use App\Models\Person\Person; -class MeterParameterService -{ +class MeterParameterService { public function __construct( private MeterParameter $meterParameter, - ) { - } + ) {} public function createMeterParameter( array $meterParameterData, @@ -36,13 +34,11 @@ public function createMeterParameter( return $meterParameter; } - public function getAll() - { + public function getAll() { return $this->meterParameter->newQuery()->get(); } - public function delete($meterParameter) - { + public function delete($meterParameter) { return $meterParameter->delete(); } } diff --git a/src/backend/app/Services/MeterRevenueService.php b/src/backend/app/Services/MeterRevenueService.php index bb1f3aad5..698227ac9 100644 --- a/src/backend/app/Services/MeterRevenueService.php +++ b/src/backend/app/Services/MeterRevenueService.php @@ -9,16 +9,13 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; -class MeterRevenueService -{ +class MeterRevenueService { public function __construct( private MeterToken $meterToken, private Transaction $transaction, - ) { - } + ) {} - public function getBySerialNumber(string $serialNumber) - { + public function getBySerialNumber(string $serialNumber) { $tokens = $this->meterToken->newQuery()->whereHas( 'meter', function ($q) use ($serialNumber) { diff --git a/src/backend/app/Services/MeterService.php b/src/backend/app/Services/MeterService.php index 6511d4631..cac55efb3 100644 --- a/src/backend/app/Services/MeterService.php +++ b/src/backend/app/Services/MeterService.php @@ -10,15 +10,12 @@ /** * @implements IBaseService */ -class MeterService implements IBaseService -{ +class MeterService implements IBaseService { public function __construct( private Meter $meter, - ) { - } + ) {} - public function getBySerialNumber($serialNumber) - { + public function getBySerialNumber($serialNumber) { return $this->meter->newQuery()->with([ 'tariff', 'device.person', @@ -30,8 +27,7 @@ public function getBySerialNumber($serialNumber) ])->where('serial_number', $serialNumber)->first(); } - public function search($term, $paginate): LengthAwarePaginator - { + public function search($term, $paginate): LengthAwarePaginator { return $this->meter->newQuery()->with(['meterType', 'tariff']) ->whereHas('tariff', fn ($q) => $q->where('name', 'LIKE', '%'.$term.'%')) ->orWhere( @@ -41,8 +37,7 @@ public function search($term, $paginate): LengthAwarePaginator )->paginate($paginate); } - public function getMeterWithAllRelations(int $meterId) - { + public function getMeterWithAllRelations(int $meterId) { return $this->meter->newQuery()->with([ 'tariff', 'device.geo', @@ -50,13 +45,11 @@ public function getMeterWithAllRelations(int $meterId) ])->find($meterId); } - public function getUsedMetersGeoWithAccessRatePayments(): Collection|array - { + public function getUsedMetersGeoWithAccessRatePayments(): Collection|array { return $this->meter->newQuery()->with(['device.geo', 'accessRatePayment'])->where('in_use', 1)->get(); } - public function getUsedMetersGeoWithAccessRatePaymentsInCities($cities): Collection|array - { + public function getUsedMetersGeoWithAccessRatePaymentsInCities($cities): Collection|array { return $this->meter->newQuery()->with(['device.geo', 'accessRatePayment']) ->whereHas( 'device', @@ -70,8 +63,7 @@ function ($q) use ($cities) { ->where('in_use', 1)->get(); } - public function create(array $meterData): Meter - { + public function create(array $meterData): Meter { return $this->meter->newQuery()->create([ 'serial_number' => $meterData['serial_number'], 'meter_type_id' => $meterData['meter_type_id'], @@ -83,8 +75,7 @@ public function create(array $meterData): Meter ]); } - public function getById(int $meterId): Meter - { + public function getById(int $meterId): Meter { return $this->meter->newQuery()->with([ 'tariff', 'device', @@ -95,13 +86,11 @@ public function getById(int $meterId): Meter ])->find($meterId); } - public function delete($meter): ?bool - { + public function delete($meter): ?bool { return $meter->delete(); } - public function getAll(?int $limit = null, $inUse = true): LengthAwarePaginator - { + public function getAll(?int $limit = null, $inUse = true): LengthAwarePaginator { if (isset($inUse)) { return $this->meter->newQuery()->with(['meterType', 'tariff'])->where( 'in_use', @@ -112,8 +101,7 @@ public function getAll(?int $limit = null, $inUse = true): LengthAwarePaginator return $this->meter->newQuery()->with(['meterType', 'tariff'])->paginate($limit); } - public function update($meter, array $meterData): Meter - { + public function update($meter, array $meterData): Meter { $meter->update($meterData); $meter->fresh(); diff --git a/src/backend/app/Services/MeterTariffMeterParameterService.php b/src/backend/app/Services/MeterTariffMeterParameterService.php index 290645901..ccfd4dafa 100644 --- a/src/backend/app/Services/MeterTariffMeterParameterService.php +++ b/src/backend/app/Services/MeterTariffMeterParameterService.php @@ -6,17 +6,14 @@ use App\Models\Meter\MeterParameter; use App\Models\Meter\MeterTariff; -class MeterTariffMeterParameterService -{ +class MeterTariffMeterParameterService { public function __construct( private MeterTariff $meterTariff, private MeterParameter $meterParameter, private Meter $meter, - ) { - } + ) {} - public function getCountById($meterTariffId): array - { + public function getCountById($meterTariffId): array { $count = $this->meterParameter->newQuery()->whereHas( 'meter', function ($q) { @@ -27,8 +24,7 @@ function ($q) { return ['count' => $count]; } - public function changeMetersTariff($meterTariffIdFrom, $meterTariffIdTo) - { + public function changeMetersTariff($meterTariffIdFrom, $meterTariffIdTo) { return $this->meterParameter->newQuery()->where('tariff_id', $meterTariffIdFrom) ->get() ->each(function ($meterParameter) use ($meterTariffIdTo) { @@ -38,8 +34,7 @@ public function changeMetersTariff($meterTariffIdFrom, $meterTariffIdTo) }); } - public function changeMeterTariff($meterSerial, $tariffId): MeterParameter - { + public function changeMeterTariff($meterSerial, $tariffId): MeterParameter { $meter = $this->meter->newQuery()->where('serial_number', $meterSerial)->firstOrFail(); $meterParameter = $this->meterParameter->newQuery()->where('meter_id', $meter->id)->firstOrFail(); $meterParameter->tariff_id = $tariffId; diff --git a/src/backend/app/Services/MeterTariffService.php b/src/backend/app/Services/MeterTariffService.php index 895cc2e20..bdab93a75 100644 --- a/src/backend/app/Services/MeterTariffService.php +++ b/src/backend/app/Services/MeterTariffService.php @@ -10,27 +10,22 @@ /** * @implements IBaseService */ -class MeterTariffService implements IBaseService -{ +class MeterTariffService implements IBaseService { public function __construct( private MeterTariff $meterTariff, - ) { - } + ) {} - public function getById(int $meterTariffId): MeterTariff - { + public function getById(int $meterTariffId): MeterTariff { return $this->meterTariff->newQuery() ->with(['accessRate', 'pricingComponent', 'socialTariff', 'tou']) ->findOrFail($meterTariffId); } - public function create(array $meterTariffData): MeterTariff - { + public function create(array $meterTariffData): MeterTariff { return $this->meterTariff->newQuery()->create($meterTariffData); } - public function update($meterTariff, array $meterTariffData): MeterTariff - { + public function update($meterTariff, array $meterTariffData): MeterTariff { $meterTariff->update( $meterTariffData ); @@ -39,13 +34,11 @@ public function update($meterTariff, array $meterTariffData): MeterTariff return $meterTariff; } - public function delete($meterTariff): ?bool - { + public function delete($meterTariff): ?bool { return $meterTariff->delete(); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->meterTariff->newQuery() ->with(['accessRate', 'pricingComponent', 'socialTariff', 'tou'])->where('factor', 1) diff --git a/src/backend/app/Services/MeterTokenPaymentHistoryService.php b/src/backend/app/Services/MeterTokenPaymentHistoryService.php index ecc5873d6..ea8255a5d 100644 --- a/src/backend/app/Services/MeterTokenPaymentHistoryService.php +++ b/src/backend/app/Services/MeterTokenPaymentHistoryService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class MeterTokenPaymentHistoryService implements IAssignationService -{ +class MeterTokenPaymentHistoryService implements IAssignationService { private PaymentHistory $paymentHistory; + private MeterToken $meterToken; - public function setAssigned($paymentHistory): void - { + public function setAssigned($paymentHistory): void { $this->paymentHistory = $paymentHistory; } - public function setAssignee($meterToken): void - { + public function setAssignee($meterToken): void { $this->meterToken = $meterToken; } - public function assign(): PaymentHistory - { + public function assign(): PaymentHistory { $this->paymentHistory->paidFor()->associate($this->meterToken); return $this->paymentHistory; diff --git a/src/backend/app/Services/MeterTypeMeterService.php b/src/backend/app/Services/MeterTypeMeterService.php index bcc35a1ed..c478f5df1 100644 --- a/src/backend/app/Services/MeterTypeMeterService.php +++ b/src/backend/app/Services/MeterTypeMeterService.php @@ -4,14 +4,10 @@ use App\Models\Meter\MeterType; -class MeterTypeMeterService -{ - public function __construct(private MeterType $meterType) - { - } +class MeterTypeMeterService { + public function __construct(private MeterType $meterType) {} - public function getByIdWithMeters($meterTypeId) - { + public function getByIdWithMeters($meterTypeId) { return $this->meterType->newQuery()->with(['meters'])->findOrFail($meterTypeId); } } diff --git a/src/backend/app/Services/MeterTypeService.php b/src/backend/app/Services/MeterTypeService.php index 8fc62632b..d57197842 100644 --- a/src/backend/app/Services/MeterTypeService.php +++ b/src/backend/app/Services/MeterTypeService.php @@ -10,32 +10,25 @@ /** * @implements IBaseService */ -class MeterTypeService implements IBaseService -{ - public function __construct(private MeterType $meterType) - { - } +class MeterTypeService implements IBaseService { + public function __construct(private MeterType $meterType) {} - public function create(array $meterTypeData): MeterType - { + public function create(array $meterTypeData): MeterType { return $this->meterType->newQuery()->create($meterTypeData); } - public function getById(int $meterTypeId): MeterType - { + public function getById(int $meterTypeId): MeterType { return $this->meterType->newQuery()->findOrFail($meterTypeId); } - public function update($meterType, array $meterTypeData): MeterType - { + public function update($meterType, array $meterTypeData): MeterType { $meterType->update($meterTypeData); $meterType->fresh(); return $meterType; } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->meterType->newQuery()->paginate($limit); } @@ -43,8 +36,7 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->meterType->newQuery()->get(); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } } diff --git a/src/backend/app/Services/MiniGridDashboardCacheDataService.php b/src/backend/app/Services/MiniGridDashboardCacheDataService.php index e29fa1d37..0a9f046e0 100644 --- a/src/backend/app/Services/MiniGridDashboardCacheDataService.php +++ b/src/backend/app/Services/MiniGridDashboardCacheDataService.php @@ -11,8 +11,7 @@ use MPM\Device\MiniGridDeviceService; use Nette\Utils\DateTime; -class MiniGridDashboardCacheDataService extends AbstractDashboardCacheDataService -{ +class MiniGridDashboardCacheDataService extends AbstractDashboardCacheDataService { private const CACHE_KEY_MINI_GRIDS_DATA = 'MiniGridsData'; public function __construct( @@ -32,15 +31,14 @@ public function __construct( parent::__construct(self::CACHE_KEY_MINI_GRIDS_DATA); } - public function setData($dateRange = []) - { + public function setData($dateRange = []) { if (empty($dateRange)) { $startDate = date('Y-01-01'); // first day of the year $endDate = date('Y-m-d H:i:s', strtotime('today')); $dateRange[0] = $startDate; $dateRange[1] = $endDate; } else { - list($startDate, $endDate) = $dateRange; + [$startDate, $endDate] = $dateRange; } $miniGrids = $this->miniGridService->getAll(); diff --git a/src/backend/app/Services/MiniGridEnergyService.php b/src/backend/app/Services/MiniGridEnergyService.php index c8f756a32..31fea954b 100644 --- a/src/backend/app/Services/MiniGridEnergyService.php +++ b/src/backend/app/Services/MiniGridEnergyService.php @@ -7,14 +7,10 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection; -class MiniGridEnergyService -{ - public function __construct(private MiniGrid $miniGrid, private Energy $energy) - { - } +class MiniGridEnergyService { + public function __construct(private MiniGrid $miniGrid, private Energy $energy) {} - public function getById($miniGridId, $startDate, $endDate): Collection|array - { + public function getById($miniGridId, $startDate, $endDate): Collection|array { $energyReadings = $this->energy->newQuery() ->where('mini_grid_id', $miniGridId); diff --git a/src/backend/app/Services/MiniGridGeographicalInformationService.php b/src/backend/app/Services/MiniGridGeographicalInformationService.php index b556001a2..bacaf8238 100644 --- a/src/backend/app/Services/MiniGridGeographicalInformationService.php +++ b/src/backend/app/Services/MiniGridGeographicalInformationService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class MiniGridGeographicalInformationService implements IAssignationService -{ +class MiniGridGeographicalInformationService implements IAssignationService { private GeographicalInformation $geographicInformation; + private MiniGrid $miniGrid; - public function setAssigned($assigned): void - { + public function setAssigned($assigned): void { $this->geographicInformation = $assigned; } - public function setAssignee($assignee): void - { + public function setAssignee($assignee): void { $this->miniGrid = $assignee; } - public function assign(): GeographicalInformation - { + public function assign(): GeographicalInformation { $this->geographicInformation->owner()->associate($this->miniGrid); return $this->geographicInformation; diff --git a/src/backend/app/Services/MiniGridRevenueService.php b/src/backend/app/Services/MiniGridRevenueService.php index 12153cec8..0bcb6bba1 100644 --- a/src/backend/app/Services/MiniGridRevenueService.php +++ b/src/backend/app/Services/MiniGridRevenueService.php @@ -6,16 +6,13 @@ use App\Models\Transaction\Transaction; use Illuminate\Support\Carbon; -class MiniGridRevenueService -{ +class MiniGridRevenueService { public function __construct( private Transaction $transaction, private MeterToken $meterToken, - ) { - } + ) {} - public function getById($miniGridId, $startDate, $endDate, $miniGridDeviceService) - { + public function getById($miniGridId, $startDate, $endDate, $miniGridDeviceService) { $startDate = $startDate ?? date('Y-01-01'); $endDate = $endDate ?? date('Y-m-t'); $miniGridMeters = $miniGridDeviceService->getMetersByMiniGridId($miniGridId); @@ -33,8 +30,7 @@ static function ($q) { ->whereBetween('created_at', [$startDate, Carbon::parse($endDate)->endOfDay()])->get(); } - public function getSoldEnergyById($miniGridId, $startDate, $endDate, $miniGridDeviceService) - { + public function getSoldEnergyById($miniGridId, $startDate, $endDate, $miniGridDeviceService) { $startDate = $startDate ?? date('Y-01-01'); $endDate = $endDate ?? date('Y-m-t'); $miniGridMeters = $miniGridDeviceService->getMetersByMiniGridId($miniGridId); diff --git a/src/backend/app/Services/MiniGridService.php b/src/backend/app/Services/MiniGridService.php index c9f9f1aa8..b3e5626d6 100644 --- a/src/backend/app/Services/MiniGridService.php +++ b/src/backend/app/Services/MiniGridService.php @@ -11,37 +11,31 @@ /** * @implements IBaseService */ -class MiniGridService implements IBaseService -{ +class MiniGridService implements IBaseService { public function __construct( private MiniGrid $miniGrid, private Cluster $cluster, - ) { - } + ) {} - public function getByIdWithLocation($miniGridId) - { + public function getByIdWithLocation($miniGridId) { return $this->miniGrid->newQuery()->with(['location'])->find($miniGridId); } - public function getById($miniGridId): MiniGrid - { + public function getById($miniGridId): MiniGrid { /** @var MiniGrid $model */ $model = $this->miniGrid->newQuery()->find($miniGridId); return $model; } - public function create($miniGridData): MiniGrid - { + public function create($miniGridData): MiniGrid { /** @var MiniGrid $result */ $result = $this->miniGrid->newQuery()->create($miniGridData); return $result; } - public function update($miniGrid, $miniGridData): MiniGrid - { + public function update($miniGrid, $miniGridData): MiniGrid { $miniGrid->update([ 'name' => $miniGridData['name'] ?? $miniGrid->name, ]); @@ -50,8 +44,7 @@ public function update($miniGrid, $miniGridData): MiniGrid return $miniGrid; } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { $miniGrids = $this->miniGrid->newQuery()->with(['location']); if ($limit) { @@ -61,8 +54,7 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $miniGrids->newQuery()->get(); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } } diff --git a/src/backend/app/Services/MpmPluginService.php b/src/backend/app/Services/MpmPluginService.php index 78b9c5e53..3eac5fe6e 100644 --- a/src/backend/app/Services/MpmPluginService.php +++ b/src/backend/app/Services/MpmPluginService.php @@ -10,38 +10,31 @@ /** * @implements IBaseService */ -class MpmPluginService implements IBaseService -{ +class MpmPluginService implements IBaseService { public function __construct( private MpmPlugin $mpmPlugin, - ) { - } + ) {} - public function getById($id): MpmPlugin - { + public function getById($id): MpmPlugin { /** @var MpmPlugin $result */ $result = $this->mpmPlugin->newQuery()->findOrFail($id); return $result; } - public function create(array $data): MpmPlugin - { + public function create(array $data): MpmPlugin { throw new \Exception('Method create() not yet implemented.'); } - public function update($model, array $data): MpmPlugin - { + public function update($model, array $data): MpmPlugin { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->mpmPlugin->newQuery() ->paginate($limit); diff --git a/src/backend/app/Services/PaymentHistoryService.php b/src/backend/app/Services/PaymentHistoryService.php index 63896d00e..db9bc4a23 100644 --- a/src/backend/app/Services/PaymentHistoryService.php +++ b/src/backend/app/Services/PaymentHistoryService.php @@ -12,12 +12,10 @@ /** * @implements IAssociative */ -class PaymentHistoryService implements IAssociative -{ +class PaymentHistoryService implements IAssociative { public function __construct( private PaymentHistory $paymentHistory, - ) { - } + ) {} public function findPayingCustomersInRange( array $customerIds, @@ -27,16 +25,14 @@ public function findPayingCustomersInRange( return $this->paymentHistory->findCustomersPaidInRange($customerIds, $startDate, $endDate); } - public function findCustomerLastPayment(int $customerId): PaymentHistory - { + public function findCustomerLastPayment(int $customerId): PaymentHistory { return $this->paymentHistory ->whereHasMorph('owner', [Person::class], fn (Builder $q) => $q->where('id', $customerId)) ->latest('created_at') ->first(); } - public function getBySerialNumber(string $serialNumber, int $paginate): LengthAwarePaginator - { + public function getBySerialNumber(string $serialNumber, int $paginate): LengthAwarePaginator { return $this->paymentHistory->newQuery()->with(['transaction', 'paidFor']) ->whereHas( 'transaction', @@ -46,13 +42,11 @@ function ($q) use ($serialNumber) { )->latest()->paginate($paginate); } - public function make(array $paymentHistoryData): PaymentHistory - { + public function make(array $paymentHistoryData): PaymentHistory { return $this->paymentHistory->newQuery()->make($paymentHistoryData); } - public function save($paymentHistory): bool - { + public function save($paymentHistory): bool { return $paymentHistory->save(); } } diff --git a/src/backend/app/Services/PdfService.php b/src/backend/app/Services/PdfService.php index 96f2f6381..2a58f4021 100644 --- a/src/backend/app/Services/PdfService.php +++ b/src/backend/app/Services/PdfService.php @@ -5,17 +5,14 @@ use Barryvdh\DomPDF\PDF; use Illuminate\Support\Facades\Storage; -class PdfService -{ +class PdfService { private PDF $pdf; - public function __construct(PDF $pdf) - { + public function __construct(PDF $pdf) { $this->pdf = $pdf; } - public function generatePdfFromView(string $view, $dataToInject): string - { + public function generatePdfFromView(string $view, $dataToInject): string { $this->pdf->loadView($view, ['data' => $dataToInject]); $filePath = Storage::path('non-paying').time().'.pdf'; diff --git a/src/backend/app/Services/PeriodService.php b/src/backend/app/Services/PeriodService.php index 62495e2d6..32bdcea83 100644 --- a/src/backend/app/Services/PeriodService.php +++ b/src/backend/app/Services/PeriodService.php @@ -2,21 +2,13 @@ namespace App\Services; -class PeriodService -{ +class PeriodService { /** - * @param $startDate - * @param $endDate - * @param $interval - * @param $initialData * @param (int|int[])[]|int $initialData * - * @return array - * * @throws \Exception */ - public function generatePeriodicList(string $startDate, string $endDate, string $interval, $initialData): array - { + public function generatePeriodicList(string $startDate, string $endDate, string $interval, $initialData): array { $result = []; $begin = date_create($startDate); $end = date_create($endDate); diff --git a/src/backend/app/Services/PersonAddressService.php b/src/backend/app/Services/PersonAddressService.php index da991bae3..51c51b5de 100644 --- a/src/backend/app/Services/PersonAddressService.php +++ b/src/backend/app/Services/PersonAddressService.php @@ -9,35 +9,30 @@ /** * @implements IAssignationService */ -class PersonAddressService implements IAssignationService -{ +class PersonAddressService implements IAssignationService { private Address $address; + private Person $person; - public function setOldPrimaryAddressToNotPrimary(): Person - { + public function setOldPrimaryAddressToNotPrimary(): Person { $this->person->addresses()->where('is_primary', 1)->update(['is_primary' => 0]); return $this->person; } - public function getPersonAddresses($person) - { + public function getPersonAddresses($person) { return $person->addresses()->with('city', 'geo')->orderBy('is_primary', 'DESC')->paginate(5); } - public function setAssigned($address): void - { + public function setAssigned($address): void { $this->address = $address; } - public function setAssignee($person): void - { + public function setAssignee($person): void { $this->person = $person; } - public function assign(): Address - { + public function assign(): Address { $this->address->owner()->associate($this->person); return $this->address; diff --git a/src/backend/app/Services/PersonMeterService.php b/src/backend/app/Services/PersonMeterService.php index f9d3ddffb..e42334b74 100644 --- a/src/backend/app/Services/PersonMeterService.php +++ b/src/backend/app/Services/PersonMeterService.php @@ -5,21 +5,17 @@ use App\Models\Meter\Meter; use App\Models\Person\Person; -class PersonMeterService -{ +class PersonMeterService { public function __construct( private Person $person, private Meter $meter, - ) { - } + ) {} - public function getPersonMeters(int $personId) - { + public function getPersonMeters(int $personId) { return $this->person->newQuery()->with(['meters.tariff', 'meters.meter'])->find($personId); } - public function getPersonMetersGeographicalInformation(int $personId) - { + public function getPersonMetersGeographicalInformation(int $personId) { return $this->person->newQuery()->with(['meters.meter', 'meters.geo'])->find($personId); } } diff --git a/src/backend/app/Services/PersonPaymentHistoryService.php b/src/backend/app/Services/PersonPaymentHistoryService.php index 1e0d7ad7a..05dbd7a49 100644 --- a/src/backend/app/Services/PersonPaymentHistoryService.php +++ b/src/backend/app/Services/PersonPaymentHistoryService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class PersonPaymentHistoryService implements IAssignationService -{ +class PersonPaymentHistoryService implements IAssignationService { private PaymentHistory $paymentHistory; + private Person $person; - public function setAssigned($paymentHistory): void - { + public function setAssigned($paymentHistory): void { $this->paymentHistory = $paymentHistory; } - public function setAssignee($person): void - { + public function setAssignee($person): void { $this->person = $person; } - public function assign(): PaymentHistory - { + public function assign(): PaymentHistory { $this->paymentHistory->payer()->associate($this->person); return $this->paymentHistory; diff --git a/src/backend/app/Services/PersonService.php b/src/backend/app/Services/PersonService.php index 4011bf9f2..4e394e0d9 100644 --- a/src/backend/app/Services/PersonService.php +++ b/src/backend/app/Services/PersonService.php @@ -15,26 +15,21 @@ /** * @implements IBaseService */ -class PersonService implements IBaseService -{ +class PersonService implements IBaseService { public function __construct( private Person $person, - ) { - } + ) {} - public function getAllRegisteredPeople(): Collection|array - { + public function getAllRegisteredPeople(): Collection|array { return $this->person->newQuery()->get(); } // associates the person with a country - public function addCitizenship(Person $person, Country $country): Model - { + public function addCitizenship(Person $person, Country $country): Model { return $person->citizenship()->associate($country); } - public function getDetails(int $personID, bool $allRelations = false) - { + public function getDetails(int $personID, bool $allRelations = false) { if (!$allRelations) { return $this->getById($personID); } @@ -61,8 +56,7 @@ public function getDetails(int $personID, bool $allRelations = false) * * @psalm-return Collection|LengthAwarePaginator|array */ - public function searchPerson($searchTerm, $paginate) - { + public function searchPerson($searchTerm, $paginate) { $query = $this->person->newQuery()->with(['addresses.city', 'devices'])->whereHas( 'addresses', fn ($q) => $q->where('phone', 'LIKE', '%'.$searchTerm.'%') @@ -79,13 +73,11 @@ public function searchPerson($searchTerm, $paginate) return $query->get(); } - public function getPersonTransactions($person) - { + public function getPersonTransactions($person) { return $person->payments()->with('transaction.token')->latest()->paginate(7); } - public function createMaintenancePerson(array $personData): Person - { + public function createMaintenancePerson(array $personData): Person { $personData['is_customer'] = 0; /** @var Person $person */ $person = $this->person->newQuery()->create($personData); @@ -93,13 +85,11 @@ public function createMaintenancePerson(array $personData): Person return $person; } - public function livingInCluster(int $clusterId) - { + public function livingInCluster(int $clusterId) { return $this->person->livingInClusterQuery($clusterId); } - public function getBulkDetails(array $peopleId): Builder - { + public function getBulkDetails(array $peopleId): Builder { return $this->person->newQuery()->with( [ 'addresses' => fn ($q) => $q->where('is_primary', '=', 1), @@ -112,19 +102,16 @@ public function getBulkDetails(array $peopleId): Builder )->whereIn('id', $peopleId); } - public function updatePersonUpdatedDate(Person $person) - { + public function updatePersonUpdatedDate(Person $person) { $person->updated_at = Carbon::now(); $person->save(); } - public function isMaintenancePerson($customerType): bool - { + public function isMaintenancePerson($customerType): bool { return $customerType !== null && $customerType !== 'customer' && $customerType === 'maintenance'; } - public function createPersonDataFromRequest(Request $request): array - { + public function createPersonDataFromRequest(Request $request): array { return [ 'title' => $request->get('title'), 'education' => $request->get('education'), @@ -136,21 +123,18 @@ public function createPersonDataFromRequest(Request $request): array ]; } - public function getById(int $personId): Person - { + public function getById(int $personId): Person { /** @var Person $model */ $model = $this->person->newQuery()->find($personId); return $model; } - public function create(array $personData): Person - { + public function create(array $personData): Person { return $this->person->newQuery()->create($personData); } - public function update($person, array $personData): Person - { + public function update($person, array $personData): Person { foreach ($personData as $key => $value) { $person->$key = $value; } @@ -161,13 +145,11 @@ public function update($person, array $personData): Person return $person; } - public function delete($person): ?bool - { + public function delete($person): ?bool { return $person->delete(); } - public function getAll(?int $limit = null, $customerType = 1): LengthAwarePaginator - { + public function getAll(?int $limit = null, $customerType = 1): LengthAwarePaginator { return $this->person->newQuery()->with([ 'addresses' => function ($q) { return $q->where('is_primary', 1); @@ -177,8 +159,7 @@ public function getAll(?int $limit = null, $customerType = 1): LengthAwarePagina ])->where('is_customer', $customerType)->paginate($limit); } - public function createFromRequest(Request $request): Model - { + public function createFromRequest(Request $request): Model { $person = $this->person->newQuery()->create($request->only([ 'title', 'education', @@ -204,8 +185,7 @@ public function createFromRequest(Request $request): Model return $person; } - public function getByPhoneNumber($phoneNumber): ?Person - { + public function getByPhoneNumber($phoneNumber): ?Person { return $this->person->newQuery()->whereHas('addresses', fn ($q) => $q->where('phone', $phoneNumber)) ->first(); } diff --git a/src/backend/app/Services/PersonTicketService.php b/src/backend/app/Services/PersonTicketService.php index 43c04bc27..47cafe994 100644 --- a/src/backend/app/Services/PersonTicketService.php +++ b/src/backend/app/Services/PersonTicketService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class PersonTicketService implements IAssignationService -{ +class PersonTicketService implements IAssignationService { private Ticket $ticket; + private Person $person; - public function setAssigned($ticket): void - { + public function setAssigned($ticket): void { $this->ticket = $ticket; } - public function setAssignee($person): void - { + public function setAssignee($person): void { $this->person = $person; } - public function assign(): Ticket - { + public function assign(): Ticket { $this->ticket->owner()->associate($this->person); return $this->ticket; diff --git a/src/backend/app/Services/PluginsService.php b/src/backend/app/Services/PluginsService.php index 6ecde7a27..90c8be505 100644 --- a/src/backend/app/Services/PluginsService.php +++ b/src/backend/app/Services/PluginsService.php @@ -6,31 +6,26 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Pagination\LengthAwarePaginator; -class PluginsService -{ +class PluginsService { public function __construct( private Plugins $plugin, - ) { - } + ) {} - public function create(array $pluginData): Plugins - { + public function create(array $pluginData): Plugins { /** @var Plugins $plugin */ $plugin = $this->plugin->newQuery()->create($pluginData); return $plugin; } - public function update($model, array $data): Plugins - { + public function update($model, array $data): Plugins { $model->update($data); $model->fresh(); return $model; } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->plugin->newQuery()->paginate($limit); } @@ -38,13 +33,11 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->plugin->newQuery()->get(); } - public function getByMpmPluginId($mpmPluginId) - { + public function getByMpmPluginId($mpmPluginId) { return $this->plugin->newQuery()->where('mpm_plugin_id', $mpmPluginId)->first(); } - public function isPluginActive(int $pluginId): bool - { + public function isPluginActive(int $pluginId): bool { return $this->plugin->newQuery() ->where('mpm_plugin_id', '=', $pluginId) ->exists(); diff --git a/src/backend/app/Services/RegistrationTailService.php b/src/backend/app/Services/RegistrationTailService.php index 82af06afb..f0c0cb337 100644 --- a/src/backend/app/Services/RegistrationTailService.php +++ b/src/backend/app/Services/RegistrationTailService.php @@ -11,25 +11,20 @@ /** * @implements IBaseService */ -class RegistrationTailService implements IBaseService -{ +class RegistrationTailService implements IBaseService { public function __construct( private RegistrationTail $registrationTail, - ) { - } + ) {} - public function getById(int $id): RegistrationTail - { + public function getById(int $id): RegistrationTail { return $this->registrationTail->newQuery()->find($id); } - public function create(array $registrationTailData): RegistrationTail - { + public function create(array $registrationTailData): RegistrationTail { return $this->registrationTail->newQuery()->create($registrationTailData); } - public function update($registrationTail, array $registrationTailData): RegistrationTail - { + public function update($registrationTail, array $registrationTailData): RegistrationTail { if (array_key_exists('tail', $registrationTailData)) { $registrationTail->update($registrationTailData); } else { @@ -41,23 +36,19 @@ public function update($registrationTail, array $registrationTailData): Registra return $registrationTail; } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { return $this->registrationTail->newQuery()->get(); } - public function getFirst($limit = null) - { + public function getFirst($limit = null) { return $this->registrationTail->newQuery()->firstOrCreate(); } - public function addMpmPluginToRegistrationTail(RegistrationTail $registrationTail, MpmPlugin $mpmPlugin): RegistrationTail - { + public function addMpmPluginToRegistrationTail(RegistrationTail $registrationTail, MpmPlugin $mpmPlugin): RegistrationTail { $tail = !empty($registrationTail->tail) ? json_decode($registrationTail->tail, true) : []; array_push($tail, [ @@ -76,8 +67,7 @@ public function addMpmPluginToRegistrationTail(RegistrationTail $registrationTai ); } - public function removeMpmPluginFromRegistrationTail(RegistrationTail $registrationTail, MpmPlugin $mpmPlugin): RegistrationTail - { + public function removeMpmPluginFromRegistrationTail(RegistrationTail $registrationTail, MpmPlugin $mpmPlugin): RegistrationTail { $tail = !empty($registrationTail->tail) ? json_decode($registrationTail->tail, true) : []; $updatedTail = array_filter($tail, function ($item) use ($mpmPlugin) { diff --git a/src/backend/app/Services/RestrictionService.php b/src/backend/app/Services/RestrictionService.php index f9a3220d7..ebd002234 100644 --- a/src/backend/app/Services/RestrictionService.php +++ b/src/backend/app/Services/RestrictionService.php @@ -9,40 +9,32 @@ /** * @implements IBaseService */ -class RestrictionService implements IBaseService -{ +class RestrictionService implements IBaseService { public function __construct( private Restriction $restriction, - ) { - } + ) {} - public function getRestrictionForTarget($target) - { + public function getRestrictionForTarget($target) { return $this->restriction->newQuery()->where('target', $target)->firstOrFail(); } - public function getById(int $id): Restriction - { + public function getById(int $id): Restriction { throw new \Exception('Method getById() not yet implemented.'); } - public function create(array $data): Restriction - { + public function create(array $data): Restriction { throw new \Exception('Method create() not yet implemented.'); } - public function update($model, array $data): Restriction - { + public function update($model, array $data): Restriction { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } } diff --git a/src/backend/app/Services/RevenueService.php b/src/backend/app/Services/RevenueService.php index 47318dc93..9564c5651 100644 --- a/src/backend/app/Services/RevenueService.php +++ b/src/backend/app/Services/RevenueService.php @@ -2,10 +2,8 @@ namespace App\Services; -class RevenueService -{ - public function fetchTargets($targetData): array - { +class RevenueService { + public function fetchTargets($targetData): array { $formattedTarget = []; if (is_object($targetData) && count($targetData) >= 1) { foreach ($targetData as $targets) { diff --git a/src/backend/app/Services/RolesService.php b/src/backend/app/Services/RolesService.php index b1a2f14a1..a65c54a26 100644 --- a/src/backend/app/Services/RolesService.php +++ b/src/backend/app/Services/RolesService.php @@ -9,25 +9,23 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; -class RolesService -{ +class RolesService { /** * @var Roles */ private $role; + /** * @var RoleDefinition */ private $definiton; - public function __construct(Roles $role, RoleDefinition $definition) - { + public function __construct(Roles $role, RoleDefinition $definition) { $this->role = $role; $this->definiton = $definition; } - public function findOrCreateRoleDefinition(string $roleName) - { + public function findOrCreateRoleDefinition(string $roleName) { return $this->definiton->firstOrCreate(['role_name' => $roleName]); } @@ -36,21 +34,18 @@ public function findOrCreateRoleDefinition(string $roleName) * * @psalm-return Collection|array */ - public function findRoleByDefinition(RoleDefinition $definition) - { + public function findRoleByDefinition(RoleDefinition $definition) { return $this->role->with()->get(); } /** * @return Model|false */ - public function attachToOwner(RoleInterface $roleOwner, Roles $role) // person or a company - { + public function attachToOwner(RoleInterface $roleOwner, Roles $role) { // person or a company return $roleOwner->roleowner()->save($role); } - public function create(RoleDefinition $definition): Roles - { + public function create(RoleDefinition $definition): Roles { $this->role->definitions()->associate($definition); return $this->role; diff --git a/src/backend/app/Services/SessionService.php b/src/backend/app/Services/SessionService.php index a85928ba0..86605826c 100644 --- a/src/backend/app/Services/SessionService.php +++ b/src/backend/app/Services/SessionService.php @@ -5,12 +5,10 @@ use App\Models\Base\BaseModel; use Illuminate\Database\Eloquent\Model; -class SessionService -{ +class SessionService { private BaseModel|Model $model; - public function setModel(BaseModel|Model $model): void - { + public function setModel(BaseModel|Model $model): void { $this->model = $model; $databaseName = $model->getConnectionName(); if (!$this->checkDatabaseName($databaseName)) { @@ -18,13 +16,11 @@ public function setModel(BaseModel|Model $model): void } } - private function checkDatabaseName($databaseName): bool - { + private function checkDatabaseName($databaseName): bool { return $this->getAuthenticatedUserDatabaseName() == $databaseName; } - public function getAuthenticatedUserDatabaseName(): string - { + public function getAuthenticatedUserDatabaseName(): string { return config()->get('database.connections.shard.database'); } } diff --git a/src/backend/app/Services/SmsAndroidSettingService.php b/src/backend/app/Services/SmsAndroidSettingService.php index c69937670..4d15bf6f4 100644 --- a/src/backend/app/Services/SmsAndroidSettingService.php +++ b/src/backend/app/Services/SmsAndroidSettingService.php @@ -4,24 +4,21 @@ use App\Models\SmsAndroidSetting; -class SmsAndroidSettingService -{ +class SmsAndroidSettingService { private string $fireBaseKey; + private string $callbackUrl; - public function __construct(private SmsAndroidSetting $smsAndroidSetting, private UserService $userService) - { + public function __construct(private SmsAndroidSetting $smsAndroidSetting, private UserService $userService) { $this->fireBaseKey = config('services.sms.android.key'); $this->callbackUrl = config('services.sms.callback').$this->userService->getCompanyId(); } - public function getSmsAndroidSetting() - { + public function getSmsAndroidSetting() { return $this->smsAndroidSetting->newQuery()->get(); } - public function createSmsAndroidSetting($androidPhoneToken) - { + public function createSmsAndroidSetting($androidPhoneToken) { $smsAndroidSettingData = [ 'callback' => $this->callbackUrl, 'token' => $androidPhoneToken, @@ -32,8 +29,7 @@ public function createSmsAndroidSetting($androidPhoneToken) return $this->smsAndroidSetting->newQuery()->get(); } - public function updateSmsAndroidSetting(SmsAndroidSetting $smsAndroidSetting, $androidPhoneToken) - { + public function updateSmsAndroidSetting(SmsAndroidSetting $smsAndroidSetting, $androidPhoneToken) { $fireBaseKey = config('services.sms.android.key'); $callbackUrl = config('services.sms.android.callback_url').$this->userService->getCompanyId(); @@ -46,8 +42,7 @@ public function updateSmsAndroidSetting(SmsAndroidSetting $smsAndroidSetting, $a return $this->smsAndroidSetting->newQuery()->get(); } - public function deleteSmsAndroidSetting(SmsAndroidSetting $smsAndroidSetting) - { + public function deleteSmsAndroidSetting(SmsAndroidSetting $smsAndroidSetting) { $smsAndroidSetting->delete(); return $this->smsAndroidSetting->newQuery()->get(); diff --git a/src/backend/app/Services/SmsApplianceRemindRateService.php b/src/backend/app/Services/SmsApplianceRemindRateService.php index 9abc32fe9..257bb38be 100644 --- a/src/backend/app/Services/SmsApplianceRemindRateService.php +++ b/src/backend/app/Services/SmsApplianceRemindRateService.php @@ -6,26 +6,21 @@ use App\Models\SmsApplianceRemindRate; use Illuminate\Support\Collection; -class SmsApplianceRemindRateService -{ +class SmsApplianceRemindRateService { public function __construct( private SmsApplianceRemindRate $smsApplianceRemindRate, private Asset $appliance, - ) { - } + ) {} - public function getApplianceRemindRatesWithAppliances(): Collection - { + public function getApplianceRemindRatesWithAppliances(): Collection { return $this->appliance->newQuery()->with(['smsReminderRate'])->get(); } - public function getApplianceRemindRates(): Collection - { + public function getApplianceRemindRates(): Collection { return $this->smsApplianceRemindRate->newQuery()->get(); } - public function updateApplianceRemindRate(SmsApplianceRemindRate $smsApplianceRemindRate, $data): Asset - { + public function updateApplianceRemindRate(SmsApplianceRemindRate $smsApplianceRemindRate, $data): Asset { $smsApplianceRemindRate->update([ 'appliance_id' => $data['appliance_id'], 'overdue_remind_rate' => $data['overdue_remind_rate'], @@ -38,8 +33,7 @@ public function updateApplianceRemindRate(SmsApplianceRemindRate $smsApplianceRe return $result; } - public function createApplianceRemindRate($data): Collection - { + public function createApplianceRemindRate($data): Collection { $this->smsApplianceRemindRate->newQuery()->create([ 'appliance_id' => $data['appliance_type_id'], 'overdue_remind_rate' => $data['overdue_remind_rate'], diff --git a/src/backend/app/Services/SmsBodyService.php b/src/backend/app/Services/SmsBodyService.php index 719db5f29..97837f118 100644 --- a/src/backend/app/Services/SmsBodyService.php +++ b/src/backend/app/Services/SmsBodyService.php @@ -4,27 +4,22 @@ use App\Models\SmsBody; -class SmsBodyService -{ +class SmsBodyService { private $smsBody; - public function __construct(SmsBody $smsBody) - { + public function __construct(SmsBody $smsBody) { $this->smsBody = $smsBody; } - public function getSmsBodyByReference($reference) - { + public function getSmsBodyByReference($reference) { return $this->smsBody->newQuery()->where('reference', $reference)->firstOrFail(); } - public function getSmsBodies() - { + public function getSmsBodies() { return $this->smsBody->newQuery()->get(); } - public function updateSmsBodies($smsBodiesData) - { + public function updateSmsBodies($smsBodiesData) { $smsBodies = $this->smsBody->newQuery()->get(); collect($smsBodiesData[0])->each(function ($smsBody) use ($smsBodies) { $smsBodies->filter(function ($body) use ($smsBody) { @@ -37,8 +32,7 @@ public function updateSmsBodies($smsBodiesData) return $smsBodies; } - public function getNullBodies() - { + public function getNullBodies() { return $this->smsBody->newQuery()->whereNull('body')->get(); } } diff --git a/src/backend/app/Services/SmsResendInformationKeyService.php b/src/backend/app/Services/SmsResendInformationKeyService.php index 6019d2148..34b10fa2d 100644 --- a/src/backend/app/Services/SmsResendInformationKeyService.php +++ b/src/backend/app/Services/SmsResendInformationKeyService.php @@ -4,22 +4,18 @@ use App\Models\SmsResendInformationKey; -class SmsResendInformationKeyService -{ +class SmsResendInformationKeyService { private $smsResendInformationKey; - public function __construct(SmsResendInformationKey $smsResendInformationKey) - { + public function __construct(SmsResendInformationKey $smsResendInformationKey) { $this->smsResendInformationKey = $smsResendInformationKey; } - public function getResendInformationKeys() - { + public function getResendInformationKeys() { return $this->smsResendInformationKey->newQuery()->get(); } - public function updateResendInformationKey(SmsResendInformationKey $smsResendInformationKey, $data) - { + public function updateResendInformationKey(SmsResendInformationKey $smsResendInformationKey, $data) { $smsResendInformationKey->update([ 'key' => $data['key'], ]); diff --git a/src/backend/app/Services/SmsService.php b/src/backend/app/Services/SmsService.php index 0b01bcf6f..2dc9a1851 100644 --- a/src/backend/app/Services/SmsService.php +++ b/src/backend/app/Services/SmsService.php @@ -14,19 +14,18 @@ use App\Sms\SmsTypes; use Illuminate\Support\Facades\Log; -class SmsService -{ +class SmsService { public const TICKET = 1; + public const FEEDBACK = 2; + public const DIRECTION_OUTGOING = 1; public function __construct( private Sms $sms, - ) { - } + ) {} - public function checkMessageType($message) - { + public function checkMessageType($message) { $wordsInMessage = explode(' ', $message); $firstWord = $wordsInMessage[0]; switch (strtolower($firstWord)) { @@ -37,8 +36,7 @@ public function checkMessageType($message) } } - public function createAndSendSms($smsData): Sms - { + public function createAndSendSms($smsData): Sms { $sms = $this->createSms($smsData); $data = [ @@ -50,16 +48,14 @@ public function createAndSendSms($smsData): Sms return $sms; } - public function createSms($smsData): Sms - { + public function createSms($smsData): Sms { /** @var Sms $sms */ $sms = $this->sms->newQuery()->create($smsData); return $sms; } - private function getSmsAndroidSettings() - { + private function getSmsAndroidSettings() { try { return SmsAndroidSetting::getResponsible(); } catch (SmsAndroidSettingNotExistingException $exception) { @@ -67,8 +63,7 @@ private function getSmsAndroidSettings() } } - public function sendSms($data, $smsType, $smsConfigs) - { + public function sendSms($data, $smsType, $smsConfigs) { try { $smsAndroidSettings = $this->getSmsAndroidSettings(); $smsType = $this->resolveSmsType($data, $smsType, $smsConfigs, $smsAndroidSettings); @@ -91,8 +86,7 @@ public function sendSms($data, $smsType, $smsConfigs) $this->associateSmsWithForSmsType($smsType, $data, $uuid, $receiver, $smsAndroidSettings); } - private function resolveSmsType($data, $smsType, $smsConfigs, $smsAndroidSettings) - { + private function resolveSmsType($data, $smsType, $smsConfigs, $smsAndroidSettings) { $configs = resolve($smsConfigs); if (!array_key_exists($smsType, $configs->smsTypes)) { throw new SmsTypeNotFoundException('SmsType could not resolve.'); @@ -112,8 +106,7 @@ private function resolveSmsType($data, $smsType, $smsConfigs, $smsAndroidSetting ]); } - private function associateSmsWithForSmsType($smsType, $data, $uuid, $receiver, $smsAndroidSettings) - { + private function associateSmsWithForSmsType($smsType, $data, $uuid, $receiver, $smsAndroidSettings) { if (!($smsType instanceof ManualSms)) { $sms = Sms::query()->make([ 'uuid' => $uuid, diff --git a/src/backend/app/Services/SmsVariableDefaultValueService.php b/src/backend/app/Services/SmsVariableDefaultValueService.php index f06ff49cd..109e0b5d7 100644 --- a/src/backend/app/Services/SmsVariableDefaultValueService.php +++ b/src/backend/app/Services/SmsVariableDefaultValueService.php @@ -4,17 +4,14 @@ use App\Models\SmsVariableDefaultValue; -class SmsVariableDefaultValueService -{ +class SmsVariableDefaultValueService { private $smsVariableDefaultValue; - public function __construct(SmsVariableDefaultValue $smsVariableDefaultValue) - { + public function __construct(SmsVariableDefaultValue $smsVariableDefaultValue) { $this->smsVariableDefaultValue = $smsVariableDefaultValue; } - public function getSmsVariableDefaultValues() - { + public function getSmsVariableDefaultValues() { return $this->smsVariableDefaultValue->newQuery()->get(); } } diff --git a/src/backend/app/Services/SocialTariffService.php b/src/backend/app/Services/SocialTariffService.php index 08b08122d..4377be0d7 100644 --- a/src/backend/app/Services/SocialTariffService.php +++ b/src/backend/app/Services/SocialTariffService.php @@ -9,43 +9,35 @@ /** * @implements IBaseService */ -class SocialTariffService implements IBaseService -{ +class SocialTariffService implements IBaseService { public function __construct( private SocialTariff $socialTariff, - ) { - } + ) {} - public function create(array $socialTariffData): SocialTariff - { + public function create(array $socialTariffData): SocialTariff { return $this->socialTariff->newQuery()->create($socialTariffData); } - public function getById(int $socialTariffId): SocialTariff - { + public function getById(int $socialTariffId): SocialTariff { return $this->socialTariff->newQuery()->find($socialTariffId); } - public function update($socialTariff, array $socialTariffData): SocialTariff - { + public function update($socialTariff, array $socialTariffData): SocialTariff { $socialTariff->update($socialTariffData); $socialTariff->fresh(); return $socialTariff; } - public function deleteByTariffId($meterTariffId) - { + public function deleteByTariffId($meterTariffId) { $this->socialTariff->newQuery()->where('tariff_id', $meterTariffId)->delete(); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } } diff --git a/src/backend/app/Services/SubConnectionTypeService.php b/src/backend/app/Services/SubConnectionTypeService.php index ac5a968b9..cc7af9535 100644 --- a/src/backend/app/Services/SubConnectionTypeService.php +++ b/src/backend/app/Services/SubConnectionTypeService.php @@ -10,41 +10,34 @@ /** * @implements IBaseService */ -class SubConnectionTypeService implements IBaseService -{ +class SubConnectionTypeService implements IBaseService { public function __construct( private SubConnectionType $subConnectionType, - ) { - } + ) {} - public function getSubConnectionTypesByConnectionTypeId($connectionTypeId, $limit = null): LengthAwarePaginator|Collection - { + public function getSubConnectionTypesByConnectionTypeId($connectionTypeId, $limit = null): LengthAwarePaginator|Collection { return $limit ? $this->subConnectionType->newQuery()->where('connection_type_id', $connectionTypeId) ->paginate($limit) : $this->subConnectionType->newQuery()->where('connection_type_id', $connectionTypeId) - ->get(); + ->get(); } - public function getById(int $subConnectionTypeId): SubConnectionType - { + public function getById(int $subConnectionTypeId): SubConnectionType { return $this->subConnectionType->newQuery()->findOrFail($subConnectionTypeId); } - public function create(array $subConnectionServiceData): SubConnectionType - { + public function create(array $subConnectionServiceData): SubConnectionType { return $this->subConnectionType->newQuery()->create($subConnectionServiceData); } - public function update($subConnectionType, array $subConnectionTypeData): SubConnectionType - { + public function update($subConnectionType, array $subConnectionTypeData): SubConnectionType { $subConnectionType->update($subConnectionTypeData); $subConnectionType->fresh(); return $subConnectionType; } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->subConnectionType->newQuery()->paginate($limit); } @@ -52,8 +45,7 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->subConnectionType->newQuery()->get(); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } } diff --git a/src/backend/app/Services/SubTargetService.php b/src/backend/app/Services/SubTargetService.php index 8177906a2..eac3f3646 100644 --- a/src/backend/app/Services/SubTargetService.php +++ b/src/backend/app/Services/SubTargetService.php @@ -9,22 +9,18 @@ /** * @implements IBaseService */ -class SubTargetService implements IBaseService -{ +class SubTargetService implements IBaseService { public function __construct( private SubTarget $subTarget, - ) { - } + ) {} - public function getById(int $id): SubTarget - { + public function getById(int $id): SubTarget { throw new \Exception('Method getById() not yet implemented.'); return new SubTarget(); } - public function create(array $subTargetData): SubTarget - { + public function create(array $subTargetData): SubTarget { $targetId = $subTargetData['targetId']; foreach ($subTargetData['data'] as $data) { @@ -42,20 +38,17 @@ public function create(array $subTargetData): SubTarget return $this->subTarget; } - public function update($model, array $data): SubTarget - { + public function update($model, array $data): SubTarget { throw new \Exception('Method update() not yet implemented.'); return new SubTarget(); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } } diff --git a/src/backend/app/Services/TargetService.php b/src/backend/app/Services/TargetService.php index 5a8d4193d..0baedefd5 100644 --- a/src/backend/app/Services/TargetService.php +++ b/src/backend/app/Services/TargetService.php @@ -10,22 +10,17 @@ use Illuminate\Support\Collection; use MPM\Target\TargetAssignable; -class TargetService -{ - public function __construct(private Target $target) - { - } +class TargetService { + public function __construct(private Target $target) {} - public function getById($targetId): Target - { + public function getById($targetId): Target { /** @var Target $model */ $model = $this->target->newQuery()->with(['subTargets', 'city'])->find($targetId); return $model; } - public function create(CarbonImmutable $period, string $targetForType, TargetAssignable $targetOwner): Target - { + public function create(CarbonImmutable $period, string $targetForType, TargetAssignable $targetOwner): Target { /** @var Target $target */ $target = $this->target->newQuery()->make([ 'target_date' => $period->format('Y-m-d'), @@ -40,8 +35,7 @@ public function create(CarbonImmutable $period, string $targetForType, TargetAss return $target; } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->target->newQuery()->with(['owner', 'subTargets.connectionType'])->orderBy( 'target_date', @@ -55,8 +49,7 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator )->get(); } - public function getTakenSlots($targetDate): Collection - { + public function getTakenSlots($targetDate): Collection { return $this->target->newQuery()->whereBetween('target_date', $targetDate)->get(); } } diff --git a/src/backend/app/Services/TariffPricingComponentService.php b/src/backend/app/Services/TariffPricingComponentService.php index 0f42ea050..bbdf7a955 100644 --- a/src/backend/app/Services/TariffPricingComponentService.php +++ b/src/backend/app/Services/TariffPricingComponentService.php @@ -9,20 +9,16 @@ /** * @implements IBaseService */ -class TariffPricingComponentService implements IBaseService -{ +class TariffPricingComponentService implements IBaseService { public function __construct( private TariffPricingComponent $tariffPricingComponent, - ) { - } + ) {} - public function make($tariffPricingComponentData) - { + public function make($tariffPricingComponentData) { return $this->tariffPricingComponent->newQuery()->make($tariffPricingComponentData); } - public function deleteByTariffId($meterTariffId) - { + public function deleteByTariffId($meterTariffId) { $this->tariffPricingComponent->newQuery()->where('owner_type', 'meter_tariff')->where( 'owner_id', $meterTariffId @@ -31,28 +27,23 @@ public function deleteByTariffId($meterTariffId) }); } - public function getById(int $id): TariffPricingComponent - { + public function getById(int $id): TariffPricingComponent { throw new \Exception('Method getById() not yet implemented.'); } - public function create(array $data): TariffPricingComponent - { + public function create(array $data): TariffPricingComponent { throw new \Exception('Method create() not yet implemented.'); } - public function update($model, array $data): TariffPricingComponent - { + public function update($model, array $data): TariffPricingComponent { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } } diff --git a/src/backend/app/Services/TicketSettingsService.php b/src/backend/app/Services/TicketSettingsService.php index 5bea79434..0dc653869 100644 --- a/src/backend/app/Services/TicketSettingsService.php +++ b/src/backend/app/Services/TicketSettingsService.php @@ -8,23 +8,19 @@ /** * @implements ISettingsService */ -class TicketSettingsService implements ISettingsService -{ +class TicketSettingsService implements ISettingsService { public function __construct( private TicketSettings $ticketSettings, - ) { - } + ) {} - public function update($ticketSettings, array $ticketSettingsData): TicketSettings - { + public function update($ticketSettings, array $ticketSettingsData): TicketSettings { $ticketSettings->update($ticketSettingsData); $ticketSettings->fresh(); return $ticketSettings; } - public function get(): TicketSettings - { + public function get(): TicketSettings { return $this->ticketSettings->newQuery()->first(); } } diff --git a/src/backend/app/Services/TimeOfUsageService.php b/src/backend/app/Services/TimeOfUsageService.php index 348b267c2..35470e495 100644 --- a/src/backend/app/Services/TimeOfUsageService.php +++ b/src/backend/app/Services/TimeOfUsageService.php @@ -9,38 +9,31 @@ /** * @implements IBaseService */ -class TimeOfUsageService implements IBaseService -{ +class TimeOfUsageService implements IBaseService { public function __construct( private TimeOfUsage $timeOfUsage, - ) { - } + ) {} - public function create(array $timeOfUsageData): TimeOfUsage - { + public function create(array $timeOfUsageData): TimeOfUsage { return $this->timeOfUsage->newQuery()->create($timeOfUsageData); } - public function getById(int $timeOfUsageId): TimeOfUsage - { + public function getById(int $timeOfUsageId): TimeOfUsage { return $this->timeOfUsage->newQuery()->find($timeOfUsageId); } - public function update($timeOfUsage, array $timeOfUsageData): TimeOfUsage - { + public function update($timeOfUsage, array $timeOfUsageData): TimeOfUsage { $timeOfUsage->update($timeOfUsageData); $timeOfUsage->fresh(); return $timeOfUsage; } - public function delete($timeOfUsage): ?bool - { + public function delete($timeOfUsage): ?bool { return $timeOfUsage->delete(); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } } diff --git a/src/backend/app/Services/TokenService.php b/src/backend/app/Services/TokenService.php index c71b6485e..f5e484d85 100644 --- a/src/backend/app/Services/TokenService.php +++ b/src/backend/app/Services/TokenService.php @@ -10,37 +10,30 @@ /** * @implements IBaseService */ -class TokenService implements IBaseService -{ +class TokenService implements IBaseService { public function __construct( private Token $token, - ) { - } + ) {} - public function getById(int $id): Token - { + public function getById(int $id): Token { return $this->token->newQuery()->find($id); } - public function create(array $data): Token - { + public function create(array $data): Token { return $this->token->newQuery()->create($data); } - public function update($model, array $data): Token - { + public function update($model, array $data): Token { throw new \Exception('Method update() not yet implemented.'); return new Token(); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->token->newQuery()->paginate($limit); } diff --git a/src/backend/app/Services/TransactionPaymentHistoryService.php b/src/backend/app/Services/TransactionPaymentHistoryService.php index 6d05d2107..bc44c95ee 100644 --- a/src/backend/app/Services/TransactionPaymentHistoryService.php +++ b/src/backend/app/Services/TransactionPaymentHistoryService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class TransactionPaymentHistoryService implements IAssignationService -{ +class TransactionPaymentHistoryService implements IAssignationService { private PaymentHistory $paymentHistory; + private Transaction $transaction; - public function setAssigned($paymentHistory): void - { + public function setAssigned($paymentHistory): void { $this->paymentHistory = $paymentHistory; } - public function setAssignee($transaction): void - { + public function setAssignee($transaction): void { $this->transaction = $transaction; } - public function assign(): PaymentHistory - { + public function assign(): PaymentHistory { $this->paymentHistory->transaction()->associate($this->transaction); return $this->paymentHistory; diff --git a/src/backend/app/Services/TransactionProviderService.php b/src/backend/app/Services/TransactionProviderService.php index 73af1789d..9c002263a 100644 --- a/src/backend/app/Services/TransactionProviderService.php +++ b/src/backend/app/Services/TransactionProviderService.php @@ -4,22 +4,17 @@ use App\Models\Transaction\Transaction; -class TransactionProviderService -{ +class TransactionProviderService { private $transaction; /** * TransactionProviderService constructor. - * - * @param Transaction $transaction */ - public function __construct(Transaction $transaction) - { + public function __construct(Transaction $transaction) { $this->transaction = $transaction; } - public function getTransactionProviders() - { + public function getTransactionProviders() { return $this->transaction->withAll('BelongsToMorph'); } } diff --git a/src/backend/app/Services/UsageTypeService.php b/src/backend/app/Services/UsageTypeService.php index ff76287af..b5614a6a7 100644 --- a/src/backend/app/Services/UsageTypeService.php +++ b/src/backend/app/Services/UsageTypeService.php @@ -10,41 +10,34 @@ /** * @implements IBaseService */ -class UsageTypeService implements IBaseService -{ +class UsageTypeService implements IBaseService { public function __construct( private UsageType $usageType, - ) { - } + ) {} - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { return $this->usageType->newQuery()->get(); } - public function getById(int $id): UsageType - { + public function getById(int $id): UsageType { throw new \Exception('Method getById() not yet implemented.'); return new UsageType(); } - public function create(array $data): UsageType - { + public function create(array $data): UsageType { throw new \Exception('Method create() not yet implemented.'); return new UsageType(); } - public function update($model, array $data): UsageType - { + public function update($model, array $data): UsageType { throw new \Exception('Method update() not yet implemented.'); return new UsageType(); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } } diff --git a/src/backend/app/Services/UserAddressService.php b/src/backend/app/Services/UserAddressService.php index d2e0a5060..28d6fd5c6 100644 --- a/src/backend/app/Services/UserAddressService.php +++ b/src/backend/app/Services/UserAddressService.php @@ -5,19 +5,17 @@ use App\Models\Address\Address; use App\Models\User; -class UserAddressService -{ +class UserAddressService { private $address; + private $user; - public function __construct(Address $address, User $user) - { + public function __construct(Address $address, User $user) { $this->address = $address; $this->user = $user; } - public function create(User $user, $data) - { + public function create(User $user, $data) { $address = $this->address->newQuery()->create([ 'email' => $data['email'] ?? '', 'phone' => $data['phone'] ?? '', @@ -32,8 +30,7 @@ public function create(User $user, $data) return $address->with(['city']); } - public function update(User $user, $data) - { + public function update(User $user, $data) { $user->name = $data['name']; $user->update(); $address = $user->address()->first(); diff --git a/src/backend/app/Services/UserAppliancePersonService.php b/src/backend/app/Services/UserAppliancePersonService.php index 8f2d1d891..4818fc653 100644 --- a/src/backend/app/Services/UserAppliancePersonService.php +++ b/src/backend/app/Services/UserAppliancePersonService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class UserAppliancePersonService implements IAssignationService -{ +class UserAppliancePersonService implements IAssignationService { private AssetPerson $appliancePerson; + private User $user; - public function setAssigned($appliancePerson): void - { + public function setAssigned($appliancePerson): void { $this->appliancePerson = $appliancePerson; } - public function setAssignee($user): void - { + public function setAssignee($user): void { $this->user = $user; } - public function assign(): AssetPerson - { + public function assign(): AssetPerson { $this->appliancePerson->creator()->associate($this->user); return $this->appliancePerson; diff --git a/src/backend/app/Services/UserService.php b/src/backend/app/Services/UserService.php index 8d0f6ef96..bbe13150f 100644 --- a/src/backend/app/Services/UserService.php +++ b/src/backend/app/Services/UserService.php @@ -11,14 +11,10 @@ use Illuminate\Support\Collection; use MPM\User\Events\UserCreatedEvent; -class UserService -{ - public function __construct(private User $user, private MailHelperInterface $mailHelper) - { - } +class UserService { + public function __construct(private User $user, private MailHelperInterface $mailHelper) {} - public function create(array $userData, ?int $companyId = null): User - { + public function create(array $userData, ?int $companyId = null): User { $shouldSyncUserWithMasterDatabase = $companyId !== null; $companyId = $companyId ?? auth('api')->payload()->get('companyId'); @@ -35,15 +31,13 @@ public function create(array $userData, ?int $companyId = null): User return $user; } - public function update($user, $data) - { + public function update($user, $data) { $user->update(['password' => $data['password']]); return $user->fresh(); } - public function resetPassword(string $email): ?User - { + public function resetPassword(string $email): ?User { try { $newPassword = PasswordGenerator::generatePassword(); } catch (\Exception $exception) { @@ -77,16 +71,14 @@ public function resetPassword(string $email): ?User return $user; } - public function list(): LengthAwarePaginator - { + public function list(): LengthAwarePaginator { return $this->buildQuery() ->select('id', 'name', 'email') ->with(['addressDetails']) ->paginate(); } - public function get($id): User - { + public function get($id): User { /** @var User $user */ $user = User::with(['addressDetails']) ->where('id', '=', $id) @@ -95,8 +87,7 @@ public function get($id): User return $user; } - public function resetAdminPassword(): array - { + public function resetAdminPassword(): array { /** @var User $user */ $user = $this->buildQuery()->first(); $randomPassword = str_random(8); @@ -109,13 +100,11 @@ public function resetAdminPassword(): array return $admin; } - private function buildQuery(): Builder - { + private function buildQuery(): Builder { return $this->user->newQuery(); } - public function getCompanyId(): int - { + public function getCompanyId(): int { /** @var User $user */ $user = $this->buildQuery() ->select(User::COL_COMPANY_ID) @@ -124,23 +113,19 @@ public function getCompanyId(): int return $user->getCompanyId(); } - public function getById($id) - { + public function getById($id) { return $this->user->newQuery()->find($id); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } - public function getUsers(): Collection - { + public function getUsers(): Collection { return $this->user->newQuery()->get(); } } diff --git a/src/backend/app/Services/UserTicketService.php b/src/backend/app/Services/UserTicketService.php index 9e4240034..477cc8ed9 100644 --- a/src/backend/app/Services/UserTicketService.php +++ b/src/backend/app/Services/UserTicketService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class UserTicketService implements IAssignationService -{ +class UserTicketService implements IAssignationService { private Ticket $ticket; + private User $user; - public function setAssigned($ticket): void - { + public function setAssigned($ticket): void { $this->ticket = $ticket; } - public function setAssignee($user): void - { + public function setAssignee($user): void { $this->user = $user; } - public function assign(): Ticket - { + public function assign(): Ticket { $this->ticket->creator()->associate($this->user); return $this->ticket; diff --git a/src/backend/app/Sms/AndroidGateway.php b/src/backend/app/Sms/AndroidGateway.php index 4067480dc..7ecaac59d 100644 --- a/src/backend/app/Sms/AndroidGateway.php +++ b/src/backend/app/Sms/AndroidGateway.php @@ -7,18 +7,13 @@ use App\Models\SmsAndroidSetting; use Illuminate\Support\Facades\Log; -class AndroidGateway implements ISmsProvider -{ +class AndroidGateway implements ISmsProvider { /** * Sends the sms to the sms provider. * - * @param string $number - * @param string $body - * @param string $callback * @param SmsAndroidSetting $smsAndroidSettings */ - public function sendSms(string $number, string $body, string $callback, SmsAndroidSetting $smsAndroidSetting) - { + public function sendSms(string $number, string $body, string $callback, SmsAndroidSetting $smsAndroidSetting) { if (!config('app.env') == 'production') { Log::debug('Send sms on allowed in production', ['number' => $number, 'message' => $body]); diff --git a/src/backend/app/Sms/BodyParsers/AccessRateConfirmation.php b/src/backend/app/Sms/BodyParsers/AccessRateConfirmation.php index b7ae9b3b4..372a9f732 100644 --- a/src/backend/app/Sms/BodyParsers/AccessRateConfirmation.php +++ b/src/backend/app/Sms/BodyParsers/AccessRateConfirmation.php @@ -4,18 +4,16 @@ use App\Models\PaymentHistory; -class AccessRateConfirmation extends SmsBodyParser -{ +class AccessRateConfirmation extends SmsBodyParser { protected $variables = ['amount']; + protected $paymentHistory; - public function __construct(PaymentHistory $paymentHistory) - { + public function __construct(PaymentHistory $paymentHistory) { $this->paymentHistory = $paymentHistory; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'amount': $variable = $this->paymentHistory->amount; diff --git a/src/backend/app/Sms/BodyParsers/AssetRatePayment.php b/src/backend/app/Sms/BodyParsers/AssetRatePayment.php index 381810f19..03e7cd0ee 100644 --- a/src/backend/app/Sms/BodyParsers/AssetRatePayment.php +++ b/src/backend/app/Sms/BodyParsers/AssetRatePayment.php @@ -4,18 +4,16 @@ use App\Models\PaymentHistory; -class AssetRatePayment extends SmsBodyParser -{ +class AssetRatePayment extends SmsBodyParser { protected $variables = ['appliance_type_name', 'amount']; + protected $paymentHistory; - public function __construct(PaymentHistory $paymentHistory) - { + public function __construct(PaymentHistory $paymentHistory) { $this->paymentHistory = $paymentHistory; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'appliance_type_name': $variable = $this->paymentHistory->paidFor->assetPerson->assetType; diff --git a/src/backend/app/Sms/BodyParsers/AssetRateReminder.php b/src/backend/app/Sms/BodyParsers/AssetRateReminder.php index da9c6ba63..671ee2615 100644 --- a/src/backend/app/Sms/BodyParsers/AssetRateReminder.php +++ b/src/backend/app/Sms/BodyParsers/AssetRateReminder.php @@ -4,18 +4,16 @@ use App\Models\AssetRate; -class AssetRateReminder extends SmsBodyParser -{ +class AssetRateReminder extends SmsBodyParser { protected $variables = ['appliance_type_name', 'remaining', 'due_date']; + protected $reminderData; - public function __construct(AssetRate $reminderData) - { + public function __construct(AssetRate $reminderData) { $this->reminderData = $reminderData; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'appliance_type_name': $variable = $this->reminderData->assetPerson->assetType->name; diff --git a/src/backend/app/Sms/BodyParsers/EnergyConfirmation.php b/src/backend/app/Sms/BodyParsers/EnergyConfirmation.php index 39a16d996..08cd3593a 100644 --- a/src/backend/app/Sms/BodyParsers/EnergyConfirmation.php +++ b/src/backend/app/Sms/BodyParsers/EnergyConfirmation.php @@ -4,18 +4,16 @@ use App\Models\PaymentHistory; -class EnergyConfirmation extends SmsBodyParser -{ +class EnergyConfirmation extends SmsBodyParser { protected $variables = ['meter', 'token', 'energy', 'amount']; + protected $paymentHistory; - public function __construct(PaymentHistory $paymentHistory) - { + public function __construct(PaymentHistory $paymentHistory) { $this->paymentHistory = $paymentHistory; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { $token = $this->paymentHistory->paidFor()->first(); $transaction = $this->paymentHistory->transaction()->first(); switch ($variable) { diff --git a/src/backend/app/Sms/BodyParsers/OverDueAssetRateReminder.php b/src/backend/app/Sms/BodyParsers/OverDueAssetRateReminder.php index 75325f2a5..638af1963 100644 --- a/src/backend/app/Sms/BodyParsers/OverDueAssetRateReminder.php +++ b/src/backend/app/Sms/BodyParsers/OverDueAssetRateReminder.php @@ -4,18 +4,16 @@ use App\Models\AssetRate; -class OverDueAssetRateReminder extends SmsBodyParser -{ +class OverDueAssetRateReminder extends SmsBodyParser { public $variables = ['appliance_type_name', 'remaining', 'due_date']; + protected $reminderData; - public function __construct(AssetRate $reminderData) - { + public function __construct(AssetRate $reminderData) { $this->reminderData = $reminderData; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'appliance_type_name': $variable = $this->reminderData->assetPerson->assetType->name; diff --git a/src/backend/app/Sms/BodyParsers/PricingDetails.php b/src/backend/app/Sms/BodyParsers/PricingDetails.php index 1af916854..238f12d32 100644 --- a/src/backend/app/Sms/BodyParsers/PricingDetails.php +++ b/src/backend/app/Sms/BodyParsers/PricingDetails.php @@ -5,21 +5,21 @@ use App\Models\MainSettings; use App\Models\Transaction\Transaction; -class PricingDetails extends SmsBodyParser -{ +class PricingDetails extends SmsBodyParser { public $variables = ['amount', 'vat_energy', 'vat_others']; + protected $transaction; + private $vatEnergy = 0; + private $vatOtherStaffs = 0; - public function __construct(Transaction $transaction) - { + public function __construct(Transaction $transaction) { $this->transaction = $transaction; $this->calculateTaxes(); } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'amount': $variable = $this->transaction->amount; @@ -35,8 +35,7 @@ protected function getVariableValue($variable) return $variable; } - private function calculateTaxes() - { + private function calculateTaxes() { $mainSettings = MainSettings::query()->first(); $energy = $this->transaction->paymentHistories->where('payment_type', 'energy')->sum('amount'); $other = $this->transaction->paymentHistories->where('payment_type', '!=', 'energy')->sum('amount'); diff --git a/src/backend/app/Sms/BodyParsers/ResendInformation.php b/src/backend/app/Sms/BodyParsers/ResendInformation.php index c8115b621..5d3e6827f 100644 --- a/src/backend/app/Sms/BodyParsers/ResendInformation.php +++ b/src/backend/app/Sms/BodyParsers/ResendInformation.php @@ -4,18 +4,16 @@ use App\Models\PaymentHistory; -class ResendInformation extends SmsBodyParser -{ +class ResendInformation extends SmsBodyParser { protected $variables = ['meter', 'token', 'energy', 'amount']; + protected $paymentHistory; - public function __construct(PaymentHistory $paymentHistory) - { + public function __construct(PaymentHistory $paymentHistory) { $this->paymentHistory = $paymentHistory; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { $token = $this->paymentHistory->paidFor()->first(); $transaction = $this->paymentHistory->transaction()->first(); switch ($variable) { diff --git a/src/backend/app/Sms/BodyParsers/ResendInformationLastTransactionNotFound.php b/src/backend/app/Sms/BodyParsers/ResendInformationLastTransactionNotFound.php index ad3adfde2..228ead7f0 100644 --- a/src/backend/app/Sms/BodyParsers/ResendInformationLastTransactionNotFound.php +++ b/src/backend/app/Sms/BodyParsers/ResendInformationLastTransactionNotFound.php @@ -2,19 +2,16 @@ namespace App\Sms\BodyParsers; -class ResendInformationLastTransactionNotFound extends SmsBodyParser -{ +class ResendInformationLastTransactionNotFound extends SmsBodyParser { protected $variables = ['meter']; protected $data; - public function __construct($data) - { + public function __construct($data) { $this->data = $data; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { return $this->data['meter']; } } diff --git a/src/backend/app/Sms/BodyParsers/SmsBodyParser.php b/src/backend/app/Sms/BodyParsers/SmsBodyParser.php index 53ebbafee..efa325188 100644 --- a/src/backend/app/Sms/BodyParsers/SmsBodyParser.php +++ b/src/backend/app/Sms/BodyParsers/SmsBodyParser.php @@ -2,12 +2,10 @@ namespace App\Sms\BodyParsers; -abstract class SmsBodyParser -{ +abstract class SmsBodyParser { protected $variables; - public function parseSms($body) - { + public function parseSms($body) { foreach ($this->variables as $variable) { $body = str_replace('['.$variable.']', $this->getVariableValue($variable), $body); } @@ -15,8 +13,7 @@ public function parseSms($body) return $body; } - protected function getVariableValue($varialbe) - { + protected function getVariableValue($varialbe) { return new \Exception('implement it on each class'); } } diff --git a/src/backend/app/Sms/BodyParsers/SmsReminderHeader.php b/src/backend/app/Sms/BodyParsers/SmsReminderHeader.php index 824114890..5a77a4848 100644 --- a/src/backend/app/Sms/BodyParsers/SmsReminderHeader.php +++ b/src/backend/app/Sms/BodyParsers/SmsReminderHeader.php @@ -4,18 +4,16 @@ use App\Models\AssetRate; -class SmsReminderHeader extends SmsBodyParser -{ +class SmsReminderHeader extends SmsBodyParser { protected $variables = ['name', 'surname']; + protected $reminderData; - public function __construct(AssetRate $reminderData) - { + public function __construct(AssetRate $reminderData) { $this->reminderData = $reminderData; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { $person = $this->reminderData->assetPerson->person; switch ($variable) { case 'name': diff --git a/src/backend/app/Sms/BodyParsers/SmsResendInformationHeader.php b/src/backend/app/Sms/BodyParsers/SmsResendInformationHeader.php index 1789c322a..4c587dc25 100644 --- a/src/backend/app/Sms/BodyParsers/SmsResendInformationHeader.php +++ b/src/backend/app/Sms/BodyParsers/SmsResendInformationHeader.php @@ -4,18 +4,16 @@ use App\Models\Person\Person; -class SmsResendInformationHeader extends SmsBodyParser -{ +class SmsResendInformationHeader extends SmsBodyParser { protected $variables = ['name', 'surname']; + protected $data; - public function __construct($data) - { + public function __construct($data) { $this->data = $data; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { if (!is_array($this->data)) { $person = $this->data->meter->meterParameter->owner()->first(); } else { diff --git a/src/backend/app/Sms/BodyParsers/SmsTransactionHeader.php b/src/backend/app/Sms/BodyParsers/SmsTransactionHeader.php index 75ca9612e..a69480de1 100644 --- a/src/backend/app/Sms/BodyParsers/SmsTransactionHeader.php +++ b/src/backend/app/Sms/BodyParsers/SmsTransactionHeader.php @@ -4,18 +4,16 @@ use App\Models\Transaction\Transaction; -class SmsTransactionHeader extends SmsBodyParser -{ +class SmsTransactionHeader extends SmsBodyParser { protected $variables = ['name', 'surname', 'transaction_amount']; + protected $transaction; - public function __construct(Transaction $transaction) - { + public function __construct(Transaction $transaction) { $this->transaction = $transaction; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { $person = $this->transaction->device->person->first(); switch ($variable) { case 'name': diff --git a/src/backend/app/Sms/Senders/AssetRateNotification.php b/src/backend/app/Sms/Senders/AssetRateNotification.php index 7270527a3..ee49e0b4d 100644 --- a/src/backend/app/Sms/Senders/AssetRateNotification.php +++ b/src/backend/app/Sms/Senders/AssetRateNotification.php @@ -2,8 +2,7 @@ namespace App\Sms\Senders; -class AssetRateNotification extends SmsSender -{ +class AssetRateNotification extends SmsSender { protected $references = [ 'header' => 'SmsReminderHeader', 'body' => 'AssetRateReminder', diff --git a/src/backend/app/Sms/Senders/ManualSms.php b/src/backend/app/Sms/Senders/ManualSms.php index 35bf44cd5..83980680c 100644 --- a/src/backend/app/Sms/Senders/ManualSms.php +++ b/src/backend/app/Sms/Senders/ManualSms.php @@ -2,16 +2,16 @@ namespace App\Sms\Senders; -class ManualSms extends SmsSender -{ +class ManualSms extends SmsSender { protected $data; + public $body = ''; + protected $references = [ 'body' => '', ]; - public function prepareBody() - { + public function prepareBody() { $this->body .= $this->data['message']; } } diff --git a/src/backend/app/Sms/Senders/OverDueAssetRateNotification.php b/src/backend/app/Sms/Senders/OverDueAssetRateNotification.php index 13d5f2bc3..37dbe350b 100644 --- a/src/backend/app/Sms/Senders/OverDueAssetRateNotification.php +++ b/src/backend/app/Sms/Senders/OverDueAssetRateNotification.php @@ -2,8 +2,7 @@ namespace App\Sms\Senders; -class OverDueAssetRateNotification extends SmsSender -{ +class OverDueAssetRateNotification extends SmsSender { protected $references = [ 'header' => 'SmsReminderHeader', 'body' => 'OverDueAssetRateReminder', diff --git a/src/backend/app/Sms/Senders/ResendInformationNotification.php b/src/backend/app/Sms/Senders/ResendInformationNotification.php index 321f1f841..4ff53ec9f 100644 --- a/src/backend/app/Sms/Senders/ResendInformationNotification.php +++ b/src/backend/app/Sms/Senders/ResendInformationNotification.php @@ -8,18 +8,18 @@ use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Support\Facades\Log; -class ResendInformationNotification extends SmsSender -{ +class ResendInformationNotification extends SmsSender { protected $data; + public $body = ''; + protected $references = [ 'header' => 'SmsResendInformationHeader', 'footer' => 'SmsResendInformationFooter', 'body' => 'ResendInformation', ]; - public function prepareBody() - { + public function prepareBody() { if (!is_array($this->data)) { try { $smsBody = $this->smsBodyService->getSmsBodyByReference('ResendInformation'); diff --git a/src/backend/app/Sms/Senders/SmsConfigs.php b/src/backend/app/Sms/Senders/SmsConfigs.php index 5d4993ac3..f6065199a 100644 --- a/src/backend/app/Sms/Senders/SmsConfigs.php +++ b/src/backend/app/Sms/Senders/SmsConfigs.php @@ -2,6 +2,4 @@ namespace App\Sms\Senders; -class SmsConfigs extends SmsConfigsCore -{ -} +class SmsConfigs extends SmsConfigsCore {} diff --git a/src/backend/app/Sms/Senders/SmsConfigsCore.php b/src/backend/app/Sms/Senders/SmsConfigsCore.php index 911a23eef..310e5d9a2 100644 --- a/src/backend/app/Sms/Senders/SmsConfigsCore.php +++ b/src/backend/app/Sms/Senders/SmsConfigsCore.php @@ -4,8 +4,7 @@ use App\Sms\SmsTypes; -abstract class SmsConfigsCore -{ +abstract class SmsConfigsCore { public $smsTypes = [ SmsTypes::TRANSACTION_CONFIRMATION => 'App\Sms\Senders\TransactionConfirmation', SmsTypes::APPLIANCE_RATE => 'App\Sms\Senders\AssetRateNotification', @@ -13,6 +12,8 @@ abstract class SmsConfigsCore SmsTypes::MANUAL_SMS => 'App\Sms\Senders\ManualSms', SmsTypes::RESEND_INFORMATION => 'App\Sms\Senders\ResendInformationNotification', ]; + public $bodyParsersPath = 'App\\Sms\\BodyParsers\\'; + public $servicePath = 'App\Services\SmsBodyService'; } diff --git a/src/backend/app/Sms/Senders/SmsSender.php b/src/backend/app/Sms/Senders/SmsSender.php index 4ef350066..8e874f12b 100644 --- a/src/backend/app/Sms/Senders/SmsSender.php +++ b/src/backend/app/Sms/Senders/SmsSender.php @@ -14,27 +14,31 @@ use Inensus\ViberMessaging\Services\ViberContactService; use Webpatser\Uuid\Uuid; -abstract class SmsSender -{ +abstract class SmsSender { protected $smsBodyService; + protected $data; + protected $references; + public $body = ''; + protected $receiver; + protected $callback; + protected $parserSubPath; + private $smsAndroidSettings; - public function __construct($data, $smsBodyService, $parserSubPath, $smsAndroidSettings) - { + public function __construct($data, $smsBodyService, $parserSubPath, $smsAndroidSettings) { $this->smsBodyService = $smsBodyService; $this->data = $data; $this->parserSubPath = $parserSubPath; $this->smsAndroidSettings = $smsAndroidSettings; } - public function sendSms() - { + public function sendSms() { $viberId = $this->checkForViberIdOfReceiverIfPluginIsActive(); if ($viberId) { resolve('ViberGateway') @@ -61,8 +65,7 @@ public function sendSms() } } - public function prepareHeader() - { + public function prepareHeader() { try { $smsBody = $this->getSmsBody('header'); } catch (MissingSmsReferencesException $exception) { @@ -81,8 +84,7 @@ public function prepareHeader() } } - public function prepareBody() - { + public function prepareBody() { try { $smsBody = $this->getSmsBody('body'); } catch (MissingSmsReferencesException $exception) { @@ -99,8 +101,7 @@ public function prepareBody() } } - public function prepareFooter() - { + public function prepareFooter() { try { $smsBody = $this->getSmsBody('footer'); $this->body .= ' '.$smsBody->body; @@ -110,8 +111,7 @@ public function prepareFooter() } } - private function getSmsBody($reference) - { + private function getSmsBody($reference) { try { $smsBody = $this->smsBodyService->getSmsBodyByReference($this->references[$reference]); } catch (ModelNotFoundException $e) { @@ -121,8 +121,7 @@ private function getSmsBody($reference) return $smsBody; } - public function validateReferences() - { + public function validateReferences() { if (($this->data instanceof Transaction) || ($this->data instanceof AssetRate)) { $nullSmsBodies = $this->smsBodyService->getNullBodies(); if (count($nullSmsBodies)) { @@ -145,8 +144,7 @@ public function validateReferences() } } - public function getReceiver() - { + public function getReceiver() { if ($this->data instanceof Transaction) { $this->receiver = strpos($this->data->sender, '+') === 0 ? $this->data->sender : '+'.$this->data->sender; } elseif ($this->data instanceof AssetRate) { @@ -170,16 +168,14 @@ public function getReceiver() return $this->receiver; } - public function generateCallbackAndGetUuid($callback) - { + public function generateCallbackAndGetUuid($callback) { $uuid = (string) Uuid::generate(4); $this->callback = sprintf($callback, $uuid); return $uuid; } - private function checkForViberIdOfReceiverIfPluginIsActive() - { + private function checkForViberIdOfReceiverIfPluginIsActive() { $pluginsService = app()->make(PluginsService::class); $viberContactService = app()->make(ViberContactService::class); $viberMessagingPlugin = $pluginsService->getByMpmPluginId(MpmPlugin::VIBER_MESSAGING); diff --git a/src/backend/app/Sms/Senders/TransactionConfirmation.php b/src/backend/app/Sms/Senders/TransactionConfirmation.php index c7eb4df95..b33172356 100644 --- a/src/backend/app/Sms/Senders/TransactionConfirmation.php +++ b/src/backend/app/Sms/Senders/TransactionConfirmation.php @@ -6,21 +6,24 @@ use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Support\Facades\Log; -class TransactionConfirmation extends SmsSender -{ +class TransactionConfirmation extends SmsSender { protected $data; + public $body = ''; + protected $references = [ 'header' => 'SmsTransactionHeader', 'footer' => 'SmsTransactionFooter', 'body' => '', ]; + public const ENERGY_CONFIRMATION = 'energy'; + public const ACCESS_RATE_PAYMENT = 'access rate'; + public const ASSET_RATE_PAYMENT = 'loan rate'; - public function prepareBody() - { + public function prepareBody() { $this->data->paymentHistories()->each(function ($payment) { switch ($payment->payment_type) { case self::ENERGY_CONFIRMATION: @@ -37,13 +40,11 @@ public function prepareBody() $this->preparePricingDetails(); } - public function preparePricingDetails() - { + public function preparePricingDetails() { $this->prepareBodyByClassReference('PricingDetails', $this->data); } - private function prepareBodyByClassReference($reference, $payload) - { + private function prepareBodyByClassReference($reference, $payload) { try { $smsBody = $this->smsBodyService->getSmsBodyByReference($reference); } catch (ModelNotFoundException $exception) { diff --git a/src/backend/app/Sms/SmsTypes.php b/src/backend/app/Sms/SmsTypes.php index faed45285..76e0d7e73 100644 --- a/src/backend/app/Sms/SmsTypes.php +++ b/src/backend/app/Sms/SmsTypes.php @@ -2,11 +2,14 @@ namespace App\Sms; -class SmsTypes -{ +class SmsTypes { public const TRANSACTION_CONFIRMATION = 1; + public const APPLIANCE_RATE = 2; + public const OVER_DUE_APPLIANCE_RATE = 3; + public const MANUAL_SMS = 4; + public const RESEND_INFORMATION = 5; } diff --git a/src/backend/app/Traits/RestExceptionHandler.php b/src/backend/app/Traits/RestExceptionHandler.php index 19070639f..b2b76f06c 100644 --- a/src/backend/app/Traits/RestExceptionHandler.php +++ b/src/backend/app/Traits/RestExceptionHandler.php @@ -11,18 +11,15 @@ use Tymon\JWTAuth\Exceptions\TokenExpiredException; use Tymon\JWTAuth\Exceptions\TokenInvalidException; -trait RestExceptionHandler -{ +trait RestExceptionHandler { /** * Creates a new response based on exception type. * - * @param Request $request * @param \Exception $e * * @return JsonResponse */ - protected function getJsonResponseForException(Request $request, \Exception|\Throwable $e) - { + protected function getJsonResponseForException(Request $request, \Exception|\Throwable $e) { switch (true) { case $e instanceof TokenExpiredException: return response()->json(['error' => 'Token is expired'], 401); @@ -51,8 +48,7 @@ protected function getJsonResponseForException(Request $request, \Exception|\Thr * * @return JsonResponse */ - protected function badRequest($message = 'Bad request', $status_code = 400) - { + protected function badRequest($message = 'Bad request', $status_code = 400) { return $this->jsonResponse( [ 'message' => $message, @@ -70,8 +66,7 @@ protected function badRequest($message = 'Bad request', $status_code = 400) * * @return JsonResponse */ - protected function modelNotFound($message = 'Record not found', $status_code = 404) - { + protected function modelNotFound($message = 'Record not found', $status_code = 404) { return $this->jsonResponse( [ 'message' => $message, @@ -89,8 +84,7 @@ protected function modelNotFound($message = 'Record not found', $status_code = 4 * * @return JsonResponse */ - protected function validationError($message = 'Validation failed', $status_code = 422) - { + protected function validationError($message = 'Validation failed', $status_code = 422) { return $this->jsonResponse( [ 'message' => $message, @@ -104,11 +98,8 @@ protected function validationError($message = 'Validation failed', $status_code * Determines if the exception type is Model not found exception. * * @param \Exception $e - * - * @return bool */ - protected function isModelNotFoundException($e): bool - { + protected function isModelNotFoundException($e): bool { return $e instanceof ModelNotFoundException; } @@ -116,24 +107,17 @@ protected function isModelNotFoundException($e): bool * Determines if given Exception is Validation Exception. * * @param \Exception $e - * - * @return bool */ - protected function isValidationException($e): bool - { + protected function isValidationException($e): bool { return $e instanceof ValidationException; } /** * Generates a json response & returns it. * - * @param array|null $payload - * @param $status_code - * * @return JsonResponse */ - protected function jsonResponse(?array $payload = null, $status_code) - { + protected function jsonResponse(?array $payload, $status_code) { $payload = $payload ?: []; return response()->json( diff --git a/src/backend/app/Traits/ScheduledPluginCommand.php b/src/backend/app/Traits/ScheduledPluginCommand.php index 5fc51df7b..27fe6d63e 100644 --- a/src/backend/app/Traits/ScheduledPluginCommand.php +++ b/src/backend/app/Traits/ScheduledPluginCommand.php @@ -4,12 +4,10 @@ use App\Models\Plugins; -trait ScheduledPluginCommand -{ +trait ScheduledPluginCommand { private static int $ACTIVE = 1; - protected function checkForPluginStatusIsActive($mpmPluginId) - { + protected function checkForPluginStatusIsActive($mpmPluginId) { $plugin = Plugins::query()->where('mpm_plugin_id', $mpmPluginId)->first(); return $plugin && $plugin->status === self::$ACTIVE; diff --git a/src/backend/app/Utils/AccessRatePayer.php b/src/backend/app/Utils/AccessRatePayer.php index 0c44df771..6c3f1e171 100644 --- a/src/backend/app/Utils/AccessRatePayer.php +++ b/src/backend/app/Utils/AccessRatePayer.php @@ -7,21 +7,22 @@ use App\Models\Transaction\Transaction; use App\Services\AccessRatePaymentService; -class AccessRatePayer -{ +class AccessRatePayer { public const MINIMUM_AMOUNT = 0; + private AccessRatePayment $accessRatePayment; + private TransactionDataContainer $transactionData; + private Transaction $transaction; + private float $debtAmount; - public function __construct(private AccessRatePaymentService $accessRatePaymentService) - { + public function __construct(private AccessRatePaymentService $accessRatePaymentService) { $this->debtAmount = self::MINIMUM_AMOUNT; } - public function initialize(TransactionDataContainer $container) - { + public function initialize(TransactionDataContainer $container) { $meter = $container->device->device; $accessRatePayment = $this->accessRatePaymentService->getAccessRatePaymentByMeter($meter); @@ -34,8 +35,7 @@ public function initialize(TransactionDataContainer $container) $this->transaction = $container->transaction; } - public function pay() - { + public function pay() { $meter = $this->transactionData->device->device; $owner = $this->transactionData->device->person; if ($this->debtAmount > self::MINIMUM_AMOUNT) { // there is unpaid amount @@ -64,8 +64,7 @@ public function pay() return $this->transactionData; } - public function consumeAmount() - { + public function consumeAmount() { $this->transaction->amount -= $this->debtAmount; return $this->transaction->amount; diff --git a/src/backend/app/Utils/ApplianceInstallmentPayer.php b/src/backend/app/Utils/ApplianceInstallmentPayer.php index 27146da7d..ef41f0b4d 100644 --- a/src/backend/app/Utils/ApplianceInstallmentPayer.php +++ b/src/backend/app/Utils/ApplianceInstallmentPayer.php @@ -13,12 +13,15 @@ use Illuminate\Support\Collection; use MPM\Device\DeviceService; -class ApplianceInstallmentPayer -{ +class ApplianceInstallmentPayer { private Person $customer; + private Transaction $transaction; + public array $paidRates = []; + public ?AssetPerson $shsLoan = null; + public $consumableAmount; public function __construct( @@ -26,19 +29,16 @@ public function __construct( private ApplianceRateService $applianceRateService, private AppliancePaymentService $appliancePaymentService, private DeviceService $deviceService, - ) { - } + ) {} - public function initialize(TransactionDataContainer $transactionData): void - { + public function initialize(TransactionDataContainer $transactionData): void { $this->transaction = $transactionData->transaction; $this->consumableAmount = $this->transaction->amount; $this->customer = $this->getCustomerByDeviceSerial($this->transaction->message); } // This function pays the installments for the device number that provided in transaction - public function payInstallmentsForDevice(TransactionDataContainer $container) - { + public function payInstallmentsForDevice(TransactionDataContainer $container) { $customer = $container->appliancePerson->person; $this->appliancePaymentService->setPaymentAmount($container->transaction->amount); $installments = $container->appliancePerson->rates; @@ -47,8 +47,7 @@ public function payInstallmentsForDevice(TransactionDataContainer $container) // This function processes the payment of all installments (excluding device-recorded ones) that are due, right before generating the meter token. // If meter number is provided in transaction - public function payInstallments() - { + public function payInstallments() { $customer = $this->customer; $appliancePersonIds = $this->appliancePersonService->getLoanIdsForCustomerId($customer->id); $installments = $this->applianceRateService->getByLoanIdsForDueDate($appliancePersonIds); @@ -57,8 +56,7 @@ public function payInstallments() return $this->transaction->amount; } - public function consumeAmount() - { + public function consumeAmount() { $installments = $this->getInstallments($this->customer); $installments->each(function ($installment) { if ($installment->remaining > $this->consumableAmount) {// money is not enough to cover the @@ -76,8 +74,7 @@ public function consumeAmount() return $this->consumableAmount; } - private function getCustomerByDeviceSerial(string $serialNumber): Person - { + private function getCustomerByDeviceSerial(string $serialNumber): Person { $device = $this->deviceService->getBySerialNumber($serialNumber); if (!$device) { @@ -87,15 +84,13 @@ private function getCustomerByDeviceSerial(string $serialNumber): Person return $device->person; } - private function getInstallments($customer) - { + private function getInstallments($customer) { $loans = $this->appliancePersonService->getLoanIdsForCustomerId($customer->id); return $this->applianceRateService->getByLoanIdsForDueDate($loans); } - private function pay(Collection $installments, mixed $customer): void - { + private function pay(Collection $installments, mixed $customer): void { $installments->map(function ($installment) use ($customer) { if ($installment->remaining > $this->transaction->amount) {// money is not enough to cover the whole rate // add payment history for the installment diff --git a/src/backend/app/Utils/DummyCompany.php b/src/backend/app/Utils/DummyCompany.php index 9b69b0dee..52d70e54f 100644 --- a/src/backend/app/Utils/DummyCompany.php +++ b/src/backend/app/Utils/DummyCompany.php @@ -2,8 +2,8 @@ namespace App\Utils; -class DummyCompany -{ +class DummyCompany { public const DUMMY_COMPANY_ID = 1; + public const DUMMY_COMPANY_DATABASE_NAME = 'DummyCompany_1'; } diff --git a/src/backend/app/Utils/MinimumPurchaseAmountValidator.php b/src/backend/app/Utils/MinimumPurchaseAmountValidator.php index 640a544fb..b05a10708 100644 --- a/src/backend/app/Utils/MinimumPurchaseAmountValidator.php +++ b/src/backend/app/Utils/MinimumPurchaseAmountValidator.php @@ -4,13 +4,12 @@ use App\Misc\TransactionDataContainer; -class MinimumPurchaseAmountValidator -{ +class MinimumPurchaseAmountValidator { private float $restAmount; + private TransactionDataContainer $transactionData; - public function validate(TransactionDataContainer $transactionData, $minimumPurchaseAmount): bool - { + public function validate(TransactionDataContainer $transactionData, $minimumPurchaseAmount): bool { $this->transactionData = $transactionData; $this->restAmount = $this->transactionData->transaction->amount; diff --git a/src/backend/app/Utils/TariffPriceCalculator.php b/src/backend/app/Utils/TariffPriceCalculator.php index b524281ef..43a5adbd4 100644 --- a/src/backend/app/Utils/TariffPriceCalculator.php +++ b/src/backend/app/Utils/TariffPriceCalculator.php @@ -9,15 +9,13 @@ use App\Services\TariffPricingComponentService; use App\Services\TimeOfUsageService; -class TariffPriceCalculator -{ +class TariffPriceCalculator { public function __construct( private AccessRateService $accessRateService, private SocialTariffService $socialTariffService, private TimeOfUsageService $timeOfUsageService, private TariffPricingComponentService $tariffPricingComponentService, - ) { - } + ) {} public function calculateTotalPrice( MeterTariff $meterTariff, @@ -37,8 +35,7 @@ public function calculateTotalPrice( $this->setAdditionalComponents($additionalComponents, $meterTariff); } - private function setAccessRate($accessRate, $meterTariff) - { + private function setAccessRate($accessRate, $meterTariff) { if ($accessRate) { if (isset($accessRate['id'])) { $updatedAccessRate = $this->accessRateService->getById($accessRate['id']); @@ -62,8 +59,7 @@ private function setAccessRate($accessRate, $meterTariff) } } - private function setSocialTariff($socialTariff, $meterTariff) - { + private function setSocialTariff($socialTariff, $meterTariff) { if ($socialTariff) { if (isset($socialTariff['id'])) { $updatedSocialTariff = $this->socialTariffService->getById($socialTariff['id']); @@ -91,8 +87,7 @@ private function setSocialTariff($socialTariff, $meterTariff) } } - private function setTimeOfUsages($timeOfUsage, $meterTariff) - { + private function setTimeOfUsages($timeOfUsage, $meterTariff) { if ($timeOfUsage) { foreach ($timeOfUsage as $key => $value) { $tou = isset($timeOfUsage[$key]['id']) ? $this->timeOfUsageService->getById($timeOfUsage[$key]['id']) : @@ -118,8 +113,7 @@ private function setTimeOfUsages($timeOfUsage, $meterTariff) } } - private function setAdditionalComponents($additionalComponents, $meterTariff) - { + private function setAdditionalComponents($additionalComponents, $meterTariff) { $this->tariffPricingComponentService->deleteByTariffId($meterTariff->id); if ($additionalComponents) { diff --git a/src/backend/app/modules/Apps/CustomerRegistration/CustomerRegistrationAppService.php b/src/backend/app/modules/Apps/CustomerRegistration/CustomerRegistrationAppService.php index 267370fdb..55b31347e 100644 --- a/src/backend/app/modules/Apps/CustomerRegistration/CustomerRegistrationAppService.php +++ b/src/backend/app/modules/Apps/CustomerRegistration/CustomerRegistrationAppService.php @@ -13,8 +13,7 @@ use MPM\Device\DeviceService; use MPM\Meter\MeterDeviceService; -class CustomerRegistrationAppService -{ +class CustomerRegistrationAppService { public function __construct( private PersonService $personService, private MeterService $meterService, @@ -24,11 +23,9 @@ public function __construct( private DeviceAddressService $deviceAddressService, private GeographicalInformationService $geographicalInformationService, private AddressGeographicalInformationService $addressGeographicalInformationService, - ) { - } + ) {} - public function createCustomer(AndroidAppRequest $request): Person - { + public function createCustomer(AndroidAppRequest $request): Person { $serialNumber = $request->input('serial_number'); $meter = $this->meterService->getBySerialNumber($serialNumber); $phone = $request->input('phone'); diff --git a/src/backend/app/modules/CustomBulkRegistration/Abstract/CreatorService.php b/src/backend/app/modules/CustomBulkRegistration/Abstract/CreatorService.php index 8af3ed60f..5c43fec04 100644 --- a/src/backend/app/modules/CustomBulkRegistration/Abstract/CreatorService.php +++ b/src/backend/app/modules/CustomBulkRegistration/Abstract/CreatorService.php @@ -2,17 +2,14 @@ namespace MPM\CustomBulkRegistration\Abstract; -abstract class CreatorService -{ +abstract class CreatorService { protected $model; - public function __construct($model) - { + public function __construct($model) { $this->model = $model; } - public function createRelatedDataIfDoesNotExists($resolvedCsvData) - { + public function createRelatedDataIfDoesNotExists($resolvedCsvData) { return $this->model->newQuery()->firstOrCreate($resolvedCsvData, $resolvedCsvData); } diff --git a/src/backend/app/modules/CustomBulkRegistration/Ecosys/CustomerDatabaseParser.php b/src/backend/app/modules/CustomBulkRegistration/Ecosys/CustomerDatabaseParser.php index 54f6a7fc7..3ee588d25 100644 --- a/src/backend/app/modules/CustomBulkRegistration/Ecosys/CustomerDatabaseParser.php +++ b/src/backend/app/modules/CustomBulkRegistration/Ecosys/CustomerDatabaseParser.php @@ -22,13 +22,12 @@ use MPM\CustomBulkRegistration\Ecosys\Services\PersonService; use ParseCsv\Csv; -class CustomerDatabaseParser -{ +class CustomerDatabaseParser { private $path; + private $recentlyCreatedRecords; - public function __construct(private Csv $csv) - { + public function __construct(private Csv $csv) { $this->path = __DIR__.'/CustomerDb/customer_db.csv'; $this->recentlyCreatedRecords = [ 'customer' => 0, @@ -39,15 +38,13 @@ public function __construct(private Csv $csv) ]; } - private function parseCsvFromFilePath() - { + private function parseCsvFromFilePath() { $this->csv->auto($this->path); return $this->csv->data; } - public function insertFromCsv() - { + public function insertFromCsv() { $parsedCsvData = $this->parseCsvFromFilePath(); $cluster = Cluster::query()->first(); $miniGrid = MiniGrid::query()->first(); @@ -131,15 +128,13 @@ public function insertFromCsv() return $this->recentlyCreatedRecords; } - private function createRecordFromCsv($row, $service) - { + private function createRecordFromCsv($row, $service) { $service = app()->make($service); return $service->resolveCsvDataFromComingRow($row); } - private function checkRecordWasRecentlyCreated($record, $type) - { + private function checkRecordWasRecentlyCreated($record, $type) { if ($record->wasRecentlyCreated) { ++$this->recentlyCreatedRecords[$type]; } diff --git a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/AddressService.php b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/AddressService.php index 5ac8d5d47..f5ede905f 100644 --- a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/AddressService.php +++ b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/AddressService.php @@ -5,15 +5,12 @@ use App\Models\Address\Address; use MPM\CustomBulkRegistration\Abstract\CreatorService; -class AddressService extends CreatorService -{ - public function __construct(Address $address) - { +class AddressService extends CreatorService { + public function __construct(Address $address) { parent::__construct($address); } - public function resolveCsvDataFromComingRow($csvData): void - { + public function resolveCsvDataFromComingRow($csvData): void { $addressConfig = [ 'person_id' => 'person_id', 'city_id' => 'city_id', @@ -44,8 +41,7 @@ public function resolveCsvDataFromComingRow($csvData): void $this->createRelatedDataIfDoesNotExists($returnAddresses); } - public function createRelatedDataIfDoesNotExists($addresses): void - { + public function createRelatedDataIfDoesNotExists($addresses): void { foreach ($addresses as $address) { Address::query()->firstOrCreate($address, $address); } diff --git a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/AppliancePersonService.php b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/AppliancePersonService.php index b5b99d49c..21bee70f6 100644 --- a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/AppliancePersonService.php +++ b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/AppliancePersonService.php @@ -13,27 +13,34 @@ use App\Models\User; use MPM\CustomBulkRegistration\Abstract\CreatorService; -class AppliancePersonService extends CreatorService -{ +class AppliancePersonService extends CreatorService { private $newTarifName; + private ?float $price = null; + private $minimumAmount; + private $meterParameterId; + private $personId; + private $downPayment; + private $applianceId; + private $totalPaid; + private $secondPaymentAmount; + private $createdAt; + private $lastPaymentDate; - public function __construct(AssetPerson $appliancePerson) - { + public function __construct(AssetPerson $appliancePerson) { parent::__construct($appliancePerson); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $creatorId = User::query()->first()->id; $appliancePersonConfig = [ 'asset_id' => 'asset_id', @@ -75,8 +82,7 @@ public function resolveCsvDataFromComingRow($csvData) return $this->createRelatedDataIfDoesNotExists($appliancePersonData); } - private function calculateRateCount($price, $downPayment, $minimumPaymentAmount): int - { + private function calculateRateCount($price, $downPayment, $minimumPaymentAmount): int { $rawCost = $price - $downPayment; $rateCount = 0; @@ -88,8 +94,7 @@ private function calculateRateCount($price, $downPayment, $minimumPaymentAmount) return $rateCount; } - public function createRelatedDataIfDoesNotExists($appliancePersonData) - { + public function createRelatedDataIfDoesNotExists($appliancePersonData) { $creatorId = User::query()->first()->id; $currency = MainSettings::query()->first() ? MainSettings::query()->first()->currency : 'MTn'; $newTariffData = [ @@ -217,8 +222,7 @@ static function ($q) { return $appliancePerson; } - private function updateRateRemaining($id, $amount): ?AssetRate - { + private function updateRateRemaining($id, $amount): ?AssetRate { /** @var AssetRate|null $applianceRate */ $applianceRate = AssetRate::query()->find($id); $applianceRate->remaining -= $amount; @@ -228,8 +232,7 @@ private function updateRateRemaining($id, $amount): ?AssetRate return $applianceRate; } - private function createPaymentHistory($amount, $buyer, $applianceRate, $transaction): void - { + private function createPaymentHistory($amount, $buyer, $applianceRate, $transaction): void { event( 'payment.successful', [ diff --git a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/ApplianceService.php b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/ApplianceService.php index b49fcfc0b..f13d300bf 100644 --- a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/ApplianceService.php +++ b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/ApplianceService.php @@ -5,18 +5,16 @@ use App\Models\Asset; use MPM\CustomBulkRegistration\Abstract\CreatorService; -class ApplianceService extends CreatorService -{ +class ApplianceService extends CreatorService { private $appliance1 = 'SunKing Home 40Plus - Sofala - Humanitário 2'; + private $appliance2 = 'SunKing Home 40Plus - Nacional - COVID PLUS 2'; - public function __construct(Asset $asset) - { + public function __construct(Asset $asset) { parent::__construct($asset); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $applianceConfig = [ 'price' => 'price', ]; diff --git a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/CityService.php b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/CityService.php index af3cd1e92..50f2a7a5d 100644 --- a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/CityService.php +++ b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/CityService.php @@ -5,15 +5,12 @@ use App\Models\City; use MPM\CustomBulkRegistration\Abstract\CreatorService; -class CityService extends CreatorService -{ - public function __construct(City $city) - { +class CityService extends CreatorService { + public function __construct(City $city) { parent::__construct($city); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $cityConfig = [ 'cluster_id' => 'cluster_id', 'mini_grid_id' => 'mini_grid_id', diff --git a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/ConnectionGroupService.php b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/ConnectionGroupService.php index e37c3a964..17d8b1422 100644 --- a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/ConnectionGroupService.php +++ b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/ConnectionGroupService.php @@ -5,18 +5,16 @@ use App\Models\ConnectionGroup; use MPM\CustomBulkRegistration\Abstract\CreatorService; -class ConnectionGroupService extends CreatorService -{ +class ConnectionGroupService extends CreatorService { private $group1 = 'SunKing Home 40Plus - Sofala - Humanitário 2'; + private $group2 = 'SunKing Home 40Plus - Nacional - COVID PLUS 2'; - public function __construct(ConnectionGroup $connectionGroup) - { + public function __construct(ConnectionGroup $connectionGroup) { parent::__construct($connectionGroup); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $connectionConfig = [ 'price' => 'price', ]; diff --git a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/GeographicalInformationService.php b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/GeographicalInformationService.php index f8d53e6f8..1586941a2 100644 --- a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/GeographicalInformationService.php +++ b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/GeographicalInformationService.php @@ -5,15 +5,12 @@ use App\Models\GeographicalInformation; use MPM\CustomBulkRegistration\Abstract\CreatorService; -class GeographicalInformationService extends CreatorService -{ - public function __construct(GeographicalInformation $geo) - { +class GeographicalInformationService extends CreatorService { + public function __construct(GeographicalInformation $geo) { parent::__construct($geo); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $geoConfig = [ 'owner_type' => 'meter_parameter', 'owner_id' => 'meter_parameter_id', diff --git a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/MeterParameterService.php b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/MeterParameterService.php index b109ba89a..5f70cdec0 100644 --- a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/MeterParameterService.php +++ b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/MeterParameterService.php @@ -5,15 +5,12 @@ use App\Models\Meter\MeterParameter; use MPM\CustomBulkRegistration\Abstract\CreatorService; -class MeterParameterService extends CreatorService -{ - public function __construct(MeterParameter $meterParameter) - { +class MeterParameterService extends CreatorService { + public function __construct(MeterParameter $meterParameter) { parent::__construct($meterParameter); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $meterParameterConfig = [ 'owner_type' => 'person', 'owner_id' => 'person_id', diff --git a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/MeterService.php b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/MeterService.php index 5277845f1..0f5339bbf 100644 --- a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/MeterService.php +++ b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/MeterService.php @@ -5,15 +5,12 @@ use App\Models\Meter\Meter; use MPM\CustomBulkRegistration\Abstract\CreatorService; -class MeterService extends CreatorService -{ - public function __construct(Meter $meter) - { +class MeterService extends CreatorService { + public function __construct(Meter $meter) { parent::__construct($meter); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $meterConfig = [ 'serial_number' => 'device', 'manufacturer_id' => 'manufacturer_id', diff --git a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/PersonService.php b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/PersonService.php index b49ea96c6..ae2348021 100644 --- a/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/PersonService.php +++ b/src/backend/app/modules/CustomBulkRegistration/Ecosys/Services/PersonService.php @@ -5,17 +5,14 @@ use App\Models\Person\Person; use MPM\CustomBulkRegistration\Abstract\CreatorService; -class PersonService extends CreatorService -{ +class PersonService extends CreatorService { private $phone; - public function __construct(Person $person) - { + public function __construct(Person $person) { parent::__construct($person); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $personConfig = [ 'name' => 'name', 'gender' => 'gender', @@ -34,13 +31,11 @@ public function resolveCsvDataFromComingRow($csvData) return $this->createRelatedDataIfDoesNotExists($personData); } - private function getBirthDateByGivenAge($age) - { + private function getBirthDateByGivenAge($age) { return date('Y-m-d', strtotime('-'.$age.' years')); } - public function createRelatedDataIfDoesNotExists($personData) - { + public function createRelatedDataIfDoesNotExists($personData) { $phone = $this->phone; $existingPerson = Person::query() diff --git a/src/backend/app/modules/DatabaseProxy/DatabaseProxyManagerService.php b/src/backend/app/modules/DatabaseProxy/DatabaseProxyManagerService.php index 742bfd7f5..bb7400c33 100644 --- a/src/backend/app/modules/DatabaseProxy/DatabaseProxyManagerService.php +++ b/src/backend/app/modules/DatabaseProxy/DatabaseProxyManagerService.php @@ -10,40 +10,33 @@ use Illuminate\Database\DatabaseManager; use Illuminate\Database\Eloquent\Builder; -class DatabaseProxyManagerService -{ +class DatabaseProxyManagerService { public function __construct( private DatabaseProxy $databaseProxy, private DatabaseManager $databaseManager, private CompanyDatabase $companyDatabase, - ) { - } + ) {} - public function findByEmail(string $email): DatabaseProxy - { + public function findByEmail(string $email): DatabaseProxy { return $this->databaseProxy->findByEmail($email); } - public function runForCompany(int $companyId, callable $callable) - { + public function runForCompany(int $companyId, callable $callable) { $database = $this->companyDatabase->findByCompanyId($companyId); $this->buildDatabaseConnection($database->getDatabaseName()); return $callable(); } - public function queryAllConnections(): Builder - { + public function queryAllConnections(): Builder { return $this->companyDatabase->newQuery(); } - public function buildDatabaseConnectionDummyCompany(): void - { + public function buildDatabaseConnectionDummyCompany(): void { $this->buildDatabaseConnection(DummyCompany::DUMMY_COMPANY_DATABASE_NAME); } - private function buildDatabaseConnection(string $databaseName): void - { + private function buildDatabaseConnection(string $databaseName): void { $databaseConnections = config()->get('database.connections'); $databaseConnections['shard'] = [ 'driver' => 'mysql', diff --git a/src/backend/app/modules/Device/ClusterDeviceService.php b/src/backend/app/modules/Device/ClusterDeviceService.php index 70ccbdc6d..53869b6a0 100644 --- a/src/backend/app/modules/Device/ClusterDeviceService.php +++ b/src/backend/app/modules/Device/ClusterDeviceService.php @@ -6,29 +6,23 @@ use App\Models\Device; use App\Models\Meter\Meter; -class ClusterDeviceService -{ - public function __construct(private Cluster $cluster, private Device $device) - { - } +class ClusterDeviceService { + public function __construct(private Cluster $cluster, private Device $device) {} - public function getCountByClusterId($clusterId): int - { + public function getCountByClusterId($clusterId): int { return $this->device->newQuery() ->whereHas('address', fn ($q) => $q->whereHas('city', fn ($q) => $q->where('cluster_id', $clusterId))) ->count(); } - public function getByClusterId($clusterId) - { + public function getByClusterId($clusterId) { return $this->device->newQuery() ->with('device') ->whereHas('address', fn ($q) => $q->whereHas('city', fn ($q) => $q->where('cluster_id', $clusterId))) ->get(); } - public function getMetersByClusterId($clusterId) - { + public function getMetersByClusterId($clusterId) { return $this->device->newQuery() ->whereHasMorph( 'device', diff --git a/src/backend/app/modules/Device/DeviceAddressService.php b/src/backend/app/modules/Device/DeviceAddressService.php index 772b14ccc..b87ff9fba 100644 --- a/src/backend/app/modules/Device/DeviceAddressService.php +++ b/src/backend/app/modules/Device/DeviceAddressService.php @@ -9,30 +9,26 @@ /** * @implements IAssignationService */ -class DeviceAddressService implements IAssignationService -{ +class DeviceAddressService implements IAssignationService { private Address $address; + private Device $device; - public function setAssigned($assigned): void - { + public function setAssigned($assigned): void { $this->address = $assigned; } - public function setAssignee($assignee): void - { + public function setAssignee($assignee): void { $this->device = $assignee; } - public function assign(): Address - { + public function assign(): Address { $this->address->owner()->associate($this->device); return $this->address; } - public function getAddressByDevice(Device $device): ?Address - { + public function getAddressByDevice(Device $device): ?Address { $result = Address::query()->with('geo') ->where('owner_id', $device->id) ->where('owner_type', 'device') @@ -41,11 +37,7 @@ public function getAddressByDevice(Device $device): ?Address return $result; } - /** - * @return Address - */ - public function updateDeviceAddress($deviceAddress, $addressData): Address - { + public function updateDeviceAddress($deviceAddress, $addressData): Address { $points = $addressData['lat'].','.$addressData['lon']; $deviceAddress->geo()->update([ 'points' => $points, diff --git a/src/backend/app/modules/Device/DeviceService.php b/src/backend/app/modules/Device/DeviceService.php index 3a107c842..83495a984 100644 --- a/src/backend/app/modules/Device/DeviceService.php +++ b/src/backend/app/modules/Device/DeviceService.php @@ -12,15 +12,12 @@ * @implements IBaseService * @implements IAssociative */ -class DeviceService implements IBaseService, IAssociative -{ +class DeviceService implements IAssociative, IBaseService { public function __construct( private Device $device, - ) { - } + ) {} - public function make($deviceData): Device - { + public function make($deviceData): Device { $result = $this->device->newQuery()->create([ 'person_id' => $deviceData['person_id'], 'device_serial' => $deviceData['device_serial'], @@ -29,8 +26,7 @@ public function make($deviceData): Device return $result; } - public function getBySerialNumber($serialNumber): ?Device - { + public function getBySerialNumber($serialNumber): ?Device { $result = $this->device->newQuery() ->with(['address.geo', 'device.manufacturer', 'person']) ->where('device_serial', $serialNumber) @@ -39,40 +35,34 @@ public function getBySerialNumber($serialNumber): ?Device return $result; } - public function save($device): bool - { + public function save($device): bool { return $device->save(); } - public function getById(int $id): Device - { + public function getById(int $id): Device { throw new \Exception('Method getById() not yet implemented.'); return new Device(); } - public function create(array $data): Device - { + public function create(array $data): Device { throw new \Exception('Method create() not yet implemented.'); return new Device(); } - public function update($device, array $deviceData): Device - { + public function update($device, array $deviceData): Device { $device->update($deviceData); $device->fresh(); return $device; } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->device->newQuery()->with(['person', 'device'])->paginate($limit); } diff --git a/src/backend/app/modules/Device/MiniGridDeviceService.php b/src/backend/app/modules/Device/MiniGridDeviceService.php index 7bb80f7ad..cdf77a8cf 100644 --- a/src/backend/app/modules/Device/MiniGridDeviceService.php +++ b/src/backend/app/modules/Device/MiniGridDeviceService.php @@ -7,14 +7,10 @@ use App\Models\MiniGrid; use Illuminate\Support\Collection; -class MiniGridDeviceService -{ - public function __construct(private Device $device, private MiniGrid $miniGrid) - { - } +class MiniGridDeviceService { + public function __construct(private Device $device, private MiniGrid $miniGrid) {} - public function getMetersByMiniGridId($miniGridId) - { + public function getMetersByMiniGridId($miniGridId) { return $this->device->newQuery() ->with('device') ->whereHasMorph( @@ -25,8 +21,7 @@ public function getMetersByMiniGridId($miniGridId) ->get()->pluck('device'); } - public function getDevicesByMiniGridId($miniGridId): Collection - { + public function getDevicesByMiniGridId($miniGridId): Collection { return $this->device->newQuery() ->with(['device', 'address.geo']) ->whereHasMorph( diff --git a/src/backend/app/modules/EBike/EBikeDeviceService.php b/src/backend/app/modules/EBike/EBikeDeviceService.php index 3aed09e05..a620c755d 100644 --- a/src/backend/app/modules/EBike/EBikeDeviceService.php +++ b/src/backend/app/modules/EBike/EBikeDeviceService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class EBikeDeviceService implements IAssignationService -{ +class EBikeDeviceService implements IAssignationService { private Device $device; + protected EBike $eBike; - public function setAssigned($assigned): void - { + public function setAssigned($assigned): void { $this->device = $assigned; } - public function setAssignee($assignee): void - { + public function setAssignee($assignee): void { $this->eBike = $assignee; } - public function assign(): Device - { + public function assign(): Device { $this->device->device()->associate($this->eBike); return $this->device; diff --git a/src/backend/app/modules/EBike/EBikeService.php b/src/backend/app/modules/EBike/EBikeService.php index b9354369d..846772040 100644 --- a/src/backend/app/modules/EBike/EBikeService.php +++ b/src/backend/app/modules/EBike/EBikeService.php @@ -10,15 +10,12 @@ /** * @implements IBaseService */ -class EBikeService implements IBaseService -{ +class EBikeService implements IBaseService { public function __construct( private EBike $eBike, - ) { - } + ) {} - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->eBike->newQuery()->with(['manufacturer', 'appliance', 'device.person'])->paginate($limit); } @@ -26,18 +23,15 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->eBike->newQuery()->with(['manufacturer', 'appliance', 'device.person'])->get(); } - public function getById(int $id): EBike - { + public function getById(int $id): EBike { return $this->eBike->newQuery()->with(['manufacturer', 'appliance', 'device.person'])->find($id); } - public function create(array $data): EBike - { + public function create(array $data): EBike { return $this->eBike->newQuery()->create($data); } - public function search($term, $paginate): LengthAwarePaginator - { + public function search($term, $paginate): LengthAwarePaginator { return $this->eBike->newQuery() ->with(['manufacturer', 'appliance', 'device.person']) ->whereHas( @@ -45,7 +39,7 @@ public function search($term, $paginate): LengthAwarePaginator fn ($q) => $q->whereHas( 'person', fn ($q) => $q->where('name', 'LIKE', '%'.$term.'%') - ->orWhere('surname', 'LIKE', '%'.$term.'%') + ->orWhere('surname', 'LIKE', '%'.$term.'%') ) ) ->orWhere( @@ -55,16 +49,14 @@ public function search($term, $paginate): LengthAwarePaginator )->paginate($paginate); } - public function update($model, array $data): EBike - { + public function update($model, array $data): EBike { $model->newQuery()->update($data); $model->fresh(); return $model; } - public function getBySerialNumber($serialNumber) - { + public function getBySerialNumber($serialNumber) { return $this->eBike->newQuery() ->with(['manufacturer', 'appliance', 'device.person'])->where( 'serial_number', @@ -72,8 +64,7 @@ public function getBySerialNumber($serialNumber) )->first(); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } } diff --git a/src/backend/app/modules/Meter/MeterDeviceService.php b/src/backend/app/modules/Meter/MeterDeviceService.php index c9c9f1049..cad8158af 100644 --- a/src/backend/app/modules/Meter/MeterDeviceService.php +++ b/src/backend/app/modules/Meter/MeterDeviceService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class MeterDeviceService implements IAssignationService -{ +class MeterDeviceService implements IAssignationService { private Device $device; + private Meter $meter; - public function setAssigned($assigned): void - { + public function setAssigned($assigned): void { $this->device = $assigned; } - public function setAssignee($assignee): void - { + public function setAssignee($assignee): void { $this->meter = $assignee; } - public function assign(): Device - { + public function assign(): Device { $this->device->device()->associate($this->meter); return $this->device; diff --git a/src/backend/app/modules/OutstandingDebts/OutstandingDebtsExportService.php b/src/backend/app/modules/OutstandingDebts/OutstandingDebtsExportService.php index 61ffe009c..508ca7383 100644 --- a/src/backend/app/modules/OutstandingDebts/OutstandingDebtsExportService.php +++ b/src/backend/app/modules/OutstandingDebts/OutstandingDebtsExportService.php @@ -10,20 +10,17 @@ use Carbon\CarbonImmutable; use Illuminate\Support\Collection; -class OutstandingDebtsExportService extends AbstractExportService -{ +class OutstandingDebtsExportService extends AbstractExportService { public function __construct( private readonly UserService $userService, private ApplianceRateService $applianceService, private ApplianceRateService $applianceRateService, private MailHelper $mailHelper, - ) { - } + ) {} private Collection $outstandingDebtsData; - public function writeOutstandingDebtsData(): void - { + public function writeOutstandingDebtsData(): void { $this->setActivatedSheet('Sheet1'); foreach ($this->exportingData as $key => $value) { @@ -39,8 +36,7 @@ public function writeOutstandingDebtsData(): void } } - public function setExportingData(): void - { + public function setExportingData(): void { $this->exportingData = $this->outstandingDebtsData->map(function ($applianceRate) { return [ $applianceRate->assetPerson->person->name.' '.$applianceRate->assetPerson->person->surname, @@ -52,18 +48,15 @@ public function setExportingData(): void }); } - public function setOutstandingDebtsData($outstandingDebtsData): void - { + public function setOutstandingDebtsData($outstandingDebtsData): void { $this->outstandingDebtsData = $outstandingDebtsData; } - public function getTemplatePath(): string - { + public function getTemplatePath(): string { return storage_path('appliance/export_outstanding_debts_template.xlsx'); } - public function createReport(CarbonImmutable $toDate): string - { + public function createReport(CarbonImmutable $toDate): string { $currency = $this->applianceRateService->getCurrencyFromMainSettings(); $data = $this->applianceService->queryOutstandingDebtsByApplianceRates($toDate)->get(); @@ -76,8 +69,7 @@ public function createReport(CarbonImmutable $toDate): string return $this->saveSpreadSheet(); } - public function sendApplianceDebtsAsEmail(): void - { + public function sendApplianceDebtsAsEmail(): void { $reportDate = CarbonImmutable::now()->endOfWeek()->endOfDay(); $path = $this->createReport($reportDate); @@ -92,8 +84,7 @@ public function sendApplianceDebtsAsEmail(): void }); } - public function getPrefix(): string - { + public function getPrefix(): string { return 'OutstandingDebtsExport'; } } diff --git a/src/backend/app/modules/Sharding/ApiCompanyResolverService.php b/src/backend/app/modules/Sharding/ApiCompanyResolverService.php index 78b7dd31c..c6a03537b 100644 --- a/src/backend/app/modules/Sharding/ApiCompanyResolverService.php +++ b/src/backend/app/modules/Sharding/ApiCompanyResolverService.php @@ -10,14 +10,10 @@ use MPM\Sharding\ApiResolvers\ApiResolverInterface; use MPM\Sharding\ApiResolvers\Data\ApiResolverMap; -class ApiCompanyResolverService -{ - public function __construct(private ApiResolverMap $apiResolverMap) - { - } +class ApiCompanyResolverService { + public function __construct(private ApiResolverMap $apiResolverMap) {} - public function resolve(Request $request): int - { + public function resolve(Request $request): int { $api = collect($this->apiResolverMap::RESOLVABLE_APIS)->filter(fn ($apiPath) => Str::startsWith(Str::lower($request->path()), Str::lower($apiPath))); if (!$api) { throw new ValidationException('No api resolver registered for '.$request->path()); @@ -28,8 +24,7 @@ public function resolve(Request $request): int return $resolver->resolveCompanyId($request); } - private function startResolver(string $api): ApiResolverInterface - { + private function startResolver(string $api): ApiResolverInterface { $apiResolver = $this->apiResolverMap->getApiResolver($api); if (!$apiResolver) { throw new ValidationException('Api is registered to resolve but no resolver class is assigned'.$api); diff --git a/src/backend/app/modules/Sharding/ApiResolvers/AndroidGatewayCallbackApiResolver.php b/src/backend/app/modules/Sharding/ApiResolvers/AndroidGatewayCallbackApiResolver.php index 9becf1fe3..4a86416fe 100644 --- a/src/backend/app/modules/Sharding/ApiResolvers/AndroidGatewayCallbackApiResolver.php +++ b/src/backend/app/modules/Sharding/ApiResolvers/AndroidGatewayCallbackApiResolver.php @@ -5,10 +5,8 @@ use App\Exceptions\ValidationException; use Illuminate\Http\Request; -class AndroidGatewayCallbackApiResolver implements ApiResolverInterface -{ - public function resolveCompanyId(Request $request): int - { +class AndroidGatewayCallbackApiResolver implements ApiResolverInterface { + public function resolveCompanyId(Request $request): int { $segments = $request->segments(); if (count($segments) !== 5) { throw new ValidationException('failed to parse company identifier from the webhook'); diff --git a/src/backend/app/modules/Sharding/ApiResolvers/ApiResolverInterface.php b/src/backend/app/modules/Sharding/ApiResolvers/ApiResolverInterface.php index 34748eb1a..6b674e1c4 100644 --- a/src/backend/app/modules/Sharding/ApiResolvers/ApiResolverInterface.php +++ b/src/backend/app/modules/Sharding/ApiResolvers/ApiResolverInterface.php @@ -4,7 +4,6 @@ use Illuminate\Http\Request; -interface ApiResolverInterface -{ +interface ApiResolverInterface { public function resolveCompanyId(Request $request): int; } diff --git a/src/backend/app/modules/Sharding/ApiResolvers/Data/ApiResolverMap.php b/src/backend/app/modules/Sharding/ApiResolvers/Data/ApiResolverMap.php index 75141ed83..a5d85138e 100644 --- a/src/backend/app/modules/Sharding/ApiResolvers/Data/ApiResolverMap.php +++ b/src/backend/app/modules/Sharding/ApiResolvers/Data/ApiResolverMap.php @@ -12,15 +12,21 @@ use MPM\Sharding\ApiResolvers\ViberMessagingApiResolver; use MPM\Sharding\ApiResolvers\WaveMoneyApiResolver; -class ApiResolverMap -{ +class ApiResolverMap { public const VIBER_API = 'api/viber-messaging/webhook'; + public const TEST_API = 'api/testApi'; + public const WAVE_MONEY_API = 'api/wave-money/wave-money-transaction'; + public const ANDROID_GATEWAY_CALLBACK_API = 'api/sms-android-callback'; + public const SWIFTA_PAYMENT_API = 'api/swifta/'; + public const REPORT_DOWNLOADING_API = 'api/report-downloading'; + public const DATA_EXPORTING_API = 'api/export'; + public const RESOLVABLE_APIS = [ self::TEST_API, self::VIBER_API, @@ -41,13 +47,11 @@ class ApiResolverMap self::DATA_EXPORTING_API => DataExportResolver::class, ]; - public function getResolvableApis(): array - { + public function getResolvableApis(): array { return self::RESOLVABLE_APIS; } - public function getApiResolver(string $api): string - { + public function getApiResolver(string $api): string { return self::API_RESOLVER[$api]; } } diff --git a/src/backend/app/modules/Sharding/ApiResolvers/DataExportResolver.php b/src/backend/app/modules/Sharding/ApiResolvers/DataExportResolver.php index d9018b46d..15f02ba1c 100644 --- a/src/backend/app/modules/Sharding/ApiResolvers/DataExportResolver.php +++ b/src/backend/app/modules/Sharding/ApiResolvers/DataExportResolver.php @@ -6,14 +6,10 @@ use Illuminate\Http\Request; use MPM\DatabaseProxy\DatabaseProxyManagerService; -class DataExportResolver implements ApiResolverInterface -{ - public function __construct(private DatabaseProxyManagerService $databaseProxyManager) - { - } +class DataExportResolver implements ApiResolverInterface { + public function __construct(private DatabaseProxyManagerService $databaseProxyManager) {} - public function resolveCompanyId(Request $request): int - { + public function resolveCompanyId(Request $request): int { $segments = $request->segments(); if (count($segments) !== 4) { throw new ValidationException('failed to parse company identifier from the webhook'); diff --git a/src/backend/app/modules/Sharding/ApiResolvers/DownloadingReportsResolver.php b/src/backend/app/modules/Sharding/ApiResolvers/DownloadingReportsResolver.php index b0fc3f7c0..393aa6edb 100644 --- a/src/backend/app/modules/Sharding/ApiResolvers/DownloadingReportsResolver.php +++ b/src/backend/app/modules/Sharding/ApiResolvers/DownloadingReportsResolver.php @@ -5,10 +5,8 @@ use App\Exceptions\ValidationException; use Illuminate\Http\Request; -class DownloadingReportsResolver implements ApiResolverInterface -{ - public function resolveCompanyId(Request $request): int - { +class DownloadingReportsResolver implements ApiResolverInterface { + public function resolveCompanyId(Request $request): int { $segments = $request->segments(); if (count($segments) !== 5) { throw new ValidationException('failed to parse company identifier from the webhook'); diff --git a/src/backend/app/modules/Sharding/ApiResolvers/JetsonApiResolver.php b/src/backend/app/modules/Sharding/ApiResolvers/JetsonApiResolver.php index eaab9f4ca..d8021b25b 100644 --- a/src/backend/app/modules/Sharding/ApiResolvers/JetsonApiResolver.php +++ b/src/backend/app/modules/Sharding/ApiResolvers/JetsonApiResolver.php @@ -5,10 +5,8 @@ use App\Exceptions\ValidationException; use Illuminate\Http\Request; -class JetsonApiResolver implements ApiResolverInterface -{ - public function resolveCompanyId(Request $request): int - { +class JetsonApiResolver implements ApiResolverInterface { + public function resolveCompanyId(Request $request): int { $segments = $request->segments(); if (count($segments) < 6) { throw new ValidationException('failed to parse company identifier from the webhook'); diff --git a/src/backend/app/modules/Sharding/ApiResolvers/SwiftaPaymentApiResolver.php b/src/backend/app/modules/Sharding/ApiResolvers/SwiftaPaymentApiResolver.php index 2fea62fbb..edd2127cd 100644 --- a/src/backend/app/modules/Sharding/ApiResolvers/SwiftaPaymentApiResolver.php +++ b/src/backend/app/modules/Sharding/ApiResolvers/SwiftaPaymentApiResolver.php @@ -4,10 +4,8 @@ use Illuminate\Http\Request; -class SwiftaPaymentApiResolver implements ApiResolverInterface -{ - public function resolveCompanyId(Request $request): int - { +class SwiftaPaymentApiResolver implements ApiResolverInterface { + public function resolveCompanyId(Request $request): int { return (int) auth()->payload()->get('companyId'); } } diff --git a/src/backend/app/modules/Sharding/ApiResolvers/TestApiResolver.php b/src/backend/app/modules/Sharding/ApiResolvers/TestApiResolver.php index d499c42ed..7306a0d0e 100644 --- a/src/backend/app/modules/Sharding/ApiResolvers/TestApiResolver.php +++ b/src/backend/app/modules/Sharding/ApiResolvers/TestApiResolver.php @@ -8,12 +8,10 @@ use Illuminate\Http\Request; // test-api passes the company id within the callback url -class TestApiResolver implements ApiResolverInterface -{ +class TestApiResolver implements ApiResolverInterface { private const QUERY_PARAM_COMPANY_ID = 'c'; - public function resolveCompanyId(Request $request): int - { + public function resolveCompanyId(Request $request): int { $companyId = $request->input(self::QUERY_PARAM_COMPANY_ID); if (!is_numeric($companyId)) { throw new ValidationException('the field which is used to identify the company is not provided'); diff --git a/src/backend/app/modules/Sharding/ApiResolvers/ViberMessagingApiResolver.php b/src/backend/app/modules/Sharding/ApiResolvers/ViberMessagingApiResolver.php index 1a6be172e..4f8110ac2 100644 --- a/src/backend/app/modules/Sharding/ApiResolvers/ViberMessagingApiResolver.php +++ b/src/backend/app/modules/Sharding/ApiResolvers/ViberMessagingApiResolver.php @@ -7,10 +7,8 @@ use App\Exceptions\ValidationException; use Illuminate\Http\Request; -class ViberMessagingApiResolver implements ApiResolverInterface -{ - public function resolveCompanyId(Request $request): int - { +class ViberMessagingApiResolver implements ApiResolverInterface { + public function resolveCompanyId(Request $request): int { $segments = $request->segments(); if (count($segments) !== 4) { throw new ValidationException('failed to parse company identifier from the webhook'); diff --git a/src/backend/app/modules/Sharding/ApiResolvers/WaveMoneyApiResolver.php b/src/backend/app/modules/Sharding/ApiResolvers/WaveMoneyApiResolver.php index 919d59667..0edd39db8 100644 --- a/src/backend/app/modules/Sharding/ApiResolvers/WaveMoneyApiResolver.php +++ b/src/backend/app/modules/Sharding/ApiResolvers/WaveMoneyApiResolver.php @@ -5,10 +5,8 @@ use App\Exceptions\ValidationException; use Illuminate\Http\Request; -class WaveMoneyApiResolver implements ApiResolverInterface -{ - public function resolveCompanyId(Request $request): int - { +class WaveMoneyApiResolver implements ApiResolverInterface { + public function resolveCompanyId(Request $request): int { $segments = $request->segments(); if (count($segments) !== 5) { throw new ValidationException('failed to parse company identifier from the webhook'); diff --git a/src/backend/app/modules/SolarHomeSystem/SolarHomeSystemDeviceService.php b/src/backend/app/modules/SolarHomeSystem/SolarHomeSystemDeviceService.php index a87031a57..2fc8a2496 100644 --- a/src/backend/app/modules/SolarHomeSystem/SolarHomeSystemDeviceService.php +++ b/src/backend/app/modules/SolarHomeSystem/SolarHomeSystemDeviceService.php @@ -9,23 +9,20 @@ /** * @implements IAssignationService */ -class SolarHomeSystemDeviceService implements IAssignationService -{ +class SolarHomeSystemDeviceService implements IAssignationService { private Device $device; + protected SolarHomeSystem $shs; - public function setAssigned($assigned): void - { + public function setAssigned($assigned): void { $this->device = $assigned; } - public function setAssignee($assignee): void - { + public function setAssignee($assignee): void { $this->shs = $assignee; } - public function assign(): Device - { + public function assign(): Device { $this->device->device()->associate($this->shs); return $this->device; diff --git a/src/backend/app/modules/SolarHomeSystem/SolarHomeSystemService.php b/src/backend/app/modules/SolarHomeSystem/SolarHomeSystemService.php index b9b9c8c9a..521e18f08 100644 --- a/src/backend/app/modules/SolarHomeSystem/SolarHomeSystemService.php +++ b/src/backend/app/modules/SolarHomeSystem/SolarHomeSystemService.php @@ -10,14 +10,10 @@ /** * @implements IBaseService */ -class SolarHomeSystemService implements IBaseService -{ - public function __construct(private SolarHomeSystem $solarHomeSystem) - { - } +class SolarHomeSystemService implements IBaseService { + public function __construct(private SolarHomeSystem $solarHomeSystem) {} - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->solarHomeSystem->newQuery()->with(['manufacturer', 'appliance', 'device.person'])->paginate($limit); } @@ -25,8 +21,7 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->solarHomeSystem->newQuery()->with(['manufacturer', 'appliance', 'device.person'])->get(); } - public function getById(int $id): SolarHomeSystem - { + public function getById(int $id): SolarHomeSystem { /** @var SolarHomeSystem|null $result */ $result = $this->solarHomeSystem->newQuery() ->with(['manufacturer', 'appliance', 'device.person']) @@ -35,16 +30,14 @@ public function getById(int $id): SolarHomeSystem return $result; } - public function create(array $data): SolarHomeSystem - { + public function create(array $data): SolarHomeSystem { /** @var SolarHomeSystem $result */ $result = $this->solarHomeSystem->newQuery()->create($data); return $result; } - public function search($term, $paginate): LengthAwarePaginator - { + public function search($term, $paginate): LengthAwarePaginator { return $this->solarHomeSystem->newQuery() ->with(['manufacturer', 'appliance', 'device.person']) ->whereHas( @@ -62,13 +55,11 @@ public function search($term, $paginate): LengthAwarePaginator )->paginate($paginate); } - public function update($model, array $data): SolarHomeSystem - { + public function update($model, array $data): SolarHomeSystem { throw new \Exception('not implemented'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('not implemented'); } } diff --git a/src/backend/app/modules/Target/TargetAssignable.php b/src/backend/app/modules/Target/TargetAssignable.php index 3bdd14d62..c09a05565 100644 --- a/src/backend/app/modules/Target/TargetAssignable.php +++ b/src/backend/app/modules/Target/TargetAssignable.php @@ -2,6 +2,4 @@ namespace MPM\Target; -interface TargetAssignable -{ -} +interface TargetAssignable {} diff --git a/src/backend/app/modules/Transaction/ApplianceTransactionService.php b/src/backend/app/modules/Transaction/ApplianceTransactionService.php index d8e6cbe78..47a9a38ce 100644 --- a/src/backend/app/modules/Transaction/ApplianceTransactionService.php +++ b/src/backend/app/modules/Transaction/ApplianceTransactionService.php @@ -2,6 +2,4 @@ namespace MPM\Transaction; -class ApplianceTransactionService -{ -} +class ApplianceTransactionService {} diff --git a/src/backend/app/modules/Transaction/EBikeTransactionService.php b/src/backend/app/modules/Transaction/EBikeTransactionService.php index d2bf4123b..278870fbc 100644 --- a/src/backend/app/modules/Transaction/EBikeTransactionService.php +++ b/src/backend/app/modules/Transaction/EBikeTransactionService.php @@ -5,11 +5,8 @@ use App\Models\EBike; use App\Models\Transaction\Transaction; -class EBikeTransactionService -{ - public function __construct(private Transaction $transaction) - { - } +class EBikeTransactionService { + public function __construct(private Transaction $transaction) {} public function search( ?string $serialNumber = null, diff --git a/src/backend/app/modules/Transaction/Export/TransactionExportService.php b/src/backend/app/modules/Transaction/Export/TransactionExportService.php index 42efc0a30..90acf6a87 100644 --- a/src/backend/app/modules/Transaction/Export/TransactionExportService.php +++ b/src/backend/app/modules/Transaction/Export/TransactionExportService.php @@ -4,13 +4,12 @@ use App\Services\AbstractExportService; -class TransactionExportService extends AbstractExportService -{ +class TransactionExportService extends AbstractExportService { private $path = __DIR__.'/export_transactions_template.xlsx'; + private $transactionData; - public function writeTransactionData(): void - { + public function writeTransactionData(): void { $this->setActivatedSheet('Sheet1'); foreach ($this->exportingData as $key => $value) { @@ -28,8 +27,7 @@ public function writeTransactionData(): void } } - public function setExportingData(): void - { + public function setExportingData(): void { $this->exportingData = $this->transactionData->map(function ($transaction) { $status = $transaction->originalTransaction->status == 1 ? 'Success' : ($transaction->status == 0 ? 'Pending' : 'Failed'); $readableAmount = $this->readable($transaction->amount); @@ -46,18 +44,15 @@ public function setExportingData(): void }); } - public function setTransactionData($transactionData): void - { + public function setTransactionData($transactionData): void { $this->transactionData = $transactionData; } - public function getTemplatePath(): string - { + public function getTemplatePath(): string { return storage_path('transaction/export_transactions_template.xlsx'); } - public function getPrefix(): string - { + public function getPrefix(): string { return 'TransactionExport'; } } diff --git a/src/backend/app/modules/Transaction/FullySupportedTransactionInterface.php b/src/backend/app/modules/Transaction/FullySupportedTransactionInterface.php index 8a87439b8..f0f4374da 100644 --- a/src/backend/app/modules/Transaction/FullySupportedTransactionInterface.php +++ b/src/backend/app/modules/Transaction/FullySupportedTransactionInterface.php @@ -4,7 +4,6 @@ namespace MPM\Transaction; -interface FullySupportedTransactionInterface -{ +interface FullySupportedTransactionInterface { public static function getTransactionName(): string; } diff --git a/src/backend/app/modules/Transaction/MeterTransactionService.php b/src/backend/app/modules/Transaction/MeterTransactionService.php index b72071e1a..3a2db9e5b 100644 --- a/src/backend/app/modules/Transaction/MeterTransactionService.php +++ b/src/backend/app/modules/Transaction/MeterTransactionService.php @@ -5,11 +5,8 @@ use App\Models\Meter\Meter; use App\Models\Transaction\Transaction; -class MeterTransactionService -{ - public function __construct(private Transaction $transaction) - { - } +class MeterTransactionService { + public function __construct(private Transaction $transaction) {} public function search( ?string $serialNumber = null, diff --git a/src/backend/app/modules/Transaction/Provider/AgentTransactionProvider.php b/src/backend/app/modules/Transaction/Provider/AgentTransactionProvider.php index c57ba5a5e..dcbf7548d 100644 --- a/src/backend/app/modules/Transaction/Provider/AgentTransactionProvider.php +++ b/src/backend/app/modules/Transaction/Provider/AgentTransactionProvider.php @@ -12,19 +12,16 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\ModelNotFoundException; -class AgentTransactionProvider implements ITransactionProvider -{ +class AgentTransactionProvider implements ITransactionProvider { private array $validData; public function __construct( private AgentTransactionModel $agentTransaction, private Transaction $transaction, private FirebaseService $fireBaseService, - ) { - } + ) {} - public function saveTransaction(): void - { + public function saveTransaction(): void { $this->agentTransaction = new AgentTransactionModel(); $this->transaction = new Transaction(); // assign data @@ -33,8 +30,7 @@ public function saveTransaction(): void $this->saveData($this->agentTransaction); } - private function assignData(array $data): void - { + private function assignData(array $data): void { // provider specific data $this->agentTransaction->agent_id = (int) $data['agent_id']; $this->agentTransaction->device_id = (int) $data['device_id']; @@ -47,13 +43,11 @@ private function assignData(array $data): void $this->transaction->original_transaction_type = 'agent_transaction'; } - public function saveData(AgentTransactionModel $agentTransaction): void - { + public function saveData(AgentTransactionModel $agentTransaction): void { $agentTransaction->save(); } - public function sendResult(bool $requestType, Transaction $transaction): void - { + public function sendResult(bool $requestType, Transaction $transaction): void { $this->agentTransaction->update(['status' => $requestType === true ? 1 : -1]); $agent = $this->agentTransaction->agent; @@ -95,8 +89,7 @@ public function sendResult(bool $requestType, Transaction $transaction): void $this->fireBaseService->sendNotify($agent->fire_base_token, $body); } - private function prepareBodySuccess(Transaction $transaction): array - { + private function prepareBodySuccess(Transaction $transaction): array { $transaction = Transaction::with( 'token', 'originalTransaction', @@ -118,8 +111,7 @@ private function prepareBodySuccess(Transaction $transaction): array ]; } - private function prepareBodyFail(Transaction $transaction): array - { + private function prepareBodyFail(Transaction $transaction): array { return [ 'message' => 'Transaction failed', 'type' => 'agent_transaction', @@ -129,8 +121,7 @@ private function prepareBodyFail(Transaction $transaction): array ]; } - public function validateRequest($request): void - { + public function validateRequest($request): void { $deviceId = request()->header('device-id'); $agent = Agent::query()->find(auth('agent_api')->user()->id); $agentId = $agent->id; @@ -151,39 +142,32 @@ public function validateRequest($request): void $this->validData['agent_id'] = $agentId; } - public function confirm(): void - { + public function confirm(): void { // No need to confirm the trigger request } - public function getMessage(): string - { + public function getMessage(): string { return $this->transaction->message; } - public function getAmount(): int - { + public function getAmount(): int { return $this->transaction->amount; } - public function getSender(): string - { + public function getSender(): string { return $this->transaction->sender; } - public function saveCommonData(): Model - { + public function saveCommonData(): Model { return $this->agentTransaction->transaction()->save($this->transaction); } - public function init($transaction): void - { + public function init($transaction): void { $this->agentTransaction = $transaction; $this->transaction = $transaction->transaction()->first(); } - public function addConflict(?string $message): void - { + public function addConflict(?string $message): void { $conflict = new TransactionConflicts(); $conflict->state = $message; $conflict->transaction()->associate($this->agentTransaction); @@ -191,8 +175,7 @@ public function addConflict(?string $message): void $this->agentTransaction->update(['status' => -1]); } - public function getTransaction(): Transaction - { + public function getTransaction(): Transaction { return $this->transaction; } } diff --git a/src/backend/app/modules/Transaction/Provider/AirtelTransactionProvider.php b/src/backend/app/modules/Transaction/Provider/AirtelTransactionProvider.php index e8b11be50..a713246fe 100644 --- a/src/backend/app/modules/Transaction/Provider/AirtelTransactionProvider.php +++ b/src/backend/app/modules/Transaction/Provider/AirtelTransactionProvider.php @@ -13,16 +13,12 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Validator; -class AirtelTransactionProvider implements ITransactionProvider -{ +class AirtelTransactionProvider implements ITransactionProvider { private \SimpleXMLElement $validData; - public function __construct(private AirtelTransaction $airtelTransaction, private Transaction $transaction) - { - } + public function __construct(private AirtelTransaction $airtelTransaction, private Transaction $transaction) {} - public function saveTransaction(): void - { + public function saveTransaction(): void { $this->airtelTransaction = new AirtelTransaction(); $this->transaction = new Transaction(); // assign data @@ -32,12 +28,7 @@ public function saveTransaction(): void $this->saveData($this->airtelTransaction); } - /** - * @param bool $requestType - * @param Transaction $transaction - */ - public function sendResult(bool $requestType, Transaction $transaction): void - { + public function sendResult(bool $requestType, Transaction $transaction): void { // approve transaction : airtel transactions are automatically confirmed thus // only save it as successful if ($requestType) { @@ -71,8 +62,7 @@ public function sendResult(bool $requestType, Transaction $transaction): void } } - public function validateRequest($request): bool - { + public function validateRequest($request): bool { $transactionXml = new \SimpleXMLElement($request); $transactionData = json_encode($transactionXml); $transactionData = json_decode($transactionData, true); @@ -101,8 +91,7 @@ public function validateRequest($request): bool return true; } - public function confirm(): void - { + public function confirm(): void { echo $xmlResponse = ''. ''. @@ -116,34 +105,28 @@ public function confirm(): void ''; } - public function getMessage(): string - { + public function getMessage(): string { return $this->transaction->message; } - public function getAmount(): int - { + public function getAmount(): int { return $this->transaction->amount; } - public function getSender(): string - { + public function getSender(): string { return $this->transaction->sender; } - public function saveCommonData(): Model - { + public function saveCommonData(): Model { return $this->airtelTransaction->transaction()->save($this->transaction); } - public function init($transaction): void - { + public function init($transaction): void { $this->airtelTransaction = $transaction; $this->transaction = $transaction->transaction()->first(); } - private function assignData(\SimpleXMLElement $data): void - { + private function assignData(\SimpleXMLElement $data): void { // provider specific data $this->airtelTransaction->interface_id = (string) $data->INTERFACEID; $this->airtelTransaction->business_number = (string) $data->BusinessNumber; @@ -157,25 +140,20 @@ private function assignData(\SimpleXMLElement $data): void /** * Saves the airtel transaction. - * - * @param AirtelTransaction $airtelTransaction */ - public function saveData(AirtelTransaction $airtelTransaction): void - { + public function saveData(AirtelTransaction $airtelTransaction): void { $airtelTransaction->save(); event('transaction.confirm'); } - public function addConflict(?string $message): void - { + public function addConflict(?string $message): void { $conflict = new TransactionConflicts(); $conflict->state = $message; $conflict->transaction()->associate($this->airtelTransaction); $conflict->save(); } - public function getTransaction(): Transaction - { + public function getTransaction(): Transaction { return $this->transaction; } diff --git a/src/backend/app/modules/Transaction/Provider/AirtelVoltTerraProvider.php b/src/backend/app/modules/Transaction/Provider/AirtelVoltTerraProvider.php index ced9293c0..a2673006d 100644 --- a/src/backend/app/modules/Transaction/Provider/AirtelVoltTerraProvider.php +++ b/src/backend/app/modules/Transaction/Provider/AirtelVoltTerraProvider.php @@ -16,24 +16,18 @@ use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Support\Facades\Validator; -class AirtelVoltTerraProvider implements ITransactionProvider -{ +class AirtelVoltTerraProvider implements ITransactionProvider { private $validData; /** * DI will initialize the needed models. - * - * @param AirtelTransaction $airtelTransaction - * @param Transaction $transaction */ public function __construct( private AirtelTransaction $airtelTransaction, private Transaction $transaction, - ) { - } + ) {} - public function saveTransaction(): void - { + public function saveTransaction(): void { $this->airtelTransaction = new AirtelTransaction(); $this->transaction = new Transaction(); // assign data @@ -43,12 +37,7 @@ public function saveTransaction(): void $this->saveData($this->airtelTransaction); } - /** - * @param bool $requestType - * @param Transaction $transaction - */ - public function sendResult(bool $requestType, Transaction $transaction): void - { + public function sendResult(bool $requestType, Transaction $transaction): void { if ($requestType) { $this->airtelTransaction->status = 1; $this->airtelTransaction->save(); @@ -60,14 +49,12 @@ public function sendResult(bool $requestType, Transaction $transaction): void } } - public function init($transaction): void - { + public function init($transaction): void { $this->airtelTransaction = $transaction; $this->transaction = $transaction->transaction()->first(); } - public function validateRequest($request): bool - { + public function validateRequest($request): bool { $meterSerial = $request['meterSerial']; $amount = $request['amount']; $validator = Validator::make([ @@ -119,8 +106,7 @@ public function validateRequest($request): bool return true; } - private function getTransactionSender($meterSerial) - { + private function getTransactionSender($meterSerial) { $meterParameter = MeterParameter::query() ->whereHas( 'meter', @@ -146,8 +132,7 @@ function ($q) use ($personId) { } } - private function assignData(): void - { + private function assignData(): void { // provider specific data $this->airtelTransaction->interface_id = 'Airtel Transactions Email Interface'; $this->airtelTransaction->business_number = 'Airtel Transactions Email Interface'; @@ -159,47 +144,39 @@ private function assignData(): void $this->transaction->message = $this->validData['meterSerial']; } - public function saveData(AirtelTransaction $airtelTransaction): void - { + public function saveData(AirtelTransaction $airtelTransaction): void { $airtelTransaction->save(); event('transaction.confirm'); } - public function saveCommonData(): Model - { + public function saveCommonData(): Model { return $this->airtelTransaction->transaction()->save($this->transaction); } - public function addConflict(?string $message): void - { + public function addConflict(?string $message): void { $conflict = new TransactionConflicts(); $conflict->state = $message; $conflict->transaction()->associate($this->airtelTransaction); $conflict->save(); } - public function confirm(): void - { + public function confirm(): void { throw new \Exception('not implemented'); } - public function getMessage(): string - { + public function getMessage(): string { throw new \Exception('not implemented'); } - public function getAmount(): int - { + public function getAmount(): int { throw new \Exception('not implemented'); } - public function getSender(): string - { + public function getSender(): string { throw new \Exception('not implemented'); } - public function getTransaction(): Transaction - { + public function getTransaction(): Transaction { throw new \Exception('not implemented'); } } diff --git a/src/backend/app/modules/Transaction/Provider/CashTransactionProvider.php b/src/backend/app/modules/Transaction/Provider/CashTransactionProvider.php index 318ac09a4..2dff48b25 100644 --- a/src/backend/app/modules/Transaction/Provider/CashTransactionProvider.php +++ b/src/backend/app/modules/Transaction/Provider/CashTransactionProvider.php @@ -7,18 +7,15 @@ use App\Models\Transaction\TransactionConflicts; use Illuminate\Database\Eloquent\Model; -class CashTransactionProvider implements ITransactionProvider -{ +class CashTransactionProvider implements ITransactionProvider { private array $validData; public function __construct( private CashTransaction $cashTransaction, private Transaction $transaction, - ) { - } + ) {} - public function saveTransaction(): void - { + public function saveTransaction(): void { $this->cashTransaction = new CashTransaction(); $this->transaction = new Transaction(); @@ -29,8 +26,7 @@ public function saveTransaction(): void $this->saveData($this->cashTransaction); } - private function assignData(array $data): void - { + private function assignData(array $data): void { // provider specific data $this->cashTransaction->user_id = (int) $data['user_id']; @@ -41,62 +37,51 @@ private function assignData(array $data): void $this->transaction->original_transaction_type = 'cash_transaction'; } - public function saveData(CashTransaction $cashTransaction): void - { + public function saveData(CashTransaction $cashTransaction): void { $cashTransaction->save(); } - public function sendResult(bool $requestType, Transaction $transaction) - { + public function sendResult(bool $requestType, Transaction $transaction) { // TODO: Implement sendResult() method. } - public function validateRequest($request) - { + public function validateRequest($request) { // TODO: Implement validateRequest() method. } - public function confirm(): void - { + public function confirm(): void { // TODO: Implement confirm() method. } - public function getMessage(): string - { + public function getMessage(): string { return ''; } - public function getAmount(): int - { + public function getAmount(): int { return $this->transaction->amount; } - public function getSender(): string - { + public function getSender(): string { return $this->transaction->sender; } - public function saveCommonData(): Model - { + public function saveCommonData(): Model { return $this->cashTransaction->transaction()->save($this->transaction); } - public function init($transaction): void - { + public function init($transaction): void { $this->cashTransaction = $transaction; $this->transaction = $transaction->transaction()->first(); } - public function addConflict(?string $message): void - { + public function addConflict(?string $message): void { $conflict = new TransactionConflicts(); $conflict->state = $message; $conflict->transaction()->associate($this->cashTransaction); $conflict->save(); } - public function getTransaction(): Transaction - { + public function getTransaction(): Transaction { return $this->transaction; } } diff --git a/src/backend/app/modules/Transaction/Provider/ITransactionProvider.php b/src/backend/app/modules/Transaction/Provider/ITransactionProvider.php index d01e639c2..ce7a048c7 100644 --- a/src/backend/app/modules/Transaction/Provider/ITransactionProvider.php +++ b/src/backend/app/modules/Transaction/Provider/ITransactionProvider.php @@ -5,8 +5,7 @@ use App\Models\Transaction\Transaction; use Illuminate\Database\Eloquent\Model; -interface ITransactionProvider -{ +interface ITransactionProvider { // saves the main transaction public function saveTransaction(); diff --git a/src/backend/app/modules/Transaction/Provider/TransactionAdapter.php b/src/backend/app/modules/Transaction/Provider/TransactionAdapter.php index 87217bcbf..4ee7e5048 100644 --- a/src/backend/app/modules/Transaction/Provider/TransactionAdapter.php +++ b/src/backend/app/modules/Transaction/Provider/TransactionAdapter.php @@ -9,15 +9,11 @@ use Inensus\WavecomPaymentProvider\Models\WaveComTransaction; use Inensus\WaveMoneyPaymentProvider\Models\WaveMoneyTransaction; -class TransactionAdapter -{ +class TransactionAdapter { /** * @param ITransactionProvider $transactionProvider - * - * @return ITransactionProvider */ - public static function getTransaction($transactionProvider): ?ITransactionProvider - { + public static function getTransaction($transactionProvider): ?ITransactionProvider { if ($transactionProvider instanceof VodacomTransaction) { $baseTransaction = resolve('VodacomPaymentProvider'); $baseTransaction->init($transactionProvider); diff --git a/src/backend/app/modules/Transaction/Provider/VodacomTransactionProvider.php b/src/backend/app/modules/Transaction/Provider/VodacomTransactionProvider.php index 2864fa4f0..41e6efdfe 100644 --- a/src/backend/app/modules/Transaction/Provider/VodacomTransactionProvider.php +++ b/src/backend/app/modules/Transaction/Provider/VodacomTransactionProvider.php @@ -15,17 +15,17 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Validator; -class VodacomTransactionProvider implements ITransactionProvider -{ +class VodacomTransactionProvider implements ITransactionProvider { private VodacomTransaction $vodacomTransaction; + private Transaction $transaction; + private \SimpleXMLElement $valid_data; /** * Is responsible for the whole incoming Transaction process. */ - public function saveTransaction(): void - { + public function saveTransaction(): void { // initializes needed model $this->vodacomTransaction = new VodacomTransaction(); @@ -39,12 +39,8 @@ public function saveTransaction(): void /** * Sends the final state of the transaction based on resultType. - * - * @param bool $requestType - * @param Transaction $transaction */ - public function sendResult(bool $requestType, Transaction $transaction): void - { + public function sendResult(bool $requestType, Transaction $transaction): void { if (!app()->environment('production')) { return; } @@ -125,12 +121,9 @@ public function sendResult(bool $requestType, Transaction $transaction): void * Validates incoming request * stores the request data to valid_data if request is valid. * - * @param $request - * * @throws \Exception */ - public function validateRequest($request): void - { + public function validateRequest($request): void { if ($request === 'JUMEME') { throw new VodacomHeartBeatException('heartbeat'); } @@ -165,8 +158,7 @@ public function validateRequest($request): void * Send a confirmation (output for incoming api request) that the transaction passed validation and will be * processed. */ - public function confirm(): void - { + public function confirm(): void { echo $xmlResponse = ''. ''. @@ -184,31 +176,22 @@ public function confirm(): void /** * The message which is been typed by the user. - * - * @return string */ - public function getMessage(): string - { + public function getMessage(): string { return $this->transaction->message; } /** * The amount sent by the user. - * - * @return int */ - public function getAmount(): int - { + public function getAmount(): int { return $this->transaction->amount; } /** * The number, which sent money. - * - * @return string */ - public function getSender(): string - { + public function getSender(): string { return $this->transaction->sender; } @@ -217,18 +200,14 @@ public function getSender(): string * * @return Transaction */ - public function saveCommonData(): Model - { + public function saveCommonData(): Model { return $this->vodacomTransaction->transaction()->save($this->transaction); } /** * Assign request data to model. - * - * @param $data */ - private function assignData(\SimpleXMLElement $data): void - { + private function assignData(\SimpleXMLElement $data): void { $transaction_data = $data->request->transaction; $this->vodacomTransaction->conversation_id = (string) $transaction_data->conversationID; $this->vodacomTransaction->originator_conversation_id = (string) $transaction_data->originatorConversationID; @@ -241,15 +220,13 @@ private function assignData(\SimpleXMLElement $data): void $this->transaction->message = (string) $transaction_data->accountReference; } - public function saveData(VodacomTransaction $vodacomTransaction): void - { + public function saveData(VodacomTransaction $vodacomTransaction): void { $vodacomTransaction->save(); // confirm transaction with event('transaction.confirm', $this); } - private function prepareRequest(bool $requestType): string - { + private function prepareRequest(bool $requestType): string { $time = date('YmdHis'); $providerPassword = $this->encryptProviderPassword($time); $phonePassword = $this->encryptPhonePassword(); @@ -283,8 +260,6 @@ private function prepareRequest(bool $requestType): string * @param string $time Y-md H:i:s * @param string $result * @param int $resultCode - * - * @return string */ private function serveResult( $serviceProviderPassword, @@ -320,8 +295,7 @@ private function serveResult( '; } - private function encryptProviderPassword(string $time): string - { + private function encryptProviderPassword(string $time): string { $password = strtoupper( hash( 'sha256', @@ -341,8 +315,7 @@ private function encryptProviderPassword(string $time): string /** * @return string */ - private function encryptPhonePassword() - { + private function encryptPhonePassword() { $keyFile = fopen(\config()->get('services.vodacom.certs.broker'), 'rb'); $publicKey = fread($keyFile, 8192); fclose($keyFile); @@ -351,22 +324,19 @@ private function encryptPhonePassword() return base64_encode($encrypted); } - public function init($transaction): void - { + public function init($transaction): void { $this->vodacomTransaction = $transaction; $this->transaction = $transaction->transaction()->first(); } - public function addConflict(?string $message): void - { + public function addConflict(?string $message): void { $conflict = new TransactionConflicts(); $conflict->state = $message; $conflict->transaction()->associate($this->vodacomTransaction); $conflict->save(); } - public function getTransaction(): Transaction - { + public function getTransaction(): Transaction { return $this->transaction; } } diff --git a/src/backend/app/modules/Transaction/SolarHomeSystemTransactionService.php b/src/backend/app/modules/Transaction/SolarHomeSystemTransactionService.php index 14f01472f..d02b70461 100644 --- a/src/backend/app/modules/Transaction/SolarHomeSystemTransactionService.php +++ b/src/backend/app/modules/Transaction/SolarHomeSystemTransactionService.php @@ -5,11 +5,8 @@ use App\Models\SolarHomeSystem; use App\Models\Transaction\Transaction; -class SolarHomeSystemTransactionService -{ - public function __construct(private Transaction $transaction) - { - } +class SolarHomeSystemTransactionService { + public function __construct(private Transaction $transaction) {} public function search( ?string $serialNumber = null, diff --git a/src/backend/app/modules/Transaction/TransactionPaymentProcessor.php b/src/backend/app/modules/Transaction/TransactionPaymentProcessor.php index 3e8e020b0..cc22e6457 100644 --- a/src/backend/app/modules/Transaction/TransactionPaymentProcessor.php +++ b/src/backend/app/modules/Transaction/TransactionPaymentProcessor.php @@ -9,21 +9,20 @@ use App\Models\SolarHomeSystem; use MPM\Device\DeviceService; -class TransactionPaymentProcessor -{ +class TransactionPaymentProcessor { protected const PROCESSORS_BY_DEVICE_TYPE = [ Meter::RELATION_NAME => EnergyTransactionProcessor::class, SolarHomeSystem::RELATION_NAME => ApplianceTransactionProcessor::class, EBike::RELATION_NAME => ApplianceTransactionProcessor::class, ]; + protected const QUEUE_BY_DEVICE_TYPE = [ Meter::RELATION_NAME => 'energy', SolarHomeSystem::RELATION_NAME => 'payment', EBike::RELATION_NAME => 'payment', ]; - public static function process(int $transactionId): void - { + public static function process(int $transactionId): void { $transactionService = app()->make(TransactionService::class); $transaction = $transactionService->getById($transactionId); $serialNumber = $transaction->message; diff --git a/src/backend/app/modules/Transaction/TransactionService.php b/src/backend/app/modules/Transaction/TransactionService.php index 9bfc8ca1f..ecdb90d70 100644 --- a/src/backend/app/modules/Transaction/TransactionService.php +++ b/src/backend/app/modules/Transaction/TransactionService.php @@ -15,11 +15,13 @@ * @implements IAssociative * @implements IBaseService */ -class TransactionService implements IAssociative, IBaseService -{ +class TransactionService implements IAssociative, IBaseService { public const YESTERDAY = 0; + public const SAME_DAY_LAST_WEEK = 1; + public const LAST_SEVEN_DAYS = 2; + public const LAST_THIRTY_DAYS = 3; public const PERCENTAGE_DIVIDER = 100; @@ -30,11 +32,9 @@ public function __construct( private SolarHomeSystemTransactionService $solarHomeSystemTransactionService, private ApplianceTransactionService $applianceTransactionService, private EBikeTransactionService $eBikeTransactionService, - ) { - } + ) {} - private function getTotalAmountOfConfirmedTransaction($transactionIds) - { + private function getTotalAmountOfConfirmedTransaction($transactionIds) { return $this->transaction->newQuery()->whereHasMorph( 'originalTransaction', '*', @@ -44,8 +44,7 @@ private function getTotalAmountOfConfirmedTransaction($transactionIds) ->sum('amount'); } - private function getTransactionCountByStatus($transactionIds, bool $status): int - { + private function getTransactionCountByStatus($transactionIds, bool $status): int { $status = $status === true ? 1 : 0; return $this->transaction->newQuery()->whereHasMorph( @@ -57,8 +56,7 @@ private function getTransactionCountByStatus($transactionIds, bool $status): int ->count(); } - private function getPercentage(int $base, int $wanted, bool $baseShouldGreater = true): float - { + private function getPercentage(int $base, int $wanted, bool $baseShouldGreater = true): float { if ($base === 0 || $wanted === 0) { return 0; } @@ -72,8 +70,7 @@ private function getPercentage(int $base, int $wanted, bool $baseShouldGreater = return round($percentage - 100, 2); } - public function getRelatedService(string $type): ApplianceTransactionService|MeterTransactionService|SolarHomeSystemTransactionService|EBikeTransactionService - { + public function getRelatedService(string $type): ApplianceTransactionService|MeterTransactionService|SolarHomeSystemTransactionService|EBikeTransactionService { switch ($type) { case SolarHomeSystem::RELATION_NAME: return $this->solarHomeSystemTransactionService; @@ -86,8 +83,7 @@ public function getRelatedService(string $type): ApplianceTransactionService|Met } } - public function determinePeriod($period): ?array - { + public function determinePeriod($period): ?array { $comparisonPeriod = null; switch ($period) { case self::YESTERDAY: @@ -149,8 +145,7 @@ public function determinePeriod($period): ?array return $comparisonPeriod; } - public function getByComparisonPeriod(array $comparisonPeriod): array - { + public function getByComparisonPeriod(array $comparisonPeriod): array { $currentTransactions = $this->transaction->newQuery()->whereBetween( 'created_at', [ @@ -174,8 +169,7 @@ public function getByComparisonPeriod(array $comparisonPeriod): array ]; } - public function getAnalysis($transactionIds): ?array - { + public function getAnalysis($transactionIds): ?array { if (count($transactionIds) === 0) { return null; } @@ -202,8 +196,7 @@ public function getAnalysis($transactionIds): ?array ]; } - public function getEmptyCompareResult(): array - { + public function getEmptyCompareResult(): array { return [ 'total' => 0, 'amount' => 0, @@ -214,8 +207,7 @@ public function getEmptyCompareResult(): array ]; } - public function comparePeriods(array $currentTransactions, array $pastTransactions): array - { + public function comparePeriods(array $currentTransactions, array $pastTransactions): array { $totalPercentage = $this->getPercentage($pastTransactions['total'], $currentTransactions['total'], false); $confirmationPercentage = round( $currentTransactions['confirmedPercentage'] - $pastTransactions['confirmedPercentage'], @@ -247,18 +239,15 @@ public function comparePeriods(array $currentTransactions, array $pastTransactio ]; } - public function make(array $transactionData): Transaction - { + public function make(array $transactionData): Transaction { return $this->transaction->newQuery()->make($transactionData); } - public function save($transaction): bool - { + public function save($transaction): bool { return $transaction->save(); } - public function getById(int $id): Transaction - { + public function getById(int $id): Transaction { return $this->transaction->newQuery()->with([ 'token', 'originalTransaction', @@ -268,8 +257,7 @@ public function getById(int $id): Transaction 'device' => fn ($q) => $q->whereHas('person')->with(['device', 'person'])])->find($id); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->transaction->newQuery()->with(['originalTransaction'])->latest()->paginate($limit); } @@ -277,18 +265,15 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->transaction->newQuery()->latest()->get(); } - public function create(array $data): Transaction - { + public function create(array $data): Transaction { throw new \Exception('Method create() not yet implemented.'); } - public function update($model, array $data): Transaction - { + public function update($model, array $data): Transaction { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } } diff --git a/src/backend/app/modules/User/Events/UserCreatedEvent.php b/src/backend/app/modules/User/Events/UserCreatedEvent.php index 0e9a16609..28939de07 100644 --- a/src/backend/app/modules/User/Events/UserCreatedEvent.php +++ b/src/backend/app/modules/User/Events/UserCreatedEvent.php @@ -6,9 +6,6 @@ use App\Models\User; -class UserCreatedEvent -{ - public function __construct(public User $user, public bool $shouldSyncUser) - { - } +class UserCreatedEvent { + public function __construct(public User $user, public bool $shouldSyncUser) {} } diff --git a/src/backend/app/modules/User/UserEventSubscriber.php b/src/backend/app/modules/User/UserEventSubscriber.php index 6dcc4b39e..37e73d4e9 100644 --- a/src/backend/app/modules/User/UserEventSubscriber.php +++ b/src/backend/app/modules/User/UserEventSubscriber.php @@ -7,10 +7,8 @@ use Illuminate\Events\Dispatcher; use MPM\User\Events\UserCreatedEvent; -class UserEventSubscriber -{ - public function subscribe(Dispatcher $events) - { +class UserEventSubscriber { + public function subscribe(Dispatcher $events) { $events->listen([UserCreatedEvent::class], UserListener::class); } } diff --git a/src/backend/app/modules/User/UserListener.php b/src/backend/app/modules/User/UserListener.php index 66ff8a0a2..73fe1e534 100644 --- a/src/backend/app/modules/User/UserListener.php +++ b/src/backend/app/modules/User/UserListener.php @@ -11,26 +11,22 @@ use Inensus\Ticket\Services\TicketUserService; use MPM\User\Events\UserCreatedEvent; -class UserListener -{ +class UserListener { public function __construct( private DatabaseProxyService $databaseProxyService, private CompanyDatabaseService $companyDatabaseService, private TicketUserService $ticketUserService, private CompanyService $companyService, private MailHelperInterface $mailHelper, - ) { - } + ) {} - public function handle($event): void - { + public function handle($event): void { if ($event instanceof UserCreatedEvent) { $this->handleUserCreatedEvent($event); } } - public function handleUserCreatedEvent(UserCreatedEvent $event): void - { + public function handleUserCreatedEvent(UserCreatedEvent $event): void { if ($event->shouldSyncUser) { $companyDatabase = $this->companyDatabaseService->findByCompanyId($event->user->getCompanyId()); diff --git a/src/backend/composer.json b/src/backend/composer.json index 57f1d2799..d6af505e7 100644 --- a/src/backend/composer.json +++ b/src/backend/composer.json @@ -104,5 +104,6 @@ "php-cs-fixer-check": "php-cs-fixer check --diff", "php-cs-fixer-version": "php-cs-fixer --version", "phpstan-analyse": "phpstan analyse --memory-limit=2G --no-progress" + } } diff --git a/src/backend/composer.lock b/src/backend/composer.lock index 685cfc326..808059911 100644 --- a/src/backend/composer.lock +++ b/src/backend/composer.lock @@ -14827,14 +14827,14 @@ "aliases": [], "minimum-stability": "dev", "stability-flags": { - "roave/security-advisories": 20, - "tymon/jwt-auth": 20 + "tymon/jwt-auth": 20, + "roave/security-advisories": 20 }, "prefer-stable": true, "prefer-lowest": false, "platform": { "php": "^8.0" }, - "platform-dev": {}, + "platform-dev": [], "plugin-api-version": "2.6.0" } diff --git a/src/backend/database/factories/AccessRate/AccessRateFactory.php b/src/backend/database/factories/AccessRate/AccessRateFactory.php index 247fe91d1..a82403d3a 100644 --- a/src/backend/database/factories/AccessRate/AccessRateFactory.php +++ b/src/backend/database/factories/AccessRate/AccessRateFactory.php @@ -5,12 +5,10 @@ use App\Models\AccessRate\AccessRate; use Illuminate\Database\Eloquent\Factories\Factory; -class AccessRateFactory extends Factory -{ +class AccessRateFactory extends Factory { protected $model = AccessRate::class; - public function definition(): array - { + public function definition(): array { return [ 'amount' => $this->faker->randomElement([7500, 15000]), 'period' => $this->faker->randomElement([7, 30]), diff --git a/src/backend/database/factories/AccessRatePaymentFactory.php b/src/backend/database/factories/AccessRatePaymentFactory.php index c9ca48ed9..474280d3a 100644 --- a/src/backend/database/factories/AccessRatePaymentFactory.php +++ b/src/backend/database/factories/AccessRatePaymentFactory.php @@ -6,8 +6,7 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\Factory; -class AccessRatePaymentFactory extends Factory -{ +class AccessRatePaymentFactory extends Factory { protected $model = AccessRatePayment::class; /** @@ -15,8 +14,7 @@ class AccessRatePaymentFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'debt' => 0, 'due_date' => Carbon::now()->addDays(7), diff --git a/src/backend/database/factories/Address/AddressFactory.php b/src/backend/database/factories/Address/AddressFactory.php index 80da555a6..a576201b0 100644 --- a/src/backend/database/factories/Address/AddressFactory.php +++ b/src/backend/database/factories/Address/AddressFactory.php @@ -5,8 +5,7 @@ use App\Models\Address\Address; use Illuminate\Database\Eloquent\Factories\Factory; -class AddressFactory extends Factory -{ +class AddressFactory extends Factory { protected $model = Address::class; /** @@ -14,8 +13,7 @@ class AddressFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'email' => $this->faker->unique()->safeEmail, 'phone' => $this->faker->unique()->e164PhoneNumber(), diff --git a/src/backend/database/factories/AgentAssignedApplianceFactory.php b/src/backend/database/factories/AgentAssignedApplianceFactory.php index a310a2200..e5528c9b5 100644 --- a/src/backend/database/factories/AgentAssignedApplianceFactory.php +++ b/src/backend/database/factories/AgentAssignedApplianceFactory.php @@ -5,8 +5,7 @@ use App\Models\AgentAssignedAppliances; use Illuminate\Database\Eloquent\Factories\Factory; -class AgentAssignedApplianceFactory extends Factory -{ +class AgentAssignedApplianceFactory extends Factory { protected $model = AgentAssignedAppliances::class; /** @@ -14,8 +13,7 @@ class AgentAssignedApplianceFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'agent_id' => $this->faker->numberBetween(1, 10), 'appliance_type_id' => $this->faker->numberBetween(1, 10), diff --git a/src/backend/database/factories/AgentBalanceHistoryFactory.php b/src/backend/database/factories/AgentBalanceHistoryFactory.php index cb30af397..8ec9a01e7 100644 --- a/src/backend/database/factories/AgentBalanceHistoryFactory.php +++ b/src/backend/database/factories/AgentBalanceHistoryFactory.php @@ -5,8 +5,7 @@ use App\Models\AgentBalanceHistory; use Illuminate\Database\Eloquent\Factories\Factory; -class AgentBalanceHistoryFactory extends Factory -{ +class AgentBalanceHistoryFactory extends Factory { protected $model = AgentBalanceHistory::class; /** @@ -14,8 +13,7 @@ class AgentBalanceHistoryFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'agent_id' => $this->faker->numberBetween(1, 10), 'amount' => $this->faker->randomFloat(2, 1, 100), diff --git a/src/backend/database/factories/AgentChargeFactory.php b/src/backend/database/factories/AgentChargeFactory.php index 3476cc0d4..62f2d8433 100644 --- a/src/backend/database/factories/AgentChargeFactory.php +++ b/src/backend/database/factories/AgentChargeFactory.php @@ -5,8 +5,7 @@ use App\Models\AgentCharge; use Illuminate\Database\Eloquent\Factories\Factory; -class AgentChargeFactory extends Factory -{ +class AgentChargeFactory extends Factory { protected $model = AgentCharge::class; /** @@ -14,8 +13,7 @@ class AgentChargeFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'user_id' => 1, 'amount' => $this->faker->randomDigitNotNull() * 100000, diff --git a/src/backend/database/factories/AgentCommissionFactory.php b/src/backend/database/factories/AgentCommissionFactory.php index 66edf430e..6a8bd80cd 100644 --- a/src/backend/database/factories/AgentCommissionFactory.php +++ b/src/backend/database/factories/AgentCommissionFactory.php @@ -5,8 +5,7 @@ use App\Models\AgentCommission; use Illuminate\Database\Eloquent\Factories\Factory; -class AgentCommissionFactory extends Factory -{ +class AgentCommissionFactory extends Factory { protected $model = AgentCommission::class; /** @@ -14,8 +13,7 @@ class AgentCommissionFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'name' => 'Sample Commission', 'energy_commission' => 0.05, diff --git a/src/backend/database/factories/AgentFactory.php b/src/backend/database/factories/AgentFactory.php index 2f3a0270c..d40056224 100644 --- a/src/backend/database/factories/AgentFactory.php +++ b/src/backend/database/factories/AgentFactory.php @@ -5,8 +5,7 @@ use App\Models\Agent; use Illuminate\Database\Eloquent\Factories\Factory; -class AgentFactory extends Factory -{ +class AgentFactory extends Factory { protected $model = Agent::class; /** @@ -14,8 +13,7 @@ class AgentFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'password' => '123456', 'email' => $this->faker->unique()->safeEmail, diff --git a/src/backend/database/factories/AgentReceiptFactory.php b/src/backend/database/factories/AgentReceiptFactory.php index 1c47ab510..1489f7062 100644 --- a/src/backend/database/factories/AgentReceiptFactory.php +++ b/src/backend/database/factories/AgentReceiptFactory.php @@ -5,8 +5,7 @@ use App\Models\AgentReceipt; use Illuminate\Database\Eloquent\Factories\Factory; -class AgentReceiptFactory extends Factory -{ +class AgentReceiptFactory extends Factory { protected $model = AgentReceipt::class; /** @@ -14,8 +13,7 @@ class AgentReceiptFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'user_id' => $this->faker->numberBetween(1, 10), 'agent_id' => $this->faker->numberBetween(1, 10), diff --git a/src/backend/database/factories/AgentSoldApplianceFactory.php b/src/backend/database/factories/AgentSoldApplianceFactory.php index 158533b2c..e6763271e 100644 --- a/src/backend/database/factories/AgentSoldApplianceFactory.php +++ b/src/backend/database/factories/AgentSoldApplianceFactory.php @@ -4,15 +4,13 @@ use Illuminate\Database\Eloquent\Factories\Factory; -class AgentSoldApplianceFactory extends Factory -{ +class AgentSoldApplianceFactory extends Factory { /** * Define the model's default state. * * @return array */ - public function definition() - { + public function definition() { return [ 'person_id' => $this->faker->randomNumber(), 'agent_assigned_appliance_id' => $this->faker->randomNumber(), diff --git a/src/backend/database/factories/AgentTransactionFactory.php b/src/backend/database/factories/AgentTransactionFactory.php index 6026abef6..f1c398856 100644 --- a/src/backend/database/factories/AgentTransactionFactory.php +++ b/src/backend/database/factories/AgentTransactionFactory.php @@ -5,8 +5,7 @@ use App\Models\Transaction\AgentTransaction; use Illuminate\Database\Eloquent\Factories\Factory; -class AgentTransactionFactory extends Factory -{ +class AgentTransactionFactory extends Factory { protected $model = AgentTransaction::class; /** @@ -14,8 +13,7 @@ class AgentTransactionFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'agent_id' => 1, 'device_id' => '123456789', diff --git a/src/backend/database/factories/AppliancePersonFactory.php b/src/backend/database/factories/AppliancePersonFactory.php index 40a196010..9bf1ff3d8 100644 --- a/src/backend/database/factories/AppliancePersonFactory.php +++ b/src/backend/database/factories/AppliancePersonFactory.php @@ -5,8 +5,7 @@ use App\Models\AssetPerson; use Illuminate\Database\Eloquent\Factories\Factory; -class AppliancePersonFactory extends Factory -{ +class AppliancePersonFactory extends Factory { protected $model = AssetPerson::class; /** @@ -14,8 +13,7 @@ class AppliancePersonFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'person_id' => $this->faker->numberBetween(1, 10), 'first_payment_date' => $this->faker->date(), diff --git a/src/backend/database/factories/AssetFactory.php b/src/backend/database/factories/AssetFactory.php index 870a088d8..9032d1945 100644 --- a/src/backend/database/factories/AssetFactory.php +++ b/src/backend/database/factories/AssetFactory.php @@ -5,8 +5,7 @@ use App\Models\Asset; use Illuminate\Database\Eloquent\Factories\Factory; -class AssetFactory extends Factory -{ +class AssetFactory extends Factory { protected $model = Asset::class; /** @@ -14,8 +13,7 @@ class AssetFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'name' => $this->faker->word, 'price' => $this->faker->randomDigitNotNull() * 100000, diff --git a/src/backend/database/factories/AssetTypeFactory.php b/src/backend/database/factories/AssetTypeFactory.php index b90b97225..915c376f0 100644 --- a/src/backend/database/factories/AssetTypeFactory.php +++ b/src/backend/database/factories/AssetTypeFactory.php @@ -5,8 +5,7 @@ use App\Models\AssetType; use Illuminate\Database\Eloquent\Factories\Factory; -class AssetTypeFactory extends Factory -{ +class AssetTypeFactory extends Factory { protected $model = AssetType::class; /** @@ -14,8 +13,7 @@ class AssetTypeFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'name' => $this->faker->word, ]; diff --git a/src/backend/database/factories/CityFactory.php b/src/backend/database/factories/CityFactory.php index 55b211486..54d0a3f8c 100644 --- a/src/backend/database/factories/CityFactory.php +++ b/src/backend/database/factories/CityFactory.php @@ -6,8 +6,7 @@ use Faker\Provider\en_NG\Address; use Illuminate\Database\Eloquent\Factories\Factory; -class CityFactory extends Factory -{ +class CityFactory extends Factory { protected $model = City::class; public function __construct( @@ -21,8 +20,7 @@ public function __construct( * * @return array */ - public function definition() - { + public function definition() { return [ 'name' => $this->faker->city, 'country_id' => 1, diff --git a/src/backend/database/factories/ClusterFactory.php b/src/backend/database/factories/ClusterFactory.php index 66f86e5a7..918ac05ea 100644 --- a/src/backend/database/factories/ClusterFactory.php +++ b/src/backend/database/factories/ClusterFactory.php @@ -6,8 +6,7 @@ use Faker\Provider\en_NG\Address; use Illuminate\Database\Eloquent\Factories\Factory; -class ClusterFactory extends Factory -{ +class ClusterFactory extends Factory { protected $model = Cluster::class; public function __construct( @@ -21,8 +20,7 @@ public function __construct( * * @return array */ - public function definition() - { + public function definition() { return [ 'name' => 'Cluster '.$this->faker->county, 'geo_data' => '{"leaflet_id":416,"type":"manual","geojson":{"type":"Polygon","coordinates":[[[-1.0021831137920607,34.09735878800838],[-1.0037278294879668,34.08104951280351],[-0.9961758791705448,34.08001945331692],[-0.9831315606570004,34.079332746992485],[-0.9745497443261169,34.08036280647911],[-0.9889671831741885,34.09890387723834]]]},"display_name":"My Cluster","selected":true,"draw_type":"draw","lat":-0.991455885101313,"lon":34.08617119747313}', diff --git a/src/backend/database/factories/CompanyDatabaseFactory.php b/src/backend/database/factories/CompanyDatabaseFactory.php index 28080bec2..c15fe1635 100644 --- a/src/backend/database/factories/CompanyDatabaseFactory.php +++ b/src/backend/database/factories/CompanyDatabaseFactory.php @@ -5,8 +5,7 @@ use App\Models\CompanyDatabase; use Illuminate\Database\Eloquent\Factories\Factory; -class CompanyDatabaseFactory extends Factory -{ +class CompanyDatabaseFactory extends Factory { protected $model = CompanyDatabase::class; /** @@ -14,8 +13,7 @@ class CompanyDatabaseFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'company_id' => 1, 'database_name' => 'test_company_db', diff --git a/src/backend/database/factories/CompanyFactory.php b/src/backend/database/factories/CompanyFactory.php index a3ec5ad2a..0e1ae5097 100644 --- a/src/backend/database/factories/CompanyFactory.php +++ b/src/backend/database/factories/CompanyFactory.php @@ -6,8 +6,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Model; -class CompanyFactory extends Factory -{ +class CompanyFactory extends Factory { protected $model = Company::class; /** @@ -15,8 +14,7 @@ class CompanyFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'name' => $this->faker->company, 'phone' => $this->faker->phoneNumber, @@ -26,8 +24,7 @@ public function definition() ]; } - public function createWithEmail(string $email): Model - { + public function createWithEmail(string $email): Model { $base = $this->definition(); $base['email'] = $email; diff --git a/src/backend/database/factories/ConnectionGroupFactory.php b/src/backend/database/factories/ConnectionGroupFactory.php index 776fd918f..aa8661d12 100644 --- a/src/backend/database/factories/ConnectionGroupFactory.php +++ b/src/backend/database/factories/ConnectionGroupFactory.php @@ -5,12 +5,10 @@ use App\Models\ConnectionGroup; use Illuminate\Database\Eloquent\Factories\Factory; -class ConnectionGroupFactory extends Factory -{ +class ConnectionGroupFactory extends Factory { protected $model = ConnectionGroup::class; - public function definition(): array - { + public function definition(): array { return [ 'name' => $this->faker->name, ]; diff --git a/src/backend/database/factories/ConnectionTypeFactory.php b/src/backend/database/factories/ConnectionTypeFactory.php index d6238f0ea..97bbe266f 100644 --- a/src/backend/database/factories/ConnectionTypeFactory.php +++ b/src/backend/database/factories/ConnectionTypeFactory.php @@ -5,12 +5,10 @@ use App\Models\ConnectionType; use Illuminate\Database\Eloquent\Factories\Factory; -class ConnectionTypeFactory extends Factory -{ +class ConnectionTypeFactory extends Factory { protected $model = ConnectionType::class; - public function definition(): array - { + public function definition(): array { return [ 'name' => $this->faker->name, ]; diff --git a/src/backend/database/factories/DeviceFactory.php b/src/backend/database/factories/DeviceFactory.php index a64a2dd32..b563631ce 100644 --- a/src/backend/database/factories/DeviceFactory.php +++ b/src/backend/database/factories/DeviceFactory.php @@ -4,15 +4,13 @@ use Illuminate\Database\Eloquent\Factories\Factory; -class DeviceFactory extends Factory -{ +class DeviceFactory extends Factory { /** * Define the model's default state. * * @return array */ - public function definition() - { + public function definition() { return [ 'device_serial' => $this->faker->unique()->uuid, ]; diff --git a/src/backend/database/factories/GeographicalInformationFactory.php b/src/backend/database/factories/GeographicalInformationFactory.php index c0a4da762..e8fc300a0 100644 --- a/src/backend/database/factories/GeographicalInformationFactory.php +++ b/src/backend/database/factories/GeographicalInformationFactory.php @@ -5,13 +5,11 @@ use App\Models\GeographicalInformation; use Illuminate\Database\Eloquent\Factories\Factory; -class GeographicalInformationFactory extends Factory -{ +class GeographicalInformationFactory extends Factory { protected $model = GeographicalInformation::class; - private function add_random_offset_to_coordinates(string $coord_string, int $distance): string - { - list($lat, $lng) = explode(',', $coord_string); + private function add_random_offset_to_coordinates(string $coord_string, int $distance): string { + [$lat, $lng] = explode(',', $coord_string); $lat = (float) $lat; $lng = (float) $lng; @@ -28,8 +26,7 @@ private function add_random_offset_to_coordinates(string $coord_string, int $dis * * @return Factory */ - public function randomizePointsInVillage() - { + public function randomizePointsInVillage() { return $this->state(function (array $attributes) { return [ 'points' => $this->add_random_offset_to_coordinates($attributes['points'], 1000), @@ -42,8 +39,7 @@ public function randomizePointsInVillage() * * @return Factory */ - public function randomizePointsInHousehold() - { + public function randomizePointsInHousehold() { return $this->state(function (array $attributes) { return [ 'points' => $this->add_random_offset_to_coordinates($attributes['points'], 10), @@ -51,8 +47,7 @@ public function randomizePointsInHousehold() }); } - public function definition() - { + public function definition() { return [ 'points' => '0.000000,0.000000', ]; diff --git a/src/backend/database/factories/MainSettingsFactory.php b/src/backend/database/factories/MainSettingsFactory.php index 741c2c9c9..fb6acd078 100644 --- a/src/backend/database/factories/MainSettingsFactory.php +++ b/src/backend/database/factories/MainSettingsFactory.php @@ -6,12 +6,10 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\Factory; -class MainSettingsFactory extends Factory -{ +class MainSettingsFactory extends Factory { protected $model = MainSettingsAlias::class; - public function definition(): array - { + public function definition(): array { return [ 'site_title' => 'MPM - The easiest way to manage your Mini-Grid', 'company_name' => 'MicroPowerManager', diff --git a/src/backend/database/factories/ManufacturerFactory.php b/src/backend/database/factories/ManufacturerFactory.php index 36c654a43..dd87c423d 100644 --- a/src/backend/database/factories/ManufacturerFactory.php +++ b/src/backend/database/factories/ManufacturerFactory.php @@ -6,8 +6,7 @@ use Doctrine\Inflector\InflectorFactory; use Illuminate\Database\Eloquent\Factories\Factory; -class ManufacturerFactory extends Factory -{ +class ManufacturerFactory extends Factory { protected $model = Manufacturer::class; /** @@ -15,8 +14,7 @@ class ManufacturerFactory extends Factory * * @return Factory */ - public function isMeterManufacturer() - { + public function isMeterManufacturer() { return $this->state(function (array $attributes) { return [ 'type' => 'meter', @@ -29,8 +27,7 @@ public function isMeterManufacturer() * * @return Factory */ - public function isShsManufacturer() - { + public function isShsManufacturer() { return $this->state(function (array $attributes) { return [ 'type' => 'shs', @@ -38,8 +35,7 @@ public function isShsManufacturer() }); } - public function definition(): array - { + public function definition(): array { $inflector = InflectorFactory::create()->build(); $companyName = $this->faker->company; diff --git a/src/backend/database/factories/Meter/MeterFactory.php b/src/backend/database/factories/Meter/MeterFactory.php index 5c7417dfc..4c851ddea 100644 --- a/src/backend/database/factories/Meter/MeterFactory.php +++ b/src/backend/database/factories/Meter/MeterFactory.php @@ -5,12 +5,10 @@ use App\Models\Meter\Meter; use Illuminate\Database\Eloquent\Factories\Factory; -class MeterFactory extends Factory -{ +class MeterFactory extends Factory { protected $model = Meter::class; - public function definition() - { + public function definition() { return [ 'meter_type_id' => $this->faker->randomNumber(1), 'in_use' => false, diff --git a/src/backend/database/factories/Meter/MeterTariffFactory.php b/src/backend/database/factories/Meter/MeterTariffFactory.php index 70d7f4c07..23d0405bf 100644 --- a/src/backend/database/factories/Meter/MeterTariffFactory.php +++ b/src/backend/database/factories/Meter/MeterTariffFactory.php @@ -5,12 +5,10 @@ use App\Models\Meter\MeterTariff; use Illuminate\Database\Eloquent\Factories\Factory; -class MeterTariffFactory extends Factory -{ +class MeterTariffFactory extends Factory { protected $model = MeterTariff::class; - public function definition() - { + public function definition() { return [ 'name' => $this->faker->randomElement(['Productive Usage', 'Household Usage', 'Commercial Usage']), 'price' => 100000, diff --git a/src/backend/database/factories/Meter/MeterTypeFactory.php b/src/backend/database/factories/Meter/MeterTypeFactory.php index c1851a912..d54e9004a 100644 --- a/src/backend/database/factories/Meter/MeterTypeFactory.php +++ b/src/backend/database/factories/Meter/MeterTypeFactory.php @@ -5,8 +5,7 @@ use App\Models\Meter\MeterType; use Illuminate\Database\Eloquent\Factories\Factory; -class MeterTypeFactory extends Factory -{ +class MeterTypeFactory extends Factory { protected $model = MeterType::class; /** @@ -14,8 +13,7 @@ class MeterTypeFactory extends Factory * * @return Factory */ - public function isOnline() - { + public function isOnline() { return $this->state(function (array $attributes) { return [ 'online' => 1, @@ -23,8 +21,7 @@ public function isOnline() }); } - public function definition(): array - { + public function definition(): array { return [ 'online' => 0, 'phase' => 1, diff --git a/src/backend/database/factories/MeterConsumptionFactory.php b/src/backend/database/factories/MeterConsumptionFactory.php index f7c716242..6c328bb49 100644 --- a/src/backend/database/factories/MeterConsumptionFactory.php +++ b/src/backend/database/factories/MeterConsumptionFactory.php @@ -6,8 +6,7 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\Factory; -class MeterConsumptionFactory extends Factory -{ +class MeterConsumptionFactory extends Factory { protected $model = MeterConsumption::class; /** @@ -15,8 +14,7 @@ class MeterConsumptionFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'meter_id' => 1, 'total_consumption' => $this->faker->randomFloat(2, 0, 100), diff --git a/src/backend/database/factories/MeterParameterFactory.php b/src/backend/database/factories/MeterParameterFactory.php index 6544ff487..b964fb54c 100644 --- a/src/backend/database/factories/MeterParameterFactory.php +++ b/src/backend/database/factories/MeterParameterFactory.php @@ -5,8 +5,7 @@ use App\Models\Meter\MeterParameter; use Illuminate\Database\Eloquent\Factories\Factory; -class MeterParameterFactory extends Factory -{ +class MeterParameterFactory extends Factory { protected $model = MeterParameter::class; /** @@ -14,8 +13,7 @@ class MeterParameterFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'owner_type' => 'person', 'owner_id' => $this->faker->randomNumber(1), diff --git a/src/backend/database/factories/MeterTokenFactory.php b/src/backend/database/factories/MeterTokenFactory.php index c194249bb..0cac9dc71 100644 --- a/src/backend/database/factories/MeterTokenFactory.php +++ b/src/backend/database/factories/MeterTokenFactory.php @@ -5,8 +5,7 @@ use App\Models\Meter\MeterToken; use Illuminate\Database\Eloquent\Factories\Factory; -class MeterTokenFactory extends Factory -{ +class MeterTokenFactory extends Factory { protected $model = MeterToken::class; /** @@ -14,8 +13,7 @@ class MeterTokenFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'transaction_id' => 1, 'meter_id' => 1, diff --git a/src/backend/database/factories/MiniGridFactory.php b/src/backend/database/factories/MiniGridFactory.php index f68a51992..ad566469f 100644 --- a/src/backend/database/factories/MiniGridFactory.php +++ b/src/backend/database/factories/MiniGridFactory.php @@ -6,8 +6,7 @@ use Faker\Provider\en_NG\Address; use Illuminate\Database\Eloquent\Factories\Factory; -class MiniGridFactory extends Factory -{ +class MiniGridFactory extends Factory { protected $model = MiniGrid::class; public function __construct( @@ -21,8 +20,7 @@ public function __construct( * * @return array */ - public function definition() - { + public function definition() { return [ 'name' => 'MiniGrid '.$this->faker->region, ]; diff --git a/src/backend/database/factories/PaymentHistoryFactory.php b/src/backend/database/factories/PaymentHistoryFactory.php index f1ac99f3d..8445344c0 100644 --- a/src/backend/database/factories/PaymentHistoryFactory.php +++ b/src/backend/database/factories/PaymentHistoryFactory.php @@ -5,8 +5,7 @@ use App\Models\PaymentHistory; use Illuminate\Database\Eloquent\Factories\Factory; -class PaymentHistoryFactory extends Factory -{ +class PaymentHistoryFactory extends Factory { protected $model = PaymentHistory::class; /** @@ -14,8 +13,7 @@ class PaymentHistoryFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'id' => 1, 'transaction_id' => 1, diff --git a/src/backend/database/factories/Person/PersonFactory.php b/src/backend/database/factories/Person/PersonFactory.php index 6d0c92dd6..0b123b291 100644 --- a/src/backend/database/factories/Person/PersonFactory.php +++ b/src/backend/database/factories/Person/PersonFactory.php @@ -5,8 +5,7 @@ use App\Models\Person\Person; use Illuminate\Database\Eloquent\Factories\Factory; -class PersonFactory extends Factory -{ +class PersonFactory extends Factory { protected $model = Person::class; /** @@ -14,8 +13,7 @@ class PersonFactory extends Factory * * @return Factory */ - public function isCustomer() - { + public function isCustomer() { return $this->state(function (array $attributes) { return [ 'is_customer' => true, @@ -28,8 +26,7 @@ public function isCustomer() * * @return Factory */ - public function isAgent($village_name = 'Demo') - { + public function isAgent($village_name = 'Demo') { return $this->state(function (array $attributes) use ($village_name) { return [ 'is_customer' => false, @@ -41,11 +38,8 @@ public function isAgent($village_name = 'Demo') /** * Define the model's default state. - * - * @return array */ - public function definition(): array - { + public function definition(): array { $sex = fake()->randomKey(['male', 'female']); $gender = $sex === 0 ? 'male' diff --git a/src/backend/database/factories/SmsResendInformationKeyFactory.php b/src/backend/database/factories/SmsResendInformationKeyFactory.php index 64cd743d5..fa7cf3429 100644 --- a/src/backend/database/factories/SmsResendInformationKeyFactory.php +++ b/src/backend/database/factories/SmsResendInformationKeyFactory.php @@ -5,12 +5,10 @@ use App\Models\SmsResendInformationKey; use Illuminate\Database\Eloquent\Factories\Factory; -class SmsResendInformationKeyFactory extends Factory -{ +class SmsResendInformationKeyFactory extends Factory { protected $model = SmsResendInformationKey::class; - public function definition() - { + public function definition() { return [ 'key' => 'Resend', ]; diff --git a/src/backend/database/factories/SolarHomeSystemFactory.php b/src/backend/database/factories/SolarHomeSystemFactory.php index 416670063..8b371c988 100644 --- a/src/backend/database/factories/SolarHomeSystemFactory.php +++ b/src/backend/database/factories/SolarHomeSystemFactory.php @@ -5,12 +5,10 @@ use App\Models\SolarHomeSystem; use Illuminate\Database\Eloquent\Factories\Factory; -class SolarHomeSystemFactory extends Factory -{ +class SolarHomeSystemFactory extends Factory { protected $model = SolarHomeSystem::class; - public function definition(): array - { + public function definition(): array { return [ // 'asset_id' => 1, 'serial_number' => $this->faker->unique()->uuid, diff --git a/src/backend/database/factories/SubConnectionTypeFactory.php b/src/backend/database/factories/SubConnectionTypeFactory.php index d418cb3f1..8a500ccbc 100644 --- a/src/backend/database/factories/SubConnectionTypeFactory.php +++ b/src/backend/database/factories/SubConnectionTypeFactory.php @@ -5,8 +5,7 @@ use App\Models\SubConnectionType; use Illuminate\Database\Eloquent\Factories\Factory; -class SubConnectionTypeFactory extends Factory -{ +class SubConnectionTypeFactory extends Factory { protected $model = SubConnectionType::class; /** @@ -14,8 +13,7 @@ class SubConnectionTypeFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'name' => $this->faker->word, 'connection_type_id' => $this->faker->numberBetween(1, 10), diff --git a/src/backend/database/factories/SubTargetFactory.php b/src/backend/database/factories/SubTargetFactory.php index d5e6da8ab..986ed981b 100644 --- a/src/backend/database/factories/SubTargetFactory.php +++ b/src/backend/database/factories/SubTargetFactory.php @@ -5,8 +5,7 @@ use App\Models\SubTarget; use Illuminate\Database\Eloquent\Factories\Factory; -class SubTargetFactory extends Factory -{ +class SubTargetFactory extends Factory { protected $model = SubTarget::class; /** @@ -14,8 +13,7 @@ class SubTargetFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'target_id' => $this->faker->randomNumber(1, 10), 'connection_id' => $this->faker->randomNumber(1, 10), diff --git a/src/backend/database/factories/TargetFactory.php b/src/backend/database/factories/TargetFactory.php index e87d61dc8..023ca2553 100644 --- a/src/backend/database/factories/TargetFactory.php +++ b/src/backend/database/factories/TargetFactory.php @@ -5,8 +5,7 @@ use App\Models\Target; use Illuminate\Database\Eloquent\Factories\Factory; -class TargetFactory extends Factory -{ +class TargetFactory extends Factory { protected $model = Target::class; /** @@ -14,8 +13,7 @@ class TargetFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'target_date' => $this->faker->date('Y-m-d'), 'type' => $this->faker->randomElement(['mini-grid', 'cluster']), diff --git a/src/backend/database/factories/TicketBoardFactory.php b/src/backend/database/factories/TicketBoardFactory.php index d282a9cb8..0364b847a 100644 --- a/src/backend/database/factories/TicketBoardFactory.php +++ b/src/backend/database/factories/TicketBoardFactory.php @@ -5,8 +5,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Inensus\Ticket\Models\TicketBoard; -class TicketBoardFactory extends Factory -{ +class TicketBoardFactory extends Factory { protected $model = TicketBoard::class; /** @@ -14,8 +13,7 @@ class TicketBoardFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { // includes existing board id in trello for testing return [ 'board_id' => '6291424c4e11631cfad78a37', diff --git a/src/backend/database/factories/TicketCardFactory.php b/src/backend/database/factories/TicketCardFactory.php index aaefdd8b3..9b72820a8 100644 --- a/src/backend/database/factories/TicketCardFactory.php +++ b/src/backend/database/factories/TicketCardFactory.php @@ -5,8 +5,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Inensus\Ticket\Models\TicketCard; -class TicketCardFactory extends Factory -{ +class TicketCardFactory extends Factory { protected $model = TicketCard::class; /** @@ -14,8 +13,7 @@ class TicketCardFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { // includes existing list id in trello as card_id for testing return [ 'card_id' => '62914ca11509c55ab1c1ba56', diff --git a/src/backend/database/factories/TicketFactory.php b/src/backend/database/factories/TicketFactory.php index 9a4aed5ae..f46a37ea8 100644 --- a/src/backend/database/factories/TicketFactory.php +++ b/src/backend/database/factories/TicketFactory.php @@ -5,8 +5,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Inensus\Ticket\Models\Ticket; -class TicketFactory extends Factory -{ +class TicketFactory extends Factory { protected $model = Ticket::class; /** @@ -14,8 +13,7 @@ class TicketFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'ticket_id' => strval($this->faker->uuid), 'creator_id' => $this->faker->numberBetween(1, 10), diff --git a/src/backend/database/factories/TicketOutsourceFactory.php b/src/backend/database/factories/TicketOutsourceFactory.php index 9af5aec16..383a7210d 100644 --- a/src/backend/database/factories/TicketOutsourceFactory.php +++ b/src/backend/database/factories/TicketOutsourceFactory.php @@ -5,8 +5,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Inensus\Ticket\Models\TicketOutsource; -class TicketOutsourceFactory extends Factory -{ +class TicketOutsourceFactory extends Factory { protected $model = TicketOutsource::class; /** @@ -14,8 +13,7 @@ class TicketOutsourceFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'ticket_id' => $this->faker->numberBetween(1, 10), 'amount' => $this->faker->numberBetween(1, 10), diff --git a/src/backend/database/factories/TicketOutsourceReportFactory.php b/src/backend/database/factories/TicketOutsourceReportFactory.php index 62e05d3b2..2fcaacf0e 100644 --- a/src/backend/database/factories/TicketOutsourceReportFactory.php +++ b/src/backend/database/factories/TicketOutsourceReportFactory.php @@ -5,8 +5,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Inensus\Ticket\Models\TicketOutsourceReport; -class TicketOutsourceReportFactory extends Factory -{ +class TicketOutsourceReportFactory extends Factory { protected $model = TicketOutsourceReport::class; /** @@ -14,8 +13,7 @@ class TicketOutsourceReportFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'date' => $this->faker->date(), 'path' => $this->faker->url, diff --git a/src/backend/database/factories/TicketUserFactory.php b/src/backend/database/factories/TicketUserFactory.php index 1579ff051..f0f5baf06 100644 --- a/src/backend/database/factories/TicketUserFactory.php +++ b/src/backend/database/factories/TicketUserFactory.php @@ -5,8 +5,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Inensus\Ticket\Models\TicketUser; -class TicketUserFactory extends Factory -{ +class TicketUserFactory extends Factory { protected $model = TicketUser::class; /** @@ -14,8 +13,7 @@ class TicketUserFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'user_name' => $this->faker->name, 'user_tag' => $this->faker->word, diff --git a/src/backend/database/factories/TimeOfUsageFactory.php b/src/backend/database/factories/TimeOfUsageFactory.php index b951bb2fc..0393ba9f6 100644 --- a/src/backend/database/factories/TimeOfUsageFactory.php +++ b/src/backend/database/factories/TimeOfUsageFactory.php @@ -5,8 +5,7 @@ use App\Models\TimeOfUsage; use Illuminate\Database\Eloquent\Factories\Factory; -class TimeOfUsageFactory extends Factory -{ +class TimeOfUsageFactory extends Factory { protected $model = TimeOfUsage::class; /** @@ -14,8 +13,7 @@ class TimeOfUsageFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'tariff_id' => 1, 'start' => '00:00', diff --git a/src/backend/database/factories/TransactionFactory.php b/src/backend/database/factories/TransactionFactory.php index 27c3ad3b7..10bb700d9 100644 --- a/src/backend/database/factories/TransactionFactory.php +++ b/src/backend/database/factories/TransactionFactory.php @@ -5,12 +5,10 @@ use App\Models\Transaction\Transaction; use Illuminate\Database\Eloquent\Factories\Factory; -class TransactionFactory extends Factory -{ +class TransactionFactory extends Factory { protected $model = Transaction::class; - public function definition(): array - { + public function definition(): array { return [ 'id' => $this->faker->unique()->randomNumber(), 'amount' => $this->faker->unique()->randomNumber(), diff --git a/src/backend/database/factories/UserFactory.php b/src/backend/database/factories/UserFactory.php index bd8ddd498..73a063715 100644 --- a/src/backend/database/factories/UserFactory.php +++ b/src/backend/database/factories/UserFactory.php @@ -7,8 +7,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Facades\Hash; -class UserFactory extends Factory -{ +class UserFactory extends Factory { protected $model = User::class; /** @@ -16,8 +15,7 @@ class UserFactory extends Factory * * @return Factory */ - public function clusterAdmin() - { + public function clusterAdmin() { return $this->state(function (array $attributes) { return [ 'name' => 'Cluster Admin', @@ -25,8 +23,7 @@ public function clusterAdmin() }); } - public function definition() - { + public function definition() { return [ 'name' => $this->faker->name, 'company_id' => DummyCompany::DUMMY_COMPANY_ID, diff --git a/src/backend/database/factories/VodacomTransactionFactory.php b/src/backend/database/factories/VodacomTransactionFactory.php index 3f14640ba..2cb701498 100644 --- a/src/backend/database/factories/VodacomTransactionFactory.php +++ b/src/backend/database/factories/VodacomTransactionFactory.php @@ -5,8 +5,7 @@ use App\Models\Transaction\VodacomTransaction; use Illuminate\Database\Eloquent\Factories\Factory; -class VodacomTransactionFactory extends Factory -{ +class VodacomTransactionFactory extends Factory { /** * The name of the factory's corresponding model. * @@ -16,11 +15,8 @@ class VodacomTransactionFactory extends Factory /** * Define the model's default state. - * - * @return array */ - public function definition(): array - { + public function definition(): array { return [ 'conversation_id' => $this->faker->unique()->randomNumber(), 'originator_conversation_id' => $this->faker->unique(true)->randomNumber(), diff --git a/src/backend/database/migrations/2022_03_10_120408_create_companies_table.php b/src/backend/database/migrations/2022_03_10_120408_create_companies_table.php index 86d746c4e..e6f0ec929 100644 --- a/src/backend/database/migrations/2022_03_10_120408_create_companies_table.php +++ b/src/backend/database/migrations/2022_03_10_120408_create_companies_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::create('companies', function (Blueprint $table) { $table->id(); $table->string('name'); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::dropIfExists('companies'); } }; diff --git a/src/backend/database/migrations/2022_03_10_134450_create_company_databases_table.php b/src/backend/database/migrations/2022_03_10_134450_create_company_databases_table.php index d2b568602..038a2e2b4 100644 --- a/src/backend/database/migrations/2022_03_10_134450_create_company_databases_table.php +++ b/src/backend/database/migrations/2022_03_10_134450_create_company_databases_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::create('company_databases', function (Blueprint $table) { $table->id(); $table->integer('company_id')->unsigned(); @@ -25,8 +24,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::dropIfExists('company_databases'); } }; diff --git a/src/backend/database/migrations/2022_06_18_204649_create_database_proxies_table.php b/src/backend/database/migrations/2022_06_18_204649_create_database_proxies_table.php index 6f51e02b3..59bd8ac9c 100644 --- a/src/backend/database/migrations/2022_06_18_204649_create_database_proxies_table.php +++ b/src/backend/database/migrations/2022_06_18_204649_create_database_proxies_table.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up(): void - { + public function up(): void { Schema::create('database_proxies', function (Blueprint $table) { $table->id(); $table->string('email'); @@ -16,8 +15,7 @@ public function up(): void }); } - public function down(): void - { + public function down(): void { Schema::dropIfExists('database_proxies'); } }; diff --git a/src/backend/database/migrations/2022_06_21_102121_create_mpm_plugins_table.php b/src/backend/database/migrations/2022_06_21_102121_create_mpm_plugins_table.php index 252e717ed..d9907ad43 100644 --- a/src/backend/database/migrations/2022_06_21_102121_create_mpm_plugins_table.php +++ b/src/backend/database/migrations/2022_06_21_102121_create_mpm_plugins_table.php @@ -13,8 +13,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::create('mpm_plugins', function (Blueprint $table) { $table->id(); $table->string('name'); @@ -87,8 +86,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::dropIfExists('mpm_plugins'); } }; diff --git a/src/backend/database/migrations/2022_06_21_122032_add_email_to_companies_table.php b/src/backend/database/migrations/2022_06_21_122032_add_email_to_companies_table.php index 683ee1f16..21bbdd4d9 100644 --- a/src/backend/database/migrations/2022_06_21_122032_add_email_to_companies_table.php +++ b/src/backend/database/migrations/2022_06_21_122032_add_email_to_companies_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::table('companies', function (Blueprint $table) { $table->string('email'); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::table('companies', function (Blueprint $table) { $table->dropColumn('email'); }); diff --git a/src/backend/database/migrations/2022_07_05_093903_add_tail_tag_to_mpm_plugins_table.php b/src/backend/database/migrations/2022_07_05_093903_add_tail_tag_to_mpm_plugins_table.php index 2f2079520..6210cbd40 100644 --- a/src/backend/database/migrations/2022_07_05_093903_add_tail_tag_to_mpm_plugins_table.php +++ b/src/backend/database/migrations/2022_07_05_093903_add_tail_tag_to_mpm_plugins_table.php @@ -13,8 +13,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::table('mpm_plugins', function (Blueprint $table) { $table->string('tail_tag')->nullable(); }); @@ -43,8 +42,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::table('mpm_plugins', function (Blueprint $table) { $table->dropColumn('tail_tag'); }); diff --git a/src/backend/database/migrations/2022_07_07_140545_add_installation_command_to_mpm_plugins_table.php b/src/backend/database/migrations/2022_07_07_140545_add_installation_command_to_mpm_plugins_table.php index 693d3017d..fdd6753df 100644 --- a/src/backend/database/migrations/2022_07_07_140545_add_installation_command_to_mpm_plugins_table.php +++ b/src/backend/database/migrations/2022_07_07_140545_add_installation_command_to_mpm_plugins_table.php @@ -13,8 +13,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::table('mpm_plugins', function (Blueprint $table) { $table->string('installation_command')->nullable(); }); @@ -43,8 +42,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::table('mpm_plugins', function (Blueprint $table) { $table->dropColumn('installation_command'); }); diff --git a/src/backend/database/migrations/2022_09_20_0000000_add_bulk_registration_to_mpm_plugin_table.php b/src/backend/database/migrations/2022_09_20_0000000_add_bulk_registration_to_mpm_plugin_table.php index 98a51abd1..f843f64bd 100644 --- a/src/backend/database/migrations/2022_09_20_0000000_add_bulk_registration_to_mpm_plugin_table.php +++ b/src/backend/database/migrations/2022_09_20_0000000_add_bulk_registration_to_mpm_plugin_table.php @@ -6,8 +6,7 @@ use Illuminate\Support\Facades\DB; return new class extends Migration { - public function up() - { + public function up() { DB::table('mpm_plugins')->insert([ [ 'id' => MpmPlugin::BULK_REGISTRATION, @@ -21,10 +20,9 @@ public function up() ]); } - public function down() - { + public function down() { DB::table('mpm_plugins') - ->where('id', MpmPlugin::BULK_REGISTRATION) - ->delete(); + ->where('id', MpmPlugin::BULK_REGISTRATION) + ->delete(); } }; diff --git a/src/backend/database/migrations/2022_11_08_0000000_add_viber_messaging_to_mpm_plugin_table.php b/src/backend/database/migrations/2022_11_08_0000000_add_viber_messaging_to_mpm_plugin_table.php index d40b82c81..6fd6a8f5e 100644 --- a/src/backend/database/migrations/2022_11_08_0000000_add_viber_messaging_to_mpm_plugin_table.php +++ b/src/backend/database/migrations/2022_11_08_0000000_add_viber_messaging_to_mpm_plugin_table.php @@ -6,8 +6,7 @@ use Illuminate\Support\Facades\DB; return new class extends Migration { - public function up() - { + public function up() { DB::table('mpm_plugins')->insert([ [ 'id' => MpmPlugin::VIBER_MESSAGING, @@ -21,10 +20,9 @@ public function up() ]); } - public function down() - { + public function down() { DB::table('mpm_plugins') - ->where('id', MpmPlugin::VIBER_MESSAGING) - ->delete(); + ->where('id', MpmPlugin::VIBER_MESSAGING) + ->delete(); } }; diff --git a/src/backend/database/migrations/2022_11_08_154321_update_email_field_for_database_proxies_table.php b/src/backend/database/migrations/2022_11_08_154321_update_email_field_for_database_proxies_table.php index 8b5267dfa..717b0a66d 100644 --- a/src/backend/database/migrations/2022_11_08_154321_update_email_field_for_database_proxies_table.php +++ b/src/backend/database/migrations/2022_11_08_154321_update_email_field_for_database_proxies_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::table('database_proxies', function (Blueprint $table) { $table->string('email')->unique()->change(); }); @@ -22,9 +21,7 @@ public function up() * * @return void */ - public function down() - { - Schema::table('database_proxies', function (Blueprint $table) { - }); + public function down() { + Schema::table('database_proxies', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/2022_11_21_000000_add_wave_money_payment_to_mpm_plugin_table.php b/src/backend/database/migrations/2022_11_21_000000_add_wave_money_payment_to_mpm_plugin_table.php index bcff0e49f..2f9f4ce5b 100644 --- a/src/backend/database/migrations/2022_11_21_000000_add_wave_money_payment_to_mpm_plugin_table.php +++ b/src/backend/database/migrations/2022_11_21_000000_add_wave_money_payment_to_mpm_plugin_table.php @@ -6,8 +6,7 @@ use Illuminate\Support\Facades\DB; return new class extends Migration { - public function up() - { + public function up() { DB::table('mpm_plugins')->insert([ [ 'id' => MpmPlugin::WAVE_MONEY_PAYMENT_PROVIDER, @@ -21,10 +20,9 @@ public function up() ]); } - public function down() - { + public function down() { DB::table('mpm_plugins') - ->where('id', MpmPlugin::WAVE_MONEY_PAYMENT_PROVIDER) - ->delete(); + ->where('id', MpmPlugin::WAVE_MONEY_PAYMENT_PROVIDER) + ->delete(); } }; diff --git a/src/backend/database/migrations/2022_11_25_085948_create_jobs_table.php b/src/backend/database/migrations/2022_11_25_085948_create_jobs_table.php index 1be9e8a80..90d9ead73 100644 --- a/src/backend/database/migrations/2022_11_25_085948_create_jobs_table.php +++ b/src/backend/database/migrations/2022_11_25_085948_create_jobs_table.php @@ -4,15 +4,13 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreateJobsTable extends Migration -{ +class CreateJobsTable extends Migration { /** * Run the migrations. * * @return void */ - public function up() - { + public function up() { Schema::create('jobs', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('queue')->index(); @@ -29,8 +27,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::dropIfExists('jobs'); } } diff --git a/src/backend/database/migrations/2022_11_25_091725_create_company_jobs.php b/src/backend/database/migrations/2022_11_25_091725_create_company_jobs.php index f5cb6bfaf..47043d85e 100644 --- a/src/backend/database/migrations/2022_11_25_091725_create_company_jobs.php +++ b/src/backend/database/migrations/2022_11_25_091725_create_company_jobs.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::create('company_jobs', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('job_name'); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::disableForeignKeyConstraints(); Schema::dropIfExists('company_jobs'); Schema::enableForeignKeyConstraints(); diff --git a/src/backend/database/migrations/2022_11_29_000000_add_micro_star_to_mpm_plugin_table.php b/src/backend/database/migrations/2022_11_29_000000_add_micro_star_to_mpm_plugin_table.php index 3d1646056..bfb8f8663 100644 --- a/src/backend/database/migrations/2022_11_29_000000_add_micro_star_to_mpm_plugin_table.php +++ b/src/backend/database/migrations/2022_11_29_000000_add_micro_star_to_mpm_plugin_table.php @@ -6,8 +6,7 @@ use Illuminate\Support\Facades\DB; return new class extends Migration { - public function up() - { + public function up() { DB::table('mpm_plugins')->insert([ [ 'id' => MpmPlugin::MICRO_STAR_METERS, @@ -21,10 +20,9 @@ public function up() ]); } - public function down() - { + public function down() { DB::table('mpm_plugins') - ->where('id', MpmPlugin::MICRO_STAR_METERS) - ->delete(); + ->where('id', MpmPlugin::MICRO_STAR_METERS) + ->delete(); } }; diff --git a/src/backend/database/migrations/2022_12_12_000000_add_root_class_to_mpm_plugins_table.php b/src/backend/database/migrations/2022_12_12_000000_add_root_class_to_mpm_plugins_table.php index 052cf053a..242b651bd 100644 --- a/src/backend/database/migrations/2022_12_12_000000_add_root_class_to_mpm_plugins_table.php +++ b/src/backend/database/migrations/2022_12_12_000000_add_root_class_to_mpm_plugins_table.php @@ -13,8 +13,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::table('mpm_plugins', function (Blueprint $table) { $table->string('root_class')->nullable(); }); @@ -47,8 +46,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::table('mpm_plugins', function (Blueprint $table) { $table->dropColumn('root_class'); }); diff --git a/src/backend/database/migrations/2022_14_12_000000_add_sun_king_to_mpm_plugin_table.php b/src/backend/database/migrations/2022_14_12_000000_add_sun_king_to_mpm_plugin_table.php index 8d67a6420..e68465e30 100644 --- a/src/backend/database/migrations/2022_14_12_000000_add_sun_king_to_mpm_plugin_table.php +++ b/src/backend/database/migrations/2022_14_12_000000_add_sun_king_to_mpm_plugin_table.php @@ -6,8 +6,7 @@ use Illuminate\Support\Facades\DB; return new class extends Migration { - public function up() - { + public function up() { DB::table('mpm_plugins')->insert([ [ 'id' => MpmPlugin::SUN_KING_SHS, @@ -22,10 +21,9 @@ public function up() ]); } - public function down() - { + public function down() { DB::table('mpm_plugins') - ->where('id', MpmPlugin::SUN_KING_SHS) - ->delete(); + ->where('id', MpmPlugin::SUN_KING_SHS) + ->delete(); } }; diff --git a/src/backend/database/migrations/2023_01_24_110414_create_protected_pages_table.php b/src/backend/database/migrations/2023_01_24_110414_create_protected_pages_table.php index 37e51a3b8..2adbdaa6b 100644 --- a/src/backend/database/migrations/2023_01_24_110414_create_protected_pages_table.php +++ b/src/backend/database/migrations/2023_01_24_110414_create_protected_pages_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::create('protected_pages', function (Blueprint $table) { $table->id(); $table->string('name'); @@ -179,8 +178,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::dropIfExists('protected_pages'); } }; diff --git a/src/backend/database/migrations/2023_01_24_112359_add_protected_page_password_to_companies_table.php b/src/backend/database/migrations/2023_01_24_112359_add_protected_page_password_to_companies_table.php index 0ed96210f..dec84277d 100644 --- a/src/backend/database/migrations/2023_01_24_112359_add_protected_page_password_to_companies_table.php +++ b/src/backend/database/migrations/2023_01_24_112359_add_protected_page_password_to_companies_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::table('companies', function (Blueprint $table) { $table->string('protected_page_password')->nullable(); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::table('companies', function (Blueprint $table) { $table->dropColumn('protected_page_password'); }); diff --git a/src/backend/database/migrations/2023_02_06_000000_add_gome_long_to_mpm_plugin_table.php b/src/backend/database/migrations/2023_02_06_000000_add_gome_long_to_mpm_plugin_table.php index cd47cf4eb..522846f9c 100644 --- a/src/backend/database/migrations/2023_02_06_000000_add_gome_long_to_mpm_plugin_table.php +++ b/src/backend/database/migrations/2023_02_06_000000_add_gome_long_to_mpm_plugin_table.php @@ -6,8 +6,7 @@ use Illuminate\Support\Facades\DB; return new class extends Migration { - public function up() - { + public function up() { DB::table('mpm_plugins')->insert([ [ 'id' => MpmPlugin::GOME_LONG_METERS, @@ -22,10 +21,9 @@ public function up() ]); } - public function down() - { + public function down() { DB::table('mpm_plugins') - ->where('id', MpmPlugin::GOME_LONG_METERS) - ->delete(); + ->where('id', MpmPlugin::GOME_LONG_METERS) + ->delete(); } }; diff --git a/src/backend/database/migrations/2023_04_02_121811_add_wavecom_to_mpm_plugin_table.php b/src/backend/database/migrations/2023_04_02_121811_add_wavecom_to_mpm_plugin_table.php index 837a9135e..552ca919d 100644 --- a/src/backend/database/migrations/2023_04_02_121811_add_wavecom_to_mpm_plugin_table.php +++ b/src/backend/database/migrations/2023_04_02_121811_add_wavecom_to_mpm_plugin_table.php @@ -6,8 +6,7 @@ use Illuminate\Support\Facades\DB; return new class extends Migration { - public function up() - { + public function up() { DB::table('mpm_plugins')->insert([ [ 'id' => MpmPlugin::WAVECOM_PAYMENT_PROVIDER, @@ -22,10 +21,9 @@ public function up() ]); } - public function down() - { + public function down() { DB::table('mpm_plugins') - ->where('id', MpmPlugin::WAVECOM_PAYMENT_PROVIDER) - ->delete(); + ->where('id', MpmPlugin::WAVECOM_PAYMENT_PROVIDER) + ->delete(); } }; diff --git a/src/backend/database/migrations/2023_11_23_134944_update_description_column_in_mpm_plugins_table.php b/src/backend/database/migrations/2023_11_23_134944_update_description_column_in_mpm_plugins_table.php index 4157e3ac7..09ff8a571 100644 --- a/src/backend/database/migrations/2023_11_23_134944_update_description_column_in_mpm_plugins_table.php +++ b/src/backend/database/migrations/2023_11_23_134944_update_description_column_in_mpm_plugins_table.php @@ -13,8 +13,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::table('mpm_plugins', function (Blueprint $table) { $table->text('description')->change(); }); @@ -37,8 +36,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { $mpm_plugins_mapping = [ MpmPlugin::STEAMACO_METER => 'This plugin integrates Steamaco meters to Micropowermanager. It uses the same credentials as ui.steama.co for authentication. After it got authenticated, the plugin synchronizes Site, Customer ..', MpmPlugin::BULK_REGISTRATION => 'This plugin provides bulk registration of the company\'s existing records. NOTE: Please do not use this plugin to register your Spark & Stemaco meter records. These records will be synchronized automatically once you configure your credential settings for these plugins.', diff --git a/src/backend/database/migrations/2024_01_01_000000_add_daly_bms_to_mpm_plugin_table.php b/src/backend/database/migrations/2024_01_01_000000_add_daly_bms_to_mpm_plugin_table.php index bf28ebc30..beec8e793 100644 --- a/src/backend/database/migrations/2024_01_01_000000_add_daly_bms_to_mpm_plugin_table.php +++ b/src/backend/database/migrations/2024_01_01_000000_add_daly_bms_to_mpm_plugin_table.php @@ -6,8 +6,7 @@ use Illuminate\Support\Facades\DB; return new class extends Migration { - public function up() - { + public function up() { DB::table('mpm_plugins')->insert([ [ 'id' => MpmPlugin::DALY_BMS, @@ -22,10 +21,9 @@ public function up() ]); } - public function down() - { + public function down() { DB::table('mpm_plugins') - ->where('id', MpmPlugin::DALY_BMS) - ->delete(); + ->where('id', MpmPlugin::DALY_BMS) + ->delete(); } }; diff --git a/src/backend/database/migrations/2024_01_12_000000_add_angaza_to_mpm_plugin_table.php b/src/backend/database/migrations/2024_01_12_000000_add_angaza_to_mpm_plugin_table.php index b11cd9575..1927b7929 100644 --- a/src/backend/database/migrations/2024_01_12_000000_add_angaza_to_mpm_plugin_table.php +++ b/src/backend/database/migrations/2024_01_12_000000_add_angaza_to_mpm_plugin_table.php @@ -6,8 +6,7 @@ use Illuminate\Support\Facades\DB; return new class extends Migration { - public function up() - { + public function up() { DB::table('mpm_plugins')->insert([ [ 'id' => MpmPlugin::AGAZA_SHS, @@ -22,10 +21,9 @@ public function up() ]); } - public function down() - { + public function down() { DB::table('mpm_plugins') - ->where('id', MpmPlugin::AGAZA_SHS) - ->delete(); + ->where('id', MpmPlugin::AGAZA_SHS) + ->delete(); } }; diff --git a/src/backend/database/migrations/2024_02_07_100345_create_usage_types_table.php b/src/backend/database/migrations/2024_02_07_100345_create_usage_types_table.php index d97075caf..75d2e3707 100644 --- a/src/backend/database/migrations/2024_02_07_100345_create_usage_types_table.php +++ b/src/backend/database/migrations/2024_02_07_100345_create_usage_types_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::create('usage_types', function (Blueprint $table) { $table->id(); $table->string('name'); @@ -72,8 +71,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::dropIfExists('usage_types'); } }; diff --git a/src/backend/database/migrations/2024_02_07_113319_add_usage_type_column_to_mpm_plugins_table.php b/src/backend/database/migrations/2024_02_07_113319_add_usage_type_column_to_mpm_plugins_table.php index f8f2db0b7..80e2d3d72 100644 --- a/src/backend/database/migrations/2024_02_07_113319_add_usage_type_column_to_mpm_plugins_table.php +++ b/src/backend/database/migrations/2024_02_07_113319_add_usage_type_column_to_mpm_plugins_table.php @@ -13,8 +13,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::table('mpm_plugins', function (Blueprint $table) { $table->enum('usage_type', [ 'mini-grid', @@ -57,8 +56,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::table('mpm_plugins', function (Blueprint $table) { $table->dropColumn('usage_type'); }); diff --git a/src/backend/database/migrations/2024_03_21_121825_add_message_and_trace_columns_to_company_jobs_table.php b/src/backend/database/migrations/2024_03_21_121825_add_message_and_trace_columns_to_company_jobs_table.php index f2b07ddaa..fb7fc18f9 100644 --- a/src/backend/database/migrations/2024_03_21_121825_add_message_and_trace_columns_to_company_jobs_table.php +++ b/src/backend/database/migrations/2024_03_21_121825_add_message_and_trace_columns_to_company_jobs_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::table('company_jobs', function (Blueprint $table) { $table->string('message')->nullable(); $table->string('trace')->nullable(); @@ -23,8 +22,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::table('company_jobs', function (Blueprint $table) { $table->dropColumn('message'); $table->dropColumn('trace'); diff --git a/src/backend/database/migrations/micropowermanager/2014_10_12_000000_create_users_table.php b/src/backend/database/migrations/micropowermanager/2014_10_12_000000_create_users_table.php index 5a9665ae8..4f6ea16d9 100644 --- a/src/backend/database/migrations/micropowermanager/2014_10_12_000000_create_users_table.php +++ b/src/backend/database/migrations/micropowermanager/2014_10_12_000000_create_users_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); @@ -28,8 +27,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('users'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2014_10_12_100000_create_password_resets_table.php b/src/backend/database/migrations/micropowermanager/2014_10_12_100000_create_password_resets_table.php index f1d5cd1e2..02627ea3d 100644 --- a/src/backend/database/migrations/micropowermanager/2014_10_12_100000_create_password_resets_table.php +++ b/src/backend/database/migrations/micropowermanager/2014_10_12_100000_create_password_resets_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('password_resets', function (Blueprint $table) { $table->string('email')->index(); $table->string('token'); @@ -24,8 +23,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('password_resets'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_05_24_195615_create_vodacom_transactions_table.php b/src/backend/database/migrations/micropowermanager/2018_05_24_195615_create_vodacom_transactions_table.php index c7b377d77..037351275 100644 --- a/src/backend/database/migrations/micropowermanager/2018_05_24_195615_create_vodacom_transactions_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_05_24_195615_create_vodacom_transactions_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('vodacom_transactions', function (Blueprint $table) { $table->increments('id'); $table->string('conversation_id')->unique(); @@ -29,8 +28,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('vodacom_transactions'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_05_24_201051_create_transactions_table.php b/src/backend/database/migrations/micropowermanager/2018_05_24_201051_create_transactions_table.php index 6a2bbb5ae..085069397 100644 --- a/src/backend/database/migrations/micropowermanager/2018_05_24_201051_create_transactions_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_05_24_201051_create_transactions_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('transactions', function (Blueprint $table) { $table->increments('id'); $table->integer('original_transaction_id'); @@ -29,8 +28,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('transactions'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_05_24_213335_create_airtel_transactions_table.php b/src/backend/database/migrations/micropowermanager/2018_05_24_213335_create_airtel_transactions_table.php index 0ac0b8858..80a941a1f 100644 --- a/src/backend/database/migrations/micropowermanager/2018_05_24_213335_create_airtel_transactions_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_05_24_213335_create_airtel_transactions_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('airtel_transactions', function (Blueprint $table) { $table->increments('id'); $table->string('interface_id'); @@ -28,8 +27,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('airtel_transactions'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_05_25_131106_create_payment_histories_table.php b/src/backend/database/migrations/micropowermanager/2018_05_25_131106_create_payment_histories_table.php index 0e5f8a612..d867f60af 100644 --- a/src/backend/database/migrations/micropowermanager/2018_05_25_131106_create_payment_histories_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_05_25_131106_create_payment_histories_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('payment_histories', function (Blueprint $table) { $table->increments('id'); $table->integer('amount'); @@ -30,8 +29,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('payment_histories'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_05_25_131119_create_meter_tariffs_table.php b/src/backend/database/migrations/micropowermanager/2018_05_25_131119_create_meter_tariffs_table.php index b0744f4d0..b71d598ce 100644 --- a/src/backend/database/migrations/micropowermanager/2018_05_25_131119_create_meter_tariffs_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_05_25_131119_create_meter_tariffs_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('meter_tariffs', function (Blueprint $table) { $table->increments('id'); $table->string('name'); @@ -28,8 +27,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('meter_tariffs'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_05_29_071453_create_addresses_table.php b/src/backend/database/migrations/micropowermanager/2018_05_29_071453_create_addresses_table.php index 5428f4d4d..1dddc8cce 100644 --- a/src/backend/database/migrations/micropowermanager/2018_05_29_071453_create_addresses_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_05_29_071453_create_addresses_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('addresses', function (Blueprint $table) { $table->increments('id'); $table->morphs('owner'); // adds owner_id and owner_type automatically @@ -32,8 +31,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('addresses'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_05_29_080926_create_geographical_informations_table.php b/src/backend/database/migrations/micropowermanager/2018_05_29_080926_create_geographical_informations_table.php index a52a9b450..ba4547235 100644 --- a/src/backend/database/migrations/micropowermanager/2018_05_29_080926_create_geographical_informations_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_05_29_080926_create_geographical_informations_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('geographical_informations', function (Blueprint $table) { $table->increments('id'); $table->integer('owner_id'); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('geographical_informations'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_05_29_140926_create_meter_types_table.php b/src/backend/database/migrations/micropowermanager/2018_05_29_140926_create_meter_types_table.php index 0b9b325a4..46d784122 100644 --- a/src/backend/database/migrations/micropowermanager/2018_05_29_140926_create_meter_types_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_05_29_140926_create_meter_types_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('meter_types'); } @@ -20,8 +19,7 @@ public function down() * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('meter_types', function (Blueprint $table) { $table->increments('id'); $table->boolean('online')->default(false); diff --git a/src/backend/database/migrations/micropowermanager/2018_05_30_124521_create_meters_table.php b/src/backend/database/migrations/micropowermanager/2018_05_30_124521_create_meters_table.php index e32b18a61..23eea84ca 100644 --- a/src/backend/database/migrations/micropowermanager/2018_05_30_124521_create_meters_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_05_30_124521_create_meters_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('meters', function (Blueprint $table) { $table->increments('id'); $table->string('serial_number')->unique(); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('meters'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_05_31_071601_create_manufacturers_table.php b/src/backend/database/migrations/micropowermanager/2018_05_31_071601_create_manufacturers_table.php index 0e15fcd86..036a86046 100644 --- a/src/backend/database/migrations/micropowermanager/2018_05_31_071601_create_manufacturers_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_05_31_071601_create_manufacturers_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('manufacturers', function (Blueprint $table) { $table->increments('id'); $table->string('name'); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('manufacturers'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_05_31_075346_create_cities_table.php b/src/backend/database/migrations/micropowermanager/2018_05_31_075346_create_cities_table.php index 9529c29fc..f0b36ae13 100644 --- a/src/backend/database/migrations/micropowermanager/2018_05_31_075346_create_cities_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_05_31_075346_create_cities_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('cities', function (Blueprint $table) { $table->increments('id'); $table->string('name'); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('cities'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_05_31_075353_create_countries_table.php b/src/backend/database/migrations/micropowermanager/2018_05_31_075353_create_countries_table.php index a62992da9..ebc6582a9 100644 --- a/src/backend/database/migrations/micropowermanager/2018_05_31_075353_create_countries_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_05_31_075353_create_countries_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('countries', function (Blueprint $table) { $table->increments('id'); $table->string('country_code'); @@ -25,8 +24,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('countries'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_06_01_141845_create_people_table.php b/src/backend/database/migrations/micropowermanager/2018_06_01_141845_create_people_table.php index 0139098bc..e9956cd60 100644 --- a/src/backend/database/migrations/micropowermanager/2018_06_01_141845_create_people_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_06_01_141845_create_people_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('people', function (Blueprint $table) { $table->increments('id'); $table->string('title', 50)->nullable(); @@ -32,8 +31,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('people'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_06_04_124637_create__roles_table.php b/src/backend/database/migrations/micropowermanager/2018_06_04_124637_create__roles_table.php index d0450ff81..c76c0850b 100644 --- a/src/backend/database/migrations/micropowermanager/2018_06_04_124637_create__roles_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_06_04_124637_create__roles_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('role_definitions', function (Blueprint $table) { $table->increments('id'); $table->string('role_name'); @@ -30,8 +29,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('role_definitions'); Schema::connection('shard')->dropIfExists('roles'); } diff --git a/src/backend/database/migrations/micropowermanager/2018_06_07_155444_create_meter_tokens_table.php b/src/backend/database/migrations/micropowermanager/2018_06_07_155444_create_meter_tokens_table.php index 23877aee2..1ad3eaec1 100644 --- a/src/backend/database/migrations/micropowermanager/2018_06_07_155444_create_meter_tokens_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_06_07_155444_create_meter_tokens_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('meter_tokens', function (Blueprint $table) { $table->increments('id'); $table->integer('transaction_id')->unique(); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('meter_tokens'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_06_08_102610_create_meter_parameters_table.php b/src/backend/database/migrations/micropowermanager/2018_06_08_102610_create_meter_parameters_table.php index a1b6fb9b4..f8955db78 100644 --- a/src/backend/database/migrations/micropowermanager/2018_06_08_102610_create_meter_parameters_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_06_08_102610_create_meter_parameters_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('meter_parameters', function (Blueprint $table) { $table->increments('id'); $table->morphs('owner'); @@ -28,8 +27,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('meter_parameters'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_06_11_131951_create_sms_table.php b/src/backend/database/migrations/micropowermanager/2018_06_11_131951_create_sms_table.php index 61220d925..30fa50ddc 100644 --- a/src/backend/database/migrations/micropowermanager/2018_06_11_131951_create_sms_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_06_11_131951_create_sms_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('sms', function (Blueprint $table) { $table->increments('id'); $table->string('receiver'); @@ -29,8 +28,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('sms'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_06_15_082352_create_transaction_conflicts_table.php b/src/backend/database/migrations/micropowermanager/2018_06_15_082352_create_transaction_conflicts_table.php index 6252b570d..69ef04948 100644 --- a/src/backend/database/migrations/micropowermanager/2018_06_15_082352_create_transaction_conflicts_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_06_15_082352_create_transaction_conflicts_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('transaction_conflicts', function (Blueprint $table) { $table->increments('id'); $table->morphs('transaction'); @@ -25,8 +24,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('transaction_conflicts'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_06_28_080905_create_access_rates_table.php b/src/backend/database/migrations/micropowermanager/2018_06_28_080905_create_access_rates_table.php index 4c36881bc..dd80e5004 100644 --- a/src/backend/database/migrations/micropowermanager/2018_06_28_080905_create_access_rates_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_06_28_080905_create_access_rates_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('access_rates', function (Blueprint $table) { $table->increments('id'); $table->integer('tariff_id'); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('access_rates'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_06_28_080914_create_access_rate_payments_table.php b/src/backend/database/migrations/micropowermanager/2018_06_28_080914_create_access_rate_payments_table.php index 1d4ac732e..a6c2a1cfb 100644 --- a/src/backend/database/migrations/micropowermanager/2018_06_28_080914_create_access_rate_payments_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_06_28_080914_create_access_rate_payments_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('access_rate_payments', function (Blueprint $table) { $table->increments('id'); $table->integer('meter_id'); @@ -28,8 +27,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('access_rate_payments'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_07_11_075002_create_permission_tables.php b/src/backend/database/migrations/micropowermanager/2018_07_11_075002_create_permission_tables.php index 52a64a061..0a42ab8c0 100644 --- a/src/backend/database/migrations/micropowermanager/2018_07_11_075002_create_permission_tables.php +++ b/src/backend/database/migrations/micropowermanager/2018_07_11_075002_create_permission_tables.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { $tableNames = config('permission.table_names'); Schema::connection('shard')->create($tableNames['permissions'], function (Blueprint $table) { @@ -77,8 +76,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { $tableNames = config('permission.table_names'); Schema::connection('shard')->drop($tableNames['role_has_permissions']); diff --git a/src/backend/database/migrations/micropowermanager/2018_07_12_133700_create_loans_table.php b/src/backend/database/migrations/micropowermanager/2018_07_12_133700_create_loans_table.php index 6202eb9a0..e325372c4 100644 --- a/src/backend/database/migrations/micropowermanager/2018_07_12_133700_create_loans_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_07_12_133700_create_loans_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('loans', function (Blueprint $table) { $table->increments('id'); $table->timestamps(); @@ -23,8 +22,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('loans'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_07_12_134253_create_customers_table.php b/src/backend/database/migrations/micropowermanager/2018_07_12_134253_create_customers_table.php index a74747af6..b297be88c 100644 --- a/src/backend/database/migrations/micropowermanager/2018_07_12_134253_create_customers_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_07_12_134253_create_customers_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('customers', function (Blueprint $table) { $table->increments('id'); $table->morphs('role_owner'); @@ -24,8 +23,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('customers'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_10_04_195503_create_histories_table.php b/src/backend/database/migrations/micropowermanager/2018_10_04_195503_create_histories_table.php index 059b726ac..9b24d6788 100644 --- a/src/backend/database/migrations/micropowermanager/2018_10_04_195503_create_histories_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_10_04_195503_create_histories_table.php @@ -7,11 +7,8 @@ return new class extends Migration { /** * Run the migrations. - * - * @return void */ - public function up(): void - { + public function up(): void { Schema::connection('shard')->create('histories', function (Blueprint $table) { $table->increments('id'); $table->morphs('target'); // it contains a the target information @@ -24,11 +21,8 @@ public function up(): void /** * Reverse the migrations. - * - * @return void */ - public function down(): void - { + public function down(): void { Schema::connection('shard')->dropIfExists('histories'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_10_12_110924_create_meter_consumptions_table.php b/src/backend/database/migrations/micropowermanager/2018_10_12_110924_create_meter_consumptions_table.php index 3780d7efd..1274451bc 100644 --- a/src/backend/database/migrations/micropowermanager/2018_10_12_110924_create_meter_consumptions_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_10_12_110924_create_meter_consumptions_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('meter_consumptions', function (Blueprint $table) { $table->increments('id'); $table->integer('meter_id'); @@ -28,8 +27,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('meter_consumptions'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_10_12_123911_create_payment_profiles_table.php b/src/backend/database/migrations/micropowermanager/2018_10_12_123911_create_payment_profiles_table.php index 9594e3c81..270736fea 100644 --- a/src/backend/database/migrations/micropowermanager/2018_10_12_123911_create_payment_profiles_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_10_12_123911_create_payment_profiles_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('payment_profiles', function (Blueprint $table) { $table->increments('id'); $table->timestamps(); @@ -23,8 +22,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('payment_profiles'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_11_29_090603_create_clusters_table.php b/src/backend/database/migrations/micropowermanager/2018_11_29_090603_create_clusters_table.php index 1c4048b7b..1a8536cd6 100644 --- a/src/backend/database/migrations/micropowermanager/2018_11_29_090603_create_clusters_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_11_29_090603_create_clusters_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('clusters', function (Blueprint $table) { $table->increments('id'); $table->string('name'); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('clusters'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_12_05_144906_create_revenues_table.php b/src/backend/database/migrations/micropowermanager/2018_12_05_144906_create_revenues_table.php index 729380b0e..8950ecf4e 100644 --- a/src/backend/database/migrations/micropowermanager/2018_12_05_144906_create_revenues_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_12_05_144906_create_revenues_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('revenues', function (Blueprint $table) { $table->increments('id'); $table->timestamps(); @@ -23,8 +22,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('revenues'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_12_11_083717_create_connection_types_table.php b/src/backend/database/migrations/micropowermanager/2018_12_11_083717_create_connection_types_table.php index e35198c21..b70def4e7 100644 --- a/src/backend/database/migrations/micropowermanager/2018_12_11_083717_create_connection_types_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_12_11_083717_create_connection_types_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('connection_types', function (Blueprint $table) { $table->increments('id'); $table->string('name'); @@ -32,8 +31,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('connection_types'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_12_13_083722_create_targets_table.php b/src/backend/database/migrations/micropowermanager/2018_12_13_083722_create_targets_table.php index 5f68c0492..912e1c748 100644 --- a/src/backend/database/migrations/micropowermanager/2018_12_13_083722_create_targets_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_12_13_083722_create_targets_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('targets', function (Blueprint $table) { $table->increments('id'); $table->date('target_date'); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('targets'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2018_12_13_100738_create_sub_targets_table.php b/src/backend/database/migrations/micropowermanager/2018_12_13_100738_create_sub_targets_table.php index a9d3433fa..75e19a11e 100644 --- a/src/backend/database/migrations/micropowermanager/2018_12_13_100738_create_sub_targets_table.php +++ b/src/backend/database/migrations/micropowermanager/2018_12_13_100738_create_sub_targets_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('sub_targets', function (Blueprint $table) { $table->increments('id'); $table->integer('target_id'); @@ -31,8 +30,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('sub_targets'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2019_04_19_083645_customer_group.php b/src/backend/database/migrations/micropowermanager/2019_04_19_083645_customer_group.php index dc1b08a2d..9258f34b5 100644 --- a/src/backend/database/migrations/micropowermanager/2019_04_19_083645_customer_group.php +++ b/src/backend/database/migrations/micropowermanager/2019_04_19_083645_customer_group.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('customer_groups', function (Blueprint $table) { $table->increments('id'); $table->integer('tariff_id'); @@ -25,8 +24,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('customer_groups'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2019_04_25_092438_create_sub_connection_types_table.php b/src/backend/database/migrations/micropowermanager/2019_04_25_092438_create_sub_connection_types_table.php index 0392b37c7..ebf2c41c4 100644 --- a/src/backend/database/migrations/micropowermanager/2019_04_25_092438_create_sub_connection_types_table.php +++ b/src/backend/database/migrations/micropowermanager/2019_04_25_092438_create_sub_connection_types_table.php @@ -9,11 +9,8 @@ return new class extends Migration { /** * Run the migrations. - * - * @return void */ - public function up(): void - { + public function up(): void { Schema::connection('shard')->create('sub_connection_types', static function (Blueprint $table) { $table->increments('id'); $table->string('name'); @@ -33,11 +30,8 @@ public function up(): void /** * Reverse the migrations. - * - * @return void */ - public function down(): void - { + public function down(): void { Schema::connection('shard')->dropIfExists('sub_connection_types'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2019_05_01_103123_create_connection_groups_table.php b/src/backend/database/migrations/micropowermanager/2019_05_01_103123_create_connection_groups_table.php index c19716b7a..26394d193 100644 --- a/src/backend/database/migrations/micropowermanager/2019_05_01_103123_create_connection_groups_table.php +++ b/src/backend/database/migrations/micropowermanager/2019_05_01_103123_create_connection_groups_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('connection_groups', function (Blueprint $table) { $table->increments('id'); $table->string('name'); @@ -32,8 +31,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('connection_groups'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2019_05_15_122118_reports.php b/src/backend/database/migrations/micropowermanager/2019_05_15_122118_reports.php index de15e08a0..3f0e8df31 100644 --- a/src/backend/database/migrations/micropowermanager/2019_05_15_122118_reports.php +++ b/src/backend/database/migrations/micropowermanager/2019_05_15_122118_reports.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('reports', static function (Blueprint $table) { $table->increments('id'); $table->string('name'); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->drop('reports'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2019_06_24_160040_create_mini_grids_table.php b/src/backend/database/migrations/micropowermanager/2019_06_24_160040_create_mini_grids_table.php index 58ae32ad7..b5a1fdacb 100644 --- a/src/backend/database/migrations/micropowermanager/2019_06_24_160040_create_mini_grids_table.php +++ b/src/backend/database/migrations/micropowermanager/2019_06_24_160040_create_mini_grids_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('mini_grids', function (Blueprint $table) { $table->increments('id'); $table->integer('cluster_id'); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('mini_grids'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2019_07_01_133655_create_maintenance_users_table.php b/src/backend/database/migrations/micropowermanager/2019_07_01_133655_create_maintenance_users_table.php index 7ed712525..54a34b1c3 100644 --- a/src/backend/database/migrations/micropowermanager/2019_07_01_133655_create_maintenance_users_table.php +++ b/src/backend/database/migrations/micropowermanager/2019_07_01_133655_create_maintenance_users_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('maintenance_users', function (Blueprint $table) { $table->increments('id'); $table->integer('person_id'); @@ -25,8 +24,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('maintenance_users'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2019_11_06_121116_create_energies_table.php b/src/backend/database/migrations/micropowermanager/2019_11_06_121116_create_energies_table.php index ceb964f95..0a5839607 100644 --- a/src/backend/database/migrations/micropowermanager/2019_11_06_121116_create_energies_table.php +++ b/src/backend/database/migrations/micropowermanager/2019_11_06_121116_create_energies_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('energies', function (Blueprint $table) { $table->increments('id'); $table->integer('mini_grid_id'); @@ -35,8 +34,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('energies'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2019_11_15_102431_create_solars_table.php b/src/backend/database/migrations/micropowermanager/2019_11_15_102431_create_solars_table.php index 092056f67..4f80734a2 100644 --- a/src/backend/database/migrations/micropowermanager/2019_11_15_102431_create_solars_table.php +++ b/src/backend/database/migrations/micropowermanager/2019_11_15_102431_create_solars_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('solars', function (Blueprint $table) { $table->increments('id'); $table->integer('mini_grid_id'); @@ -34,8 +33,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('solars'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2019_11_26_063009_create_batteries_table.php b/src/backend/database/migrations/micropowermanager/2019_11_26_063009_create_batteries_table.php index e84d8693c..5c1af3658 100644 --- a/src/backend/database/migrations/micropowermanager/2019_11_26_063009_create_batteries_table.php +++ b/src/backend/database/migrations/micropowermanager/2019_11_26_063009_create_batteries_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('batteries', function (Blueprint $table) { $table->increments('id'); $table->integer('mini_grid_id'); @@ -44,8 +43,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('batteries'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2019_12_16_090907_create_assets_table.php b/src/backend/database/migrations/micropowermanager/2019_12_16_090907_create_assets_table.php index 864a51c53..541b53561 100644 --- a/src/backend/database/migrations/micropowermanager/2019_12_16_090907_create_assets_table.php +++ b/src/backend/database/migrations/micropowermanager/2019_12_16_090907_create_assets_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('assets', function (Blueprint $table) { $table->increments('id'); $table->string('name'); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('assets'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2019_12_16_091934_create_asset_types_table.php b/src/backend/database/migrations/micropowermanager/2019_12_16_091934_create_asset_types_table.php index 14e065fcd..e0ae5be26 100644 --- a/src/backend/database/migrations/micropowermanager/2019_12_16_091934_create_asset_types_table.php +++ b/src/backend/database/migrations/micropowermanager/2019_12_16_091934_create_asset_types_table.php @@ -9,11 +9,8 @@ return new class extends Migration { /** * Run the migrations. - * - * @return void */ - public function up(): void - { + public function up(): void { Schema::connection('shard')->create('asset_types', static function (Blueprint $table) { $table->increments('id'); $table->string('name'); @@ -22,33 +19,31 @@ public function up(): void }); // Insert initial data - DB::connection('shard')->table('asset_types')->insert([ + DB::connection('shard')->table('asset_types')->insert( [ - 'name' => 'Solar Home System', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'name' => 'E-Bike', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'name' => 'Electronics', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - ] + [ + 'name' => 'Solar Home System', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'name' => 'E-Bike', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'name' => 'Electronics', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + ] ); } /** * Reverse the migrations. - * - * @return void */ - public function down(): void - { + public function down(): void { Schema::connection('shard')->dropIfExists('asset_types'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2019_12_16_092044_create_asset_people_table.php b/src/backend/database/migrations/micropowermanager/2019_12_16_092044_create_asset_people_table.php index bf5851245..14a92d61d 100644 --- a/src/backend/database/migrations/micropowermanager/2019_12_16_092044_create_asset_people_table.php +++ b/src/backend/database/migrations/micropowermanager/2019_12_16_092044_create_asset_people_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('asset_people', function (Blueprint $table) { $table->increments('id'); $table->integer('asset_type_id'); @@ -28,8 +27,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('asset_people'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2019_12_16_093223_create_asset_rates_table.php b/src/backend/database/migrations/micropowermanager/2019_12_16_093223_create_asset_rates_table.php index bf5ff42ba..e30b33b69 100644 --- a/src/backend/database/migrations/micropowermanager/2019_12_16_093223_create_asset_rates_table.php +++ b/src/backend/database/migrations/micropowermanager/2019_12_16_093223_create_asset_rates_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('asset_rates', function (Blueprint $table) { $table->increments('id'); $table->integer('asset_person_id'); @@ -28,8 +27,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('asset_rates'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_01_27_135206_create_logs_table.php b/src/backend/database/migrations/micropowermanager/2020_01_27_135206_create_logs_table.php index 8b6eb8dc4..a6114d554 100644 --- a/src/backend/database/migrations/micropowermanager/2020_01_27_135206_create_logs_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_01_27_135206_create_logs_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('logs', static function (Blueprint $table) { $table->increments('id'); $table->morphs('affected'); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('logs'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_04_05_233604_create_p_v_s_table.php b/src/backend/database/migrations/micropowermanager/2020_04_05_233604_create_p_v_s_table.php index 4248e8a37..d1cb05bbe 100644 --- a/src/backend/database/migrations/micropowermanager/2020_04_05_233604_create_p_v_s_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_04_05_233604_create_p_v_s_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('p_v_s', function (Blueprint $table) { $table->bigIncrements('id'); $table->integer('mini_grid_id'); @@ -32,8 +31,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('p_v_s'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_04_19_234527_create_restrictions_table.php b/src/backend/database/migrations/micropowermanager/2020_04_19_234527_create_restrictions_table.php index 343eb5b1e..390ff4e8d 100644 --- a/src/backend/database/migrations/micropowermanager/2020_04_19_234527_create_restrictions_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_04_19_234527_create_restrictions_table.php @@ -11,8 +11,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('restrictions', static function (Blueprint $table) { $table->bigIncrements('id'); $table->string('target'); @@ -28,13 +27,11 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('restrictions'); } - public function addDefault() - { + public function addDefault() { $timeStamp = Carbon\Carbon::now(); DB::table('restrictions')->insert([ diff --git a/src/backend/database/migrations/micropowermanager/2020_04_19_235421_create_upgrades_table.php b/src/backend/database/migrations/micropowermanager/2020_04_19_235421_create_upgrades_table.php index 758fd9dc6..a75f70003 100644 --- a/src/backend/database/migrations/micropowermanager/2020_04_19_235421_create_upgrades_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_04_19_235421_create_upgrades_table.php @@ -11,8 +11,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('upgrades', static function (Blueprint $table) { $table->bigIncrements('id'); $table->integer('restriction_id'); @@ -28,14 +27,12 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('upgrades'); } // TODO : add to seeders - public function addDefault() - { + public function addDefault() { DB::table('upgrades')->insert([ 'restriction_id' => 1, 'cost' => 36000, diff --git a/src/backend/database/migrations/micropowermanager/2020_04_20_001454_create_subscriptions_table.php b/src/backend/database/migrations/micropowermanager/2020_04_20_001454_create_subscriptions_table.php index 03f59e136..ace10ba31 100644 --- a/src/backend/database/migrations/micropowermanager/2020_04_20_001454_create_subscriptions_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_04_20_001454_create_subscriptions_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('subscriptions', static function (Blueprint $table) { $table->bigIncrements('id'); $table->integer('upgrade_id'); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('subscriptions'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_06_20_085555_weather_data.php b/src/backend/database/migrations/micropowermanager/2020_06_20_085555_weather_data.php index 40ce2c983..f8412b701 100644 --- a/src/backend/database/migrations/micropowermanager/2020_06_20_085555_weather_data.php +++ b/src/backend/database/migrations/micropowermanager/2020_06_20_085555_weather_data.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('weather_data', static function (Blueprint $table) { $table->increments('id'); $table->integer('solar_id'); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('weather_data'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_06_21_131740_create_tariff_pricing_components_table.php b/src/backend/database/migrations/micropowermanager/2020_06_21_131740_create_tariff_pricing_components_table.php index 748b295cb..9142b4e37 100644 --- a/src/backend/database/migrations/micropowermanager/2020_06_21_131740_create_tariff_pricing_components_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_06_21_131740_create_tariff_pricing_components_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('tariff_pricing_components', function (Blueprint $table) { $table->id(); $table->string('name'); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('tariff_pricing_components'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_06_21_194542_create_social_tariffs_table.php b/src/backend/database/migrations/micropowermanager/2020_06_21_194542_create_social_tariffs_table.php index 26d61b55b..5cd1a8105 100644 --- a/src/backend/database/migrations/micropowermanager/2020_06_21_194542_create_social_tariffs_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_06_21_194542_create_social_tariffs_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('social_tariffs', function (Blueprint $table) { $table->id(); $table->integer('tariff_id'); @@ -28,8 +27,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('social_tariffs'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_06_22_085345_create_social_tariff_piggy_banks_table.php b/src/backend/database/migrations/micropowermanager/2020_06_22_085345_create_social_tariff_piggy_banks_table.php index 61697c8b9..3e21f5a40 100644 --- a/src/backend/database/migrations/micropowermanager/2020_06_22_085345_create_social_tariff_piggy_banks_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_06_22_085345_create_social_tariff_piggy_banks_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('social_tariff_piggy_banks', function (Blueprint $table) { $table->id(); $table->integer('savings'); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('social_tariff_piggy_banks'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_06_22_115405_add_total_price_to_meter_tariffs.php b/src/backend/database/migrations/micropowermanager/2020_06_22_115405_add_total_price_to_meter_tariffs.php index 6d311f3d0..20faeecc8 100644 --- a/src/backend/database/migrations/micropowermanager/2020_06_22_115405_add_total_price_to_meter_tariffs.php +++ b/src/backend/database/migrations/micropowermanager/2020_06_22_115405_add_total_price_to_meter_tariffs.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('meter_tariffs', function (Blueprint $table) { $table->integer('total_price')->unsigned()->nullable(); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('meter_tariffs', function (Blueprint $table) { $table->dropColumn('total_price'); }); diff --git a/src/backend/database/migrations/micropowermanager/2020_07_12_192802_create_agents_table.php b/src/backend/database/migrations/micropowermanager/2020_07_12_192802_create_agents_table.php index 84b02871f..e5dc05c94 100644 --- a/src/backend/database/migrations/micropowermanager/2020_07_12_192802_create_agents_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_07_12_192802_create_agents_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('agents', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('person_id'); @@ -36,8 +35,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('agents'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_07_13_130601_create_agent_transactions_table.php b/src/backend/database/migrations/micropowermanager/2020_07_13_130601_create_agent_transactions_table.php index 86730eb84..ba4bb07e3 100644 --- a/src/backend/database/migrations/micropowermanager/2020_07_13_130601_create_agent_transactions_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_07_13_130601_create_agent_transactions_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('agent_transactions', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('agent_id'); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('agent_transactions'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_07_13_132006_create_agent_balance_histories_table.php b/src/backend/database/migrations/micropowermanager/2020_07_13_132006_create_agent_balance_histories_table.php index e73d0b7c3..b06214f5e 100644 --- a/src/backend/database/migrations/micropowermanager/2020_07_13_132006_create_agent_balance_histories_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_07_13_132006_create_agent_balance_histories_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('agent_balance_histories', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('agent_id'); @@ -29,8 +28,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('agent_balance_histories'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_07_13_132423_create_agent_assigned_appliances_table.php b/src/backend/database/migrations/micropowermanager/2020_07_13_132423_create_agent_assigned_appliances_table.php index 6f0e7e097..e094e8d3a 100644 --- a/src/backend/database/migrations/micropowermanager/2020_07_13_132423_create_agent_assigned_appliances_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_07_13_132423_create_agent_assigned_appliances_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('agent_assigned_appliances', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('agent_id'); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('agent_assigned_appliances'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_07_13_132811_create_agent_sold_appliances_table.php b/src/backend/database/migrations/micropowermanager/2020_07_13_132811_create_agent_sold_appliances_table.php index 1cc6849f5..3a8fe6ff5 100644 --- a/src/backend/database/migrations/micropowermanager/2020_07_13_132811_create_agent_sold_appliances_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_07_13_132811_create_agent_sold_appliances_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('agent_sold_appliances', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('person_id'); @@ -25,8 +24,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('agent_sold_appliances'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_07_25_083600_create_agent_commissions_table.php b/src/backend/database/migrations/micropowermanager/2020_07_25_083600_create_agent_commissions_table.php index 9002d5b8a..2321266c6 100644 --- a/src/backend/database/migrations/micropowermanager/2020_07_25_083600_create_agent_commissions_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_07_25_083600_create_agent_commissions_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('agent_commissions', function (Blueprint $table) { $table->id(); $table->string('name'); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('agent_commissions'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_07_25_155837_create_agent_receipts_table.php b/src/backend/database/migrations/micropowermanager/2020_07_25_155837_create_agent_receipts_table.php index ac1b4a33f..d6e9a714b 100644 --- a/src/backend/database/migrations/micropowermanager/2020_07_25_155837_create_agent_receipts_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_07_25_155837_create_agent_receipts_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('agent_receipts', function (Blueprint $table) { $table->id(); $table->integer('agent_id'); @@ -28,8 +27,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('agent_receipts'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_08_03_081836_create_agent_charges_table.php b/src/backend/database/migrations/micropowermanager/2020_08_03_081836_create_agent_charges_table.php index 45f6599bc..b6423b896 100644 --- a/src/backend/database/migrations/micropowermanager/2020_08_03_081836_create_agent_charges_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_08_03_081836_create_agent_charges_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('agent_charges', function (Blueprint $table) { $table->id(); $table->integer('agent_id'); @@ -25,8 +24,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('agent_charges'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_08_05_133748_create_agent_receipt_details_table.php b/src/backend/database/migrations/micropowermanager/2020_08_05_133748_create_agent_receipt_details_table.php index 52dd76cea..123ad0f14 100644 --- a/src/backend/database/migrations/micropowermanager/2020_08_05_133748_create_agent_receipt_details_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_08_05_133748_create_agent_receipt_details_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('agent_receipt_details', function (Blueprint $table) { $table->id(); $table->integer('agent_receipt_id'); @@ -29,8 +28,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('agent_receipt_details'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_10_02_072509_create_time_of_usages_table.php b/src/backend/database/migrations/micropowermanager/2020_10_02_072509_create_time_of_usages_table.php index c41292352..ac7f33161 100644 --- a/src/backend/database/migrations/micropowermanager/2020_10_02_072509_create_time_of_usages_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_10_02_072509_create_time_of_usages_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('time_of_usages', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('tariff_id'); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('time_of_usages'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_10_19_122517_create_sub_menu_items_table.php b/src/backend/database/migrations/micropowermanager/2020_10_19_122517_create_sub_menu_items_table.php index 7924e56bb..93ae96c7c 100644 --- a/src/backend/database/migrations/micropowermanager/2020_10_19_122517_create_sub_menu_items_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_10_19_122517_create_sub_menu_items_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('sub_menu_items', function (Blueprint $table) { $table->increments('id'); $table->char('name', 50); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('sub_menu_items'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_10_19_122649_create_menu_items_table.php b/src/backend/database/migrations/micropowermanager/2020_10_19_122649_create_menu_items_table.php index 2d2512d7b..8bd3c1990 100644 --- a/src/backend/database/migrations/micropowermanager/2020_10_19_122649_create_menu_items_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_10_19_122649_create_menu_items_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('menu_items', function (Blueprint $table) { $table->increments('id'); $table->char('name', 50); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('menu_items'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_10_29_170007_create_plugins_table.php b/src/backend/database/migrations/micropowermanager/2020_10_29_170007_create_plugins_table.php index b57721df7..4b799c534 100644 --- a/src/backend/database/migrations/micropowermanager/2020_10_29_170007_create_plugins_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_10_29_170007_create_plugins_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('plugins', function (Blueprint $table) { $table->id(); $table->integer('mpm_plugin_id'); @@ -25,8 +24,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('plugins'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_12_17_144527_create_main_settings_table.php b/src/backend/database/migrations/micropowermanager/2020_12_17_144527_create_main_settings_table.php index a9bfe2c7f..936504367 100644 --- a/src/backend/database/migrations/micropowermanager/2020_12_17_144527_create_main_settings_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_12_17_144527_create_main_settings_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('main_settings', function (Blueprint $table) { $table->increments('id'); $table->char('site_title', 100); @@ -44,8 +43,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('main_settings'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2020_12_23_165814_create_map_settings_table.php b/src/backend/database/migrations/micropowermanager/2020_12_23_165814_create_map_settings_table.php index 3e51dd8c6..e4ef06f47 100644 --- a/src/backend/database/migrations/micropowermanager/2020_12_23_165814_create_map_settings_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_12_23_165814_create_map_settings_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('map_settings', function (Blueprint $table) { $table->increments('id'); $table->integer('zoom'); @@ -38,8 +37,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('map_settings'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_01_02_130016_add_manufacturer_transaction_to_agent_transactions_table.php b/src/backend/database/migrations/micropowermanager/2021_01_02_130016_add_manufacturer_transaction_to_agent_transactions_table.php index b80888dad..c7a7eac71 100644 --- a/src/backend/database/migrations/micropowermanager/2021_01_02_130016_add_manufacturer_transaction_to_agent_transactions_table.php +++ b/src/backend/database/migrations/micropowermanager/2021_01_02_130016_add_manufacturer_transaction_to_agent_transactions_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('agent_transactions', function (Blueprint $table) { $table->string('manufacturer_transaction_type')->nullable(); $table->integer('manufacturer_transaction_id')->nullable(); @@ -23,9 +22,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('agent_transactions', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('agent_transactions', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_01_02_130412_create_third_party_transactions.php b/src/backend/database/migrations/micropowermanager/2021_01_02_130412_create_third_party_transactions.php index 0ea1fb8d4..6d909ec95 100644 --- a/src/backend/database/migrations/micropowermanager/2021_01_02_130412_create_third_party_transactions.php +++ b/src/backend/database/migrations/micropowermanager/2021_01_02_130412_create_third_party_transactions.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('third_party_transactions', function (Blueprint $table) { $table->id(); $table->string('transaction_id'); @@ -28,8 +27,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('third_party_transactions'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_01_02_134152_add_manufacturer_transaction_to_vodacom_transactions_table.php b/src/backend/database/migrations/micropowermanager/2021_01_02_134152_add_manufacturer_transaction_to_vodacom_transactions_table.php index a8e381339..6512e7ed8 100644 --- a/src/backend/database/migrations/micropowermanager/2021_01_02_134152_add_manufacturer_transaction_to_vodacom_transactions_table.php +++ b/src/backend/database/migrations/micropowermanager/2021_01_02_134152_add_manufacturer_transaction_to_vodacom_transactions_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('vodacom_transactions', function (Blueprint $table) { $table->string('manufacturer_transaction_type')->nullable(); $table->integer('manufacturer_transaction_id')->nullable(); @@ -23,9 +22,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('vodacom_transactions', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('vodacom_transactions', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_01_02_134212_add_manufacturer_transaction_to_airtel_transactions_table.php b/src/backend/database/migrations/micropowermanager/2021_01_02_134212_add_manufacturer_transaction_to_airtel_transactions_table.php index 73fba50b3..a5bfe97ff 100644 --- a/src/backend/database/migrations/micropowermanager/2021_01_02_134212_add_manufacturer_transaction_to_airtel_transactions_table.php +++ b/src/backend/database/migrations/micropowermanager/2021_01_02_134212_add_manufacturer_transaction_to_airtel_transactions_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('airtel_transactions', function (Blueprint $table) { $table->string('manufacturer_transaction_type')->nullable(); $table->integer('manufacturer_transaction_id')->nullable(); @@ -23,9 +22,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('airtel_transactions', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('airtel_transactions', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_01_05_234039_create_ticket_settings_table.php b/src/backend/database/migrations/micropowermanager/2021_01_05_234039_create_ticket_settings_table.php index 9cdbe3bda..fd3afc23c 100644 --- a/src/backend/database/migrations/micropowermanager/2021_01_05_234039_create_ticket_settings_table.php +++ b/src/backend/database/migrations/micropowermanager/2021_01_05_234039_create_ticket_settings_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('ticket_settings', function (Blueprint $table) { $table->increments('id'); $table->string('name'); @@ -38,8 +37,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('ticket_settings'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_01_18_122556_add_columns_to_batteries_table.php b/src/backend/database/migrations/micropowermanager/2021_01_18_122556_add_columns_to_batteries_table.php index c7510e886..53ba4d034 100644 --- a/src/backend/database/migrations/micropowermanager/2021_01_18_122556_add_columns_to_batteries_table.php +++ b/src/backend/database/migrations/micropowermanager/2021_01_18_122556_add_columns_to_batteries_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('batteries', function (Blueprint $table) { $table->boolean('active')->default(0); $table->double('c_total')->default(0); @@ -30,9 +29,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('batteries', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('batteries', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_01_18_123245_add_columns_to_p_v_s_table.php b/src/backend/database/migrations/micropowermanager/2021_01_18_123245_add_columns_to_p_v_s_table.php index 3a961fc9c..39e929c52 100644 --- a/src/backend/database/migrations/micropowermanager/2021_01_18_123245_add_columns_to_p_v_s_table.php +++ b/src/backend/database/migrations/micropowermanager/2021_01_18_123245_add_columns_to_p_v_s_table.php @@ -11,8 +11,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('p_v_s', function (Blueprint $table) { $table->double('max_theoretical_output')->default(0); $table->dateTime('reading_date')->default(Carbon::now()->format('Y-m-d H:i:s')); @@ -24,9 +23,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('p_v_s', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('p_v_s', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_02_18_153556_create_sms_bodies.php b/src/backend/database/migrations/micropowermanager/2021_02_18_153556_create_sms_bodies.php index 2a10b2488..d8a85c2ca 100644 --- a/src/backend/database/migrations/micropowermanager/2021_02_18_153556_create_sms_bodies.php +++ b/src/backend/database/migrations/micropowermanager/2021_02_18_153556_create_sms_bodies.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('sms_bodies', function (Blueprint $table) { $table->increments('id'); $table->string('reference', 50)->unique(); @@ -24,134 +23,135 @@ public function up() $table->timestamps(); }); - DB::connection('shard')->table('sms_bodies')->insert([ + DB::connection('shard')->table('sms_bodies')->insert( [ - 'reference' => 'SmsTransactionHeader', - 'place_holder' => 'Dear [name] [surname], we received your transaction [transaction_amount].', - 'body' => 'Dear [name] [surname], we received your transaction [transaction_amount].', - 'variables' => 'name,surname,transaction_amount', - 'title' => 'Sms Header', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'reference' => 'SmsReminderHeader', - 'place_holder' => 'Dear [name] [surname],', - 'body' => 'Dear [name] [surname],', - 'variables' => 'name,surname', - 'title' => 'Sms Header', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'reference' => 'SmsResendInformationHeader', - 'place_holder' => 'Dear [name] [surname], we received your resend last transaction information demand.', - 'body' => 'Dear [name] [surname], we received your resend last transaction information demand.', - 'variables' => 'name,surname', - 'title' => 'Sms Header', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'reference' => 'EnergyConfirmation', - 'place_holder' => 'Meter: [meter] , [token] Unit [energy] .', - 'body' => 'Meter: [meter] , [token] Unit [energy] .', - 'variables' => 'meter,token,energy', - 'title' => 'Meter Charge', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'reference' => 'AccessRateConfirmation', - 'place_holder' => 'Service Charge: [amount] ', - 'body' => 'Service Charge: [amount] ', - 'variables' => 'amount', - 'title' => 'Tariff Fixed Cost', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'reference' => 'AssetRateReminder', - 'place_holder' => 'the next rate of [appliance_type_name] ( . [remaining] . ) is due on [due_date]', - 'body' => 'the next rate of [appliance_type_name] ( . [remaining] . ) is due on [due_date]', - 'variables' => 'appliance_type_name,remaining,due_date', - 'title' => 'Appliance Payment Reminder', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'reference' => 'AssetRatePayment', - 'place_holder' => 'Appliance: [appliance_type_name] [amount]', - 'body' => 'Appliance: [appliance_type_name] [amount]', - 'variables' => 'appliance_type_name,amount', - 'title' => 'Appliance Payment', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'reference' => 'OverdueAssetRateReminder', - 'place_holder' => 'you forgot to pay the rate of [appliance_type_name] ( [remaining] ) on [due_date]. Please pay it as soon as possible, unless you wont be able to buy energy.', - 'body' => 'you forgot to pay the rate of [appliance_type_name] ( [remaining] ) on [due_date]. Please pay it as soon as possible, unless you wont be able to buy energy.', - 'variables' => 'appliance_type_name,remaining,due_date', - 'title' => 'Overdue Appliance Payment Reminder', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'reference' => 'PricingDetails', - 'place_holder' => 'Transaction amount is [amount], \n VAT for energy : [vat_energy] \n VAT for the other staffs : [vat_others] . ', - 'body' => 'Transaction amount is [amount], \n VAT for energy : [vat_energy] \n VAT for the other staffs : [vat_others] . ', - 'variables' => 'amount,vat_energy,vat_others', - 'title' => 'Pricing Details', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'reference' => 'ResendInformation', - 'place_holder' => 'Meter: [meter] , [token] Unit [energy] KWH. Service Charge: [amount]', - 'body' => 'Meter: [meter] , [token] Unit [energy] KWH. Service Charge: [amount]', - 'variables' => 'meter,token,energy,amount', - 'title' => 'Resend Last Transaction Information', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'reference' => 'ResendInformationLastTransactionNotFound', - 'place_holder' => 'Last transaction information not found for Meter: [meter]', - 'body' => 'Last transaction information not found for Meter: [meter]', - 'variables' => 'meter', - 'title' => 'Last Transaction Information Not Found', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'reference' => 'SmsReminderFooter', - 'place_holder' => 'Your Company etc.', - 'body' => 'Your Company etc.', - 'variables' => '', - 'title' => 'Sms Footer', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'reference' => 'SmsTransactionFooter', - 'place_holder' => 'Your Company etc.', - 'body' => 'Your Company etc.', - 'variables' => '', - 'title' => 'Sms Footer', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'reference' => 'SmsResendInformationFooter', - 'place_holder' => 'Your Company etc.', - 'body' => 'Your Company etc.', - 'variables' => '', - 'title' => 'Sms Footer', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - ] + [ + 'reference' => 'SmsTransactionHeader', + 'place_holder' => 'Dear [name] [surname], we received your transaction [transaction_amount].', + 'body' => 'Dear [name] [surname], we received your transaction [transaction_amount].', + 'variables' => 'name,surname,transaction_amount', + 'title' => 'Sms Header', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'reference' => 'SmsReminderHeader', + 'place_holder' => 'Dear [name] [surname],', + 'body' => 'Dear [name] [surname],', + 'variables' => 'name,surname', + 'title' => 'Sms Header', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'reference' => 'SmsResendInformationHeader', + 'place_holder' => 'Dear [name] [surname], we received your resend last transaction information demand.', + 'body' => 'Dear [name] [surname], we received your resend last transaction information demand.', + 'variables' => 'name,surname', + 'title' => 'Sms Header', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'reference' => 'EnergyConfirmation', + 'place_holder' => 'Meter: [meter] , [token] Unit [energy] .', + 'body' => 'Meter: [meter] , [token] Unit [energy] .', + 'variables' => 'meter,token,energy', + 'title' => 'Meter Charge', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'reference' => 'AccessRateConfirmation', + 'place_holder' => 'Service Charge: [amount] ', + 'body' => 'Service Charge: [amount] ', + 'variables' => 'amount', + 'title' => 'Tariff Fixed Cost', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'reference' => 'AssetRateReminder', + 'place_holder' => 'the next rate of [appliance_type_name] ( . [remaining] . ) is due on [due_date]', + 'body' => 'the next rate of [appliance_type_name] ( . [remaining] . ) is due on [due_date]', + 'variables' => 'appliance_type_name,remaining,due_date', + 'title' => 'Appliance Payment Reminder', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'reference' => 'AssetRatePayment', + 'place_holder' => 'Appliance: [appliance_type_name] [amount]', + 'body' => 'Appliance: [appliance_type_name] [amount]', + 'variables' => 'appliance_type_name,amount', + 'title' => 'Appliance Payment', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'reference' => 'OverdueAssetRateReminder', + 'place_holder' => 'you forgot to pay the rate of [appliance_type_name] ( [remaining] ) on [due_date]. Please pay it as soon as possible, unless you wont be able to buy energy.', + 'body' => 'you forgot to pay the rate of [appliance_type_name] ( [remaining] ) on [due_date]. Please pay it as soon as possible, unless you wont be able to buy energy.', + 'variables' => 'appliance_type_name,remaining,due_date', + 'title' => 'Overdue Appliance Payment Reminder', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'reference' => 'PricingDetails', + 'place_holder' => 'Transaction amount is [amount], \n VAT for energy : [vat_energy] \n VAT for the other staffs : [vat_others] . ', + 'body' => 'Transaction amount is [amount], \n VAT for energy : [vat_energy] \n VAT for the other staffs : [vat_others] . ', + 'variables' => 'amount,vat_energy,vat_others', + 'title' => 'Pricing Details', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'reference' => 'ResendInformation', + 'place_holder' => 'Meter: [meter] , [token] Unit [energy] KWH. Service Charge: [amount]', + 'body' => 'Meter: [meter] , [token] Unit [energy] KWH. Service Charge: [amount]', + 'variables' => 'meter,token,energy,amount', + 'title' => 'Resend Last Transaction Information', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'reference' => 'ResendInformationLastTransactionNotFound', + 'place_holder' => 'Last transaction information not found for Meter: [meter]', + 'body' => 'Last transaction information not found for Meter: [meter]', + 'variables' => 'meter', + 'title' => 'Last Transaction Information Not Found', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'reference' => 'SmsReminderFooter', + 'place_holder' => 'Your Company etc.', + 'body' => 'Your Company etc.', + 'variables' => '', + 'title' => 'Sms Footer', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'reference' => 'SmsTransactionFooter', + 'place_holder' => 'Your Company etc.', + 'body' => 'Your Company etc.', + 'variables' => '', + 'title' => 'Sms Footer', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + [ + 'reference' => 'SmsResendInformationFooter', + 'place_holder' => 'Your Company etc.', + 'body' => 'Your Company etc.', + 'variables' => '', + 'title' => 'Sms Footer', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ], + ] ); } @@ -160,8 +160,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('sms_bodies'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_02_18_153556_create_sms_resend_information_keys.php b/src/backend/database/migrations/micropowermanager/2021_02_18_153556_create_sms_resend_information_keys.php index 9a80c7383..68d7d38b2 100644 --- a/src/backend/database/migrations/micropowermanager/2021_02_18_153556_create_sms_resend_information_keys.php +++ b/src/backend/database/migrations/micropowermanager/2021_02_18_153556_create_sms_resend_information_keys.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('sms_resend_information_keys', function (Blueprint $table) { $table->increments('id'); $table->string('key')->default('Resend'); @@ -32,8 +31,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('sms_resend_information_keys'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_02_18_156421_create_sms_appliance_remind_rates.php b/src/backend/database/migrations/micropowermanager/2021_02_18_156421_create_sms_appliance_remind_rates.php index 8ebddbbd0..1e9515978 100644 --- a/src/backend/database/migrations/micropowermanager/2021_02_18_156421_create_sms_appliance_remind_rates.php +++ b/src/backend/database/migrations/micropowermanager/2021_02_18_156421_create_sms_appliance_remind_rates.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('sms_appliance_remind_rates', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('appliance_type_id'); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('sms_appliance_remind_rates'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_03_03_140758_create_sms_android_settings.php b/src/backend/database/migrations/micropowermanager/2021_03_03_140758_create_sms_android_settings.php index fb89c99c4..d0a1414b2 100644 --- a/src/backend/database/migrations/micropowermanager/2021_03_03_140758_create_sms_android_settings.php +++ b/src/backend/database/migrations/micropowermanager/2021_03_03_140758_create_sms_android_settings.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('sms_android_settings', function (Blueprint $table) { $table->increments('id'); $table->string('url')->default('https://fcm.googleapis.com/fcm/send'); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('sms_android_settings'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_03_03_141706_create_sms_variable_default_values.php b/src/backend/database/migrations/micropowermanager/2021_03_03_141706_create_sms_variable_default_values.php index c4a52ea02..2b6ccc954 100644 --- a/src/backend/database/migrations/micropowermanager/2021_03_03_141706_create_sms_variable_default_values.php +++ b/src/backend/database/migrations/micropowermanager/2021_03_03_141706_create_sms_variable_default_values.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('sms_variable_default_values', function (Blueprint $table) { $table->id(); $table->string('variable'); @@ -102,8 +101,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('sms_variable_default_values'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_03_2_1561251_update_sms_table.php b/src/backend/database/migrations/micropowermanager/2021_03_2_1561251_update_sms_table.php index e86d97b26..cfa0c6d67 100644 --- a/src/backend/database/migrations/micropowermanager/2021_03_2_1561251_update_sms_table.php +++ b/src/backend/database/migrations/micropowermanager/2021_03_2_1561251_update_sms_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('sms', function (Blueprint $table) { $table->integer('status')->default(0)->change(); $table->integer('sender_id')->nullable()->change(); @@ -26,9 +25,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('sms', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('sms', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_04_28_103758_add_additional_json_column_to_people.php b/src/backend/database/migrations/micropowermanager/2021_04_28_103758_add_additional_json_column_to_people.php index 1aa2de05f..35e43531b 100644 --- a/src/backend/database/migrations/micropowermanager/2021_04_28_103758_add_additional_json_column_to_people.php +++ b/src/backend/database/migrations/micropowermanager/2021_04_28_103758_add_additional_json_column_to_people.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('people', function (Blueprint $table) { $table->json('additional_json')->nullable(); }); @@ -22,9 +21,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('people', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('people', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_04_28_104840_create_person_documents_table.php b/src/backend/database/migrations/micropowermanager/2021_04_28_104840_create_person_documents_table.php index 665872e34..b3d88ae7a 100644 --- a/src/backend/database/migrations/micropowermanager/2021_04_28_104840_create_person_documents_table.php +++ b/src/backend/database/migrations/micropowermanager/2021_04_28_104840_create_person_documents_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('person_documents', function (Blueprint $table) { $table->id(); $table->unsignedInteger('person_id'); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('person_documents'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_06_04_085817_update_meter_consumptions_table.php b/src/backend/database/migrations/micropowermanager/2021_06_04_085817_update_meter_consumptions_table.php index 82894766f..dc26ea7f8 100644 --- a/src/backend/database/migrations/micropowermanager/2021_06_04_085817_update_meter_consumptions_table.php +++ b/src/backend/database/migrations/micropowermanager/2021_06_04_085817_update_meter_consumptions_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { if (!Type::hasType('double')) { Type::addType('double', FloatType::class); } @@ -28,9 +27,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('meter_consumptions', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('meter_consumptions', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_08_17_090801_add_down_payment_to_asset_people_table.php b/src/backend/database/migrations/micropowermanager/2021_08_17_090801_add_down_payment_to_asset_people_table.php index 24351a0b9..f5affa6cc 100644 --- a/src/backend/database/migrations/micropowermanager/2021_08_17_090801_add_down_payment_to_asset_people_table.php +++ b/src/backend/database/migrations/micropowermanager/2021_08_17_090801_add_down_payment_to_asset_people_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('asset_people', function (Blueprint $table) { $table->double('down_payment')->nullable(); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('asset_people', function (Blueprint $table) { $table->dropColumn('down_payment'); }); diff --git a/src/backend/database/migrations/micropowermanager/2021_08_17_090913_add_first_payment_date_to_asset_people_table.php b/src/backend/database/migrations/micropowermanager/2021_08_17_090913_add_first_payment_date_to_asset_people_table.php index 6c7f61835..d4b70d375 100644 --- a/src/backend/database/migrations/micropowermanager/2021_08_17_090913_add_first_payment_date_to_asset_people_table.php +++ b/src/backend/database/migrations/micropowermanager/2021_08_17_090913_add_first_payment_date_to_asset_people_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('asset_people', function (Blueprint $table) { $table->date('first_payment_date')->nullable(); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('asset_people', function (Blueprint $table) { $table->dropColumn('first_payment_date'); }); diff --git a/src/backend/database/migrations/micropowermanager/2021_09_07_092522_create_cash_transactions_table.php b/src/backend/database/migrations/micropowermanager/2021_09_07_092522_create_cash_transactions_table.php index 0256a7245..2c0459995 100644 --- a/src/backend/database/migrations/micropowermanager/2021_09_07_092522_create_cash_transactions_table.php +++ b/src/backend/database/migrations/micropowermanager/2021_09_07_092522_create_cash_transactions_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('cash_transactions', function (Blueprint $table) { $table->id(); $table->unsignedInteger('user_id'); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('cash_transactions'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2021_10_18_220817_create_mail_settings.php b/src/backend/database/migrations/micropowermanager/2021_10_18_220817_create_mail_settings.php index 6373909e0..8f2a06710 100644 --- a/src/backend/database/migrations/micropowermanager/2021_10_18_220817_create_mail_settings.php +++ b/src/backend/database/migrations/micropowermanager/2021_10_18_220817_create_mail_settings.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('mail_settings', function (Blueprint $table) { $table->increments('id'); $table->string('mail_host'); @@ -40,8 +39,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('mail_settings'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2022_05_10_093215_update_meter_tariffs_table.php b/src/backend/database/migrations/micropowermanager/2022_05_10_093215_update_meter_tariffs_table.php index 090871dfe..a67b550e7 100644 --- a/src/backend/database/migrations/micropowermanager/2022_05_10_093215_update_meter_tariffs_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_05_10_093215_update_meter_tariffs_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { if (!Type::hasType('double')) { Type::addType('double', FloatType::class); } @@ -28,9 +27,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('meter_tariffs', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('meter_tariffs', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2022_05_10_101348_update_social_tariffs_table.php b/src/backend/database/migrations/micropowermanager/2022_05_10_101348_update_social_tariffs_table.php index 13d36c8b2..324cb9611 100644 --- a/src/backend/database/migrations/micropowermanager/2022_05_10_101348_update_social_tariffs_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_05_10_101348_update_social_tariffs_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { if (!Type::hasType('double')) { Type::addType('double', FloatType::class); } @@ -28,9 +27,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('social_tariffs', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('social_tariffs', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2022_05_10_101616_update_tariff_pricing_components_table.php b/src/backend/database/migrations/micropowermanager/2022_05_10_101616_update_tariff_pricing_components_table.php index 4914cdc55..189d2b7ed 100644 --- a/src/backend/database/migrations/micropowermanager/2022_05_10_101616_update_tariff_pricing_components_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_05_10_101616_update_tariff_pricing_components_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { if (!Type::hasType('double')) { Type::addType('double', FloatType::class); } @@ -27,9 +26,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('tariff_pricing_components', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('tariff_pricing_components', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2022_05_10_101855_update_social_tariff_piggy_banks_table.php b/src/backend/database/migrations/micropowermanager/2022_05_10_101855_update_social_tariff_piggy_banks_table.php index f60fdb177..ff02eef43 100644 --- a/src/backend/database/migrations/micropowermanager/2022_05_10_101855_update_social_tariff_piggy_banks_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_05_10_101855_update_social_tariff_piggy_banks_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { if (!Type::hasType('double')) { Type::addType('double', FloatType::class); } @@ -27,9 +26,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('social_tariff_piggy_banks', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('social_tariff_piggy_banks', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2022_05_10_102047_update_access_rates_table.php b/src/backend/database/migrations/micropowermanager/2022_05_10_102047_update_access_rates_table.php index 126e93461..13b2c47f3 100644 --- a/src/backend/database/migrations/micropowermanager/2022_05_10_102047_update_access_rates_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_05_10_102047_update_access_rates_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { if (!Type::hasType('double')) { Type::addType('double', FloatType::class); } @@ -27,9 +26,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('access_rates', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('access_rates', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2022_05_10_102214_update_access_rate_payments_table.php b/src/backend/database/migrations/micropowermanager/2022_05_10_102214_update_access_rate_payments_table.php index 41259c14f..4fa3addf1 100644 --- a/src/backend/database/migrations/micropowermanager/2022_05_10_102214_update_access_rate_payments_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_05_10_102214_update_access_rate_payments_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { if (!Type::hasType('double')) { Type::addType('double', FloatType::class); } @@ -28,9 +27,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('access_rate_payments', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('access_rate_payments', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2022_05_10_102507_update_asset_people_table.php b/src/backend/database/migrations/micropowermanager/2022_05_10_102507_update_asset_people_table.php index 3a25f7e40..e26cf09df 100644 --- a/src/backend/database/migrations/micropowermanager/2022_05_10_102507_update_asset_people_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_05_10_102507_update_asset_people_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { if (!Type::hasType('double')) { Type::addType('double', FloatType::class); } @@ -27,9 +26,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('asset_people', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('asset_people', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2022_05_10_102649_update_transactions_table.php b/src/backend/database/migrations/micropowermanager/2022_05_10_102649_update_transactions_table.php index 4157a34b6..e5ee75d8e 100644 --- a/src/backend/database/migrations/micropowermanager/2022_05_10_102649_update_transactions_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_05_10_102649_update_transactions_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { if (!Type::hasType('double')) { Type::addType('double', FloatType::class); } @@ -27,9 +26,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('transactions', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('transactions', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2022_05_10_102805_update_payment_histories_table.php b/src/backend/database/migrations/micropowermanager/2022_05_10_102805_update_payment_histories_table.php index 9e55c4370..04c9ae4ff 100644 --- a/src/backend/database/migrations/micropowermanager/2022_05_10_102805_update_payment_histories_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_05_10_102805_update_payment_histories_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { if (!Type::hasType('double')) { Type::addType('double', FloatType::class); } @@ -27,9 +26,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('payment_histories', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('payment_histories', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2022_05_19_102938_update_asset_types_table.php b/src/backend/database/migrations/micropowermanager/2022_05_19_102938_update_asset_types_table.php index 685ac3089..f5a8e54f6 100644 --- a/src/backend/database/migrations/micropowermanager/2022_05_19_102938_update_asset_types_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_05_19_102938_update_asset_types_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { if (!Type::hasType('double')) { Type::addType('double', FloatType::class); } @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('asset_types', function (Blueprint $table) { $table->integer('price')->unsigned()->nullable()->change(); }); diff --git a/src/backend/database/migrations/micropowermanager/2022_05_23_104138_add_connection_column_to_agents_table.php b/src/backend/database/migrations/micropowermanager/2022_05_23_104138_add_connection_column_to_agents_table.php index a9374728b..51558d492 100644 --- a/src/backend/database/migrations/micropowermanager/2022_05_23_104138_add_connection_column_to_agents_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_05_23_104138_add_connection_column_to_agents_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('agents', function (Blueprint $table) { $table->string('connection'); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('agents', function (Blueprint $table) { $table->dropColumn('connection'); }); diff --git a/src/backend/database/migrations/micropowermanager/2022_06_21_090125_create_calin_tables.php b/src/backend/database/migrations/micropowermanager/2022_06_21_090125_create_calin_tables.php index 650ee27f5..0027e12e6 100644 --- a/src/backend/database/migrations/micropowermanager/2022_06_21_090125_create_calin_tables.php +++ b/src/backend/database/migrations/micropowermanager/2022_06_21_090125_create_calin_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::hasTable('calin_api_credentials')) { Schema::connection('shard')->create('calin_api_credentials', static function (Blueprint $table) { $table->increments('id'); @@ -24,8 +23,7 @@ public function up() } } - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('calin_api_credentials'); Schema::connection('shard')->dropIfExists('calin_transactions'); } diff --git a/src/backend/database/migrations/micropowermanager/2022_06_21_090327_create_calin_smart_tables.php b/src/backend/database/migrations/micropowermanager/2022_06_21_090327_create_calin_smart_tables.php index 0cbffde97..e743c64d7 100644 --- a/src/backend/database/migrations/micropowermanager/2022_06_21_090327_create_calin_smart_tables.php +++ b/src/backend/database/migrations/micropowermanager/2022_06_21_090327_create_calin_smart_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::hasTable('calin_smart_api_credentials')) { Schema::connection('shard')->create('calin_smart_api_credentials', static function (Blueprint $table) { $table->increments('id'); @@ -26,8 +25,7 @@ public function up() } } - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('calin_smart_api_credentials'); Schema::connection('shard')->dropIfExists('calin_smart_transactions'); } diff --git a/src/backend/database/migrations/micropowermanager/2022_06_21_090338_create_kelin_tables.php b/src/backend/database/migrations/micropowermanager/2022_06_21_090338_create_kelin_tables.php index b0c7decd2..cddeafdfa 100644 --- a/src/backend/database/migrations/micropowermanager/2022_06_21_090338_create_kelin_tables.php +++ b/src/backend/database/migrations/micropowermanager/2022_06_21_090338_create_kelin_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::hasTable('kelin_api_credentials')) { Schema::connection('shard')->create('kelin_api_credentials', static function (Blueprint $table) { $table->increments('id'); @@ -158,8 +157,7 @@ public function up() } } - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('kelin_api_credentials'); Schema::connection('shard')->dropIfExists('kelin_customers'); Schema::connection('shard')->dropIfExists('kelin_meters'); diff --git a/src/backend/database/migrations/micropowermanager/2022_06_21_090345_create_mesomb_payment_provider_tables.php b/src/backend/database/migrations/micropowermanager/2022_06_21_090345_create_mesomb_payment_provider_tables.php index df8f72421..74d68aa74 100644 --- a/src/backend/database/migrations/micropowermanager/2022_06_21_090345_create_mesomb_payment_provider_tables.php +++ b/src/backend/database/migrations/micropowermanager/2022_06_21_090345_create_mesomb_payment_provider_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::hasTable('mesomb_transactions')) { Schema::connection('shard')->create('mesomb_transactions', static function (Blueprint $table) { $table->increments('id'); @@ -26,8 +25,7 @@ public function up() } } - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('mesomb_transactions'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2022_06_21_090351_create_spark_tables.php b/src/backend/database/migrations/micropowermanager/2022_06_21_090351_create_spark_tables.php index c5fae50c0..756176cb4 100644 --- a/src/backend/database/migrations/micropowermanager/2022_06_21_090351_create_spark_tables.php +++ b/src/backend/database/migrations/micropowermanager/2022_06_21_090351_create_spark_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::hasTable('sm_api_credentials')) { Schema::connection('shard')->create('sm_api_credentials', static function (Blueprint $table) { $table->increments('id'); @@ -193,8 +192,7 @@ public function up() } } - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('sm_api_credentials'); Schema::connection('shard')->dropIfExists('sm_customers'); Schema::connection('shard')->dropIfExists('sm_meter_models'); diff --git a/src/backend/database/migrations/micropowermanager/2022_06_21_090402_create_steama_tables.php b/src/backend/database/migrations/micropowermanager/2022_06_21_090402_create_steama_tables.php index b6264ceac..e1e7cebcd 100644 --- a/src/backend/database/migrations/micropowermanager/2022_06_21_090402_create_steama_tables.php +++ b/src/backend/database/migrations/micropowermanager/2022_06_21_090402_create_steama_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::hasTable('steama_agents')) { Schema::connection('shard')->create('steama_agents', function (Blueprint $table) { $table->increments('id'); @@ -296,8 +295,7 @@ public function up() } } - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('steama_agents'); Schema::connection('shard')->dropIfExists('steama_asset_rates_payment_plans'); Schema::connection('shard')->dropIfExists('steama_credentials'); diff --git a/src/backend/database/migrations/micropowermanager/2022_06_21_090412_create_stron_tables.php b/src/backend/database/migrations/micropowermanager/2022_06_21_090412_create_stron_tables.php index 8c1e7343f..c554938f3 100644 --- a/src/backend/database/migrations/micropowermanager/2022_06_21_090412_create_stron_tables.php +++ b/src/backend/database/migrations/micropowermanager/2022_06_21_090412_create_stron_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::hasTable('stron_api_credentials')) { Schema::connection('shard')->create('stron_api_credentials', static function (Blueprint $table) { $table->increments('id'); @@ -27,8 +26,7 @@ public function up() } } - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('stron_api_credentials'); Schema::connection('shard')->dropIfExists('stron_transactions'); } diff --git a/src/backend/database/migrations/micropowermanager/2022_06_21_090425_create_swifta_payment_provider_tables.php b/src/backend/database/migrations/micropowermanager/2022_06_21_090425_create_swifta_payment_provider_tables.php index 39905bf5c..64b57be1a 100644 --- a/src/backend/database/migrations/micropowermanager/2022_06_21_090425_create_swifta_payment_provider_tables.php +++ b/src/backend/database/migrations/micropowermanager/2022_06_21_090425_create_swifta_payment_provider_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::hasTable('swifta_transactions')) { Schema::connection('shard')->create('swifta_transactions', static function (Blueprint $table) { $table->increments('id'); @@ -30,8 +29,7 @@ public function up() } } - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('swifta_transactions'); Schema::connection('shard')->dropIfExists('swifta_authentication'); } diff --git a/src/backend/database/migrations/micropowermanager/2022_07_05_092948_create_registration_tail_table.php b/src/backend/database/migrations/micropowermanager/2022_07_05_092948_create_registration_tail_table.php index c0f14af3e..7e25d1143 100644 --- a/src/backend/database/migrations/micropowermanager/2022_07_05_092948_create_registration_tail_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_07_05_092948_create_registration_tail_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('registration_tail', function (Blueprint $table) { $table->id(); $table->json('tail'); @@ -25,8 +24,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('registration_tail'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2022_07_20_101605_create_ticketing_tables.php b/src/backend/database/migrations/micropowermanager/2022_07_20_101605_create_ticketing_tables.php index d2b4655c1..6175d8bce 100644 --- a/src/backend/database/migrations/micropowermanager/2022_07_20_101605_create_ticketing_tables.php +++ b/src/backend/database/migrations/micropowermanager/2022_07_20_101605_create_ticketing_tables.php @@ -4,15 +4,13 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreateTicketingTables extends Migration -{ +class CreateTicketingTables extends Migration { /** * Run the migrations. * * @return void */ - public function up() - { + public function up() { $tableNames = config('tickets.table_names'); Schema::connection('shard')->create($tableNames['ticket'], function (Blueprint $table) { @@ -73,8 +71,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { $tableNames = config('tickets.table_names'); Schema::connection('shard')->drop($tableNames['ticket']); Schema::connection('shard')->drop($tableNames['user']); diff --git a/src/backend/database/migrations/micropowermanager/2022_09_20_0000000_create_bulk_registration_tables.php b/src/backend/database/migrations/micropowermanager/2022_09_20_0000000_create_bulk_registration_tables.php index 5d4adeaeb..7125abd6d 100644 --- a/src/backend/database/migrations/micropowermanager/2022_09_20_0000000_create_bulk_registration_tables.php +++ b/src/backend/database/migrations/micropowermanager/2022_09_20_0000000_create_bulk_registration_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::connection('shard')->hasTable('bulk_registration_csv_datas')) { Schema::connection('shard')->create('bulk_registration_csv_datas', function (Blueprint $table) { $table->increments('id'); @@ -18,8 +17,7 @@ public function up() } } - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('bulk_registration_csv_datas'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2022_10_27_130327_add_direction_column_to_sms_table.php b/src/backend/database/migrations/micropowermanager/2022_10_27_130327_add_direction_column_to_sms_table.php index 34ad352e9..68b8513ad 100644 --- a/src/backend/database/migrations/micropowermanager/2022_10_27_130327_add_direction_column_to_sms_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_10_27_130327_add_direction_column_to_sms_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('sms', function (Blueprint $table) { $table->integer('direction')->default(1); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('sms', function (Blueprint $table) { $table->dropColumn('direction'); }); diff --git a/src/backend/database/migrations/micropowermanager/2022_10_27_140945_add_gateway_id_column_to_sms_table.php b/src/backend/database/migrations/micropowermanager/2022_10_27_140945_add_gateway_id_column_to_sms_table.php index ce2821e1d..5de4cf783 100644 --- a/src/backend/database/migrations/micropowermanager/2022_10_27_140945_add_gateway_id_column_to_sms_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_10_27_140945_add_gateway_id_column_to_sms_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('sms', function (Blueprint $table) { $table->integer('gateway_id')->nullable(); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('sms', function (Blueprint $table) { $table->dropColumn('gateway_id'); }); diff --git a/src/backend/database/migrations/micropowermanager/2022_10_27_142123_add_dispatched_column_to_sms_table.php b/src/backend/database/migrations/micropowermanager/2022_10_27_142123_add_dispatched_column_to_sms_table.php index 02e97429d..ff1e93bf2 100644 --- a/src/backend/database/migrations/micropowermanager/2022_10_27_142123_add_dispatched_column_to_sms_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_10_27_142123_add_dispatched_column_to_sms_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('sms', function (Blueprint $table) { $table->integer('dispatched')->default(-1); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('sms', function (Blueprint $table) { $table->dropColumn('dispatched'); }); diff --git a/src/backend/database/migrations/micropowermanager/2022_10_27_142319_add_attempts_column_to_sms_table.php b/src/backend/database/migrations/micropowermanager/2022_10_27_142319_add_attempts_column_to_sms_table.php index d8da6df80..efed405fd 100644 --- a/src/backend/database/migrations/micropowermanager/2022_10_27_142319_add_attempts_column_to_sms_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_10_27_142319_add_attempts_column_to_sms_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('sms', function (Blueprint $table) { $table->integer('attempts')->default(0); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('sms', function (Blueprint $table) { $table->dropColumn('attempts'); }); diff --git a/src/backend/database/migrations/micropowermanager/2022_11_08_0000000_create_viber_messaging_tables.php b/src/backend/database/migrations/micropowermanager/2022_11_08_0000000_create_viber_messaging_tables.php index 48c5c383c..a60981c21 100644 --- a/src/backend/database/migrations/micropowermanager/2022_11_08_0000000_create_viber_messaging_tables.php +++ b/src/backend/database/migrations/micropowermanager/2022_11_08_0000000_create_viber_messaging_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::hasTable('viber_credentials')) { Schema::connection('shard')->create('viber_credentials', static function (Blueprint $table) { $table->increments('id'); @@ -35,8 +34,7 @@ public function up() } } - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('viber_credentials'); Schema::connection('shard')->dropIfExists('viber_messages'); Schema::connection('shard')->dropIfExists('viber_contacts'); diff --git a/src/backend/database/migrations/micropowermanager/2022_11_14_101338_add_minimum_purchase_amount_to_meter_tariffs_table.php b/src/backend/database/migrations/micropowermanager/2022_11_14_101338_add_minimum_purchase_amount_to_meter_tariffs_table.php index 1bb868b51..21ae5c66a 100644 --- a/src/backend/database/migrations/micropowermanager/2022_11_14_101338_add_minimum_purchase_amount_to_meter_tariffs_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_11_14_101338_add_minimum_purchase_amount_to_meter_tariffs_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('meter_tariffs', function (Blueprint $table) { $table->double('minimum_purchase_amount')->default(0); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('meter_tariffs', function (Blueprint $table) { $table->dropColumn('minimum_purchase_amount'); }); diff --git a/src/backend/database/migrations/micropowermanager/2022_11_21_000000_create_wave_money_payment_provider_tables.php b/src/backend/database/migrations/micropowermanager/2022_11_21_000000_create_wave_money_payment_provider_tables.php index c2fd8756c..9ddb42d6d 100644 --- a/src/backend/database/migrations/micropowermanager/2022_11_21_000000_create_wave_money_payment_provider_tables.php +++ b/src/backend/database/migrations/micropowermanager/2022_11_21_000000_create_wave_money_payment_provider_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::hasTable('wave_money_transactions')) { Schema::connection('shard')->create('wave_money_transactions', static function (Blueprint $table) { $table->increments('id'); @@ -36,8 +35,7 @@ public function up() } } - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('wave_money_transactions'); Schema::connection('shard')->dropIfExists('wave_money_credentials'); } diff --git a/src/backend/database/migrations/micropowermanager/2022_11_29_000000_create_micro_star_tables.php b/src/backend/database/migrations/micropowermanager/2022_11_29_000000_create_micro_star_tables.php index f8d27f2e2..cc401dca1 100644 --- a/src/backend/database/migrations/micropowermanager/2022_11_29_000000_create_micro_star_tables.php +++ b/src/backend/database/migrations/micropowermanager/2022_11_29_000000_create_micro_star_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::hasTable('micro_star_api_credentials')) { Schema::connection('shard')->create('micro_star_api_credentials', static function (Blueprint $table) { $table->increments('id'); @@ -26,8 +25,7 @@ public function up() } } - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('micro_star_api_credentials'); Schema::connection('shard')->dropIfExists('micro_star_transactions'); } diff --git a/src/backend/database/migrations/micropowermanager/2022_12_11_000000_update_swifta_authentication_table.php b/src/backend/database/migrations/micropowermanager/2022_12_11_000000_update_swifta_authentication_table.php index dc6cb7525..e94d44582 100644 --- a/src/backend/database/migrations/micropowermanager/2022_12_11_000000_update_swifta_authentication_table.php +++ b/src/backend/database/migrations/micropowermanager/2022_12_11_000000_update_swifta_authentication_table.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { if (!Type::hasType('token')) { Type::addType('token', FloatType::class); } @@ -27,9 +26,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('swifta_authentication', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('swifta_authentication', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2022_14_12_create_sun_king_tables.php b/src/backend/database/migrations/micropowermanager/2022_14_12_create_sun_king_tables.php index 2836b3223..c0b0f1331 100644 --- a/src/backend/database/migrations/micropowermanager/2022_14_12_create_sun_king_tables.php +++ b/src/backend/database/migrations/micropowermanager/2022_14_12_create_sun_king_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::connection('shard')->hasTable('sun_king_api_credentials')) { Schema::connection('shard')->create('sun_king_api_credentials', static function (Blueprint $table) { $table->increments('id'); @@ -27,8 +26,7 @@ public function up() } } - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('sun_king_api_credentials'); Schema::connection('shard')->dropIfExists('sun_king_transactions'); } diff --git a/src/backend/database/migrations/micropowermanager/2023_03_15_092048_add_colums_to_solars_table.php b/src/backend/database/migrations/micropowermanager/2023_03_15_092048_add_colums_to_solars_table.php index 011ac4f62..1e4b95516 100644 --- a/src/backend/database/migrations/micropowermanager/2023_03_15_092048_add_colums_to_solars_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_03_15_092048_add_colums_to_solars_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('solars', function (Blueprint $table) { $table->integer('frequency')->nullable(); $table->double('pv_power')->nullable(); @@ -25,8 +24,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('solars', function (Blueprint $table) { $table->dropColumn('frequency'); $table->dropColumn('pv_power'); diff --git a/src/backend/database/migrations/micropowermanager/2023_03_16_105024_update_solars_table.php b/src/backend/database/migrations/micropowermanager/2023_03_16_105024_update_solars_table.php index 8e54b500f..1bfc816a1 100644 --- a/src/backend/database/migrations/micropowermanager/2023_03_16_105024_update_solars_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_03_16_105024_update_solars_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('solars', function (Blueprint $table) { $table->renameColumn('storage_file_name', 'storage_folder')->change(); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('solars', function (Blueprint $table) { $table->renameColumn('storage_folder', 'storage_file_name')->change(); }); diff --git a/src/backend/database/migrations/micropowermanager/2023_03_17_234630_update_data_type_values_energies_table.php b/src/backend/database/migrations/micropowermanager/2023_03_17_234630_update_data_type_values_energies_table.php index 5e05ddd44..27d7aed40 100644 --- a/src/backend/database/migrations/micropowermanager/2023_03_17_234630_update_data_type_values_energies_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_03_17_234630_update_data_type_values_energies_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('energies', function (Blueprint $table) { $table->double('used_energy_since_last', 15, 2)->default(0)->change(); $table->double('total_absorbed', 15, 2)->default(0)->change(); @@ -24,9 +23,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('energies', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('energies', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2023_03_18_014305_update_data_type_values_energies_table.php b/src/backend/database/migrations/micropowermanager/2023_03_18_014305_update_data_type_values_energies_table.php index cc2b7a167..3bd1255de 100644 --- a/src/backend/database/migrations/micropowermanager/2023_03_18_014305_update_data_type_values_energies_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_03_18_014305_update_data_type_values_energies_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('energies', function (Blueprint $table) { $table->double('used_energy_since_last', 8, 4)->default(0)->change(); $table->double('total_absorbed', 8, 4)->default(0)->change(); @@ -24,9 +23,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('energies', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('energies', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2023_04_02_121811_create_wavecom_tables.php b/src/backend/database/migrations/micropowermanager/2023_04_02_121811_create_wavecom_tables.php index 245fa7a8b..d4a681161 100644 --- a/src/backend/database/migrations/micropowermanager/2023_04_02_121811_create_wavecom_tables.php +++ b/src/backend/database/migrations/micropowermanager/2023_04_02_121811_create_wavecom_tables.php @@ -7,8 +7,7 @@ return new class extends Migration { private const TABLE_NAME = 'wavecom_transactions'; - public function up() - { + public function up() { if (!Schema::hasTable(self::TABLE_NAME)) { Schema::create(self::TABLE_NAME, function (Blueprint $table) { $table->increments('id'); @@ -22,8 +21,7 @@ public function up() } } - public function down() - { + public function down() { Schema::dropIfExists(self::TABLE_NAME); } }; diff --git a/src/backend/database/migrations/micropowermanager/2023_04_04_211421_add_api_type_to_table_transactions.php b/src/backend/database/migrations/micropowermanager/2023_04_04_211421_add_api_type_to_table_transactions.php index 2358fd0b9..a6d9d78a9 100644 --- a/src/backend/database/migrations/micropowermanager/2023_04_04_211421_add_api_type_to_table_transactions.php +++ b/src/backend/database/migrations/micropowermanager/2023_04_04_211421_add_api_type_to_table_transactions.php @@ -9,8 +9,7 @@ * * @return void */ - public function up() - { + public function up() { DB::statement("ALTER TABLE transactions MODIFY COLUMN type ENUM('energy','deferred_payment','unknown','imported','3rd party api sync')"); } @@ -19,8 +18,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { DB::statement("ALTER TABLE transactions MODIFY COLUMN type ENUM('energy','deferred_payment','unknown')"); } }; diff --git a/src/backend/database/migrations/micropowermanager/2023_04_26_223352_update_sms_table.php b/src/backend/database/migrations/micropowermanager/2023_04_26_223352_update_sms_table.php index 4c46c099e..f1f9e50a4 100644 --- a/src/backend/database/migrations/micropowermanager/2023_04_26_223352_update_sms_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_04_26_223352_update_sms_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('sms', function (Blueprint $table) { $table->string('uuid', 50)->change(); $table->dropColumn('attempts'); @@ -24,8 +23,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('sms', function (Blueprint $table) { $table->string('uuid')->change(); $table->integer('attempts')->default(0); diff --git a/src/backend/database/migrations/micropowermanager/2023_06_02_create_gome_long_tables.php b/src/backend/database/migrations/micropowermanager/2023_06_02_create_gome_long_tables.php index 71d96f441..adc406044 100644 --- a/src/backend/database/migrations/micropowermanager/2023_06_02_create_gome_long_tables.php +++ b/src/backend/database/migrations/micropowermanager/2023_06_02_create_gome_long_tables.php @@ -7,8 +7,7 @@ // Despite the migration's name, this migration was actually created on Feb 6h // Name should be 2023-02-06 not 2023-06-02... return new class extends Migration { - public function up() - { + public function up() { if (!Schema::hasTable('gome_long_api_credentials')) { Schema::create('gome_long_api_credentials', static function (Blueprint $table) { $table->increments('id'); @@ -37,8 +36,7 @@ public function up() } } - public function down() - { + public function down() { Schema::dropIfExists('gome_long_api_credentials'); Schema::dropIfExists('gome_long_transactions'); Schema::dropIfExists('gome_long_tariffs'); diff --git a/src/backend/database/migrations/micropowermanager/2023_09_25_232731_update_assets_asset_people_asset_types_tables.php b/src/backend/database/migrations/micropowermanager/2023_09_25_232731_update_assets_asset_people_asset_types_tables.php index c729cdd8b..bf262eae8 100644 --- a/src/backend/database/migrations/micropowermanager/2023_09_25_232731_update_assets_asset_people_asset_types_tables.php +++ b/src/backend/database/migrations/micropowermanager/2023_09_25_232731_update_assets_asset_people_asset_types_tables.php @@ -12,8 +12,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('asset_types', function (Blueprint $table) { $table->dropColumn('price'); }); @@ -34,8 +33,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('agent_assigned_appliances', function (Blueprint $table) { $table->renameColumn('appliance_id', 'appliance_type_id'); }); diff --git a/src/backend/database/migrations/micropowermanager/2023_09_28_130619_update_sms_appliance_remind_rates_table.php b/src/backend/database/migrations/micropowermanager/2023_09_28_130619_update_sms_appliance_remind_rates_table.php index 6182a8d76..a68fe70cd 100644 --- a/src/backend/database/migrations/micropowermanager/2023_09_28_130619_update_sms_appliance_remind_rates_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_09_28_130619_update_sms_appliance_remind_rates_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('sms_appliance_remind_rates', function (Blueprint $table) { $table->renameColumn('appliance_type_id', 'appliance_id'); }); @@ -22,7 +21,5 @@ public function up() * * @return void */ - public function down() - { - } + public function down() {} }; diff --git a/src/backend/database/migrations/micropowermanager/2023_10_25_074114_update_wavecom_wavemoney_tables.php b/src/backend/database/migrations/micropowermanager/2023_10_25_074114_update_wavecom_wavemoney_tables.php index 78b331283..f3ea808b3 100644 --- a/src/backend/database/migrations/micropowermanager/2023_10_25_074114_update_wavecom_wavemoney_tables.php +++ b/src/backend/database/migrations/micropowermanager/2023_10_25_074114_update_wavecom_wavemoney_tables.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('wave_money_transactions', function (Blueprint $table) { $table->string('manufacturer_transaction_type')->nullable(); $table->integer('manufacturer_transaction_id')->nullable(); @@ -28,7 +27,5 @@ public function up() * * @return void */ - public function down() - { - } + public function down() {} }; diff --git a/src/backend/database/migrations/micropowermanager/2023_11_03_112202_create_devices_table.php b/src/backend/database/migrations/micropowermanager/2023_11_03_112202_create_devices_table.php index 45ac7b542..7cdb45688 100644 --- a/src/backend/database/migrations/micropowermanager/2023_11_03_112202_create_devices_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_11_03_112202_create_devices_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('devices', function (Blueprint $table) { $table->id(); $table->integer('person_id')->unsigned(); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('devices'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2023_11_03_120614_create_solar_home_systems_table.php b/src/backend/database/migrations/micropowermanager/2023_11_03_120614_create_solar_home_systems_table.php index bfa0ee70a..312111634 100644 --- a/src/backend/database/migrations/micropowermanager/2023_11_03_120614_create_solar_home_systems_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_11_03_120614_create_solar_home_systems_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('solar_home_systems', function (Blueprint $table) { $table->id(); $table->string('serial_number'); @@ -25,8 +24,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('solar_home_systems'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2023_11_03_121740_add_configuration_columns_to_meters_table.php b/src/backend/database/migrations/micropowermanager/2023_11_03_121740_add_configuration_columns_to_meters_table.php index 4bfc16837..fcb7274e9 100644 --- a/src/backend/database/migrations/micropowermanager/2023_11_03_121740_add_configuration_columns_to_meters_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_11_03_121740_add_configuration_columns_to_meters_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('meters', function (Blueprint $table) { $table->integer('connection_type_id'); $table->integer('connection_group_id'); @@ -24,8 +23,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('meters', function (Blueprint $table) { $table->dropColumn('connection_type_id'); $table->dropColumn('connection_group_id'); diff --git a/src/backend/database/migrations/micropowermanager/2023_11_11_142307_update_action_field_type_logs_table.php b/src/backend/database/migrations/micropowermanager/2023_11_11_142307_update_action_field_type_logs_table.php index 2fe634fb0..4937e342a 100644 --- a/src/backend/database/migrations/micropowermanager/2023_11_11_142307_update_action_field_type_logs_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_11_11_142307_update_action_field_type_logs_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('logs', function (Blueprint $table) { $table->text('action')->change(); }); @@ -22,7 +21,5 @@ public function up() * * @return void */ - public function down() - { - } + public function down() {} }; diff --git a/src/backend/database/migrations/micropowermanager/2023_11_14_160711_drop_geo_id_column_from_address_table.php b/src/backend/database/migrations/micropowermanager/2023_11_14_160711_drop_geo_id_column_from_address_table.php index c0df218ad..2602dd77b 100644 --- a/src/backend/database/migrations/micropowermanager/2023_11_14_160711_drop_geo_id_column_from_address_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_11_14_160711_drop_geo_id_column_from_address_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('addresses', function (Blueprint $table) { $table->dropColumn('geo_id'); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('addresses', function (Blueprint $table) { $table->integer('geo_id')->nullable(); }); diff --git a/src/backend/database/migrations/micropowermanager/2023_11_16_175649_add_type_column_to_manufacturers_table.php b/src/backend/database/migrations/micropowermanager/2023_11_16_175649_add_type_column_to_manufacturers_table.php index ac84bc87c..eba7bc7b9 100644 --- a/src/backend/database/migrations/micropowermanager/2023_11_16_175649_add_type_column_to_manufacturers_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_11_16_175649_add_type_column_to_manufacturers_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('manufacturers', function (Blueprint $table) { $table->enum('type', ['meter', 'shs', 'e-bike'])->default('meter')->after('id'); }); @@ -22,9 +21,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('manufacturers', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('manufacturers', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2023_11_16_175940_add_asset_id_column_to_solar_home_systems_table.php b/src/backend/database/migrations/micropowermanager/2023_11_16_175940_add_asset_id_column_to_solar_home_systems_table.php index 88cc96d66..5ddbe8217 100644 --- a/src/backend/database/migrations/micropowermanager/2023_11_16_175940_add_asset_id_column_to_solar_home_systems_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_11_16_175940_add_asset_id_column_to_solar_home_systems_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('solar_home_systems', function (Blueprint $table) { $table->integer('asset_id')->after('id'); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('solar_home_systems', function (Blueprint $table) { $table->dropColumn('asset_id'); }); diff --git a/src/backend/database/migrations/micropowermanager/2023_11_16_220432_update_person_id_column_in_devices_table.php b/src/backend/database/migrations/micropowermanager/2023_11_16_220432_update_person_id_column_in_devices_table.php index 6d6301440..62b2b741d 100644 --- a/src/backend/database/migrations/micropowermanager/2023_11_16_220432_update_person_id_column_in_devices_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_11_16_220432_update_person_id_column_in_devices_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('devices', function (Blueprint $table) { $table->integer('person_id')->nullable()->change(); }); @@ -22,9 +21,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('devices', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('devices', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2023_11_16_220931_update_device_serial_column_in_devices_table.php b/src/backend/database/migrations/micropowermanager/2023_11_16_220931_update_device_serial_column_in_devices_table.php index bbbd60767..30b8b1f37 100644 --- a/src/backend/database/migrations/micropowermanager/2023_11_16_220931_update_device_serial_column_in_devices_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_11_16_220931_update_device_serial_column_in_devices_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('devices', function (Blueprint $table) { $table->string('device_serial')->unique()->change(); }); @@ -22,9 +21,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('devices', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('devices', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2023_11_16_221111_update_serial_number_column_in_solar_home_systems_table.php b/src/backend/database/migrations/micropowermanager/2023_11_16_221111_update_serial_number_column_in_solar_home_systems_table.php index 2ee59cbb8..810432eb1 100644 --- a/src/backend/database/migrations/micropowermanager/2023_11_16_221111_update_serial_number_column_in_solar_home_systems_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_11_16_221111_update_serial_number_column_in_solar_home_systems_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('solar_home_systems', function (Blueprint $table) { $table->string('serial_number')->unique()->change(); }); @@ -22,9 +21,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('solar_home_systems', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('solar_home_systems', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2023_11_17_095204_create_tokens_table.php b/src/backend/database/migrations/micropowermanager/2023_11_17_095204_create_tokens_table.php index a96a4b81a..4f038d9da 100644 --- a/src/backend/database/migrations/micropowermanager/2023_11_17_095204_create_tokens_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_11_17_095204_create_tokens_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('tokens', function (Blueprint $table) { $table->increments('id'); $table->integer('transaction_id')->unique(); @@ -26,8 +25,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('tokens'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2023_11_18_190332_add_device_serial_column_to_asset_people_table.php b/src/backend/database/migrations/micropowermanager/2023_11_18_190332_add_device_serial_column_to_asset_people_table.php index f082d21e1..9ef0f4219 100644 --- a/src/backend/database/migrations/micropowermanager/2023_11_18_190332_add_device_serial_column_to_asset_people_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_11_18_190332_add_device_serial_column_to_asset_people_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('asset_people', function (Blueprint $table) { $table->string('device_serial'); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('asset_people', function (Blueprint $table) { $table->dropColumn('device_serial'); }); diff --git a/src/backend/database/migrations/micropowermanager/2023_11_21_090129_update_derice_serial_column_in_asset_people_table.php b/src/backend/database/migrations/micropowermanager/2023_11_21_090129_update_derice_serial_column_in_asset_people_table.php index 2b6e6169d..afd86cd01 100644 --- a/src/backend/database/migrations/micropowermanager/2023_11_21_090129_update_derice_serial_column_in_asset_people_table.php +++ b/src/backend/database/migrations/micropowermanager/2023_11_21_090129_update_derice_serial_column_in_asset_people_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('asset_people', function (Blueprint $table) { $table->string('device_serial')->nullable()->default(null)->change(); }); @@ -22,9 +21,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('asset_people', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('asset_people', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2024_01_01_create_daly_bms_tables.php b/src/backend/database/migrations/micropowermanager/2024_01_01_create_daly_bms_tables.php index af89ef270..162e9183c 100644 --- a/src/backend/database/migrations/micropowermanager/2024_01_01_create_daly_bms_tables.php +++ b/src/backend/database/migrations/micropowermanager/2024_01_01_create_daly_bms_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::hasTable('daly_bms_api_credentials')) { Schema::create('daly_bms_api_credentials', static function (Blueprint $table) { $table->increments('id'); @@ -26,8 +25,7 @@ public function up() } } - public function down() - { + public function down() { Schema::dropIfExists('daly_bms_api_credentials'); Schema::dropIfExists('daly_bms_transactions'); } diff --git a/src/backend/database/migrations/micropowermanager/2024_01_02_124146_create_e_bikes_table.php b/src/backend/database/migrations/micropowermanager/2024_01_02_124146_create_e_bikes_table.php index c600d582c..5855600d9 100644 --- a/src/backend/database/migrations/micropowermanager/2024_01_02_124146_create_e_bikes_table.php +++ b/src/backend/database/migrations/micropowermanager/2024_01_02_124146_create_e_bikes_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->create('e_bikes', function (Blueprint $table) { $table->id(); $table->string('serial_number')->unique(); @@ -35,8 +34,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('e_bikes'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2024_01_12_create_angaza_tables.php b/src/backend/database/migrations/micropowermanager/2024_01_12_create_angaza_tables.php index 78200f4b5..3d8bfb2eb 100644 --- a/src/backend/database/migrations/micropowermanager/2024_01_12_create_angaza_tables.php +++ b/src/backend/database/migrations/micropowermanager/2024_01_12_create_angaza_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::connection('shard')->hasTable('angaza_api_credentials')) { Schema::connection('shard')->create('angaza_api_credentials', static function (Blueprint $table) { $table->increments('id'); @@ -24,8 +23,7 @@ public function up() } } - public function down() - { + public function down() { Schema::connection('shard')->dropIfExists('angaza_api_credentials'); Schema::connection('shard')->dropIfExists('angaza_transactions'); } diff --git a/src/backend/database/migrations/micropowermanager/2024_02_07_102305_add_usage_type_column_to_main_settings_table.php b/src/backend/database/migrations/micropowermanager/2024_02_07_102305_add_usage_type_column_to_main_settings_table.php index 10aa435b6..2da63c1b9 100644 --- a/src/backend/database/migrations/micropowermanager/2024_02_07_102305_add_usage_type_column_to_main_settings_table.php +++ b/src/backend/database/migrations/micropowermanager/2024_02_07_102305_add_usage_type_column_to_main_settings_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('main_settings', function (Blueprint $table) { $table->enum('usage_type', [ 'mini-grid', @@ -30,9 +29,7 @@ public function up() * * @return void */ - public function down() - { - Schema::connection('shard')->table('main_settings', function (Blueprint $table) { - }); + public function down() { + Schema::connection('shard')->table('main_settings', function (Blueprint $table) {}); } }; diff --git a/src/backend/database/migrations/micropowermanager/2024_02_07_113710_add_usage_type_column_to_menu_items_table.php b/src/backend/database/migrations/micropowermanager/2024_02_07_113710_add_usage_type_column_to_menu_items_table.php index d16cd7fb9..a21a58d3f 100644 --- a/src/backend/database/migrations/micropowermanager/2024_02_07_113710_add_usage_type_column_to_menu_items_table.php +++ b/src/backend/database/migrations/micropowermanager/2024_02_07_113710_add_usage_type_column_to_menu_items_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('menu_items', function (Blueprint $table) { $table->string('usage_type')->default('general')->after('id'); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('menu_items', function (Blueprint $table) { $table->dropColumn('usage_type'); }); diff --git a/src/backend/database/migrations/micropowermanager/2024_09_30_113302_remove_siderbar_tables.php b/src/backend/database/migrations/micropowermanager/2024_09_30_113302_remove_siderbar_tables.php index 3d7fe14f9..9ad61ab47 100644 --- a/src/backend/database/migrations/micropowermanager/2024_09_30_113302_remove_siderbar_tables.php +++ b/src/backend/database/migrations/micropowermanager/2024_09_30_113302_remove_siderbar_tables.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->dropIfExists('menu_items'); Schema::connection('shard')->dropIfExists('sub_menu_items'); } @@ -21,8 +20,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->create('menu_items', function (Blueprint $table) { $table->increments('id'); $table->string('usage_type', 191)->default('general'); diff --git a/src/backend/database/migrations/micropowermanager/2024_10_23_153042_add_amount_to_agent_charge.php b/src/backend/database/migrations/micropowermanager/2024_10_23_153042_add_amount_to_agent_charge.php index a0f9ed99e..5ca3589dc 100644 --- a/src/backend/database/migrations/micropowermanager/2024_10_23_153042_add_amount_to_agent_charge.php +++ b/src/backend/database/migrations/micropowermanager/2024_10_23_153042_add_amount_to_agent_charge.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('agent_charges', function (Blueprint $table) { $table->float('amount')->after('user_id'); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('agent_charges', function (Blueprint $table) { $table->dropColumn('amount'); }); diff --git a/src/backend/database/migrations/micropowermanager/2024_10_30_154625_create_notifications_table.php b/src/backend/database/migrations/micropowermanager/2024_10_30_154625_create_notifications_table.php index 3d6cbf7f8..65e602e12 100644 --- a/src/backend/database/migrations/micropowermanager/2024_10_30_154625_create_notifications_table.php +++ b/src/backend/database/migrations/micropowermanager/2024_10_30_154625_create_notifications_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::create('notifications', function (Blueprint $table) { $table->uuid('id')->primary(); $table->string('type'); @@ -27,8 +26,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::dropIfExists('notifications'); } }; diff --git a/src/backend/database/migrations/micropowermanager/2024_10_31_180458_remove_batteries_table.php b/src/backend/database/migrations/micropowermanager/2024_10_31_180458_remove_batteries_table.php index 4da0bd72e..bf62b709b 100644 --- a/src/backend/database/migrations/micropowermanager/2024_10_31_180458_remove_batteries_table.php +++ b/src/backend/database/migrations/micropowermanager/2024_10_31_180458_remove_batteries_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->dropIfExists('batteries'); } @@ -20,8 +19,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->create('batteries', function (Blueprint $table) { $table->increments('id'); $table->integer('mini_grid_id'); diff --git a/src/backend/database/migrations/micropowermanager/2024_10_31_180510_remove_energies_table.php b/src/backend/database/migrations/micropowermanager/2024_10_31_180510_remove_energies_table.php index 55994d8e8..a48fb5063 100644 --- a/src/backend/database/migrations/micropowermanager/2024_10_31_180510_remove_energies_table.php +++ b/src/backend/database/migrations/micropowermanager/2024_10_31_180510_remove_energies_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->dropIfExists('energies'); } @@ -20,8 +19,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->create('energies', function (Blueprint $table) { $table->increments('id'); $table->integer('mini_grid_id'); diff --git a/src/backend/database/migrations/micropowermanager/2024_10_31_180524_remove_mini_grid_frequencies_table.php b/src/backend/database/migrations/micropowermanager/2024_10_31_180524_remove_mini_grid_frequencies_table.php index 4a350e0eb..9e39a0e35 100644 --- a/src/backend/database/migrations/micropowermanager/2024_10_31_180524_remove_mini_grid_frequencies_table.php +++ b/src/backend/database/migrations/micropowermanager/2024_10_31_180524_remove_mini_grid_frequencies_table.php @@ -9,8 +9,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->dropIfExists('mini_grid_frequencies'); } @@ -19,8 +18,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { // This table never had any migration files and hence never existed // on fresh installations of MPM. } diff --git a/src/backend/database/migrations/micropowermanager/2024_10_31_180539_remove_pvs_table.php b/src/backend/database/migrations/micropowermanager/2024_10_31_180539_remove_pvs_table.php index 3b6fb8e94..f14e497ee 100644 --- a/src/backend/database/migrations/micropowermanager/2024_10_31_180539_remove_pvs_table.php +++ b/src/backend/database/migrations/micropowermanager/2024_10_31_180539_remove_pvs_table.php @@ -11,8 +11,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->dropIfExists('p_v_s'); } @@ -21,8 +20,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->create('p_v_s', function (Blueprint $table) { $table->bigIncrements('id'); $table->integer('mini_grid_id'); diff --git a/src/backend/database/migrations/micropowermanager/2024_10_31_180546_remove_solars_table.php b/src/backend/database/migrations/micropowermanager/2024_10_31_180546_remove_solars_table.php index 87b6114b5..94b958d24 100644 --- a/src/backend/database/migrations/micropowermanager/2024_10_31_180546_remove_solars_table.php +++ b/src/backend/database/migrations/micropowermanager/2024_10_31_180546_remove_solars_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->dropIfExists('solars'); } @@ -20,8 +19,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->create('solars', function (Blueprint $table) { $table->increments('id'); $table->integer('mini_grid_id'); diff --git a/src/backend/database/migrations/micropowermanager/2024_10_31_180605_remove_weather_data_table.php b/src/backend/database/migrations/micropowermanager/2024_10_31_180605_remove_weather_data_table.php index 35d582874..a14ba4d5a 100644 --- a/src/backend/database/migrations/micropowermanager/2024_10_31_180605_remove_weather_data_table.php +++ b/src/backend/database/migrations/micropowermanager/2024_10_31_180605_remove_weather_data_table.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->dropIfExists('weather_data'); } @@ -20,8 +19,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->create('weather_data', static function (Blueprint $table) { $table->increments('id'); $table->integer('solar_id'); diff --git a/src/backend/database/migrations/micropowermanager/2024_10_31_180852_remove_agent_tickets.php b/src/backend/database/migrations/micropowermanager/2024_10_31_180852_remove_agent_tickets.php index d81b62db0..9b433c424 100644 --- a/src/backend/database/migrations/micropowermanager/2024_10_31_180852_remove_agent_tickets.php +++ b/src/backend/database/migrations/micropowermanager/2024_10_31_180852_remove_agent_tickets.php @@ -9,8 +9,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->dropIfExists('agent_tickets'); } @@ -19,8 +18,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { // This table never had any migration files and hence never existed // on fresh installations of MPM. } diff --git a/src/backend/database/migrations/micropowermanager/2024_10_31_181016_remove_city_clusters.php b/src/backend/database/migrations/micropowermanager/2024_10_31_181016_remove_city_clusters.php index afc95f4a0..d53d862a1 100644 --- a/src/backend/database/migrations/micropowermanager/2024_10_31_181016_remove_city_clusters.php +++ b/src/backend/database/migrations/micropowermanager/2024_10_31_181016_remove_city_clusters.php @@ -9,8 +9,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->dropIfExists('city_clusters'); } @@ -19,8 +18,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { // This table never had any migration files and hence never existed // on fresh installations of MPM. } diff --git a/src/backend/database/migrations/micropowermanager/2024_11_11_130340_drop_data_stream_column_from_mini_grid.php b/src/backend/database/migrations/micropowermanager/2024_11_11_130340_drop_data_stream_column_from_mini_grid.php index 2f89d59cb..73940c871 100644 --- a/src/backend/database/migrations/micropowermanager/2024_11_11_130340_drop_data_stream_column_from_mini_grid.php +++ b/src/backend/database/migrations/micropowermanager/2024_11_11_130340_drop_data_stream_column_from_mini_grid.php @@ -10,8 +10,7 @@ * * @return void */ - public function up() - { + public function up() { Schema::connection('shard')->table('mini_grids', function (Blueprint $table) { $table->dropColumn('data_stream'); }); @@ -22,8 +21,7 @@ public function up() * * @return void */ - public function down() - { + public function down() { Schema::connection('shard')->table('mini_grids', function (Blueprint $table) { $table->integer('data_stream')->default(0)->after('name'); }); diff --git a/src/backend/database/seeders/AgentSeeder.php b/src/backend/database/seeders/AgentSeeder.php index 595db0c48..00da70d21 100644 --- a/src/backend/database/seeders/AgentSeeder.php +++ b/src/backend/database/seeders/AgentSeeder.php @@ -12,8 +12,7 @@ use Illuminate\Database\Seeder; use MPM\DatabaseProxy\DatabaseProxyManagerService; -class AgentSeeder extends Seeder -{ +class AgentSeeder extends Seeder { public function __construct( private DatabaseProxyManagerService $databaseProxyManagerService, ) { @@ -25,8 +24,7 @@ public function __construct( * * @return void */ - public function run() - { + public function run() { $agentCommission = AgentCommission::factory() ->create(); @@ -38,20 +36,20 @@ public function run() $village = $minigrid->cities()->get()->random(); $person = Person::factory() - ->isAgent($village->name) - ->has( - Address::factory() - ->for($village) - ->has( - GeographicalInformation::factory() - ->state(function (array $attributes, Address $address) { - return ['points' => $address->city->location->points]; - }) - ->randomizePointsInVillage(), - 'geo' - ) - ) - ->create(); + ->isAgent($village->name) + ->has( + Address::factory() + ->for($village) + ->has( + GeographicalInformation::factory() + ->state(function (array $attributes, Address $address) { + return ['points' => $address->city->location->points]; + }) + ->randomizePointsInVillage(), + 'geo' + ) + ) + ->create(); $agent = Agent::factory() ->for($minigrid) diff --git a/src/backend/database/seeders/ClusterSeeder.php b/src/backend/database/seeders/ClusterSeeder.php index 6aba9fc63..5c1e60572 100644 --- a/src/backend/database/seeders/ClusterSeeder.php +++ b/src/backend/database/seeders/ClusterSeeder.php @@ -10,8 +10,7 @@ use Illuminate\Database\Seeder; use MPM\DatabaseProxy\DatabaseProxyManagerService; -class ClusterSeeder extends Seeder -{ +class ClusterSeeder extends Seeder { public function __construct( private DatabaseProxyManagerService $databaseProxyManagerService, ) { @@ -23,8 +22,7 @@ public function __construct( * * @return void */ - public function run() - { + public function run() { $clusterAdmin = User::factory() ->clusterAdmin() ->create(); diff --git a/src/backend/database/seeders/CustomerSeeder.php b/src/backend/database/seeders/CustomerSeeder.php index 88a1e2022..ca7303b69 100644 --- a/src/backend/database/seeders/CustomerSeeder.php +++ b/src/backend/database/seeders/CustomerSeeder.php @@ -9,8 +9,7 @@ use Illuminate\Database\Seeder; use MPM\DatabaseProxy\DatabaseProxyManagerService; -class CustomerSeeder extends Seeder -{ +class CustomerSeeder extends Seeder { public function __construct( private DatabaseProxyManagerService $databaseProxyManagerService, ) { @@ -22,29 +21,28 @@ public function __construct( * * @return void */ - public function run() - { + public function run() { // Get available Villages $villages = City::all(); // For each Village generate customers foreach ($villages as $village) { Person::factory() - ->count(50) - ->isCustomer() - ->has( - Address::factory() - ->for($village) - ->has( - GeographicalInformation::factory() - ->state(function (array $attributes, Address $address) { - return ['points' => $address->city->location->points]; - }) - ->randomizePointsInVillage(), - 'geo' - ) - ) - ->create(); + ->count(50) + ->isCustomer() + ->has( + Address::factory() + ->for($village) + ->has( + GeographicalInformation::factory() + ->state(function (array $attributes, Address $address) { + return ['points' => $address->city->location->points]; + }) + ->randomizePointsInVillage(), + 'geo' + ) + ) + ->create(); } } } diff --git a/src/backend/database/seeders/DatabaseSeeder.php b/src/backend/database/seeders/DatabaseSeeder.php index ef2badd5f..be04116aa 100644 --- a/src/backend/database/seeders/DatabaseSeeder.php +++ b/src/backend/database/seeders/DatabaseSeeder.php @@ -4,15 +4,13 @@ use Illuminate\Database\Seeder; -class DatabaseSeeder extends Seeder -{ +class DatabaseSeeder extends Seeder { /** * Run the database seeds. * * @return void */ - public function run() - { + public function run() { $this->call([ TenantSeeder::class, ClusterSeeder::class, diff --git a/src/backend/database/seeders/MeterSeeder.php b/src/backend/database/seeders/MeterSeeder.php index 9b87ff906..6490e1a09 100644 --- a/src/backend/database/seeders/MeterSeeder.php +++ b/src/backend/database/seeders/MeterSeeder.php @@ -16,8 +16,7 @@ use Illuminate\Database\Seeder; use MPM\DatabaseProxy\DatabaseProxyManagerService; -class MeterSeeder extends Seeder -{ +class MeterSeeder extends Seeder { public function __construct( private DatabaseProxyManagerService $databaseProxyManagerService, ) { @@ -29,8 +28,7 @@ public function __construct( * * @return void */ - public function run() - { + public function run() { // Manufacturer // Here, we adding some dummy Manufacturers for seeding. // Additional (actual) manufacturers can be added by diff --git a/src/backend/database/seeders/SolarHomeSystemSeeder.php b/src/backend/database/seeders/SolarHomeSystemSeeder.php index e9505edd5..8bbf50f45 100644 --- a/src/backend/database/seeders/SolarHomeSystemSeeder.php +++ b/src/backend/database/seeders/SolarHomeSystemSeeder.php @@ -10,8 +10,7 @@ use Illuminate\Database\Seeder; use MPM\DatabaseProxy\DatabaseProxyManagerService; -class SolarHomeSystemSeeder extends Seeder -{ +class SolarHomeSystemSeeder extends Seeder { public function __construct( private DatabaseProxyManagerService $databaseProxyManagerService, ) { @@ -23,8 +22,7 @@ public function __construct( * * @return void */ - public function run() - { + public function run() { // Manufacturer // Here, we adding some dummy Manufacturers for seeding. // Additional (actual) manufacturers can be added by diff --git a/src/backend/database/seeders/TenantSeeder.php b/src/backend/database/seeders/TenantSeeder.php index 640786320..c3ca9d37a 100644 --- a/src/backend/database/seeders/TenantSeeder.php +++ b/src/backend/database/seeders/TenantSeeder.php @@ -29,8 +29,7 @@ 'name' => 'Dummy Company Admin', ]; -class TenantSeeder extends Seeder -{ +class TenantSeeder extends Seeder { public function __construct( private CompanyDatabaseService $companyDatabaseService, private CompanyService $companyService, @@ -38,16 +37,14 @@ public function __construct( private DatabaseProxyManagerService $databaseProxyManagerService, private RegistrationTailService $registrationTailService, private MainSettingsService $mainSettingsService, - ) { - } + ) {} /** * Run the database seeds. * * @return void */ - public function run() - { + public function run() { // Only proceed if database is empty. // In some seeders we rely on the DummyCompany having id=1. $companies = $this->companyService->getAll(); diff --git a/src/backend/database/seeders/TicketSeeder.php b/src/backend/database/seeders/TicketSeeder.php index 97944fbcb..3af874046 100644 --- a/src/backend/database/seeders/TicketSeeder.php +++ b/src/backend/database/seeders/TicketSeeder.php @@ -6,8 +6,7 @@ use Inensus\Ticket\Models\TicketCategory; use MPM\DatabaseProxy\DatabaseProxyManagerService; -class TicketSeeder extends Seeder -{ +class TicketSeeder extends Seeder { public function __construct( private DatabaseProxyManagerService $databaseProxyManagerService, ) { @@ -19,8 +18,7 @@ public function __construct( * * @return void */ - public function run() - { + public function run() { // Create Ticket categories TicketCategory::newFactory() ->count(2) diff --git a/src/backend/packages/inensus/angaza-shs/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/angaza-shs/src/Console/Commands/InstallPackage.php index 08d373c9e..e3b53fec8 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/angaza-shs/src/Console/Commands/InstallPackage.php @@ -6,9 +6,9 @@ use Inensus\AngazaSHS\Services\AngazaCredentialService; use Inensus\AngazaSHS\Services\ManufacturerService; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'angaza-shs:install'; + protected $description = 'Install AngazaSHS Package'; public function __construct( @@ -18,8 +18,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing AngazaSHS Integration Package\n'); $this->manufacturerService->register(); $this->credentialService->createCredentials(); diff --git a/src/backend/packages/inensus/angaza-shs/src/Exceptions/AngazaApiResponseException.php b/src/backend/packages/inensus/angaza-shs/src/Exceptions/AngazaApiResponseException.php index e39b3dee1..c422c03db 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Exceptions/AngazaApiResponseException.php +++ b/src/backend/packages/inensus/angaza-shs/src/Exceptions/AngazaApiResponseException.php @@ -2,10 +2,8 @@ namespace Inensus\AngazaSHS\Exceptions; -class AngazaApiResponseException extends \Exception -{ - public function __construct($message) - { +class AngazaApiResponseException extends \Exception { + public function __construct($message) { parent::__construct($message); } } diff --git a/src/backend/packages/inensus/angaza-shs/src/Http/Controllers/AngazaCredentialController.php b/src/backend/packages/inensus/angaza-shs/src/Http/Controllers/AngazaCredentialController.php index 27228446b..6061f99a0 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Http/Controllers/AngazaCredentialController.php +++ b/src/backend/packages/inensus/angaza-shs/src/Http/Controllers/AngazaCredentialController.php @@ -7,19 +7,14 @@ use Inensus\AngazaSHS\Http\Resources\AngazaResource; use Inensus\AngazaSHS\Services\AngazaCredentialService; -class AngazaCredentialController extends Controller -{ - public function __construct(private AngazaCredentialService $credentialService) - { - } +class AngazaCredentialController extends Controller { + public function __construct(private AngazaCredentialService $credentialService) {} - public function show(): AngazaResource - { + public function show(): AngazaResource { return AngazaResource::make($this->credentialService->getCredentials()); } - public function update(AngazaCredentialRequest $request): AngazaResource - { + public function update(AngazaCredentialRequest $request): AngazaResource { $credentials = $this->credentialService->getCredentials(); $updateData = $request->only([ 'client_id', diff --git a/src/backend/packages/inensus/angaza-shs/src/Http/Requests/AngazaCredentialRequest.php b/src/backend/packages/inensus/angaza-shs/src/Http/Requests/AngazaCredentialRequest.php index 5d75da699..edd79d0cb 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Http/Requests/AngazaCredentialRequest.php +++ b/src/backend/packages/inensus/angaza-shs/src/Http/Requests/AngazaCredentialRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class AngazaCredentialRequest extends FormRequest -{ +class AngazaCredentialRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'client_id' => ['required'], 'client_secret' => ['required'], diff --git a/src/backend/packages/inensus/angaza-shs/src/Http/Resources/AngazaResource.php b/src/backend/packages/inensus/angaza-shs/src/Http/Resources/AngazaResource.php index 4cd7c6ade..aa7c92501 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Http/Resources/AngazaResource.php +++ b/src/backend/packages/inensus/angaza-shs/src/Http/Resources/AngazaResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class AngazaResource extends JsonResource -{ +class AngazaResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class AngazaResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/packages/inensus/angaza-shs/src/Models/AngazaCredential.php b/src/backend/packages/inensus/angaza-shs/src/Models/AngazaCredential.php index 7665206b3..50b1b41d0 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Models/AngazaCredential.php +++ b/src/backend/packages/inensus/angaza-shs/src/Models/AngazaCredential.php @@ -4,22 +4,18 @@ use App\Models\Base\BaseModel; -class AngazaCredential extends BaseModel -{ +class AngazaCredential extends BaseModel { protected $table = 'angaza_api_credentials'; - public function getClientSecret() - { + public function getClientSecret() { return $this->client_secret; } - public function getClientId() - { + public function getClientId() { return $this->client_id; } - public function getApiUrl() - { + public function getApiUrl() { return $this->api_url; } } diff --git a/src/backend/packages/inensus/angaza-shs/src/Models/AngazaTransaction.php b/src/backend/packages/inensus/angaza-shs/src/Models/AngazaTransaction.php index 7c6de08ea..91c2c1554 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Models/AngazaTransaction.php +++ b/src/backend/packages/inensus/angaza-shs/src/Models/AngazaTransaction.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class AngazaTransaction extends BaseModel -{ +class AngazaTransaction extends BaseModel { protected $table = 'angaza_transactions'; } diff --git a/src/backend/packages/inensus/angaza-shs/src/Modules/Api/AngazaSHSApi.php b/src/backend/packages/inensus/angaza-shs/src/Modules/Api/AngazaSHSApi.php index 90a51e72c..df4ed9672 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Modules/Api/AngazaSHSApi.php +++ b/src/backend/packages/inensus/angaza-shs/src/Modules/Api/AngazaSHSApi.php @@ -12,19 +12,16 @@ use Inensus\AngazaSHS\Models\AngazaTransaction; use Inensus\AngazaSHS\Services\AngazaCredentialService; -class AngazaSHSApi implements IManufacturerAPI -{ +class AngazaSHSApi implements IManufacturerAPI { public const API_CALL_UNIT_CREDIT = '/unit_credit'; public function __construct( private AngazaCredentialService $credentialService, private AngazaTransaction $angazaTransaction, private ApiRequests $apiRequests, - ) { - } + ) {} - public function chargeMeter(TransactionDataContainer $transactionContainer): array - { + public function chargeMeter(TransactionDataContainer $transactionContainer): array { $dayDifferenceBetweenTwoInstallments = $transactionContainer->dayDifferenceBetweenTwoInstallments; $minimumPurchaseAmount = $transactionContainer->installmentCost; $minimumPurchaseAmountPerDay = @@ -84,14 +81,11 @@ public function chargeMeter(TransactionDataContainer $transactionContainer): arr } /** - * @param Meter $meters - * * @return void * * @throws ApiCallDoesNotSupportedException */ - public function clearMeter(Meter $meters) - { + public function clearMeter(Meter $meters) { throw new ApiCallDoesNotSupportedException('This api call does not supported'); } } diff --git a/src/backend/packages/inensus/angaza-shs/src/Modules/Api/ApiRequests.php b/src/backend/packages/inensus/angaza-shs/src/Modules/Api/ApiRequests.php index 0089c9c77..ecf3aa84d 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Modules/Api/ApiRequests.php +++ b/src/backend/packages/inensus/angaza-shs/src/Modules/Api/ApiRequests.php @@ -7,28 +7,27 @@ use Inensus\AngazaSHS\Exceptions\AngazaApiResponseException; use Inensus\AngazaSHS\Models\AngazaCredential; -class ApiRequests -{ +class ApiRequests { public function __construct( private Client $httpClient, - ) { - } + ) {} - public function get(AngazaCredential $credentials, array $params, string $slug) - { + public function get(AngazaCredential $credentials, array $params, string $slug) { $url = $credentials->getApiUrl().$slug; foreach ($params as $key => $value) { $url .= $key.'='.$value.'&'; } try { - $request = $this->httpClient->get($url, + $request = $this->httpClient->get( + $url, [ 'headers' => [ 'Accept' => 'application/json', 'Authorization' => $this->getBasicAuthHeader($credentials), ], - ]); + ] + ); return json_decode((string) $request->getBody(), true); } catch (\Exception $e) { @@ -39,8 +38,7 @@ public function get(AngazaCredential $credentials, array $params, string $slug) } } - public function put(AngazaCredential $credentials, array $params, string $slug) - { + public function put(AngazaCredential $credentials, array $params, string $slug) { $url = $credentials->getApiUrl().$slug; try { $request = $this->httpClient->put( @@ -62,13 +60,13 @@ public function put(AngazaCredential $credentials, array $params, string $slug) 'URL :' => $url, 'Body :' => json_encode($params), 'message :' => $e->getMessage(), - ]); + ] + ); throw new AngazaApiResponseException($e->getMessage()); } } - private function getBasicAuthHeader($credentials) - { + private function getBasicAuthHeader($credentials) { $username = $credentials->getClientId(); $password = $credentials->getClientSecret(); $credentials = $username.':'.$password; diff --git a/src/backend/packages/inensus/angaza-shs/src/Providers/AngazaSHSServiceProvider.php b/src/backend/packages/inensus/angaza-shs/src/Providers/AngazaSHSServiceProvider.php index b0b3de0aa..50321dabb 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Providers/AngazaSHSServiceProvider.php +++ b/src/backend/packages/inensus/angaza-shs/src/Providers/AngazaSHSServiceProvider.php @@ -8,10 +8,8 @@ use Inensus\AngazaSHS\Console\Commands\InstallPackage; use Inensus\AngazaSHS\Modules\Api\AngazaSHSApi; -class AngazaSHSServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class AngazaSHSServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -21,45 +19,42 @@ public function boot(Filesystem $filesystem) } } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/angaza-shs.php', 'angaza-shs'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->bind('AngazaSHSApi', AngazaSHSApi::class); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/angaza-shs.php' => config_path('angaza-shs.php'), ]); } - public function publishVueFiles() - { + public function publishVueFiles() { $this->publishes([ __DIR__.'/../resources/assets' => resource_path('assets/js/plugins/angaza-shs'), ], 'vue-components'); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_angaza_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) ->flatMap(function ($path) use ($filesystem) { if (count($filesystem->glob($path.'*_create_angaza_tables.php'))) { $file = $filesystem->glob($path.'*_create_angaza_tables.php')[0]; - file_put_contents($file, - file_get_contents(__DIR__.'/../../database/migrations/create_angaza_tables.php.stub')); + file_put_contents( + $file, + file_get_contents(__DIR__.'/../../database/migrations/create_angaza_tables.php.stub') + ); } return $filesystem->glob($path.'*_create_angaza_tables.php'); diff --git a/src/backend/packages/inensus/angaza-shs/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/angaza-shs/src/Providers/EventServiceProvider.php index 59a4b23f9..3254a5390 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/angaza-shs/src/Providers/EventServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ ]; @@ -14,8 +13,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/angaza-shs/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/angaza-shs/src/Providers/ObserverServiceProvider.php index 7f32ed28b..288bcb048 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/angaza-shs/src/Providers/ObserverServiceProvider.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/angaza-shs/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/angaza-shs/src/Providers/RouteServiceProvider.php index f4f389b69..85f5324d3 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/angaza-shs/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\AngazaSHS\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/angaza-shs/src/Services/AngazaCredentialService.php b/src/backend/packages/inensus/angaza-shs/src/Services/AngazaCredentialService.php index e63b14d25..6362c5ad1 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Services/AngazaCredentialService.php +++ b/src/backend/packages/inensus/angaza-shs/src/Services/AngazaCredentialService.php @@ -4,43 +4,36 @@ use Inensus\AngazaSHS\Models\AngazaCredential; -class AngazaCredentialService -{ +class AngazaCredentialService { public function __construct( private AngazaCredential $credential, - ) { - } + ) {} /** * This function uses one time on installation of the package. */ - public function createCredentials() - { + public function createCredentials() { return $this->credential->newQuery()->firstOrCreate(['id' => 1], [ 'client_id' => null, 'client_secret' => null, ]); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->first(); } - public function updateCredentials($credentials, $updateData) - { + public function updateCredentials($credentials, $updateData) { $credentials->update($updateData); return $credentials->fresh(); } - public function getById($id) - { + public function getById($id) { return $this->credential->newQuery()->findOrFail($id); } - public function isAccessTokenValid($credential) - { + public function isAccessTokenValid($credential) { $accessToken = $credential->getAccessToken(); if ($accessToken == null) { diff --git a/src/backend/packages/inensus/angaza-shs/src/Services/ManufacturerService.php b/src/backend/packages/inensus/angaza-shs/src/Services/ManufacturerService.php index 5b6179c7c..464edf848 100644 --- a/src/backend/packages/inensus/angaza-shs/src/Services/ManufacturerService.php +++ b/src/backend/packages/inensus/angaza-shs/src/Services/ManufacturerService.php @@ -4,14 +4,10 @@ use App\Models\Manufacturer; -class ManufacturerService -{ - public function __construct(private Manufacturer $manufacturer) - { - } +class ManufacturerService { + public function __construct(private Manufacturer $manufacturer) {} - public function register() - { + public function register() { $api = $this->manufacturer->newQuery()->where('api_name', 'AngazaSHSApi')->first(); if (!$api) { $this->manufacturer->newQuery()->create([ diff --git a/src/backend/packages/inensus/bulk-registration/database/migrations/create_bulk_registration_tables.php b/src/backend/packages/inensus/bulk-registration/database/migrations/create_bulk_registration_tables.php index 987381d2d..c3cabb04d 100644 --- a/src/backend/packages/inensus/bulk-registration/database/migrations/create_bulk_registration_tables.php +++ b/src/backend/packages/inensus/bulk-registration/database/migrations/create_bulk_registration_tables.php @@ -5,8 +5,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - public function up() - { + public function up() { if (!Schema::hasTable('bulk_registration_csv_datas')) { Schema::create('bulk_registration_csv_datas', function (Blueprint $table) { $table->increments('id'); @@ -18,8 +17,7 @@ public function up() } } - public function down() - { + public function down() { Schema::dropIfExists('bulk_registration_csv_datas'); } }; diff --git a/src/backend/packages/inensus/bulk-registration/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/bulk-registration/src/Console/Commands/InstallPackage.php index 9d282dce1..15cfa3191 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/bulk-registration/src/Console/Commands/InstallPackage.php @@ -5,9 +5,9 @@ use Illuminate\Console\Command; use Inensus\BulkRegistration\Services\MeterTypeService; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'bulk-registration:install'; + protected $description = 'Install Bulk Registration Package'; public function __construct( @@ -16,8 +16,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing BulkRegistration Integration Package\n'); $this->meterTypeService->createDefaultMeterTypeIfDoesNotExistAny(); @@ -25,8 +24,7 @@ public function handle(): void $this->info('Package installed successfully..'); } - private function publishConfigurations() - { + private function publishConfigurations() { $this->info('Copying configurations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\BulkRegistration\Providers\BulkRegistrationServiceProvider", @@ -34,8 +32,7 @@ private function publishConfigurations() ]); } - private function publishMigrations() - { + private function publishMigrations() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\BulkRegistration\Providers\BulkRegistrationServiceProvider", @@ -43,14 +40,12 @@ private function publishMigrations() ]); } - private function createDatabaseTables() - { + private function createDatabaseTables() { $this->info('Creating database tables\n'); $this->call('migrate'); } - private function publishVueFiles() - { + private function publishVueFiles() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ @@ -60,8 +55,7 @@ private function publishVueFiles() ]); } - private function createPluginRecord() - { + private function createPluginRecord() { $this->call('plugin:add', [ 'name' => 'BulkRegistration', 'composer_name' => 'inensus/bulk-registration', diff --git a/src/backend/packages/inensus/bulk-registration/src/Console/Commands/UpdatePackage.php b/src/backend/packages/inensus/bulk-registration/src/Console/Commands/UpdatePackage.php index 6685fbf17..5641ccb77 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Console/Commands/UpdatePackage.php +++ b/src/backend/packages/inensus/bulk-registration/src/Console/Commands/UpdatePackage.php @@ -6,9 +6,9 @@ use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Facades\DB; -class UpdatePackage extends Command -{ +class UpdatePackage extends Command { protected $signature = 'bulk-registration:update'; + protected $description = 'Update Bulk Registration Package'; public function __construct( @@ -17,8 +17,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Bulk Registration Updating Started\n'); $this->removeOldVersionOfPackage(); $this->installNewVersionOfPackage(); @@ -32,8 +31,7 @@ public function handle(): void $this->info('Package updated successfully..'); } - private function publishConfigurations() - { + private function publishConfigurations() { $this->info('Copying configurations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\BulkRegistration\Providers\BulkRegistrationServiceProvider", @@ -41,20 +39,17 @@ private function publishConfigurations() ]); } - private function removeOldVersionOfPackage() - { + private function removeOldVersionOfPackage() { $this->info('Removing former version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar remove inensus/bulk-registration'); } - private function installNewVersionOfPackage() - { + private function installNewVersionOfPackage() { $this->info('Installing last version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar require inensus/bulk-registration'); } - private function deleteMigration(Filesystem $filesystem) - { + private function deleteMigration(Filesystem $filesystem) { $migrationFile = $filesystem->glob(database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'*_create_bulk-registration_tables.php')[0]; $migration = DB::table('migrations') ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->first(); @@ -66,8 +61,7 @@ private function deleteMigration(Filesystem $filesystem) ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->delete(); } - private function publishMigrationsAgain() - { + private function publishMigrationsAgain() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\BulkRegistration\Providers\BulkRegistrationServiceProvider", @@ -75,14 +69,12 @@ private function publishMigrationsAgain() ]); } - private function updateDatabase() - { + private function updateDatabase() { $this->info('Updating database tables\n'); $this->call('migrate'); } - private function publishVueFilesAgain() - { + private function publishVueFilesAgain() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\BulkRegistration\Providers\BulkRegistrationServiceProvider", diff --git a/src/backend/packages/inensus/bulk-registration/src/Exceptions/ClusterNotFoundException.php b/src/backend/packages/inensus/bulk-registration/src/Exceptions/ClusterNotFoundException.php index 092c0ee75..ad3f1f299 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Exceptions/ClusterNotFoundException.php +++ b/src/backend/packages/inensus/bulk-registration/src/Exceptions/ClusterNotFoundException.php @@ -2,6 +2,4 @@ namespace Inensus\BulkRegistration\Exceptions; -class ClusterNotFoundException extends MissingDataException -{ -} +class ClusterNotFoundException extends MissingDataException {} diff --git a/src/backend/packages/inensus/bulk-registration/src/Exceptions/CsvDataParserException.php b/src/backend/packages/inensus/bulk-registration/src/Exceptions/CsvDataParserException.php index 3a75722a3..e5e8bcf3c 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Exceptions/CsvDataParserException.php +++ b/src/backend/packages/inensus/bulk-registration/src/Exceptions/CsvDataParserException.php @@ -2,6 +2,4 @@ namespace Inensus\BulkRegistration\Exceptions; -class CsvDataParserException extends \Exception -{ -} +class CsvDataParserException extends \Exception {} diff --git a/src/backend/packages/inensus/bulk-registration/src/Exceptions/GoogleMapsApiException.php b/src/backend/packages/inensus/bulk-registration/src/Exceptions/GoogleMapsApiException.php index 0b206f491..b4bd95f1a 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Exceptions/GoogleMapsApiException.php +++ b/src/backend/packages/inensus/bulk-registration/src/Exceptions/GoogleMapsApiException.php @@ -2,10 +2,8 @@ namespace Inensus\BulkRegistration\Exceptions; -class GoogleMapsApiException extends Exception -{ - public function render($request) - { +class GoogleMapsApiException extends Exception { + public function render($request) { return response()->json([ 'errors' => [ 'code' => 422, diff --git a/src/backend/packages/inensus/bulk-registration/src/Exceptions/Handler.php b/src/backend/packages/inensus/bulk-registration/src/Exceptions/Handler.php index 85c8f657e..a1d6d5d9e 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Exceptions/Handler.php +++ b/src/backend/packages/inensus/bulk-registration/src/Exceptions/Handler.php @@ -5,8 +5,7 @@ use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Spatie\Geocoder\Exceptions\CouldNotGeocode; -class Handler extends ExceptionHandler -{ +class Handler extends ExceptionHandler { /** * A list of the exception types that are not reported. * @@ -28,14 +27,11 @@ class Handler extends ExceptionHandler /** * Report or log an exception. * - * @param \Throwable $exception - * * @return void * * @throws \Exception */ - public function report(\Throwable $exception) - { + public function report(\Throwable $exception) { parent::report($exception); } @@ -43,14 +39,12 @@ public function report(\Throwable $exception) * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request - * @param \Throwable $exception * * @return \Symfony\Component\HttpFoundation\Response * * @throws \Throwable */ - public function render($request, \Throwable $exception) - { + public function render($request, \Throwable $exception) { if ($exception instanceof CouldNotGeocode) { new GoogleMapsApiException(json_encode($exception->errors())); } diff --git a/src/backend/packages/inensus/bulk-registration/src/Exceptions/ManufacturerNotSupportedException.php b/src/backend/packages/inensus/bulk-registration/src/Exceptions/ManufacturerNotSupportedException.php index 96e3416d8..6e1867634 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Exceptions/ManufacturerNotSupportedException.php +++ b/src/backend/packages/inensus/bulk-registration/src/Exceptions/ManufacturerNotSupportedException.php @@ -2,6 +2,4 @@ namespace Inensus\BulkRegistration\Exceptions; -class ManufacturerNotSupportedException extends MissingDataException -{ -} +class ManufacturerNotSupportedException extends MissingDataException {} diff --git a/src/backend/packages/inensus/bulk-registration/src/Exceptions/MiniGridNotFoundException.php b/src/backend/packages/inensus/bulk-registration/src/Exceptions/MiniGridNotFoundException.php index 956684318..1cd8960ed 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Exceptions/MiniGridNotFoundException.php +++ b/src/backend/packages/inensus/bulk-registration/src/Exceptions/MiniGridNotFoundException.php @@ -2,6 +2,4 @@ namespace Inensus\BulkRegistration\Exceptions; -class MiniGridNotFoundException extends MissingDataException -{ -} +class MiniGridNotFoundException extends MissingDataException {} diff --git a/src/backend/packages/inensus/bulk-registration/src/Exceptions/MissingDataException.php b/src/backend/packages/inensus/bulk-registration/src/Exceptions/MissingDataException.php index 7fbfa41f4..b0e06e839 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Exceptions/MissingDataException.php +++ b/src/backend/packages/inensus/bulk-registration/src/Exceptions/MissingDataException.php @@ -2,6 +2,4 @@ namespace Inensus\BulkRegistration\Exceptions; -class MissingDataException extends \Exception -{ -} +class MissingDataException extends \Exception {} diff --git a/src/backend/packages/inensus/bulk-registration/src/Exceptions/VillageNotFoundException.php b/src/backend/packages/inensus/bulk-registration/src/Exceptions/VillageNotFoundException.php index 135be2881..fd7eec95e 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Exceptions/VillageNotFoundException.php +++ b/src/backend/packages/inensus/bulk-registration/src/Exceptions/VillageNotFoundException.php @@ -2,6 +2,4 @@ namespace Inensus\BulkRegistration\Exceptions; -class VillageNotFoundException extends MissingDataException -{ -} +class VillageNotFoundException extends MissingDataException {} diff --git a/src/backend/packages/inensus/bulk-registration/src/Helpers/CsvDataProcessor.php b/src/backend/packages/inensus/bulk-registration/src/Helpers/CsvDataProcessor.php index 3371e87ef..3533acd28 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Helpers/CsvDataProcessor.php +++ b/src/backend/packages/inensus/bulk-registration/src/Helpers/CsvDataProcessor.php @@ -6,15 +6,16 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; -class CsvDataProcessor -{ +class CsvDataProcessor { public const CONNECTION_GROUP = 1; + private $geographicalLocationFinder; + private $reflections; + private $recentlyCreatedRecords; - public function __construct(GeographicalLocationFinder $geographicalLocationFinder) - { + public function __construct(GeographicalLocationFinder $geographicalLocationFinder) { $this->geographicalLocationFinder = $geographicalLocationFinder; $this->reflections = config('bulk-registration.reflections'); $this->recentlyCreatedRecords = [ @@ -29,8 +30,7 @@ public function __construct(GeographicalLocationFinder $geographicalLocationFind ]; } - public function processParsedCsvData($csvData) - { + public function processParsedCsvData($csvData) { Collect($csvData)->each(function ($row) { try { DB::connection('shard')->beginTransaction(); @@ -98,15 +98,13 @@ public function processParsedCsvData($csvData) return $this->recentlyCreatedRecords; } - private function createRecordFromCsv($row, $serviceName) - { + private function createRecordFromCsv($row, $serviceName) { $service = app()->make($serviceName); return $service->resolveCsvDataFromComingRow($row); } - private function checkRecordWasRecentlyCreated($record, $type) - { + private function checkRecordWasRecentlyCreated($record, $type) { if ($record->wasRecentlyCreated) { ++$this->recentlyCreatedRecords[$type]; } diff --git a/src/backend/packages/inensus/bulk-registration/src/Helpers/CsvFileParser.php b/src/backend/packages/inensus/bulk-registration/src/Helpers/CsvFileParser.php index 099f05e88..0db5e0e4a 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Helpers/CsvFileParser.php +++ b/src/backend/packages/inensus/bulk-registration/src/Helpers/CsvFileParser.php @@ -4,17 +4,14 @@ use ParseCsv\Csv; -class CsvFileParser -{ +class CsvFileParser { private $csv; - public function __construct() - { + public function __construct() { $this->csv = new Csv(); } - public function parseCsvFromFilePath($path) - { + public function parseCsvFromFilePath($path) { $this->csv->auto($path); return $this->csv->data; diff --git a/src/backend/packages/inensus/bulk-registration/src/Helpers/GeographicalLocationFinder.php b/src/backend/packages/inensus/bulk-registration/src/Helpers/GeographicalLocationFinder.php index 0c1d8f3b8..bcf1015ae 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Helpers/GeographicalLocationFinder.php +++ b/src/backend/packages/inensus/bulk-registration/src/Helpers/GeographicalLocationFinder.php @@ -4,10 +4,8 @@ use Spatie\Geocoder\Geocoder; -class GeographicalLocationFinder -{ - public function getCoordinatesGivenAddress($address) - { +class GeographicalLocationFinder { + public function getCoordinatesGivenAddress($address) { $client = new \GuzzleHttp\Client(); $geocoder = new Geocoder($client); $geocoder->setApiKey(config('bulk-registration.geocoder.key')); diff --git a/src/backend/packages/inensus/bulk-registration/src/Http/Controllers/ImportCsvController.php b/src/backend/packages/inensus/bulk-registration/src/Http/Controllers/ImportCsvController.php index bf92cb4df..1d5b21314 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Http/Controllers/ImportCsvController.php +++ b/src/backend/packages/inensus/bulk-registration/src/Http/Controllers/ImportCsvController.php @@ -7,18 +7,15 @@ use Inensus\BulkRegistration\Http\Resources\CsvData as CsvDataResource; use Inensus\BulkRegistration\Services\CsvDataService; -class ImportCsvController extends Controller -{ +class ImportCsvController extends Controller { private $csvDataService; - public function __construct(CsvDataService $csvDataService) - { + public function __construct(CsvDataService $csvDataService) { set_time_limit(8000000); $this->csvDataService = $csvDataService; } - public function store(ImportCsvRequest $request) - { + public function store(ImportCsvRequest $request) { return new CsvDataResource($this->csvDataService->create($request)); } } diff --git a/src/backend/packages/inensus/bulk-registration/src/Http/Requests/ImportCsvRequest.php b/src/backend/packages/inensus/bulk-registration/src/Http/Requests/ImportCsvRequest.php index fb470d0e7..036762d3b 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Http/Requests/ImportCsvRequest.php +++ b/src/backend/packages/inensus/bulk-registration/src/Http/Requests/ImportCsvRequest.php @@ -4,25 +4,20 @@ use Illuminate\Foundation\Http\FormRequest; -class ImportCsvRequest extends FormRequest -{ +class ImportCsvRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } /** * Get the validation rules that apply to the request. - * - * @return array */ - public function rules(): array - { + public function rules(): array { return ['csv' => 'required|mimes:csv,txt']; } } diff --git a/src/backend/packages/inensus/bulk-registration/src/Http/Resources/CsvData.php b/src/backend/packages/inensus/bulk-registration/src/Http/Resources/CsvData.php index 4914185d5..b1efaa41d 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Http/Resources/CsvData.php +++ b/src/backend/packages/inensus/bulk-registration/src/Http/Resources/CsvData.php @@ -4,10 +4,8 @@ use Illuminate\Http\Resources\Json\JsonResource; -class CsvData extends JsonResource -{ - public function toArray($request) - { +class CsvData extends JsonResource { + public function toArray($request) { return [ 'data' => [ 'type' => 'csv_data', diff --git a/src/backend/packages/inensus/bulk-registration/src/Models/BaseModel.php b/src/backend/packages/inensus/bulk-registration/src/Models/BaseModel.php index 7d8e10f56..a571ff2ea 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Models/BaseModel.php +++ b/src/backend/packages/inensus/bulk-registration/src/Models/BaseModel.php @@ -4,13 +4,12 @@ use Illuminate\Database\Eloquent\Model; -class BaseModel extends Model -{ +class BaseModel extends Model { protected $guarded = ['id']; + public static $rules = []; - public function resolveChildRouteBinding($childType, $value, $field) - { + public function resolveChildRouteBinding($childType, $value, $field) { // TODO: Implement resolveChildRouteBinding() method. } } diff --git a/src/backend/packages/inensus/bulk-registration/src/Models/CsvData.php b/src/backend/packages/inensus/bulk-registration/src/Models/CsvData.php index 6e58bb289..8e7cfc867 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Models/CsvData.php +++ b/src/backend/packages/inensus/bulk-registration/src/Models/CsvData.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class CsvData extends BaseModel -{ +class CsvData extends BaseModel { protected $table = 'bulk_registration_csv_datas'; } diff --git a/src/backend/packages/inensus/bulk-registration/src/Providers/BulkRegistrationServiceProvider.php b/src/backend/packages/inensus/bulk-registration/src/Providers/BulkRegistrationServiceProvider.php index 9012af2ed..94bb54c75 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Providers/BulkRegistrationServiceProvider.php +++ b/src/backend/packages/inensus/bulk-registration/src/Providers/BulkRegistrationServiceProvider.php @@ -8,10 +8,8 @@ use Inensus\BulkRegistration\Console\Commands\InstallPackage; use Inensus\BulkRegistration\Console\Commands\UpdatePackage; -class BulkRegistrationServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class BulkRegistrationServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -21,10 +19,11 @@ public function boot(Filesystem $filesystem) } } - public function register() - { - $this->mergeConfigFrom(__DIR__.'/../../config/bulk-registration.php', - 'bulk-registration'); + public function register() { + $this->mergeConfigFrom( + __DIR__.'/../../config/bulk-registration.php', + 'bulk-registration' + ); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); /* $this->app->bind(GeographicalLocationFinder::class,function($app){ @@ -32,38 +31,37 @@ public function register() });*/ } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/bulk-registration.php' => config_path('bulk-registration.php'), ], 'configurations'); } - public function publishVueFiles() - { + public function publishVueFiles() { $this->publishes([ - __DIR__.'/../resources/assets' => resource_path('assets/js/plugins/bulk-registration' + __DIR__.'/../resources/assets' => resource_path( + 'assets/js/plugins/bulk-registration' ), ], 'vue-components'); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_bulk_registration_tables.php' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) ->flatMap(function ($path) use ($filesystem) { if (count($filesystem->glob($path.'*_create_bulk-registration_tables.php'))) { $file = $filesystem->glob($path.'*_create_bulk-registration_tables.php')[0]; - file_put_contents($file, - file_get_contents(__DIR__.'/../../database/migrations/create_bulk_registration_tables.php')); + file_put_contents( + $file, + file_get_contents(__DIR__.'/../../database/migrations/create_bulk_registration_tables.php') + ); } return $filesystem->glob($path.'*_create_bulk-registration_tables.php'); diff --git a/src/backend/packages/inensus/bulk-registration/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/bulk-registration/src/Providers/EventServiceProvider.php index ffc1a4a0e..8e4be4e8b 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/bulk-registration/src/Providers/EventServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ ]; @@ -14,8 +13,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/bulk-registration/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/bulk-registration/src/Providers/ObserverServiceProvider.php index 5a2a517c9..7678526ff 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/bulk-registration/src/Providers/ObserverServiceProvider.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/bulk-registration/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/bulk-registration/src/Providers/RouteServiceProvider.php index f6aa8ae52..0e0ef405e 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/bulk-registration/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\BulkRegistration\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/AddressService.php b/src/backend/packages/inensus/bulk-registration/src/Services/AddressService.php index 066865143..e8af4a097 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/AddressService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/AddressService.php @@ -4,22 +4,18 @@ use App\Models\Address\Address; -class AddressService extends CreatorService -{ - public function __construct(Address $address) - { +class AddressService extends CreatorService { + public function __construct(Address $address) { parent::__construct($address); } - public function createRelatedDataIfDoesNotExists($addresses) - { + public function createRelatedDataIfDoesNotExists($addresses) { foreach ($addresses as $address) { Address::query()->firstOrCreate($address, $address); } } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $addressConfig = config('bulk-registration.csv_fields.address'); $returnAddresses = []; $firstAddressData = [ @@ -43,8 +39,7 @@ public function resolveCsvDataFromComingRow($csvData) $this->createRelatedDataIfDoesNotExists($returnAddresses); } - public function createForPerson(int $personId, int $cityId, ?string $phone, ?string $email, ?string $street, bool $isPrimary): Address - { + public function createForPerson(int $personId, int $cityId, ?string $phone, ?string $email, ?string $street, bool $isPrimary): Address { $address = new Address(); $address->setOwner($personId, 'person'); $address->setCityId($cityId); diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/ApplianceTypeService.php b/src/backend/packages/inensus/bulk-registration/src/Services/ApplianceTypeService.php index a145f3a48..3d2c65a04 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/ApplianceTypeService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/ApplianceTypeService.php @@ -4,22 +4,18 @@ use App\Models\AssetType; -class ApplianceTypeService extends CreatorService -{ - public function __construct(AssetType $assetType) - { +class ApplianceTypeService extends CreatorService { + public function __construct(AssetType $assetType) { parent::__construct($assetType); } - public function createRelatedDataIfDoesNotExists($appliances) - { + public function createRelatedDataIfDoesNotExists($appliances) { foreach ($appliances as $appliance) { AssetType::query()->firstOrCreate($appliance, $appliance); } } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $applianceTypeConfig = config('bulk-registration.csv_fields.appliance_type'); $applianceTypes = config('bulk-registration.appliance_types'); diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/CityService.php b/src/backend/packages/inensus/bulk-registration/src/Services/CityService.php index 690d62dea..e04e29255 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/CityService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/CityService.php @@ -5,15 +5,12 @@ use App\Models\City; use Inensus\BulkRegistration\Exceptions\VillageNotFoundException; -class CityService extends CreatorService -{ - public function __construct(City $city) - { +class CityService extends CreatorService { + public function __construct(City $city) { parent::__construct($city); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $cityConfig = config('bulk-registration.csv_fields.city'); if (!$csvData[$cityConfig['name']]) { diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/ClusterService.php b/src/backend/packages/inensus/bulk-registration/src/Services/ClusterService.php index bfde714e2..5954a180d 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/ClusterService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/ClusterService.php @@ -6,15 +6,12 @@ use App\Models\User; use Inensus\BulkRegistration\Exceptions\ClusterNotFoundException; -class ClusterService extends CreatorService -{ - public function __construct(Cluster $cluster) - { +class ClusterService extends CreatorService { + public function __construct(Cluster $cluster) { parent::__construct($cluster); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $clusterConfig = config('bulk-registration.csv_fields.cluster'); if (!$csvData[$clusterConfig['name']]) { diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/ConnectionGroupService.php b/src/backend/packages/inensus/bulk-registration/src/Services/ConnectionGroupService.php index 410e717d1..4df46eae0 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/ConnectionGroupService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/ConnectionGroupService.php @@ -4,15 +4,12 @@ use App\Models\ConnectionGroup; -class ConnectionGroupService extends CreatorService -{ - public function __construct(ConnectionGroup $connectionGroup) - { +class ConnectionGroupService extends CreatorService { + public function __construct(ConnectionGroup $connectionGroup) { parent::__construct($connectionGroup); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $connectionGroupConfig = config('bulk-registration.csv_fields.connection_group'); $connectionGroupData = [ 'name' => $csvData[$connectionGroupConfig['name']], diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/ConnectionTypeService.php b/src/backend/packages/inensus/bulk-registration/src/Services/ConnectionTypeService.php index 3874ddec4..25cb26138 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/ConnectionTypeService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/ConnectionTypeService.php @@ -4,15 +4,12 @@ use App\Models\ConnectionType; -class ConnectionTypeService extends CreatorService -{ - public function __construct(ConnectionType $connectionType) - { +class ConnectionTypeService extends CreatorService { + public function __construct(ConnectionType $connectionType) { parent::__construct($connectionType); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $connectionTypeConfig = config('bulk-registration.csv_fields.connection_type'); $connectionTypeData = [ 'name' => $csvData[$connectionTypeConfig['name']], diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/CreatorService.php b/src/backend/packages/inensus/bulk-registration/src/Services/CreatorService.php index e90c8fefc..5971fcf59 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/CreatorService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/CreatorService.php @@ -2,17 +2,14 @@ namespace Inensus\BulkRegistration\Services; -abstract class CreatorService implements ICreatorService -{ +abstract class CreatorService implements ICreatorService { protected $model; - public function __construct($model) - { + public function __construct($model) { $this->model = $model; } - public function createRelatedDataIfDoesNotExists($resolvedCsvData) - { + public function createRelatedDataIfDoesNotExists($resolvedCsvData) { return $this->model->newQuery()->firstOrCreate($resolvedCsvData, $resolvedCsvData); } diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/CsvDataService.php b/src/backend/packages/inensus/bulk-registration/src/Services/CsvDataService.php index 99040cb63..f5f7ff881 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/CsvDataService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/CsvDataService.php @@ -7,21 +7,20 @@ use Inensus\BulkRegistration\Helpers\CsvFileParser; use Inensus\BulkRegistration\Models\CsvData; -class CsvDataService -{ +class CsvDataService { private $csvData; + private $csvDataProcessor; + private $csvFileParser; - public function __construct(CsvData $csvData, CsvFileParser $csvFileParser, CsvDataProcessor $csvDataProcessor) - { + public function __construct(CsvData $csvData, CsvFileParser $csvFileParser, CsvDataProcessor $csvDataProcessor) { $this->csvData = $csvData; $this->csvDataProcessor = $csvDataProcessor; $this->csvFileParser = $csvFileParser; } - public function create($request) - { + public function create($request) { $path = $request->file('csv'); $parsedCsvData = $this->csvFileParser->parseCsvFromFilePath($path); $message = ''; diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/GeographicalInformationService.php b/src/backend/packages/inensus/bulk-registration/src/Services/GeographicalInformationService.php index 8aaf6176f..49a2c1063 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/GeographicalInformationService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/GeographicalInformationService.php @@ -7,12 +7,10 @@ use App\Models\MiniGrid; use Inensus\BulkRegistration\Helpers\GeographicalLocationFinder; -class GeographicalInformationService -{ +class GeographicalInformationService { private $geographicalInformationConfig; - public function createRelatedDataIfDoesNotExists($geographicalInformationData, $ownerModel) - { + public function createRelatedDataIfDoesNotExists($geographicalInformationData, $ownerModel) { if ($geographicalInformationData) { $geographicalInformation = GeographicalInformation::query()->make($geographicalInformationData); $geographicalInformation->owner()->associate($ownerModel); @@ -20,21 +18,22 @@ public function createRelatedDataIfDoesNotExists($geographicalInformationData, $ } } - public function resolveCsvDataFromComingRow($csvData, $ownerModel) - { + public function resolveCsvDataFromComingRow($csvData, $ownerModel) { $this->geographicalInformationConfig = config('bulk-registration.csv_fields.geographical_information'); $geographicalInformationData = ['points' => '']; if ($ownerModel instanceof MiniGrid) { $this->createMiniGridRelatedGeographicalInformation($ownerModel); } else { - $geographicalInformationData = $this->createMeterParameterRelatedGeographicalInformation($geographicalInformationData, - $csvData, $ownerModel); + $geographicalInformationData = $this->createMeterParameterRelatedGeographicalInformation( + $geographicalInformationData, + $csvData, + $ownerModel + ); $this->createRelatedDataIfDoesNotExists($geographicalInformationData, $ownerModel); } } - private function createMiniGridRelatedGeographicalInformation($ownerModel) - { + private function createMiniGridRelatedGeographicalInformation($ownerModel) { $miniGridId = $ownerModel->id; $geographicalInformation = GeographicalInformation::query()->with(['owner']) ->whereHasMorph( diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/ICreatorService.php b/src/backend/packages/inensus/bulk-registration/src/Services/ICreatorService.php index 844aeabce..10d0bad1a 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/ICreatorService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/ICreatorService.php @@ -2,7 +2,6 @@ namespace Inensus\BulkRegistration\Services; -interface ICreatorService -{ +interface ICreatorService { public function createRelatedDataIfDoesNotExists($resolvedCsvData); } diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/ManufacturerService.php b/src/backend/packages/inensus/bulk-registration/src/Services/ManufacturerService.php index 697f8e7dd..219b46ca3 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/ManufacturerService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/ManufacturerService.php @@ -5,8 +5,7 @@ use App\Models\Manufacturer; use Inensus\BulkRegistration\Exceptions\ManufacturerNotSupportedException; -class ManufacturerService extends CreatorService -{ +class ManufacturerService extends CreatorService { private $manufacturers = [ 'Calin Meter', 'Calin Smart Meter', @@ -17,13 +16,11 @@ class ManufacturerService extends CreatorService 'SunKing SHS', ]; - public function __construct(Manufacturer $manufacturer) - { + public function __construct(Manufacturer $manufacturer) { parent::__construct($manufacturer); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $manufacturerConfig = config('bulk-registration.csv_fields.manufacturer'); if (!in_array($csvData[$manufacturerConfig['name']], $this->manufacturers)) { diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/MeterParameterService.php b/src/backend/packages/inensus/bulk-registration/src/Services/MeterParameterService.php index b00e89894..0eedaf31c 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/MeterParameterService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/MeterParameterService.php @@ -4,15 +4,12 @@ use App\Models\Meter\MeterParameter; -class MeterParameterService extends CreatorService -{ - public function __construct(MeterParameter $meterParameter) - { +class MeterParameterService extends CreatorService { + public function __construct(MeterParameter $meterParameter) { parent::__construct($meterParameter); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $meterParameterConfig = config('bulk-registration.csv_fields.meter_parameter'); $meterParameterData = [ 'owner_type' => $meterParameterConfig['owner_type'], diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/MeterService.php b/src/backend/packages/inensus/bulk-registration/src/Services/MeterService.php index 1f2e9439b..1dcb8f92d 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/MeterService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/MeterService.php @@ -4,18 +4,15 @@ use App\Models\Meter\Meter; -class MeterService extends CreatorService -{ +class MeterService extends CreatorService { private $meterTypeService; - public function __construct(Meter $meter, MeterTypeService $meterTypeService) - { + public function __construct(Meter $meter, MeterTypeService $meterTypeService) { parent::__construct($meter); $this->meterTypeService = $meterTypeService; } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $meterConfig = config('bulk-registration.csv_fields.meter'); if (strlen(preg_replace('/\s+/', '', $csvData[$meterConfig['serial_number']])) > 0) { diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/MeterTypeService.php b/src/backend/packages/inensus/bulk-registration/src/Services/MeterTypeService.php index cbe298363..310d5d641 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/MeterTypeService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/MeterTypeService.php @@ -4,17 +4,14 @@ use App\Models\Meter\MeterType; -class MeterTypeService -{ +class MeterTypeService { private $meterType; - public function __construct(MeterType $meterType) - { + public function __construct(MeterType $meterType) { $this->meterType = $meterType; } - public function createDefaultMeterTypeIfDoesNotExistAny() - { + public function createDefaultMeterTypeIfDoesNotExistAny() { return $this->meterType->newQuery()->firstOrCreate(['id' => 1]); } } diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/MiniGridService.php b/src/backend/packages/inensus/bulk-registration/src/Services/MiniGridService.php index d6cb31d50..78f22ffb7 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/MiniGridService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/MiniGridService.php @@ -5,15 +5,12 @@ use App\Models\MiniGrid; use Inensus\BulkRegistration\Exceptions\MiniGridNotFoundException; -class MiniGridService extends CreatorService -{ - public function __construct(MiniGrid $miniGrid) - { +class MiniGridService extends CreatorService { + public function __construct(MiniGrid $miniGrid) { parent::__construct($miniGrid); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $miniGridConfig = config('bulk-registration.csv_fields.mini_grid'); if (!$csvData[$miniGridConfig['name']]) { diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/PersonDocumentService.php b/src/backend/packages/inensus/bulk-registration/src/Services/PersonDocumentService.php index bb47793d5..d7d117ef0 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/PersonDocumentService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/PersonDocumentService.php @@ -4,22 +4,18 @@ use App\Models\PersonDocument; -class PersonDocumentService extends CreatorService -{ - public function __construct(PersonDocument $personDocument) - { +class PersonDocumentService extends CreatorService { + public function __construct(PersonDocument $personDocument) { parent::__construct($personDocument); } - public function createRelatedDataIfDoesNotExists($personDocuments) - { + public function createRelatedDataIfDoesNotExists($personDocuments) { foreach ($personDocuments as $personDocument) { PersonDocument::query()->firstOrCreate($personDocument, $personDocument); } } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $personDocsConfig = config('bulk-registration.csv_fields.person_docs'); $personDocuments = []; diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/PersonService.php b/src/backend/packages/inensus/bulk-registration/src/Services/PersonService.php index e49af5889..64b57b688 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/PersonService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/PersonService.php @@ -4,15 +4,12 @@ use App\Models\Person\Person; -class PersonService extends CreatorService -{ - public function __construct(Person $person) - { +class PersonService extends CreatorService { + public function __construct(Person $person) { parent::__construct($person); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $personConfig = config('bulk-registration.csv_fields.person'); $personData = [ 'name' => $csvData[$personConfig['name']], diff --git a/src/backend/packages/inensus/bulk-registration/src/Services/TariffService.php b/src/backend/packages/inensus/bulk-registration/src/Services/TariffService.php index 259211c36..61513d5ea 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Services/TariffService.php +++ b/src/backend/packages/inensus/bulk-registration/src/Services/TariffService.php @@ -5,15 +5,12 @@ use App\Models\MainSettings; use App\Models\Meter\MeterTariff; -class TariffService extends CreatorService -{ - public function __construct(MeterTariff $meterTariff) - { +class TariffService extends CreatorService { + public function __construct(MeterTariff $meterTariff) { parent::__construct($meterTariff); } - public function resolveCsvDataFromComingRow($csvData) - { + public function resolveCsvDataFromComingRow($csvData) { $tariffConfig = config('bulk-registration.csv_fields.tariff'); $tariffData = [ diff --git a/src/backend/packages/inensus/bulk-registration/src/Test/Feature/ImportCsv.php b/src/backend/packages/inensus/bulk-registration/src/Test/Feature/ImportCsv.php index d457ceb95..777b82f1d 100644 --- a/src/backend/packages/inensus/bulk-registration/src/Test/Feature/ImportCsv.php +++ b/src/backend/packages/inensus/bulk-registration/src/Test/Feature/ImportCsv.php @@ -9,13 +9,11 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class ImportCsv extends TestCase -{ +class ImportCsv extends TestCase { use RefreshDatabase; /** @test */ - public function isUserSentCsv() - { + public function isUserSentCsv() { $this->withoutExceptionHandling(); $user = factory(User::class)->create(); @@ -40,8 +38,7 @@ public function isUserSentCsv() ]); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/packages/inensus/calin-meter/src/CalinMeterApi.php b/src/backend/packages/inensus/calin-meter/src/CalinMeterApi.php index b25d0e6a8..731c33617 100644 --- a/src/backend/packages/inensus/calin-meter/src/CalinMeterApi.php +++ b/src/backend/packages/inensus/calin-meter/src/CalinMeterApi.php @@ -12,10 +12,11 @@ use Inensus\CalinMeter\Models\CalinCredential; use Inensus\CalinMeter\Models\CalinTransaction; -class CalinMeterApi implements IManufacturerAPI -{ +class CalinMeterApi implements IManufacturerAPI { public const CREDIT_TOKEN = 'CreditToken'; + protected $api; + private $rootUrl = '/tokennew'; public function __construct( @@ -27,8 +28,7 @@ public function __construct( $this->api = $httpClient; } - public function chargeDevice(TransactionDataContainer $transactionContainer): array - { + public function chargeDevice(TransactionDataContainer $transactionContainer): array { $meter = $transactionContainer->device->device; $tariff = $transactionContainer->tariff; // we round the energy to be charged to 1 decimal place because the api only accepts 1 decimal place. @@ -66,8 +66,7 @@ public function chargeDevice(TransactionDataContainer $transactionContainer): ar ]; } - public function clearDevice(Device $device) - { + public function clearDevice(Device $device) { throw new ApiCallDoesNotSupportedException('This api call does not supported'); } } diff --git a/src/backend/packages/inensus/calin-meter/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/calin-meter/src/Console/Commands/InstallPackage.php index 5a0757fa2..9bef0b95a 100644 --- a/src/backend/packages/inensus/calin-meter/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/calin-meter/src/Console/Commands/InstallPackage.php @@ -6,9 +6,9 @@ use Inensus\CalinMeter\Helpers\ApiHelpers; use Inensus\CalinMeter\Services\CalinCredentialService; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'calin-meter:install'; + protected $description = 'Install CalinMeter Package'; public function __construct( @@ -18,16 +18,14 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing CalinMeter Integration Package\n'); $this->apiHelpers->registerCalinMeterManufacturer(); $this->credentialService->createCredentials(); $this->info('Package installed successfully..'); } - private function publishMigrations() - { + private function publishMigrations() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => 'qq', @@ -35,14 +33,12 @@ private function publishMigrations() ]); } - private function createDatabaseTables() - { + private function createDatabaseTables() { $this->info('Creating database tables\n'); $this->call('migrate'); } - private function publishVueFiles() - { + private function publishVueFiles() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\CalinMeter\Providers\CalinMeterServiceProvider", @@ -50,8 +46,7 @@ private function publishVueFiles() ]); } - private function createPluginRecord() - { + private function createPluginRecord() { $this->call('plugin:add', [ 'name' => 'CalinMeter', 'composer_name' => 'inensus/calin-meter', diff --git a/src/backend/packages/inensus/calin-meter/src/Console/Commands/UpdatePackage.php b/src/backend/packages/inensus/calin-meter/src/Console/Commands/UpdatePackage.php index 91bbe18f8..c8457a4c0 100644 --- a/src/backend/packages/inensus/calin-meter/src/Console/Commands/UpdatePackage.php +++ b/src/backend/packages/inensus/calin-meter/src/Console/Commands/UpdatePackage.php @@ -8,9 +8,9 @@ use Inensus\CalinMeter\Helpers\ApiHelpers; use Inensus\CalinMeter\Services\CalinCredentialService; -class UpdatePackage extends Command -{ +class UpdatePackage extends Command { protected $signature = 'calin-meter:update'; + protected $description = 'Update CalinMeter Package'; public function __construct( @@ -21,8 +21,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Calin Meter Integration Updating Started\n'); $this->removeOldVersionOfPackage(); $this->installNewVersionOfPackage(); @@ -34,20 +33,17 @@ public function handle(): void $this->info('Package updated successfully..'); } - private function removeOldVersionOfPackage() - { + private function removeOldVersionOfPackage() { $this->info('Removing former version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar remove inensus/calin-meter'); } - private function installNewVersionOfPackage() - { + private function installNewVersionOfPackage() { $this->info('Installing last version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar require inensus/calin-meter'); } - private function deleteMigration(Filesystem $filesystem) - { + private function deleteMigration(Filesystem $filesystem) { $migrationFile = $filesystem->glob(database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'*_create_calin_tables.php')[0]; $migration = DB::table('migrations') ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->first(); @@ -59,8 +55,7 @@ private function deleteMigration(Filesystem $filesystem) ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->delete(); } - private function publishMigrationsAgain() - { + private function publishMigrationsAgain() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\CalinMeter\Providers\CalinMeterServiceProvider", @@ -68,14 +63,12 @@ private function publishMigrationsAgain() ]); } - private function updateDatabase() - { + private function updateDatabase() { $this->info('Updating database tables\n'); $this->call('migrate'); } - private function publishVueFilesAgain() - { + private function publishVueFilesAgain() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\CalinMeter\Providers\CalinMeterServiceProvider", diff --git a/src/backend/packages/inensus/calin-meter/src/Exceptions/CalinApiResponseException.php b/src/backend/packages/inensus/calin-meter/src/Exceptions/CalinApiResponseException.php index aaaf40e91..feb525cad 100644 --- a/src/backend/packages/inensus/calin-meter/src/Exceptions/CalinApiResponseException.php +++ b/src/backend/packages/inensus/calin-meter/src/Exceptions/CalinApiResponseException.php @@ -2,6 +2,4 @@ namespace Inensus\CalinMeter\Exceptions; -class CalinApiResponseException extends \Exception -{ -} +class CalinApiResponseException extends \Exception {} diff --git a/src/backend/packages/inensus/calin-meter/src/Helpers/ApiHelpers.php b/src/backend/packages/inensus/calin-meter/src/Helpers/ApiHelpers.php index 5443a5b77..d2e95d89c 100644 --- a/src/backend/packages/inensus/calin-meter/src/Helpers/ApiHelpers.php +++ b/src/backend/packages/inensus/calin-meter/src/Helpers/ApiHelpers.php @@ -5,17 +5,14 @@ use App\Models\Manufacturer; use Inensus\CalinMeter\Exceptions\CalinApiResponseException; -class ApiHelpers -{ +class ApiHelpers { private $manufacturer; - public function __construct(Manufacturer $manufacturerModel) - { + public function __construct(Manufacturer $manufacturerModel) { $this->manufacturer = $manufacturerModel; } - public function registerCalinMeterManufacturer() - { + public function registerCalinMeterManufacturer() { $api = $this->manufacturer->newQuery()->where('api_name', 'CalinMeterApi')->first(); if (!$api) { $this->manufacturer->newQuery()->create([ @@ -26,8 +23,7 @@ public function registerCalinMeterManufacturer() } } - public function checkApiResult($result) - { + public function checkApiResult($result) { if ((int) $result['result_code'] !== 0) { throw new CalinApiResponseException($result['reason']); } diff --git a/src/backend/packages/inensus/calin-meter/src/Http/Controllers/CalinCredentialController.php b/src/backend/packages/inensus/calin-meter/src/Http/Controllers/CalinCredentialController.php index aaacd9ee1..da3899250 100644 --- a/src/backend/packages/inensus/calin-meter/src/Http/Controllers/CalinCredentialController.php +++ b/src/backend/packages/inensus/calin-meter/src/Http/Controllers/CalinCredentialController.php @@ -7,22 +7,18 @@ use Inensus\CalinMeter\Http\Resources\CalinResource; use Inensus\CalinMeter\Services\CalinCredentialService; -class CalinCredentialController extends Controller -{ +class CalinCredentialController extends Controller { private $credentialService; - public function __construct(CalinCredentialService $credentialService) - { + public function __construct(CalinCredentialService $credentialService) { $this->credentialService = $credentialService; } - public function show(): CalinResource - { + public function show(): CalinResource { return new CalinResource($this->credentialService->getCredentials()); } - public function update(CalinCredentialRequest $request): CalinResource - { + public function update(CalinCredentialRequest $request): CalinResource { $credentials = $this->credentialService->updateCredentials($request->only([ 'user_id', 'api_key', diff --git a/src/backend/packages/inensus/calin-meter/src/Http/Requests/CalinCredentialRequest.php b/src/backend/packages/inensus/calin-meter/src/Http/Requests/CalinCredentialRequest.php index 86cecb44a..5c83506fd 100644 --- a/src/backend/packages/inensus/calin-meter/src/Http/Requests/CalinCredentialRequest.php +++ b/src/backend/packages/inensus/calin-meter/src/Http/Requests/CalinCredentialRequest.php @@ -5,15 +5,13 @@ use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; -class CalinCredentialRequest extends FormRequest -{ +class CalinCredentialRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'user_id' => ['required', Rule::unique('shard.calin_api_credentials')->ignore($this->id)], 'api_key' => ['required', Rule::unique('shard.calin_api_credentials')->ignore($this->id)], diff --git a/src/backend/packages/inensus/calin-meter/src/Http/Requests/CalinMeterApiRequests.php b/src/backend/packages/inensus/calin-meter/src/Http/Requests/CalinMeterApiRequests.php index a99f34292..822758174 100644 --- a/src/backend/packages/inensus/calin-meter/src/Http/Requests/CalinMeterApiRequests.php +++ b/src/backend/packages/inensus/calin-meter/src/Http/Requests/CalinMeterApiRequests.php @@ -9,10 +9,11 @@ use Inensus\CalinMeter\Helpers\ApiHelpers; use Inensus\CalinMeter\Models\CalinCredential; -class CalinMeterApiRequests -{ +class CalinMeterApiRequests { private $client; + private $apiHelpers; + private $credential; public function __construct( @@ -25,8 +26,7 @@ public function __construct( $this->credential = $credentialModel; } - public function post($url, $postParams) - { + public function post($url, $postParams) { try { $request = $this->client->post( $url, @@ -53,8 +53,7 @@ public function post($url, $postParams) } } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->firstOrFail(); } } diff --git a/src/backend/packages/inensus/calin-meter/src/Http/Resources/CalinResource.php b/src/backend/packages/inensus/calin-meter/src/Http/Resources/CalinResource.php index 2c5b6dd4b..035345dee 100644 --- a/src/backend/packages/inensus/calin-meter/src/Http/Resources/CalinResource.php +++ b/src/backend/packages/inensus/calin-meter/src/Http/Resources/CalinResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class CalinResource extends JsonResource -{ +class CalinResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class CalinResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/packages/inensus/calin-meter/src/Models/CalinCredential.php b/src/backend/packages/inensus/calin-meter/src/Models/CalinCredential.php index 66bfcf98d..e0a1701da 100644 --- a/src/backend/packages/inensus/calin-meter/src/Models/CalinCredential.php +++ b/src/backend/packages/inensus/calin-meter/src/Models/CalinCredential.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class CalinCredential extends BaseModel -{ +class CalinCredential extends BaseModel { protected $table = 'calin_api_credentials'; } diff --git a/src/backend/packages/inensus/calin-meter/src/Models/CalinTransaction.php b/src/backend/packages/inensus/calin-meter/src/Models/CalinTransaction.php index 8f71256f1..50fafc752 100644 --- a/src/backend/packages/inensus/calin-meter/src/Models/CalinTransaction.php +++ b/src/backend/packages/inensus/calin-meter/src/Models/CalinTransaction.php @@ -12,42 +12,34 @@ use Inensus\WaveMoneyPaymentProvider\Models\WaveMoneyTransaction; use MPM\Transaction\Provider\VodacomTransactionProvider; -class CalinTransaction extends BaseModel implements ISubTransaction -{ +class CalinTransaction extends BaseModel implements ISubTransaction { protected $table = 'calin_transactions'; - public function agentTransaction() - { + public function agentTransaction() { return $this->morphOne(AgentTransaction::class, 'manufacturer_transaction'); } - public function vodacomTransaction() - { + public function vodacomTransaction() { return $this->morphOne(VodacomTransactionProvider::class, 'manufacturer_transaction'); } - public function airtelTransaction() - { + public function airtelTransaction() { return $this->morphOne(AirtelTransaction::class, 'manufacturer_transaction'); } - public function thirdPartyTransaction() - { + public function thirdPartyTransaction() { return $this->morphOne(ThirdPartyTransaction::class, 'manufacturer_transaction'); } - public function mesombTransaction() - { + public function mesombTransaction() { return $this->morphOne(MesombTransaction::class, 'manufacturer_transaction'); } - public function swiftaTransaction() - { + public function swiftaTransaction() { return $this->morphOne(SwiftaTransaction::class, 'manufacturer_transaction'); } - public function waveMoneyTransaction() - { + public function waveMoneyTransaction() { return $this->morphOne(WaveMoneyTransaction::class, 'manufacturer_transaction'); } } diff --git a/src/backend/packages/inensus/calin-meter/src/Providers/CalinMeterServiceProvider.php b/src/backend/packages/inensus/calin-meter/src/Providers/CalinMeterServiceProvider.php index f9de8cea1..1e25790f7 100644 --- a/src/backend/packages/inensus/calin-meter/src/Providers/CalinMeterServiceProvider.php +++ b/src/backend/packages/inensus/calin-meter/src/Providers/CalinMeterServiceProvider.php @@ -11,10 +11,8 @@ use Inensus\CalinMeter\Console\Commands\UpdatePackage; use Inensus\CalinMeter\Models\CalinTransaction; -class CalinMeterServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class CalinMeterServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -25,40 +23,36 @@ public function boot(Filesystem $filesystem) Relation::morphMap( [ 'calin_transaction' => CalinTransaction::class, - ]); + ] + ); } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/calin-meter.php', 'calin-meter'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->bind('CalinMeterApi', CalinMeterApi::class); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/calin-meter.php' => config_path('calin-meter.php'), ]); } - public function publishVueFiles() - { + public function publishVueFiles() { $this->publishes([ __DIR__.'/../resources/assets' => resource_path('assets/js/plugins/calin-meter'), ], 'vue-components'); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_calin_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) diff --git a/src/backend/packages/inensus/calin-meter/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/calin-meter/src/Providers/EventServiceProvider.php index d614d1b56..5d85c9972 100644 --- a/src/backend/packages/inensus/calin-meter/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/calin-meter/src/Providers/EventServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ ]; @@ -14,8 +13,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/calin-meter/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/calin-meter/src/Providers/ObserverServiceProvider.php index 01a2026b7..d8e33f180 100644 --- a/src/backend/packages/inensus/calin-meter/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/calin-meter/src/Providers/ObserverServiceProvider.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/calin-meter/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/calin-meter/src/Providers/RouteServiceProvider.php index 63e70f896..6d989a685 100644 --- a/src/backend/packages/inensus/calin-meter/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/calin-meter/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\CalinMeter\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/calin-meter/src/Services/CalinCredentialService.php b/src/backend/packages/inensus/calin-meter/src/Services/CalinCredentialService.php index c4bb47b4a..40005aaa3 100644 --- a/src/backend/packages/inensus/calin-meter/src/Services/CalinCredentialService.php +++ b/src/backend/packages/inensus/calin-meter/src/Services/CalinCredentialService.php @@ -4,8 +4,7 @@ use Inensus\CalinMeter\Models\CalinCredential; -class CalinCredentialService -{ +class CalinCredentialService { private $credential; public function __construct( @@ -17,21 +16,18 @@ public function __construct( /** * This function uses one time on installation of the package. */ - public function createCredentials() - { + public function createCredentials() { return $this->credential->newQuery()->firstOrCreate(['id' => 1], [ 'user_id' => null, 'api_key' => null, ]); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->first(); } - public function updateCredentials($data) - { + public function updateCredentials($data) { $credential = $this->credential->newQuery()->firstOrFail(); $credential->update([ 'user_id' => $data['user_id'], diff --git a/src/backend/packages/inensus/calin-meter/src/Tests/Unit/TokenGenerationTest.php b/src/backend/packages/inensus/calin-meter/src/Tests/Unit/TokenGenerationTest.php index 0056fea84..2d29f0af0 100644 --- a/src/backend/packages/inensus/calin-meter/src/Tests/Unit/TokenGenerationTest.php +++ b/src/backend/packages/inensus/calin-meter/src/Tests/Unit/TokenGenerationTest.php @@ -19,13 +19,11 @@ use Inensus\CalinMeter\Models\CalinCredential; use Tests\TestCase; -class TokenGenerationTest extends TestCase -{ +class TokenGenerationTest extends TestCase { use RefreshDatabase; /** @test */ - public function isTokenGenerated() - { + public function isTokenGenerated() { Queue::fake(); Config::set('app.debug', false); $transaction = $this->initializeData(); @@ -38,8 +36,7 @@ public function isTokenGenerated() Queue::assertPushed(TokenProcessor::class); } - private function initializeData() - { + private function initializeData() { // create person factory(MainSettings::class)->create(); diff --git a/src/backend/packages/inensus/calin-smart-meter/src/CalinSmartMeterApi.php b/src/backend/packages/inensus/calin-smart-meter/src/CalinSmartMeterApi.php index 0e48059c1..4491d2fed 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/CalinSmartMeterApi.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/CalinSmartMeterApi.php @@ -14,9 +14,9 @@ use Inensus\CalinSmartMeter\Models\CalinSmartCredential; use Inensus\CalinSmartMeter\Models\CalinSmartTransaction; -class CalinSmartMeterApi implements IManufacturerAPI -{ +class CalinSmartMeterApi implements IManufacturerAPI { protected $api; + private $rootUrl = '/POS_Purchase/'; public function __construct( @@ -28,8 +28,7 @@ public function __construct( $this->api = $httpClient; } - public function chargeDevice($transactionContainer): array - { + public function chargeDevice($transactionContainer): array { $meter = $transactionContainer->device->device; $tariff = $transactionContainer->tariff; $transactionContainer->chargedEnergy += $transactionContainer->amount / $tariff->total_price; @@ -78,8 +77,7 @@ public function chargeDevice($transactionContainer): array * * @psalm-return array{result_code: mixed} */ - public function clearDevice(Device $device) - { + public function clearDevice(Device $device) { $meter = $device->device; $root = '/Maintenance_ClearCredit/'; try { diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/calin-smart-meter/src/Console/Commands/InstallPackage.php index 705689792..c22241c32 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Console/Commands/InstallPackage.php @@ -6,9 +6,9 @@ use Inensus\CalinSmartMeter\Helpers\ApiHelpers; use Inensus\CalinSmartMeter\Services\CalinSmartCredentialService; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'calin-smart-meter:install'; + protected $description = 'Install CalinSmartMeter Package'; public function __construct( @@ -18,16 +18,14 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing CalinSmartMeter Integration Package\n'); $this->apiHelpers->registerCalinMeterManufacturer(); $this->credentialService->createCredentials(); $this->info('Package installed successfully..'); } - private function publishMigrations() - { + private function publishMigrations() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\CalinSmartMeter\Providers\CalinSmartMeterServiceProvider", @@ -35,14 +33,12 @@ private function publishMigrations() ]); } - private function createDatabaseTables() - { + private function createDatabaseTables() { $this->info('Creating database tables\n'); $this->call('migrate'); } - private function publishVueFiles() - { + private function publishVueFiles() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\CalinSmartMeter\Providers\CalinSmartMeterServiceProvider", @@ -50,8 +46,7 @@ private function publishVueFiles() ]); } - private function createPluginRecord() - { + private function createPluginRecord() { $this->call('plugin:add', [ 'name' => 'CalinSmartMeter', 'composer_name' => 'inensus/calin-smart-meter', diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Console/Commands/UpdatePackage.php b/src/backend/packages/inensus/calin-smart-meter/src/Console/Commands/UpdatePackage.php index 8c14d8d3b..ad8a44cad 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Console/Commands/UpdatePackage.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Console/Commands/UpdatePackage.php @@ -7,9 +7,9 @@ use Illuminate\Support\Facades\DB; use Inensus\CalinSmartMeter\Services\CalinSmartCredentialService; -class UpdatePackage extends Command -{ +class UpdatePackage extends Command { protected $signature = 'calin-smart-meter:update'; + protected $description = 'Update CalinSmartMeter Package'; public function __construct( @@ -19,8 +19,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Calin Smart Meter Integration Updating Started\n'); $this->removeOldVersionOfPackage(); $this->installNewVersionOfPackage(); @@ -32,20 +31,17 @@ public function handle(): void $this->info('Package updated successfully..'); } - private function removeOldVersionOfPackage() - { + private function removeOldVersionOfPackage() { $this->info('Removing former version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar remove inensus/calin-smart-meter'); } - private function installNewVersionOfPackage() - { + private function installNewVersionOfPackage() { $this->info('Installing last version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar require inensus/calin-smart-meter'); } - private function deleteMigration(Filesystem $filesystem) - { + private function deleteMigration(Filesystem $filesystem) { $migrationFile = $filesystem->glob(database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'*_create_calin_smart_tables.php')[0]; $migration = DB::table('migrations') ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->first(); @@ -57,8 +53,7 @@ private function deleteMigration(Filesystem $filesystem) ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->delete(); } - private function publishMigrationsAgain() - { + private function publishMigrationsAgain() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\CalinSmartMeter\Providers\CalinSmartMeterServiceProvider", @@ -66,14 +61,12 @@ private function publishMigrationsAgain() ]); } - private function updateDatabase() - { + private function updateDatabase() { $this->info('Updating database tables\n'); $this->call('migrate'); } - private function publishVueFilesAgain() - { + private function publishVueFilesAgain() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\CalinSmartMeter\Providers\CalinSmartMeterServiceProvider", diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Exceptions/CalinSmartApiResponseException.php b/src/backend/packages/inensus/calin-smart-meter/src/Exceptions/CalinSmartApiResponseException.php index 8e2bd77cd..ccb1a2365 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Exceptions/CalinSmartApiResponseException.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Exceptions/CalinSmartApiResponseException.php @@ -2,6 +2,4 @@ namespace Inensus\CalinSmartMeter\Exceptions; -class CalinSmartApiResponseException extends \Exception -{ -} +class CalinSmartApiResponseException extends \Exception {} diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Exceptions/CalinSmartCreadentialsNotFoundException.php b/src/backend/packages/inensus/calin-smart-meter/src/Exceptions/CalinSmartCreadentialsNotFoundException.php index 32d3b4a70..05c58899b 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Exceptions/CalinSmartCreadentialsNotFoundException.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Exceptions/CalinSmartCreadentialsNotFoundException.php @@ -2,6 +2,4 @@ namespace Inensus\CalinSmartMeter\Exceptions; -class CalinSmartCreadentialsNotFoundException extends \Exception -{ -} +class CalinSmartCreadentialsNotFoundException extends \Exception {} diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Helpers/ApiHelpers.php b/src/backend/packages/inensus/calin-smart-meter/src/Helpers/ApiHelpers.php index 550b05bbb..773e43986 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Helpers/ApiHelpers.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Helpers/ApiHelpers.php @@ -5,17 +5,14 @@ use App\Models\Manufacturer; use Inensus\CalinSmartMeter\Exceptions\CalinSmartApiResponseException; -class ApiHelpers -{ +class ApiHelpers { private $manufacturer; - public function __construct(Manufacturer $manufacturerModel) - { + public function __construct(Manufacturer $manufacturerModel) { $this->manufacturer = $manufacturerModel; } - public function registerCalinMeterManufacturer() - { + public function registerCalinMeterManufacturer() { $api = $this->manufacturer->newQuery()->where('api_name', 'CalinSmartMeterApi')->first(); if (!$api) { $this->manufacturer->newQuery()->create([ @@ -26,8 +23,7 @@ public function registerCalinMeterManufacturer() } } - public function checkApiResult($result) - { + public function checkApiResult($result) { if ((int) $result['result_code'] !== 0) { throw new CalinSmartApiResponseException($result['reason']); } diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Http/Controllers/CalinSmartCredentialController.php b/src/backend/packages/inensus/calin-smart-meter/src/Http/Controllers/CalinSmartCredentialController.php index ddf6aafef..972db89a9 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Http/Controllers/CalinSmartCredentialController.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Http/Controllers/CalinSmartCredentialController.php @@ -7,22 +7,18 @@ use Inensus\CalinSmartMeter\Http\Resources\CalinSmartResource; use Inensus\CalinSmartMeter\Services\CalinSmartCredentialService; -class CalinSmartCredentialController extends Controller -{ +class CalinSmartCredentialController extends Controller { private $credentialService; - public function __construct(CalinSmartCredentialService $credentialService) - { + public function __construct(CalinSmartCredentialService $credentialService) { $this->credentialService = $credentialService; } - public function show(): CalinSmartResource - { + public function show(): CalinSmartResource { return new CalinSmartResource($this->credentialService->getCredentials()); } - public function update(CalinSmartCredentialRequest $request): CalinSmartResource - { + public function update(CalinSmartCredentialRequest $request): CalinSmartResource { $credentials = $this->credentialService->updateCredentials($request->only([ 'id', 'company_name', diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Http/Requests/CalinSmartCredentialRequest.php b/src/backend/packages/inensus/calin-smart-meter/src/Http/Requests/CalinSmartCredentialRequest.php index de29f4958..b134857d7 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Http/Requests/CalinSmartCredentialRequest.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Http/Requests/CalinSmartCredentialRequest.php @@ -5,15 +5,13 @@ use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; -class CalinSmartCredentialRequest extends FormRequest -{ +class CalinSmartCredentialRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'company_name' => ['required'], 'user_name' => ['required', Rule::unique('shard.calin_smart_api_credentials')->ignore($this->id)], diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Http/Requests/CalinSmartMeterApiRequests.php b/src/backend/packages/inensus/calin-smart-meter/src/Http/Requests/CalinSmartMeterApiRequests.php index 22fbe73f7..7ddaae579 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Http/Requests/CalinSmartMeterApiRequests.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Http/Requests/CalinSmartMeterApiRequests.php @@ -9,10 +9,11 @@ use Inensus\CalinSmartMeter\Helpers\ApiHelpers; use Inensus\CalinSmartMeter\Models\CalinSmartCredential; -class CalinSmartMeterApiRequests -{ +class CalinSmartMeterApiRequests { private $client; + private $apiHelpers; + private $credential; public function __construct( @@ -25,8 +26,7 @@ public function __construct( $this->credential = $credentialModel; } - public function post($url, $postParams) - { + public function post($url, $postParams) { try { $request = $this->client->post( $url, diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Http/Resources/CalinSmartResource.php b/src/backend/packages/inensus/calin-smart-meter/src/Http/Resources/CalinSmartResource.php index 0be320896..7ddccee69 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Http/Resources/CalinSmartResource.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Http/Resources/CalinSmartResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class CalinSmartResource extends JsonResource -{ +class CalinSmartResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class CalinSmartResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Models/CalinSmartCredential.php b/src/backend/packages/inensus/calin-smart-meter/src/Models/CalinSmartCredential.php index 6dadaea7d..4cfe40274 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Models/CalinSmartCredential.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Models/CalinSmartCredential.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class CalinSmartCredential extends BaseModel -{ +class CalinSmartCredential extends BaseModel { protected $table = 'calin_smart_api_credentials'; } diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Models/CalinSmartTransaction.php b/src/backend/packages/inensus/calin-smart-meter/src/Models/CalinSmartTransaction.php index bfbb9ce5d..ba1934026 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Models/CalinSmartTransaction.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Models/CalinSmartTransaction.php @@ -12,42 +12,34 @@ use Inensus\WaveMoneyPaymentProvider\Models\WaveMoneyTransaction; use MPM\Transaction\Provider\VodacomTransactionProvider; -class CalinSmartTransaction extends BaseModel implements ISubTransaction -{ +class CalinSmartTransaction extends BaseModel implements ISubTransaction { protected $table = 'calin_smart_transactions'; - public function agentTransaction() - { + public function agentTransaction() { return $this->morphOne(AgentTransaction::class, 'manufacturer_transaction'); } - public function vodacomTransaction() - { + public function vodacomTransaction() { return $this->morphOne(VodacomTransactionProvider::class, 'manufacturer_transaction'); } - public function airtelTransaction() - { + public function airtelTransaction() { return $this->morphOne(AirtelTransaction::class, 'manufacturer_transaction'); } - public function thirdPartyTransaction() - { + public function thirdPartyTransaction() { return $this->morphOne(ThirdPartyTransaction::class, 'manufacturer_transaction'); } - public function mesombTransaction() - { + public function mesombTransaction() { return $this->morphOne(MesombTransaction::class, 'manufacturer_transaction'); } - public function swiftaTransaction() - { + public function swiftaTransaction() { return $this->morphOne(SwiftaTransaction::class, 'manufacturer_transaction'); } - public function waveMoneyTransaction() - { + public function waveMoneyTransaction() { return $this->morphOne(WaveMoneyTransaction::class, 'manufacturer_transaction'); } } diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Providers/CalinSmartMeterServiceProvider.php b/src/backend/packages/inensus/calin-smart-meter/src/Providers/CalinSmartMeterServiceProvider.php index b1cd4787a..52533bca8 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Providers/CalinSmartMeterServiceProvider.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Providers/CalinSmartMeterServiceProvider.php @@ -11,10 +11,8 @@ use Inensus\CalinSmartMeter\Console\Commands\UpdatePackage; use Inensus\CalinSmartMeter\Models\CalinSmartTransaction; -class CalinSmartMeterServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class CalinSmartMeterServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -25,40 +23,36 @@ public function boot(Filesystem $filesystem) Relation::morphMap( [ 'calin_smart_transaction' => CalinSmartTransaction::class, - ]); + ] + ); } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/calin-smart-meter.php', 'calin-smart-meter'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->bind('CalinSmartMeterApi', CalinSmartMeterApi::class); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/calin-smart-meter.php' => config_path('calin-smart-meter.php'), ]); } - public function publishVueFiles() - { + public function publishVueFiles() { $this->publishes([ __DIR__.'/../resources/assets' => resource_path('assets/js/plugins/calin-smart-meter'), ], 'vue-components'); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_calin_smart_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/calin-smart-meter/src/Providers/EventServiceProvider.php index f074a8b2d..02cef0309 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Providers/EventServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ ]; @@ -14,8 +13,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/calin-smart-meter/src/Providers/ObserverServiceProvider.php index a5793ea1f..dcc4fb87a 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Providers/ObserverServiceProvider.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/calin-smart-meter/src/Providers/RouteServiceProvider.php index e8a87be74..9c0de2276 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\CalinSmartMeter\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Services/CalinSmartCredentialService.php b/src/backend/packages/inensus/calin-smart-meter/src/Services/CalinSmartCredentialService.php index d0bdaa6b3..724bc7808 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Services/CalinSmartCredentialService.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Services/CalinSmartCredentialService.php @@ -4,8 +4,7 @@ use Inensus\CalinSmartMeter\Models\CalinSmartCredential; -class CalinSmartCredentialService -{ +class CalinSmartCredentialService { private $credential; public function __construct( @@ -17,8 +16,7 @@ public function __construct( /** * This function uses one time on installation of the package. */ - public function createCredentials() - { + public function createCredentials() { return $this->credential->newQuery()->firstOrCreate(['id' => 1], [ 'company_name' => null, 'user_name' => null, @@ -27,13 +25,11 @@ public function createCredentials() ]); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->first(); } - public function updateCredentials($data) - { + public function updateCredentials($data) { $credential = $this->credential->newQuery()->find($data['id']); $credential->update([ 'company_name' => $data['company_name'], diff --git a/src/backend/packages/inensus/calin-smart-meter/src/Tests/Unit/TokenGenerationTest.php b/src/backend/packages/inensus/calin-smart-meter/src/Tests/Unit/TokenGenerationTest.php index 466c0cb09..861775b3d 100644 --- a/src/backend/packages/inensus/calin-smart-meter/src/Tests/Unit/TokenGenerationTest.php +++ b/src/backend/packages/inensus/calin-smart-meter/src/Tests/Unit/TokenGenerationTest.php @@ -19,13 +19,11 @@ use Inensus\CalinSmartMeter\Models\CalinSmartCredential; use Tests\TestCase; -class TokenGenerationTest extends TestCase -{ +class TokenGenerationTest extends TestCase { use RefreshDatabase; /** @test */ - public function isTokenGenerated() - { + public function isTokenGenerated() { Queue::fake(); Config::set('app.debug', false); $transaction = $this->initializeData(); @@ -37,8 +35,7 @@ public function isTokenGenerated() Queue::assertPushed(TokenProcessor::class); } - private function initializeData() - { + private function initializeData() { // create person factory(MainSettings::class)->create(); diff --git a/src/backend/packages/inensus/daly-bms/src/Console/Commands/CheckPayments.php b/src/backend/packages/inensus/daly-bms/src/Console/Commands/CheckPayments.php index ac789ad46..aa833449d 100644 --- a/src/backend/packages/inensus/daly-bms/src/Console/Commands/CheckPayments.php +++ b/src/backend/packages/inensus/daly-bms/src/Console/Commands/CheckPayments.php @@ -11,14 +11,17 @@ use Inensus\DalyBms\Modules\Api\DalyBmsApi; use MPM\EBike\EBikeService; -class CheckPayments extends AbstractSharedCommand -{ +class CheckPayments extends AbstractSharedCommand { use ScheduledPluginCommand; + public const MPM_PLUGIN_ID = 16; + public const E_BIKE = 2; + public const MANUFACTURER_NAME = 'DalyBms'; protected $signature = 'daly-bms:check-payments'; + protected $description = 'Checks payments for e-bikes.'; public function __construct( @@ -31,8 +34,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { if (!$this->checkForPluginStatusIsActive(self::MPM_PLUGIN_ID)) { return; } @@ -66,8 +68,7 @@ public function handle(): void $this->info('#############################'); } - private function lockTheBike($installment): bool - { + private function lockTheBike($installment): bool { $eBike = $this->eBikeService->getBySerialNumber($installment->assetPerson->device_serial); if ($eBike->manufacturer->name != self::MANUFACTURER_NAME) { @@ -83,7 +84,8 @@ private function lockTheBike($installment): bool ]; $this->eBikeService->update( $eBike, - $updatingData); + $updatingData + ); $creator = $this->user->newQuery()->firstOrCreate([ 'name' => 'System', diff --git a/src/backend/packages/inensus/daly-bms/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/daly-bms/src/Console/Commands/InstallPackage.php index 6b5adedc1..e58231541 100644 --- a/src/backend/packages/inensus/daly-bms/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/daly-bms/src/Console/Commands/InstallPackage.php @@ -6,9 +6,9 @@ use Inensus\DalyBms\Services\DalyBmsCredentialService; use Inensus\DalyBms\Services\ManufacturerService; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'daly-bms:install'; + protected $description = 'Install DalyBms Package'; public function __construct( @@ -18,8 +18,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing DalyBms Integration Package\n'); $this->manufacturerService->register(); $this->credentialService->createCredentials(); diff --git a/src/backend/packages/inensus/daly-bms/src/Console/Commands/SyncBikes.php b/src/backend/packages/inensus/daly-bms/src/Console/Commands/SyncBikes.php index f38a968c6..df73e52a4 100644 --- a/src/backend/packages/inensus/daly-bms/src/Console/Commands/SyncBikes.php +++ b/src/backend/packages/inensus/daly-bms/src/Console/Commands/SyncBikes.php @@ -9,13 +9,15 @@ use MPM\Device\DeviceAddressService; use MPM\EBike\EBikeService; -class SyncBikes extends AbstractSharedCommand -{ +class SyncBikes extends AbstractSharedCommand { use ScheduledPluginCommand; + public const MPM_PLUGIN_ID = 16; + public const MANUFACTURER_NAME = 'DalyBms'; protected $signature = 'daly-bms:sync-bikes'; + protected $description = 'Sync bikes from Daly BMS.'; public function __construct( @@ -26,8 +28,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { if (!$this->checkForPluginStatusIsActive(self::MPM_PLUGIN_ID)) { return; } @@ -56,8 +57,7 @@ public function handle(): void $this->info('#############################'); } - private function updateBike($deviceData) - { + private function updateBike($deviceData) { $updatingData = [ 'receive_time' => $deviceData['ReceiveTime'], 'lat' => strval($deviceData['Lat']), @@ -72,7 +72,8 @@ private function updateBike($deviceData) $eBike = $this->eBikeService->getBySerialNumber($deviceData['Code']); $this->eBikeService->update( $eBike, - $updatingData); + $updatingData + ); $address = $this->deviceAddressService->getAddressByDevice($eBike->device); $geoData = [ diff --git a/src/backend/packages/inensus/daly-bms/src/Exceptions/DalyBmsApiResponseException.php b/src/backend/packages/inensus/daly-bms/src/Exceptions/DalyBmsApiResponseException.php index 6d52a892a..5a377291d 100644 --- a/src/backend/packages/inensus/daly-bms/src/Exceptions/DalyBmsApiResponseException.php +++ b/src/backend/packages/inensus/daly-bms/src/Exceptions/DalyBmsApiResponseException.php @@ -2,10 +2,8 @@ namespace Inensus\DalyBms\Exceptions; -class DalyBmsApiResponseException extends \Exception -{ - public function __construct($message) - { +class DalyBmsApiResponseException extends \Exception { + public function __construct($message) { parent::__construct($message); } } diff --git a/src/backend/packages/inensus/daly-bms/src/Http/Controllers/DalyBmsCredentialController.php b/src/backend/packages/inensus/daly-bms/src/Http/Controllers/DalyBmsCredentialController.php index 371744bf2..fe5c465ce 100644 --- a/src/backend/packages/inensus/daly-bms/src/Http/Controllers/DalyBmsCredentialController.php +++ b/src/backend/packages/inensus/daly-bms/src/Http/Controllers/DalyBmsCredentialController.php @@ -7,20 +7,16 @@ use Inensus\DalyBms\Http\Resources\DalyBmsResource; use Inensus\DalyBms\Services\DalyBmsCredentialService; -class DalyBmsCredentialController extends Controller -{ +class DalyBmsCredentialController extends Controller { public function __construct( private DalyBmsCredentialService $credentialService, - ) { - } + ) {} - public function show(): DalyBmsResource - { + public function show(): DalyBmsResource { return DalyBmsResource::make($this->credentialService->getCredentials()); } - public function update(DalyBmsCredentialRequest $request): DalyBmsResource - { + public function update(DalyBmsCredentialRequest $request): DalyBmsResource { $credentials = $this->credentialService->getCredentials(); $updateData = $request->only([ 'user_name', diff --git a/src/backend/packages/inensus/daly-bms/src/Http/Requests/DalyBmsCredentialRequest.php b/src/backend/packages/inensus/daly-bms/src/Http/Requests/DalyBmsCredentialRequest.php index 6776b01de..ce951749a 100644 --- a/src/backend/packages/inensus/daly-bms/src/Http/Requests/DalyBmsCredentialRequest.php +++ b/src/backend/packages/inensus/daly-bms/src/Http/Requests/DalyBmsCredentialRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class DalyBmsCredentialRequest extends FormRequest -{ +class DalyBmsCredentialRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'user_name' => ['required'], 'password' => ['required'], diff --git a/src/backend/packages/inensus/daly-bms/src/Http/Resources/DalyBmsResource.php b/src/backend/packages/inensus/daly-bms/src/Http/Resources/DalyBmsResource.php index 0e7cc1363..6647ae3ba 100644 --- a/src/backend/packages/inensus/daly-bms/src/Http/Resources/DalyBmsResource.php +++ b/src/backend/packages/inensus/daly-bms/src/Http/Resources/DalyBmsResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class DalyBmsResource extends JsonResource -{ +class DalyBmsResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class DalyBmsResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/packages/inensus/daly-bms/src/Models/DalyBmsCredential.php b/src/backend/packages/inensus/daly-bms/src/Models/DalyBmsCredential.php index bc90110ec..1838cadfd 100644 --- a/src/backend/packages/inensus/daly-bms/src/Models/DalyBmsCredential.php +++ b/src/backend/packages/inensus/daly-bms/src/Models/DalyBmsCredential.php @@ -4,32 +4,26 @@ use App\Models\Base\BaseModel; -class DalyBmsCredential extends BaseModel -{ +class DalyBmsCredential extends BaseModel { protected $table = 'daly_bms_api_credentials'; - public function getUserName() - { + public function getUserName() { return $this->user_name; } - public function getPassword() - { + public function getPassword() { return $this->password; } - public function getApiUrl() - { + public function getApiUrl() { return $this->api_url; } - public function getAccessToken() - { + public function getAccessToken() { return $this->access_token; } - public function getExpirationTime() - { + public function getExpirationTime() { return $this->token_expires_in; } } diff --git a/src/backend/packages/inensus/daly-bms/src/Models/DalyBmsDevice.php b/src/backend/packages/inensus/daly-bms/src/Models/DalyBmsDevice.php index 8a00d2ab5..af8f91f49 100644 --- a/src/backend/packages/inensus/daly-bms/src/Models/DalyBmsDevice.php +++ b/src/backend/packages/inensus/daly-bms/src/Models/DalyBmsDevice.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class DalyBmsDevice extends BaseModel -{ +class DalyBmsDevice extends BaseModel { protected $table = 'daly_bms_devices'; } diff --git a/src/backend/packages/inensus/daly-bms/src/Models/DalyBmsTransaction.php b/src/backend/packages/inensus/daly-bms/src/Models/DalyBmsTransaction.php index c02f10391..7b4b348fe 100644 --- a/src/backend/packages/inensus/daly-bms/src/Models/DalyBmsTransaction.php +++ b/src/backend/packages/inensus/daly-bms/src/Models/DalyBmsTransaction.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class DalyBmsTransaction extends BaseModel -{ +class DalyBmsTransaction extends BaseModel { protected $table = 'daly_bms_transactions'; } diff --git a/src/backend/packages/inensus/daly-bms/src/Modules/Api/ApiRequests.php b/src/backend/packages/inensus/daly-bms/src/Modules/Api/ApiRequests.php index 715cb475f..d753c25b8 100644 --- a/src/backend/packages/inensus/daly-bms/src/Modules/Api/ApiRequests.php +++ b/src/backend/packages/inensus/daly-bms/src/Modules/Api/ApiRequests.php @@ -8,15 +8,12 @@ use Inensus\DalyBms\Exceptions\DalyBmsApiResponseException; use Inensus\DalyBms\Models\DalyBmsCredential; -class ApiRequests -{ +class ApiRequests { public function __construct( private Client $httpClient, - ) { - } + ) {} - public function authentication($credential): array - { + public function authentication($credential): array { try { $slug = '/Login/Authenticate?'; $userName = $credential->getUserName(); @@ -47,8 +44,7 @@ public function authentication($credential): array } } - public function postWithBodyParams(DalyBmsCredential $credentials, array $params, string $slug) - { + public function postWithBodyParams(DalyBmsCredential $credentials, array $params, string $slug) { $url = $credentials->getApiUrl().$slug; try { $response = $this->httpClient->post( @@ -76,13 +72,13 @@ public function postWithBodyParams(DalyBmsCredential $credentials, array $params 'URL :' => $url, 'Body :' => json_encode($params), 'message :' => $e->getMessage(), - ]); + ] + ); throw $e; } } - public function postWithQueryParams(DalyBmsCredential $credentials, array $params, string $slug) - { + public function postWithQueryParams(DalyBmsCredential $credentials, array $params, string $slug) { $url = $credentials->getApiUrl().$slug; if (strpos($url, '?') === false) { @@ -115,7 +111,8 @@ public function postWithQueryParams(DalyBmsCredential $credentials, array $param 'URL :' => $url, 'Body :' => json_encode($params), 'message :' => $e->getMessage(), - ]); + ] + ); throw $e; } } diff --git a/src/backend/packages/inensus/daly-bms/src/Modules/Api/DalyBmsApi.php b/src/backend/packages/inensus/daly-bms/src/Modules/Api/DalyBmsApi.php index 60e6a70f7..809e74d51 100644 --- a/src/backend/packages/inensus/daly-bms/src/Modules/Api/DalyBmsApi.php +++ b/src/backend/packages/inensus/daly-bms/src/Modules/Api/DalyBmsApi.php @@ -13,12 +13,13 @@ use Inensus\DalyBms\Services\DalyBmsCredentialService; use MPM\EBike\EBikeService; -class DalyBmsApi implements IManufacturerAPI -{ +class DalyBmsApi implements IManufacturerAPI { // works with query params public const COMMAND_DEVICES_LIST = '/Monitor/Refresh'; + // works with query params public const COMMAND_DEVICE_DETAIL = '/Monitor/ShowMonitorTips?'; + // works with body params public const COMMAND_SWITCH = '/Monitor/Send'; @@ -27,11 +28,9 @@ public function __construct( private DalyBmsTransaction $dalyBmsTransaction, private EBikeService $eBikeService, private ApiRequests $apiRequests, - ) { - } + ) {} - public function getDevices(array $deviceSerials) - { + public function getDevices(array $deviceSerials) { $params = [ 'codes' => $deviceSerials, ]; @@ -46,14 +45,15 @@ public function getDevices(array $deviceSerials) return $this->apiRequests->postWithBodyParams($credentials, $params, self::COMMAND_DEVICES_LIST); } catch (DalyBmsApiResponseException $e) { - $this->credentialService->updateCredentials($credentials, - ['access_token' => null, 'token_expires_in' => null]); + $this->credentialService->updateCredentials( + $credentials, + ['access_token' => null, 'token_expires_in' => null] + ); throw $e; } } - public function getDevice(string $code) - { + public function getDevice(string $code) { $params = [ 'Code' => $code, ]; @@ -67,14 +67,15 @@ public function getDevice(string $code) return $this->apiRequests->postWithQueryParams($credentials, $params, self::COMMAND_DEVICE_DETAIL); } catch (DalyBmsApiResponseException $e) { - $this->credentialService->updateCredentials($credentials, - ['access_token' => null, 'token_expires_in' => null]); + $this->credentialService->updateCredentials( + $credentials, + ['access_token' => null, 'token_expires_in' => null] + ); throw $e; } } - public function switchDevice(string $code, bool $isOn) - { + public function switchDevice(string $code, bool $isOn) { $params = [ 'cmdKey' => '8500_004', 'data' => [ @@ -97,8 +98,7 @@ public function switchDevice(string $code, bool $isOn) } } - public function chargeDevice(TransactionDataContainer $transactionContainer): array - { + public function chargeDevice(TransactionDataContainer $transactionContainer): array { $transactionId = $transactionContainer->transaction->id; $dayDifferenceBetweenTwoInstallments = $transactionContainer->dayDifferenceBetweenTwoInstallments; $minimumPurchaseAmount = $transactionContainer->installmentCost; @@ -125,7 +125,8 @@ public function chargeDevice(TransactionDataContainer $transactionContainer): ar ]; $this->eBikeService->update( $eBike, - $updatingData); + $updatingData + ); $creator = User::query()->firstOrCreate([ 'name' => 'System', ]); @@ -146,8 +147,7 @@ public function chargeDevice(TransactionDataContainer $transactionContainer): ar ]; } - public function clearDevice(Device $device) - { + public function clearDevice(Device $device) { throw new ApiCallDoesNotSupportedException('This api call does not supported'); } } diff --git a/src/backend/packages/inensus/daly-bms/src/Providers/DalyBmsServiceProvider.php b/src/backend/packages/inensus/daly-bms/src/Providers/DalyBmsServiceProvider.php index 6cefbbcdf..8df72998c 100644 --- a/src/backend/packages/inensus/daly-bms/src/Providers/DalyBmsServiceProvider.php +++ b/src/backend/packages/inensus/daly-bms/src/Providers/DalyBmsServiceProvider.php @@ -11,10 +11,8 @@ use Inensus\DalyBms\Console\Commands\SyncBikes; use Inensus\DalyBms\Modules\Api\DalyBmsApi; -class DalyBmsServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class DalyBmsServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -32,30 +30,26 @@ public function boot(Filesystem $filesystem) }); } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/daly-bms.php', 'daly-bms.php'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->bind('DalyBmsApi', DalyBmsApi::class); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/daly-bms.php' => config_path('daly-bms.php'), ]); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_daly_bms_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) @@ -63,8 +57,10 @@ protected function getMigrationFileName(Filesystem $filesystem): string if (count($filesystem->glob($path.'*_create_daly_bms_tables.php'))) { $file = $filesystem->glob($path.'*_create_daly_bms_tables.php')[0]; - file_put_contents($file, - file_get_contents(__DIR__.'/../../database/migrations/create_daly_bms_tables.php.stub')); + file_put_contents( + $file, + file_get_contents(__DIR__.'/../../database/migrations/create_daly_bms_tables.php.stub') + ); } return $filesystem->glob($path.'*_create_daly_bms_tables.php'); diff --git a/src/backend/packages/inensus/daly-bms/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/daly-bms/src/Providers/EventServiceProvider.php index 860f76d8b..7d0749da0 100644 --- a/src/backend/packages/inensus/daly-bms/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/daly-bms/src/Providers/EventServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ ]; @@ -14,8 +13,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/daly-bms/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/daly-bms/src/Providers/ObserverServiceProvider.php index b2f547049..2109957c9 100644 --- a/src/backend/packages/inensus/daly-bms/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/daly-bms/src/Providers/ObserverServiceProvider.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/daly-bms/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/daly-bms/src/Providers/RouteServiceProvider.php index 30a1053df..5e0e844b6 100644 --- a/src/backend/packages/inensus/daly-bms/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/daly-bms/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\DalyBms\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/daly-bms/src/Services/DalyBmsCredentialService.php b/src/backend/packages/inensus/daly-bms/src/Services/DalyBmsCredentialService.php index 231cf47d9..95df2c412 100644 --- a/src/backend/packages/inensus/daly-bms/src/Services/DalyBmsCredentialService.php +++ b/src/backend/packages/inensus/daly-bms/src/Services/DalyBmsCredentialService.php @@ -4,43 +4,36 @@ use Inensus\DalyBms\Models\DalyBmsCredential; -class DalyBmsCredentialService -{ +class DalyBmsCredentialService { public function __construct( private DalyBmsCredential $credential, - ) { - } + ) {} /** * This function uses one time on installation of the package. */ - public function createCredentials() - { + public function createCredentials() { return $this->credential->newQuery()->firstOrCreate(['id' => 1], [ 'user_name' => null, 'password' => null, ]); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->first(); } - public function updateCredentials($credentials, $updateData) - { + public function updateCredentials($credentials, $updateData) { $credentials->update($updateData); return $credentials->fresh(); } - public function getById($id) - { + public function getById($id) { return $this->credential->newQuery()->findOrFail($id); } - public function isAccessTokenValid($credential) - { + public function isAccessTokenValid($credential) { $accessToken = $credential->getAccessToken(); if ($accessToken == null) { diff --git a/src/backend/packages/inensus/daly-bms/src/Services/ManufacturerService.php b/src/backend/packages/inensus/daly-bms/src/Services/ManufacturerService.php index f9902e410..fd8b651fc 100644 --- a/src/backend/packages/inensus/daly-bms/src/Services/ManufacturerService.php +++ b/src/backend/packages/inensus/daly-bms/src/Services/ManufacturerService.php @@ -4,14 +4,10 @@ use App\Models\Manufacturer; -class ManufacturerService -{ - public function __construct(private Manufacturer $manufacturer) - { - } +class ManufacturerService { + public function __construct(private Manufacturer $manufacturer) {} - public function register() - { + public function register() { $api = $this->manufacturer->newQuery()->where('api_name', 'DalyBmsApi')->first(); if (!$api) { $this->manufacturer->newQuery()->create([ diff --git a/src/backend/packages/inensus/gome-long-meter/src/Console/Commands/GomeLongMeterDataSynchronizer.php b/src/backend/packages/inensus/gome-long-meter/src/Console/Commands/GomeLongMeterDataSynchronizer.php index 802bf3f51..cd8eeca3f 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Console/Commands/GomeLongMeterDataSynchronizer.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Console/Commands/GomeLongMeterDataSynchronizer.php @@ -7,9 +7,9 @@ use Inensus\GomeLongMeter\Exceptions\CronJobException; use Inensus\GomeLongMeter\Services\GomeLongTariffService; -class GomeLongMeterDataSynchronizer extends AbstractSharedCommand -{ +class GomeLongMeterDataSynchronizer extends AbstractSharedCommand { protected $signature = 'gome-long-meter:dataSync'; + protected $description = 'Synchronize data that needs to be updated from GomeLong Meter Meter.'; public function __construct( @@ -18,8 +18,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $timeStart = microtime(true); $this->info('#############################'); $this->info('# GomeLong Meter Package #'); diff --git a/src/backend/packages/inensus/gome-long-meter/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/gome-long-meter/src/Console/Commands/InstallPackage.php index edc3c4522..f3cf47aad 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Console/Commands/InstallPackage.php @@ -6,9 +6,9 @@ use Inensus\GomeLongMeter\Services\GomeLongCredentialService; use Inensus\GomeLongMeter\Services\ManufacturerService; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'gome-long-meter:install'; + protected $description = 'Install GomeLongMeter Package'; public function __construct( @@ -18,8 +18,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing GomeLongMeter Integration Package\n'); $this->manufacturerService->register(); diff --git a/src/backend/packages/inensus/gome-long-meter/src/Exceptions/CronJobException.php b/src/backend/packages/inensus/gome-long-meter/src/Exceptions/CronJobException.php index f2eca50cc..2b9a10779 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Exceptions/CronJobException.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Exceptions/CronJobException.php @@ -2,6 +2,4 @@ namespace Inensus\GomeLongMeter\Exceptions; -class CronJobException extends \Exception -{ -} +class CronJobException extends \Exception {} diff --git a/src/backend/packages/inensus/gome-long-meter/src/Exceptions/GomeLongApiResponseException.php b/src/backend/packages/inensus/gome-long-meter/src/Exceptions/GomeLongApiResponseException.php index 26ec56c9b..3ed9d30f6 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Exceptions/GomeLongApiResponseException.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Exceptions/GomeLongApiResponseException.php @@ -2,10 +2,8 @@ namespace Inensus\GomeLongMeter\Exceptions; -class GomeLongApiResponseException extends \Exception -{ - public function __construct($message) - { +class GomeLongApiResponseException extends \Exception { + public function __construct($message) { parent::__construct($message); } } diff --git a/src/backend/packages/inensus/gome-long-meter/src/Http/Controllers/GomeLongCredentialController.php b/src/backend/packages/inensus/gome-long-meter/src/Http/Controllers/GomeLongCredentialController.php index c93d1f52a..7b2c21f7c 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Http/Controllers/GomeLongCredentialController.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Http/Controllers/GomeLongCredentialController.php @@ -7,20 +7,16 @@ use Inensus\GomeLongMeter\Http\Resources\GomeLongResource; use Inensus\GomeLongMeter\Services\GomeLongCredentialService; -class GomeLongCredentialController extends Controller -{ +class GomeLongCredentialController extends Controller { public function __construct( private GomeLongCredentialService $credentialService, - ) { - } + ) {} - public function show(): GomeLongResource - { + public function show(): GomeLongResource { return GomeLongResource::make($this->credentialService->getCredentials()); } - public function update(GomeLongCredentialRequest $request): GomeLongResource - { + public function update(GomeLongCredentialRequest $request): GomeLongResource { $credentials = $this->credentialService->getCredentials(); $updateData = $request->only([ 'user_id', diff --git a/src/backend/packages/inensus/gome-long-meter/src/Http/Requests/GomeLongCredentialRequest.php b/src/backend/packages/inensus/gome-long-meter/src/Http/Requests/GomeLongCredentialRequest.php index 31bd580b7..593c059b8 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Http/Requests/GomeLongCredentialRequest.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Http/Requests/GomeLongCredentialRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class GomeLongCredentialRequest extends FormRequest -{ +class GomeLongCredentialRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'user_id' => ['required'], 'user_password' => ['required'], diff --git a/src/backend/packages/inensus/gome-long-meter/src/Http/Resources/GomeLongResource.php b/src/backend/packages/inensus/gome-long-meter/src/Http/Resources/GomeLongResource.php index 2cae87243..265378732 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Http/Resources/GomeLongResource.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Http/Resources/GomeLongResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class GomeLongResource extends JsonResource -{ +class GomeLongResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class GomeLongResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/packages/inensus/gome-long-meter/src/Models/GomeLongCredential.php b/src/backend/packages/inensus/gome-long-meter/src/Models/GomeLongCredential.php index b395dd484..3e6b05d1d 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Models/GomeLongCredential.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Models/GomeLongCredential.php @@ -4,22 +4,18 @@ use App\Models\Base\BaseModel; -class GomeLongCredential extends BaseModel -{ +class GomeLongCredential extends BaseModel { protected $table = 'gome_long_api_credentials'; - public function getUserId() - { + public function getUserId() { return $this->user_id; } - public function getUserPassword() - { + public function getUserPassword() { return $this->user_password; } - public function getApiUrl() - { + public function getApiUrl() { return $this->api_url; } } diff --git a/src/backend/packages/inensus/gome-long-meter/src/Models/GomeLongTariff.php b/src/backend/packages/inensus/gome-long-meter/src/Models/GomeLongTariff.php index 56f6d0d24..6673c7117 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Models/GomeLongTariff.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Models/GomeLongTariff.php @@ -5,17 +5,14 @@ use App\Models\Base\BaseModel; use App\Models\Meter\MeterTariff; -class GomeLongTariff extends BaseModel -{ +class GomeLongTariff extends BaseModel { protected $table = 'gome_long_tariffs'; - public function mpmTariff() - { + public function mpmTariff() { return $this->belongsTo(MeterTariff::class, 'mpm_tariff_id'); } - public function getTariffId() - { + public function getTariffId() { return $this->tariff_id; } } diff --git a/src/backend/packages/inensus/gome-long-meter/src/Models/GomeLongTransaction.php b/src/backend/packages/inensus/gome-long-meter/src/Models/GomeLongTransaction.php index 85cdb399f..5f719126e 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Models/GomeLongTransaction.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Models/GomeLongTransaction.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class GomeLongTransaction extends BaseModel -{ +class GomeLongTransaction extends BaseModel { protected $table = 'gome_long_transactions'; } diff --git a/src/backend/packages/inensus/gome-long-meter/src/Modules/Api/ApiRequests.php b/src/backend/packages/inensus/gome-long-meter/src/Modules/Api/ApiRequests.php index 72ee96a8a..259a1a69b 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Modules/Api/ApiRequests.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Modules/Api/ApiRequests.php @@ -8,26 +8,25 @@ use Inensus\GomeLongMeter\Exceptions\GomeLongApiResponseException; use Inensus\GomeLongMeter\Models\GomeLongCredential; -class ApiRequests -{ +class ApiRequests { public function __construct( private Client $httpClient, - ) { - } + ) {} - public function get(GomeLongCredential $credentials, array $params, string $slug) - { + public function get(GomeLongCredential $credentials, array $params, string $slug) { $url = $credentials->getApiUrl().$slug; foreach ($params as $key => $value) { $url .= $key.'='.$value.'&'; } try { - $request = $this->httpClient->get($url, + $request = $this->httpClient->get( + $url, [ 'headers' => [ 'Accept' => 'application/json', ], - ]); + ] + ); $result = json_decode((string) $request->getBody(), true); if ($result['ReturnCode'] !== 0) { @@ -43,8 +42,7 @@ public function get(GomeLongCredential $credentials, array $params, string $slug } } - public function post(GomeLongCredential $credentials, array $params, string $slug) - { + public function post(GomeLongCredential $credentials, array $params, string $slug) { $url = $credentials->getApiUrl().$slug; try { $request = $this->httpClient->post( diff --git a/src/backend/packages/inensus/gome-long-meter/src/Modules/Api/GomeLongMeterApi.php b/src/backend/packages/inensus/gome-long-meter/src/Modules/Api/GomeLongMeterApi.php index 34fcec610..7be2c5d4b 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Modules/Api/GomeLongMeterApi.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Modules/Api/GomeLongMeterApi.php @@ -10,19 +10,16 @@ use Inensus\GomeLongMeter\Models\GomeLongTransaction; use Inensus\GomeLongMeter\Services\GomeLongCredentialService; -class GomeLongMeterApi implements IManufacturerAPI -{ +class GomeLongMeterApi implements IManufacturerAPI { public const API_CALL_TOKEN_GENERATION = '/EKPower'; public function __construct( private GomeLongCredentialService $credentialService, private GomeLongTransaction $gomeLongTransaction, private ApiRequests $apiRequests, - ) { - } + ) {} - public function chargeDevice(TransactionDataContainer $transactionContainer): array - { + public function chargeDevice(TransactionDataContainer $transactionContainer): array { $meter = $transactionContainer->device->device; $tariff = $transactionContainer->tariff; $transactionContainer->chargedEnergy += $transactionContainer->amount / $tariff->total_price; @@ -60,8 +57,7 @@ public function chargeDevice(TransactionDataContainer $transactionContainer): ar } } - public function clearDevice(Device $device) - { + public function clearDevice(Device $device) { throw new ApiCallDoesNotSupportedException('This api call does not supported'); } } diff --git a/src/backend/packages/inensus/gome-long-meter/src/Observers/MeterTariffObserver.php b/src/backend/packages/inensus/gome-long-meter/src/Observers/MeterTariffObserver.php index 7db874da3..24c050309 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Observers/MeterTariffObserver.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Observers/MeterTariffObserver.php @@ -9,18 +9,15 @@ use Inensus\GomeLongMeter\Services\GomeLongCredentialService; use Inensus\GomeLongMeter\Services\GomeLongTariffService; -class MeterTariffObserver -{ +class MeterTariffObserver { use ScheduledPluginCommand; public function __construct( private GomeLongTariffService $gomeLongTariffService, private GomeLongCredentialService $credentialService, - ) { - } + ) {} - public function created(MeterTariff $tariff) - { + public function created(MeterTariff $tariff) { if (!$this->checkForPluginStatusIsActive(MpmPlugin::GOME_LONG_METERS)) { return; } @@ -30,8 +27,7 @@ public function created(MeterTariff $tariff) } } - public function updated(MeterTariff $tariff) - { + public function updated(MeterTariff $tariff) { if (!$this->checkForPluginStatusIsActive(MpmPlugin::GOME_LONG_METERS)) { return; } @@ -42,8 +38,7 @@ public function updated(MeterTariff $tariff) } } - public function deleted(MeterTariff $tariff) - { + public function deleted(MeterTariff $tariff) { if (!$this->checkForPluginStatusIsActive(MpmPlugin::GOME_LONG_METERS)) { return; } diff --git a/src/backend/packages/inensus/gome-long-meter/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/gome-long-meter/src/Providers/EventServiceProvider.php index 91002d07c..de6352789 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Providers/EventServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ ]; @@ -14,8 +13,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/gome-long-meter/src/Providers/GomeLongMeterServiceProvider.php b/src/backend/packages/inensus/gome-long-meter/src/Providers/GomeLongMeterServiceProvider.php index d1583bd55..8eb0f6fa1 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Providers/GomeLongMeterServiceProvider.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Providers/GomeLongMeterServiceProvider.php @@ -10,10 +10,8 @@ use Inensus\GomeLongMeter\Console\Commands\InstallPackage; use Inensus\GomeLongMeter\Modules\Api\GomeLongMeterApi; -class GomeLongMeterServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class GomeLongMeterServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -29,45 +27,42 @@ public function boot(Filesystem $filesystem) }); } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/gome-long-meter.php', 'gome-long-meter'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->bind('GomeLongMeterApi', GomeLongMeterApi::class); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/gome-long-meter.php' => config_path('gome-long-meter.php'), ]); } - public function publishVueFiles() - { + public function publishVueFiles() { $this->publishes([ __DIR__.'/../resources/assets' => resource_path('assets/js/plugins/gome-long-meter'), ], 'vue-components'); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_gome_long_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) ->flatMap(function ($path) use ($filesystem) { if (count($filesystem->glob($path.'*_create_gome_long_tables.php'))) { $file = $filesystem->glob($path.'*_create_gome_long_tables.php')[0]; - file_put_contents($file, - file_get_contents(__DIR__.'/../../database/migrations/create_gome_long_tables.php.stub')); + file_put_contents( + $file, + file_get_contents(__DIR__.'/../../database/migrations/create_gome_long_tables.php.stub') + ); } return $filesystem->glob($path.'*_create_gome_long_tables.php'); diff --git a/src/backend/packages/inensus/gome-long-meter/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/gome-long-meter/src/Providers/ObserverServiceProvider.php index 014a765cd..60dcaa385 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Providers/ObserverServiceProvider.php @@ -6,15 +6,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Inensus\GomeLongMeter\Observers\MeterTariffObserver; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); // removed observing of tariffs since GomeLong's API does not support it // MeterTariff::observe(MeterTariffObserver::class); diff --git a/src/backend/packages/inensus/gome-long-meter/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/gome-long-meter/src/Providers/RouteServiceProvider.php index 6aef9d23b..344886aaf 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\GomeLongMeter\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/gome-long-meter/src/Services/GomeLongCredentialService.php b/src/backend/packages/inensus/gome-long-meter/src/Services/GomeLongCredentialService.php index 64a980d94..2514408f2 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Services/GomeLongCredentialService.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Services/GomeLongCredentialService.php @@ -4,38 +4,32 @@ use Inensus\GomeLongMeter\Models\GomeLongCredential; -class GomeLongCredentialService -{ +class GomeLongCredentialService { public function __construct( private GomeLongCredential $credential, - ) { - } + ) {} /** * This function uses one time on installation of the package. */ - public function createCredentials() - { + public function createCredentials() { return $this->credential->newQuery()->firstOrCreate(['id' => 1], [ 'user_id' => null, 'user_password' => null, ]); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->first(); } - public function updateCredentials($credentials, $updateData) - { + public function updateCredentials($credentials, $updateData) { $credentials->update($updateData); return $credentials->fresh(); } - public function getById($id) - { + public function getById($id) { return $this->credential->newQuery()->findOrFail($id); } } diff --git a/src/backend/packages/inensus/gome-long-meter/src/Services/GomeLongTariffService.php b/src/backend/packages/inensus/gome-long-meter/src/Services/GomeLongTariffService.php index 0e7407e74..bbbbbbe73 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Services/GomeLongTariffService.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Services/GomeLongTariffService.php @@ -8,12 +8,15 @@ use Inensus\GomeLongMeter\Models\GomeLongTariff; use Inensus\GomeLongMeter\Modules\Api\ApiRequests; -class GomeLongTariffService -{ +class GomeLongTariffService { public const API_CALL_TARIFF_LIST = '/UTSearch'; + public const API_CALL_TARIFF_CREATE = '/UTAdd'; + public const API_CALL_TARIFF_UPDATE = '/UTUpdate'; + public const API_CALL_TARIFF_DELETE = '/UTdelete'; + public const ELECTRICITY_TARIFF_TYPE = 1; public function __construct( @@ -22,16 +25,13 @@ public function __construct( private GomeLongTariff $gomeLongTariff, private GomeLongCredentialService $credentialService, private MainSettings $mainSettings, - ) { - } + ) {} - public function getByMpmTariffId($mpmTariffId) - { + public function getByMpmTariffId($mpmTariffId) { return $this->gomeLongTariff->where('mpm_tariff_id', $mpmTariffId)->first(); } - public function createGomeLongTariff($tariff) - { + public function createGomeLongTariff($tariff) { $gomeLongTariff = $this->getByMpmTariffId($tariff->id); if (!$gomeLongTariff) { @@ -56,8 +56,7 @@ public function createGomeLongTariff($tariff) } } - public function updateGomeLongTariff($tariff) - { + public function updateGomeLongTariff($tariff) { try { $gomeLongTariff = $this->getByMpmTariffId($tariff->id); @@ -86,8 +85,7 @@ public function updateGomeLongTariff($tariff) } } - public function deleteGomeLongTariff($tariff) - { + public function deleteGomeLongTariff($tariff) { try { $gomeLongTariff = $this->getByMpmTariffId($tariff->id); @@ -113,8 +111,7 @@ public function deleteGomeLongTariff($tariff) } } - public function sync() - { + public function sync() { try { $credentials = $this->credentialService->getCredentials(); diff --git a/src/backend/packages/inensus/gome-long-meter/src/Services/ManufacturerService.php b/src/backend/packages/inensus/gome-long-meter/src/Services/ManufacturerService.php index 0ee2502ee..bb9416361 100644 --- a/src/backend/packages/inensus/gome-long-meter/src/Services/ManufacturerService.php +++ b/src/backend/packages/inensus/gome-long-meter/src/Services/ManufacturerService.php @@ -4,14 +4,10 @@ use App\Models\Manufacturer; -class ManufacturerService -{ - public function __construct(private Manufacturer $manufacturer) - { - } +class ManufacturerService { + public function __construct(private Manufacturer $manufacturer) {} - public function register() - { + public function register() { $api = $this->manufacturer->newQuery()->where('api_name', 'GomeLongMeterApi')->first(); if (!$api) { $this->manufacturer->newQuery()->create([ diff --git a/src/backend/packages/inensus/kelin-meter/src/Console/Commands/AccessTokenRefresher.php b/src/backend/packages/inensus/kelin-meter/src/Console/Commands/AccessTokenRefresher.php index e0da884d8..fc6e8f3bc 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Console/Commands/AccessTokenRefresher.php +++ b/src/backend/packages/inensus/kelin-meter/src/Console/Commands/AccessTokenRefresher.php @@ -7,20 +7,20 @@ use Carbon\Carbon; use Inensus\KelinMeter\Services\KelinCredentialService; -class AccessTokenRefresher extends AbstractSharedCommand -{ +class AccessTokenRefresher extends AbstractSharedCommand { use ScheduledPluginCommand; + public const MPM_PLUGIN_ID = 5; + protected $signature = 'kelin-meter:access-token-refresher'; + protected $description = 'Refreshes access token per each one hour.'; - public function __construct(private KelinCredentialService $credentialService) - { + public function __construct(private KelinCredentialService $credentialService) { parent::__construct(); } - public function handle(): void - { + public function handle(): void { if (!$this->checkForPluginStatusIsActive(self::MPM_PLUGIN_ID)) { return; } diff --git a/src/backend/packages/inensus/kelin-meter/src/Console/Commands/DataSynchronizer.php b/src/backend/packages/inensus/kelin-meter/src/Console/Commands/DataSynchronizer.php index 190c3f1cd..6658fb4a1 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Console/Commands/DataSynchronizer.php +++ b/src/backend/packages/inensus/kelin-meter/src/Console/Commands/DataSynchronizer.php @@ -16,12 +16,13 @@ use Inensus\KelinMeter\Services\KelinSyncActionService; use Inensus\KelinMeter\Services\KelinSyncSettingService; -class DataSynchronizer extends AbstractSharedCommand -{ +class DataSynchronizer extends AbstractSharedCommand { use ScheduledPluginCommand; + public const MPM_PLUGIN_ID = 5; protected $signature = 'kelin-meter:dataSync'; + protected $description = 'Synchronize data that needs to be updated from Kelin platform.'; public function __construct( @@ -35,8 +36,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { if (!$this->checkForPluginStatusIsActive(self::MPM_PLUGIN_ID)) { return; } diff --git a/src/backend/packages/inensus/kelin-meter/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/kelin-meter/src/Console/Commands/InstallPackage.php index 96e140374..a367b8f76 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/kelin-meter/src/Console/Commands/InstallPackage.php @@ -7,9 +7,9 @@ use Inensus\KelinMeter\Services\KelinCredentialService; use Inensus\KelinMeter\Services\PackageInstallationService; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'kelin-meter:install'; + protected $description = 'Install KelinMeters Package'; public function __construct( @@ -20,8 +20,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing KelinMeters Integration Package\n'); $this->packageInstallationService->createDefaultSettingRecords(); $this->apiHelpers->registerMeterManufacturer(); @@ -29,8 +28,7 @@ public function handle(): void $this->info('Package installed successfully..'); } - private function publishConfigurations() - { + private function publishConfigurations() { $this->info('Copying configurations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\KelinMeter\Providers\KelinMeterServiceProvider", @@ -38,8 +36,7 @@ private function publishConfigurations() ]); } - private function publishMigrations() - { + private function publishMigrations() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\KelinMeter\Providers\KelinMeterServiceProvider", @@ -47,14 +44,12 @@ private function publishMigrations() ]); } - private function createDatabaseTables() - { + private function createDatabaseTables() { $this->info('Creating database tables\n'); $this->call('migrate'); } - private function publishVueFiles() - { + private function publishVueFiles() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\KelinMeter\Providers\KelinMeterServiceProvider", @@ -62,8 +57,7 @@ private function publishVueFiles() ]); } - private function createPluginRecord() - { + private function createPluginRecord() { $this->call('plugin:add', [ 'name' => 'KelinMeters', 'composer_name' => 'inensus/kelin-meter', diff --git a/src/backend/packages/inensus/kelin-meter/src/Console/Commands/ReadDailyMeterConsumptions.php b/src/backend/packages/inensus/kelin-meter/src/Console/Commands/ReadDailyMeterConsumptions.php index a71a95fb5..2398feb2e 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Console/Commands/ReadDailyMeterConsumptions.php +++ b/src/backend/packages/inensus/kelin-meter/src/Console/Commands/ReadDailyMeterConsumptions.php @@ -8,12 +8,13 @@ use Inensus\KelinMeter\Services\DailyConsumptionService; use Inensus\KelinMeter\Services\KelinCredentialService; -class ReadDailyMeterConsumptions extends AbstractSharedCommand -{ +class ReadDailyMeterConsumptions extends AbstractSharedCommand { use ScheduledPluginCommand; + public const MPM_PLUGIN_ID = 5; protected $signature = 'kelin-meter:read-daily-consumptions'; + protected $description = 'Reads daily meter consumptions.'; public function __construct( @@ -23,8 +24,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { if (!$this->checkForPluginStatusIsActive(self::MPM_PLUGIN_ID)) { return; } diff --git a/src/backend/packages/inensus/kelin-meter/src/Console/Commands/ReadMinutelyMeterConsumptions.php b/src/backend/packages/inensus/kelin-meter/src/Console/Commands/ReadMinutelyMeterConsumptions.php index 3268937d3..79d4f52ab 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Console/Commands/ReadMinutelyMeterConsumptions.php +++ b/src/backend/packages/inensus/kelin-meter/src/Console/Commands/ReadMinutelyMeterConsumptions.php @@ -8,12 +8,13 @@ use Inensus\KelinMeter\Services\KelinCredentialService; use Inensus\KelinMeter\Services\MinutelyConsumptionService; -class ReadMinutelyMeterConsumptions extends AbstractSharedCommand -{ +class ReadMinutelyMeterConsumptions extends AbstractSharedCommand { use ScheduledPluginCommand; + public const MPM_PLUGIN_ID = 5; protected $signature = 'kelin-meter:read-minutely-consumptions'; + protected $description = 'Reads daily meter consumptions.'; public function __construct( @@ -23,8 +24,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { if (!$this->checkForPluginStatusIsActive(self::MPM_PLUGIN_ID)) { return; } diff --git a/src/backend/packages/inensus/kelin-meter/src/Console/Commands/UpdatePackage.php b/src/backend/packages/inensus/kelin-meter/src/Console/Commands/UpdatePackage.php index b2f75d32c..997794c0c 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Console/Commands/UpdatePackage.php +++ b/src/backend/packages/inensus/kelin-meter/src/Console/Commands/UpdatePackage.php @@ -9,9 +9,9 @@ use Inensus\KelinMeter\Services\KelinCredentialService; use Inensus\KelinMeter\Services\PackageInstallationService; -class UpdatePackage extends Command -{ +class UpdatePackage extends Command { protected $signature = 'kelin-meter:update'; + protected $description = 'Update Kelin Meter Package'; public function __construct( @@ -23,8 +23,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Kelin Meter Integration Updating Started\n'); $this->removeOldVersionOfPackage(); @@ -38,20 +37,17 @@ public function handle(): void $this->info('Package updated successfully..'); } - private function removeOldVersionOfPackage() - { + private function removeOldVersionOfPackage() { $this->info('Removing former version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar remove inensus/kelin-meter'); } - private function installNewVersionOfPackage() - { + private function installNewVersionOfPackage() { $this->info('Installing last version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar require inensus/kelin-meter'); } - private function deleteMigration(Filesystem $filesystem) - { + private function deleteMigration(Filesystem $filesystem) { $migrationFile = $filesystem->glob(database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'*_create_kelin_tables.php')[0]; $migration = DB::table('migrations') ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->first(); @@ -63,8 +59,7 @@ private function deleteMigration(Filesystem $filesystem) ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->delete(); } - private function publishMigrationsAgain() - { + private function publishMigrationsAgain() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\KelinMeter\Providers\KelinMeterServiceProvider", @@ -72,14 +67,12 @@ private function publishMigrationsAgain() ]); } - private function updateDatabase() - { + private function updateDatabase() { $this->info('Updating database tables\n'); $this->call('migrate'); } - private function publishVueFilesAgain() - { + private function publishVueFilesAgain() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\KelinMeter\Providers\KelinMeterServiceProvider", diff --git a/src/backend/packages/inensus/kelin-meter/src/Exceptions/CronJobException.php b/src/backend/packages/inensus/kelin-meter/src/Exceptions/CronJobException.php index 4db7ad337..dc7168cce 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Exceptions/CronJobException.php +++ b/src/backend/packages/inensus/kelin-meter/src/Exceptions/CronJobException.php @@ -2,6 +2,4 @@ namespace Inensus\KelinMeter\Exceptions; -class CronJobException extends \Exception -{ -} +class CronJobException extends \Exception {} diff --git a/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiAuthenticationException.php b/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiAuthenticationException.php index c05efe0a1..faf39f98e 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiAuthenticationException.php +++ b/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiAuthenticationException.php @@ -2,6 +2,4 @@ namespace Inensus\KelinMeter\Exceptions; -class KelinApiAuthenticationException extends \Exception -{ -} +class KelinApiAuthenticationException extends \Exception {} diff --git a/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiCredentialsNotFoundException.php b/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiCredentialsNotFoundException.php index 2246d9d4c..34301a174 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiCredentialsNotFoundException.php +++ b/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiCredentialsNotFoundException.php @@ -2,6 +2,4 @@ namespace Inensus\KelinMeter\Exceptions; -class KelinApiCredentialsNotFoundException extends \Exception -{ -} +class KelinApiCredentialsNotFoundException extends \Exception {} diff --git a/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiEmtyDataException.php b/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiEmtyDataException.php index 68bd2b579..ff3866d80 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiEmtyDataException.php +++ b/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiEmtyDataException.php @@ -2,6 +2,4 @@ namespace Inensus\KelinMeter\Exceptions; -class KelinApiEmtyDataException extends \Exception -{ -} +class KelinApiEmtyDataException extends \Exception {} diff --git a/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiResponseException.php b/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiResponseException.php index 63919970c..89c16c12d 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiResponseException.php +++ b/src/backend/packages/inensus/kelin-meter/src/Exceptions/KelinApiResponseException.php @@ -2,6 +2,4 @@ namespace Inensus\KelinMeter\Exceptions; -class KelinApiResponseException extends \Exception -{ -} +class KelinApiResponseException extends \Exception {} diff --git a/src/backend/packages/inensus/kelin-meter/src/Helpers/ApiHelpers.php b/src/backend/packages/inensus/kelin-meter/src/Helpers/ApiHelpers.php index d4e2f4c6e..a96c2caad 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Helpers/ApiHelpers.php +++ b/src/backend/packages/inensus/kelin-meter/src/Helpers/ApiHelpers.php @@ -7,17 +7,14 @@ use Inensus\KelinMeter\Exceptions\KelinApiEmtyDataException; use Inensus\KelinMeter\Exceptions\KelinApiResponseException; -class ApiHelpers -{ +class ApiHelpers { private $manufacturer; - public function __construct(Manufacturer $manufacturerModel) - { + public function __construct(Manufacturer $manufacturerModel) { $this->manufacturer = $manufacturerModel; } - public function registerMeterManufacturer() - { + public function registerMeterManufacturer() { $this->manufacturer->newQuery()->firstOrCreate(['api_name' => 'KelinMeterApi'], [ 'name' => 'Kelin Meters', 'website' => '-', @@ -25,8 +22,7 @@ public function registerMeterManufacturer() ]); } - public function checkApiResult($result) - { + public function checkApiResult($result) { if (!$result) { throw new KelinApiEmtyDataException('Null result returned.'); } @@ -43,8 +39,7 @@ public function checkApiResult($result) return $result; } - public function makeHash($data) - { + public function makeHash($data) { return md5(implode('', $data)); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Clients/KelinMeterApiClient.php b/src/backend/packages/inensus/kelin-meter/src/Http/Clients/KelinMeterApiClient.php index b38ecebc7..b05170004 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Clients/KelinMeterApiClient.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Clients/KelinMeterApiClient.php @@ -10,10 +10,11 @@ use Inensus\KelinMeter\Helpers\ApiHelpers; use Inensus\KelinMeter\Models\KelinCredential; -class KelinMeterApiClient -{ +class KelinMeterApiClient { private $client; + private $apiHelpers; + private $credential; public function __construct( @@ -26,15 +27,15 @@ public function __construct( $this->credential = $credential; } - public function token($url, $queryParams) - { + public function token($url, $queryParams) { try { $credential = $this->getCredentials(); } catch (\Exception $e) { throw new KelinApiCredentialsNotFoundException($e->getMessage()); } try { - $response = $this->client->request('GET', + $response = $this->client->request( + 'GET', $credential->api_url.$url.'?param='.urlencode(json_encode($queryParams)) ); } catch (GuzzleException $exception) { @@ -44,8 +45,7 @@ public function token($url, $queryParams) return $this->apiHelpers->checkApiResult(json_decode((string) $response->getBody(), true)); } - public function get($url, $queryParams = null) - { + public function get($url, $queryParams = null) { try { $credential = $this->getCredentials(); } catch (ModelNotFoundException $e) { @@ -68,8 +68,7 @@ public function get($url, $queryParams = null) return $this->apiHelpers->checkApiResult(json_decode((string) $response->getBody(), true)); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->firstOrFail(); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/IBaseController.php b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/IBaseController.php index a470f1c13..13f153c65 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/IBaseController.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/IBaseController.php @@ -2,8 +2,7 @@ namespace Inensus\KelinMeter\Http\Controllers; -interface IBaseController -{ +interface IBaseController { public function sync(); public function checkSync(); diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinCredentialController.php b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinCredentialController.php index 87f60b78b..939786cec 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinCredentialController.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinCredentialController.php @@ -7,22 +7,18 @@ use Inensus\KelinMeter\Http\Resources\KelinCredentialResource; use Inensus\KelinMeter\Services\KelinCredentialService; -class KelinCredentialController extends Controller -{ +class KelinCredentialController extends Controller { private $credentialService; - public function __construct(KelinCredentialService $credentialService) - { + public function __construct(KelinCredentialService $credentialService) { $this->credentialService = $credentialService; } - public function show(): KelinCredentialResource - { + public function show(): KelinCredentialResource { return new KelinCredentialResource($this->credentialService->getCredentials()); } - public function update(KelinCredentialRequest $request): KelinCredentialResource - { + public function update(KelinCredentialRequest $request): KelinCredentialResource { return new KelinCredentialResource($this->credentialService->updateCredentials($request->only([ 'id', 'username', diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinCustomerController.php b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinCustomerController.php index 538af78e6..f3ef4883b 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinCustomerController.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinCustomerController.php @@ -8,27 +8,22 @@ use Inensus\KelinMeter\Http\Resources\KelinResource; use Inensus\KelinMeter\Services\KelinCustomerService; -class KelinCustomerController extends Controller implements IBaseController -{ +class KelinCustomerController extends Controller implements IBaseController { private $customerService; - public function __construct(KelinCustomerService $customerService) - { + public function __construct(KelinCustomerService $customerService) { $this->customerService = $customerService; } - public function index(Request $request) - { + public function index(Request $request) { return KelinCustomerResource::collection($this->customerService->getCustomers($request)); } - public function sync() - { + public function sync() { return KelinCustomerResource::collection($this->customerService->sync()); } - public function checkSync(): KelinResource - { + public function checkSync(): KelinResource { return new KelinResource($this->customerService->syncCheck()); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinDailyConsumptionController.php b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinDailyConsumptionController.php index 9290b972c..647eca176 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinDailyConsumptionController.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinDailyConsumptionController.php @@ -7,17 +7,14 @@ use Inensus\KelinMeter\Models\KelinMeter; use Inensus\KelinMeter\Services\DailyConsumptionService; -class KelinDailyConsumptionController extends Controller -{ +class KelinDailyConsumptionController extends Controller { private $dailyConsumptionService; - public function __construct(DailyConsumptionService $dailyConsumptionService) - { + public function __construct(DailyConsumptionService $dailyConsumptionService) { $this->dailyConsumptionService = $dailyConsumptionService; } - public function index(KelinMeter $meter) - { + public function index(KelinMeter $meter) { $perPage = \request()->get('per_page') ?? 15; return DailyConsumptionResource::collection( diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinMeterController.php b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinMeterController.php index 71703b94a..70d27df63 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinMeterController.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinMeterController.php @@ -8,27 +8,22 @@ use Inensus\KelinMeter\Http\Resources\KelinResource; use Inensus\KelinMeter\Services\KelinMeterService; -class KelinMeterController extends Controller -{ +class KelinMeterController extends Controller { private $meterService; - public function __construct(KelinMeterService $meterService) - { + public function __construct(KelinMeterService $meterService) { $this->meterService = $meterService; } - public function index(Request $request) - { + public function index(Request $request) { return KelinMeterResource::collection($this->meterService->getMeters($request)); } - public function sync() - { + public function sync() { return KelinMeterResource::collection($this->meterService->sync()); } - public function checkSync(): KelinResource - { + public function checkSync(): KelinResource { return new KelinResource($this->meterService->syncCheck()); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinMinutelyConsumptionController.php b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinMinutelyConsumptionController.php index e37a2b214..4b3f9cb9e 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinMinutelyConsumptionController.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinMinutelyConsumptionController.php @@ -7,20 +7,19 @@ use Inensus\KelinMeter\Models\KelinMeter; use Inensus\KelinMeter\Services\MinutelyConsumptionService; -class KelinMinutelyConsumptionController extends Controller -{ +class KelinMinutelyConsumptionController extends Controller { private $minutelyConsumptionService; - public function __construct(MinutelyConsumptionService $minutelyConsumptionService) - { + public function __construct(MinutelyConsumptionService $minutelyConsumptionService) { $this->minutelyConsumptionService = $minutelyConsumptionService; } - public function index(KelinMeter $meter) - { + public function index(KelinMeter $meter) { $perPage = \request()->get('per_page') ?? 15; - return MinutelyConsumptionResource::collection($this->minutelyConsumptionService->getDailyData($meter->meter_address, - $perPage)); + return MinutelyConsumptionResource::collection($this->minutelyConsumptionService->getDailyData( + $meter->meter_address, + $perPage + )); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinSettingController.php b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinSettingController.php index 8227d66af..32647dae0 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinSettingController.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinSettingController.php @@ -6,17 +6,14 @@ use Inensus\KelinMeter\Http\Resources\KelinSettingResource; use Inensus\KelinMeter\Services\KelinSettingService; -class KelinSettingController extends Controller -{ +class KelinSettingController extends Controller { private $settingService; - public function __construct(KelinSettingService $settingService) - { + public function __construct(KelinSettingService $settingService) { $this->settingService = $settingService; } - public function index() - { + public function index() { return KelinSettingResource::collection($this->settingService->getSettings()); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinStatusController.php b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinStatusController.php index af37a49c3..e9a23828d 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinStatusController.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinStatusController.php @@ -9,22 +9,18 @@ use Inensus\KelinMeter\Models\KelinMeter; use Inensus\KelinMeter\Services\KelinMeterStatusService; -class KelinStatusController extends Controller -{ +class KelinStatusController extends Controller { private $kelinMeterStatusService; - public function __construct(KelinMeterStatusService $kelinMeterStatusService) - { + public function __construct(KelinMeterStatusService $kelinMeterStatusService) { $this->kelinMeterStatusService = $kelinMeterStatusService; } - public function show(KelinMeter $meter) - { + public function show(KelinMeter $meter) { return new KelinMeterStatusResource($this->kelinMeterStatusService->getStatusOfMeter($meter)); } - public function update(Request $request, KelinMeter $meter) - { + public function update(Request $request, KelinMeter $meter) { return new KelinResource($this->kelinMeterStatusService->changeStatusOfMeter($meter->meter_address, $request->input('status'))); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinSyncSettingController.php b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinSyncSettingController.php index 92720f525..390261f67 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinSyncSettingController.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Controllers/KelinSyncSettingController.php @@ -7,17 +7,14 @@ use Inensus\KelinMeter\Http\Resources\KelinResource; use Inensus\KelinMeter\Services\KelinSyncSettingService; -class KelinSyncSettingController extends Controller -{ +class KelinSyncSettingController extends Controller { private $syncSettingService; - public function __construct(KelinSyncSettingService $syncSettingService) - { + public function __construct(KelinSyncSettingService $syncSettingService) { $this->syncSettingService = $syncSettingService; } - public function update(Request $request): KelinResource - { + public function update(Request $request): KelinResource { return new KelinResource($this->syncSettingService->updateSyncSettings($request->all())); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Requests/KelinCredentialRequest.php b/src/backend/packages/inensus/kelin-meter/src/Http/Requests/KelinCredentialRequest.php index a72e55493..9dfcd716d 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Requests/KelinCredentialRequest.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Requests/KelinCredentialRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class KelinCredentialRequest extends FormRequest -{ +class KelinCredentialRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'username' => ['required'], 'password' => 'required', diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/DailyConsumptionCollection.php b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/DailyConsumptionCollection.php index e3c9b2908..363494730 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/DailyConsumptionCollection.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/DailyConsumptionCollection.php @@ -4,8 +4,7 @@ use Illuminate\Http\Resources\Json\ResourceCollection; -class DailyConsumptionCollection extends ResourceCollection -{ +class DailyConsumptionCollection extends ResourceCollection { /** * Transform the resource collection into an array. * @@ -13,8 +12,7 @@ class DailyConsumptionCollection extends ResourceCollection * * @return array */ - public function toArray($request) - { + public function toArray($request) { return [ 'data' => $this->collection, ]; diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/DailyConsumptionResource.php b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/DailyConsumptionResource.php index 7ccfc69b2..eff111a82 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/DailyConsumptionResource.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/DailyConsumptionResource.php @@ -4,10 +4,8 @@ use Illuminate\Http\Resources\Json\JsonResource; -class DailyConsumptionResource extends JsonResource -{ - public function toArray($request) - { +class DailyConsumptionResource extends JsonResource { + public function toArray($request) { return [ 'data' => [ 'type' => 'daily_consumption', diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinCredentialResource.php b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinCredentialResource.php index 884259754..fe7d6fa84 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinCredentialResource.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinCredentialResource.php @@ -4,10 +4,8 @@ use Illuminate\Http\Resources\Json\JsonResource; -class KelinCredentialResource extends JsonResource -{ - public function toArray($request) - { +class KelinCredentialResource extends JsonResource { + public function toArray($request) { return [ 'data' => [ 'type' => 'credentials', @@ -22,8 +20,7 @@ public function toArray($request) ]; } - private function alertType($authenticationStatus) - { + private function alertType($authenticationStatus) { switch ($authenticationStatus) { case true: return [ diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinCustomerCollection.php b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinCustomerCollection.php index e5d3baeba..d875b8532 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinCustomerCollection.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinCustomerCollection.php @@ -4,8 +4,7 @@ use Illuminate\Http\Resources\Json\ResourceCollection; -class KelinCustomerCollection extends ResourceCollection -{ +class KelinCustomerCollection extends ResourceCollection { /** * Transform the resource collection into an array. * @@ -13,8 +12,7 @@ class KelinCustomerCollection extends ResourceCollection * * @return array */ - public function toArray($request) - { + public function toArray($request) { return [ 'data' => $this->collection, ]; diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinCustomerResource.php b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinCustomerResource.php index b0f13d04b..28e96a639 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinCustomerResource.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinCustomerResource.php @@ -4,10 +4,8 @@ use Illuminate\Http\Resources\Json\JsonResource; -class KelinCustomerResource extends JsonResource -{ - public function toArray($request) - { +class KelinCustomerResource extends JsonResource { + public function toArray($request) { return [ 'data' => [ 'type' => 'customer', diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinMeterCollection.php b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinMeterCollection.php index ad033f477..6456e896d 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinMeterCollection.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinMeterCollection.php @@ -4,8 +4,7 @@ use Illuminate\Http\Resources\Json\ResourceCollection; -class KelinMeterCollection extends ResourceCollection -{ +class KelinMeterCollection extends ResourceCollection { /** * Transform the resource collection into an array. * @@ -13,8 +12,7 @@ class KelinMeterCollection extends ResourceCollection * * @return array */ - public function toArray($request) - { + public function toArray($request) { return [ 'data' => $this->collection, ]; diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinMeterResource.php b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinMeterResource.php index 18fed4787..6fe8a335c 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinMeterResource.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinMeterResource.php @@ -4,10 +4,8 @@ use Illuminate\Http\Resources\Json\JsonResource; -class KelinMeterResource extends JsonResource -{ - public function toArray($request) - { +class KelinMeterResource extends JsonResource { + public function toArray($request) { return [ 'data' => [ 'type' => 'setting', diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinMeterStatusResource.php b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinMeterStatusResource.php index ac2b6c2b6..4e990d5c2 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinMeterStatusResource.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinMeterStatusResource.php @@ -4,10 +4,8 @@ use Illuminate\Http\Resources\Json\JsonResource; -class KelinMeterStatusResource extends JsonResource -{ - public function toArray($request) - { +class KelinMeterStatusResource extends JsonResource { + public function toArray($request) { return [ 'data' => [ 'type' => 'meter-status', diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinResource.php b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinResource.php index 5c5b2694f..7ec9d80a3 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinResource.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class KelinResource extends JsonResource -{ +class KelinResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class KelinResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinSettingCollection.php b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinSettingCollection.php index 560514960..7c7768ad6 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinSettingCollection.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinSettingCollection.php @@ -4,8 +4,7 @@ use Illuminate\Http\Resources\Json\ResourceCollection; -class KelinSettingCollection extends ResourceCollection -{ +class KelinSettingCollection extends ResourceCollection { /** * Transform the resource collection into an array. * @@ -13,8 +12,7 @@ class KelinSettingCollection extends ResourceCollection * * @return array */ - public function toArray($request) - { + public function toArray($request) { return [ 'data' => $this->collection, ]; diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinSettingResource.php b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinSettingResource.php index efe076175..cdaf1e157 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinSettingResource.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/KelinSettingResource.php @@ -4,10 +4,8 @@ use Illuminate\Http\Resources\Json\JsonResource; -class KelinSettingResource extends JsonResource -{ - public function toArray($request) - { +class KelinSettingResource extends JsonResource { + public function toArray($request) { return [ 'data' => [ 'type' => 'setting', diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/MinutelyConsumptionCollection.php b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/MinutelyConsumptionCollection.php index e5f600943..a519e6216 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/MinutelyConsumptionCollection.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/MinutelyConsumptionCollection.php @@ -4,8 +4,7 @@ use Illuminate\Http\Resources\Json\ResourceCollection; -class MinutelyConsumptionCollection extends ResourceCollection -{ +class MinutelyConsumptionCollection extends ResourceCollection { /** * Transform the resource collection into an array. * @@ -13,8 +12,7 @@ class MinutelyConsumptionCollection extends ResourceCollection * * @return array */ - public function toArray($request) - { + public function toArray($request) { return [ 'data' => $this->collection, ]; diff --git a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/MinutelyConsumptionResource.php b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/MinutelyConsumptionResource.php index 8b9006fa8..36a9b6eb8 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Http/Resources/MinutelyConsumptionResource.php +++ b/src/backend/packages/inensus/kelin-meter/src/Http/Resources/MinutelyConsumptionResource.php @@ -4,10 +4,8 @@ use Illuminate\Http\Resources\Json\JsonResource; -class MinutelyConsumptionResource extends JsonResource -{ - public function toArray($request) - { +class MinutelyConsumptionResource extends JsonResource { + public function toArray($request) { return [ 'data' => [ 'type' => 'minutely_consumption', diff --git a/src/backend/packages/inensus/kelin-meter/src/KelinMeterApi.php b/src/backend/packages/inensus/kelin-meter/src/KelinMeterApi.php index c70dce41a..a60e58ff2 100644 --- a/src/backend/packages/inensus/kelin-meter/src/KelinMeterApi.php +++ b/src/backend/packages/inensus/kelin-meter/src/KelinMeterApi.php @@ -13,19 +13,16 @@ use Inensus\KelinMeter\Models\KelinMeter; use Inensus\KelinMeter\Models\KelinTransaction; -class KelinMeterApi implements IManufacturerAPI -{ +class KelinMeterApi implements IManufacturerAPI { private $rootUrl = '/recharge'; public function __construct( private KelinMeter $kelinMeter, private KelinTransaction $kelinTransaction, private KelinMeterApiClient $kelinApi, - ) { - } + ) {} - public function chargeDevice($transactionContainer): array - { + public function chargeDevice($transactionContainer): array { $meter = $transactionContainer->device->device; $tariff = $transactionContainer->tariff; $transactionContainer->chargedEnergy += $transactionContainer->amount / $tariff->total_price; @@ -97,10 +94,15 @@ public function chargeDevice($transactionContainer): array 'manufacturer_transaction_type' => 'kelin_transaction', ]); - $token = $transactionResult['opType'] === 2 ? sprintf('EnergyToken : %s', - $transactionResult['payToken']) : - sprintf('OpenToken1 : %s OpenToken2 : %s', $transactionResult['openToken1'], - $transactionResult['openToken2']); + $token = $transactionResult['opType'] === 2 ? sprintf( + 'EnergyToken : %s', + $transactionResult['payToken'] + ) : + sprintf( + 'OpenToken1 : %s OpenToken2 : %s', + $transactionResult['openToken1'], + $transactionResult['openToken2'] + ); return [ 'token' => $token, @@ -109,7 +111,5 @@ public function chargeDevice($transactionContainer): array } } - public function clearDevice(Device $device) - { - } + public function clearDevice(Device $device) {} } diff --git a/src/backend/packages/inensus/kelin-meter/src/Models/KelinCredential.php b/src/backend/packages/inensus/kelin-meter/src/Models/KelinCredential.php index 0a04bf263..a9ebc0d6b 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Models/KelinCredential.php +++ b/src/backend/packages/inensus/kelin-meter/src/Models/KelinCredential.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class KelinCredential extends BaseModel -{ +class KelinCredential extends BaseModel { protected $table = 'kelin_api_credentials'; } diff --git a/src/backend/packages/inensus/kelin-meter/src/Models/KelinCustomer.php b/src/backend/packages/inensus/kelin-meter/src/Models/KelinCustomer.php index 769fca357..a188eb897 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Models/KelinCustomer.php +++ b/src/backend/packages/inensus/kelin-meter/src/Models/KelinCustomer.php @@ -5,17 +5,14 @@ use App\Models\Base\BaseModel; use App\Models\Person\Person; -class KelinCustomer extends BaseModel -{ +class KelinCustomer extends BaseModel { protected $table = 'kelin_customers'; - public function mpmPerson() - { + public function mpmPerson() { return $this->belongsTo(Person::class, 'mpm_customer_id'); } - public function kelinMeters() - { + public function kelinMeters() { return $this->hasMany(KelinMeter::class, 'customer_no', 'customer_no'); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeter.php b/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeter.php index 92821bdc4..124b6049f 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeter.php +++ b/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeter.php @@ -5,17 +5,14 @@ use App\Models\Base\BaseModel; use App\Models\Meter\Meter; -class KelinMeter extends BaseModel -{ +class KelinMeter extends BaseModel { protected $table = 'kelin_meters'; - public function mpmMeter() - { + public function mpmMeter() { return $this->belongsTo(Meter::class, 'mpm_meter_id'); } - public function kelinCustomer() - { + public function kelinCustomer() { return $this->belongsTo(KelinCustomer::class, 'customer_no', 'customer_no'); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeterConsumption.php b/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeterConsumption.php index d67028cdf..768fa1316 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeterConsumption.php +++ b/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeterConsumption.php @@ -5,12 +5,10 @@ use App\Models\Base\BaseModel; use App\Models\Meter\Meter; -class KelinMeterConsumption extends BaseModel -{ +class KelinMeterConsumption extends BaseModel { protected $table = 'kelin_meter_consumptions'; - public function meter() - { + public function meter() { return $this->belongsTo(Meter::class); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeterDailyData.php b/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeterDailyData.php index f5742487d..b3f3ecde9 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeterDailyData.php +++ b/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeterDailyData.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class KelinMeterDailyData extends BaseModel -{ +class KelinMeterDailyData extends BaseModel { protected $table = 'kelin_meter_daily_datas'; } diff --git a/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeterMinutelyData.php b/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeterMinutelyData.php index 9acc94d13..5c9d46134 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeterMinutelyData.php +++ b/src/backend/packages/inensus/kelin-meter/src/Models/KelinMeterMinutelyData.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class KelinMeterMinutelyData extends BaseModel -{ +class KelinMeterMinutelyData extends BaseModel { protected $table = 'kelin_meter_minutely_datas'; } diff --git a/src/backend/packages/inensus/kelin-meter/src/Models/KelinSetting.php b/src/backend/packages/inensus/kelin-meter/src/Models/KelinSetting.php index 8f0ff2689..5e5dfdaa9 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Models/KelinSetting.php +++ b/src/backend/packages/inensus/kelin-meter/src/Models/KelinSetting.php @@ -5,12 +5,10 @@ use App\Models\Base\BaseModel; use Illuminate\Database\Eloquent\Relations\MorphTo; -class KelinSetting extends BaseModel -{ +class KelinSetting extends BaseModel { protected $table = 'kelin_settings'; - public function setting(): MorphTo - { + public function setting(): MorphTo { return $this->morphTo(); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Models/KelinSyncAction.php b/src/backend/packages/inensus/kelin-meter/src/Models/KelinSyncAction.php index fdfd78d8a..1014e1013 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Models/KelinSyncAction.php +++ b/src/backend/packages/inensus/kelin-meter/src/Models/KelinSyncAction.php @@ -4,12 +4,10 @@ use App\Models\Base\BaseModel; -class KelinSyncAction extends BaseModel -{ +class KelinSyncAction extends BaseModel { protected $table = 'kelin_sync_actions'; - public function synSetting() - { + public function synSetting() { return $this->belongsTo(KelinSyncSetting::class, 'sync_setting_id'); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Models/KelinSyncSetting.php b/src/backend/packages/inensus/kelin-meter/src/Models/KelinSyncSetting.php index 6b80cdebb..5e4c06fba 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Models/KelinSyncSetting.php +++ b/src/backend/packages/inensus/kelin-meter/src/Models/KelinSyncSetting.php @@ -4,17 +4,14 @@ use App\Models\Base\BaseModel; -class KelinSyncSetting extends BaseModel -{ +class KelinSyncSetting extends BaseModel { protected $table = 'kelin_sync_settings'; - public function syncAction() - { + public function syncAction() { return $this->hasOne(KelinSyncAction::class); } - public function setting() - { + public function setting() { return $this->morphOne(KelinSetting::class, 'setting'); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Models/KelinTransaction.php b/src/backend/packages/inensus/kelin-meter/src/Models/KelinTransaction.php index 807e2a83d..1a9202b2c 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Models/KelinTransaction.php +++ b/src/backend/packages/inensus/kelin-meter/src/Models/KelinTransaction.php @@ -12,42 +12,34 @@ use Inensus\WaveMoneyPaymentProvider\Models\WaveMoneyTransaction; use MPM\Transaction\Provider\VodacomTransactionProvider; -class KelinTransaction extends BaseModel implements ISubTransaction -{ +class KelinTransaction extends BaseModel implements ISubTransaction { protected $table = 'kelin_transactions'; - public function agentTransaction() - { + public function agentTransaction() { return $this->morphOne(AgentTransaction::class, 'manufacturer_transaction'); } - public function vodacomTransaction() - { + public function vodacomTransaction() { return $this->morphOne(VodacomTransactionProvider::class, 'manufacturer_transaction'); } - public function airtelTransaction() - { + public function airtelTransaction() { return $this->morphOne(AirtelTransaction::class, 'manufacturer_transaction'); } - public function thirdPartyTransaction() - { + public function thirdPartyTransaction() { return $this->morphOne(ThirdPartyTransaction::class, 'manufacturer_transaction'); } - public function mesombTransaction() - { + public function mesombTransaction() { return $this->morphOne(MesombTransaction::class, 'manufacturer_transaction'); } - public function swiftaTransaction() - { + public function swiftaTransaction() { return $this->morphOne(SwiftaTransaction::class, 'manufacturer_transaction'); } - public function waveMoneyTransaction() - { + public function waveMoneyTransaction() { return $this->morphOne(WaveMoneyTransaction::class, 'manufacturer_transaction'); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Models/SyncStatus.php b/src/backend/packages/inensus/kelin-meter/src/Models/SyncStatus.php index 4ed55c70b..36e373e8b 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Models/SyncStatus.php +++ b/src/backend/packages/inensus/kelin-meter/src/Models/SyncStatus.php @@ -2,10 +2,12 @@ namespace Inensus\KelinMeter\Models; -abstract class SyncStatus -{ +abstract class SyncStatus { public const SYNCED = 1; + public const MODIFIED = 2; + public const NOT_REGISTERED_YET = 3; + public const EARLY_REGISTERED = 4; } diff --git a/src/backend/packages/inensus/kelin-meter/src/Observers/PersonObserver.php b/src/backend/packages/inensus/kelin-meter/src/Observers/PersonObserver.php index 1dc26b6e7..e51e03848 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Observers/PersonObserver.php +++ b/src/backend/packages/inensus/kelin-meter/src/Observers/PersonObserver.php @@ -7,11 +7,13 @@ use Inensus\KelinMeter\Models\KelinCustomer; use Inensus\KelinMeter\Services\KelinCustomerService; -class PersonObserver -{ +class PersonObserver { private $customerService; + private $apiHelpers; + private $person; + private $kelinCustomer; public function __construct( @@ -26,8 +28,7 @@ public function __construct( $this->kelinCustomer = $kelinCustomer; } - public function updated(Person $person) - { + public function updated(Person $person) { $kelinCustomer = $this->kelinCustomer->newQuery()->where('mpm_customer_id', $person->id)->first(); if ($kelinCustomer) { diff --git a/src/backend/packages/inensus/kelin-meter/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/kelin-meter/src/Providers/EventServiceProvider.php index 6e09ae90b..864372784 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/kelin-meter/src/Providers/EventServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ ]; @@ -14,8 +13,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Providers/KelinMeterServiceProvider.php b/src/backend/packages/inensus/kelin-meter/src/Providers/KelinMeterServiceProvider.php index ff7ca6c47..1a8534d9c 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Providers/KelinMeterServiceProvider.php +++ b/src/backend/packages/inensus/kelin-meter/src/Providers/KelinMeterServiceProvider.php @@ -25,10 +25,8 @@ use Inensus\KelinMeter\Services\KelinCustomerService; use Inensus\KelinMeter\Services\KelinMeterService; -class KelinMeterServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class KelinMeterServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -61,8 +59,7 @@ public function boot(Filesystem $filesystem) ); } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/kelin-meter.php', 'kelin-meter'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); @@ -81,30 +78,27 @@ public function register() }); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/kelin-meter.php' => config_path('kelin-meter.php'), ], 'configurations'); } - public function publishVueFiles() - { + public function publishVueFiles() { $this->publishes([ - __DIR__.'/../resources/assets' => resource_path('assets/js/plugins/kelin-meter' + __DIR__.'/../resources/assets' => resource_path( + 'assets/js/plugins/kelin-meter' ), ], 'vue-components'); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_kelin_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) @@ -112,8 +106,10 @@ protected function getMigrationFileName(Filesystem $filesystem): string if (count($filesystem->glob($path.'*_create_kelin_tables.php'))) { $file = $filesystem->glob($path.'*_create_kelin_tables.php')[0]; - file_put_contents($file, - file_get_contents(__DIR__.'/../../database/migrations/create_kelin_tables.php.stub')); + file_put_contents( + $file, + file_get_contents(__DIR__.'/../../database/migrations/create_kelin_tables.php.stub') + ); } return $filesystem->glob($path.'*_create_kelin_tables.php'); diff --git a/src/backend/packages/inensus/kelin-meter/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/kelin-meter/src/Providers/ObserverServiceProvider.php index ea9dd165c..470fb95cc 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/kelin-meter/src/Providers/ObserverServiceProvider.php @@ -6,15 +6,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Inensus\KelinMeter\Observers\PersonObserver; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); Person::observe(PersonObserver::class); } diff --git a/src/backend/packages/inensus/kelin-meter/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/kelin-meter/src/Providers/RouteServiceProvider.php index 8c031439b..45dca8ca1 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/kelin-meter/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\KelinMeter\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/kelin-meter/src/Services/DailyConsumptionService.php b/src/backend/packages/inensus/kelin-meter/src/Services/DailyConsumptionService.php index 5f14d0c36..ef729de51 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Services/DailyConsumptionService.php +++ b/src/backend/packages/inensus/kelin-meter/src/Services/DailyConsumptionService.php @@ -7,10 +7,11 @@ use Inensus\KelinMeter\Http\Clients\KelinMeterApiClient; use Inensus\KelinMeter\Models\KelinMeterDailyData; -class DailyConsumptionService -{ +class DailyConsumptionService { private $rootUrl = '/getDayData'; + private $kelinApi; + private $kelinMeterDailyData; public function __construct( @@ -21,8 +22,7 @@ public function __construct( $this->kelinMeterDailyData = $kelinMeterDailyData; } - public function getDailyDataFromAPI() - { + public function getDailyDataFromAPI() { $startDay = Carbon::now()->subDays(1)->format('Ymd'); $endDay = Carbon::now()->format('His'); $pageNo = 1; @@ -73,8 +73,7 @@ public function getDailyDataFromAPI() } while ($result['dataCount'] > 0); } - public function getDailyData($meterAddress, $perPage) - { + public function getDailyData($meterAddress, $perPage) { return $this->kelinMeterDailyData->newQuery()->where('address_of_meter', $meterAddress)->orderByDesc('id')->paginate($perPage); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Services/ISynchronizeService.php b/src/backend/packages/inensus/kelin-meter/src/Services/ISynchronizeService.php index 305c973e8..42ed6646f 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Services/ISynchronizeService.php +++ b/src/backend/packages/inensus/kelin-meter/src/Services/ISynchronizeService.php @@ -2,8 +2,7 @@ namespace Inensus\KelinMeter\Services; -interface ISynchronizeService -{ +interface ISynchronizeService { public function sync(); public function syncCheck(); diff --git a/src/backend/packages/inensus/kelin-meter/src/Services/KelinCredentialService.php b/src/backend/packages/inensus/kelin-meter/src/Services/KelinCredentialService.php index fdfb14a75..0b881890e 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Services/KelinCredentialService.php +++ b/src/backend/packages/inensus/kelin-meter/src/Services/KelinCredentialService.php @@ -8,10 +8,11 @@ use Inensus\KelinMeter\Http\Clients\KelinMeterApiClient; use Inensus\KelinMeter\Models\KelinCredential; -class KelinCredentialService -{ +class KelinCredentialService { private $rootUrl = '/login'; + private $credential; + private $kelinApi; public function __construct( @@ -25,8 +26,7 @@ public function __construct( /** * This function uses one time on installation of the package. */ - public function createCredentials() - { + public function createCredentials() { return $this->credential->newQuery()->firstOrCreate(['id' => 1], [ 'username' => null, 'password' => null, @@ -36,13 +36,11 @@ public function createCredentials() ]); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->first(); } - public function updateCredentials($data) - { + public function updateCredentials($data) { $credential = $this->getCredentials(); $credential->update([ 'username' => $data['username'], @@ -75,8 +73,7 @@ public function updateCredentials($data) return $credential->fresh(); } - public function refreshAccessToken() - { + public function refreshAccessToken() { $credential = $this->getCredentials(); if (!$credential->username && !$credential->password) { Log::debug('KelinMeter credentials is not registered yet.'); diff --git a/src/backend/packages/inensus/kelin-meter/src/Services/KelinCustomerService.php b/src/backend/packages/inensus/kelin-meter/src/Services/KelinCustomerService.php index aa71f5dca..ed8291f77 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Services/KelinCustomerService.php +++ b/src/backend/packages/inensus/kelin-meter/src/Services/KelinCustomerService.php @@ -14,14 +14,19 @@ use Inensus\KelinMeter\Models\KelinCustomer; use Inensus\KelinMeter\Models\SyncStatus; -class KelinCustomerService implements ISynchronizeService -{ +class KelinCustomerService implements ISynchronizeService { private $rootUrl = '/listCons'; + private $kelinCustomer; + private $person; + private $kelinApiClient; + private $apiHelpers; + private $syncSettingService; + private $syncActionService; public function __construct( @@ -40,8 +45,7 @@ public function __construct( $this->syncSettingService = $syncSettingService; } - public function sync() - { + public function sync() { $synSetting = $this->syncSettingService->getSyncSettingsByActionName('Customers'); $syncAction = $this->syncActionService->getSyncActionBySynSettingId($synSetting->id); try { @@ -50,8 +54,10 @@ public function sync() $syncCheck['data']->filter(function ($value) { return $value['syncStatus'] === SyncStatus::EARLY_REGISTERED; })->each(function ($customer) { - $person = $this->updateRelatedPerson($customer, - $customer['relatedPerson']); + $person = $this->updateRelatedPerson( + $customer, + $customer['relatedPerson'] + ); try { $this->kelinCustomer->newQuery()->create([ 'customer_no' => $customer['consNo'], @@ -114,8 +120,7 @@ public function sync() } } - public function syncCheck($returnData = false) - { + public function syncCheck($returnData = false) { try { $url = $this->rootUrl; $result = $this->kelinApiClient->get($url); @@ -173,8 +178,7 @@ public function syncCheck($returnData = false) return $returnData ? ['data' => $customersCollection, 'result' => true] : ['result' => true]; } - public function createRelatedPerson($customer) - { + public function createRelatedPerson($customer) { $names = explode(' ', $customer['consName']); $phone = ltrim($customer['mobile'], $customer['mobile'][0]); @@ -213,8 +217,7 @@ public function createRelatedPerson($customer) return $person; } - public function updateRelatedPerson($customer, $person) - { + public function updateRelatedPerson($customer, $person) { $names = explode(' ', $customer['consName']); if (count($names) == 1) { $name = $customer['consName']; @@ -240,15 +243,13 @@ public function updateRelatedPerson($customer, $person) return $person; } - public function getCustomers($request) - { + public function getCustomers($request) { $perPage = $request->input('per_page') ?? 15; return $this->kelinCustomer->newQuery()->with(['mpmPerson.addresses'])->paginate($perPage); } - private function kelinCustomerHasher($kelinCustomer) - { + private function kelinCustomerHasher($kelinCustomer) { $phone = ltrim($kelinCustomer['mobile'], $kelinCustomer['mobile'][0]); return $this->apiHelpers->makeHash([ @@ -259,8 +260,7 @@ private function kelinCustomerHasher($kelinCustomer) ]); } - private function findRegisteredCustomer($customer) - { + private function findRegisteredCustomer($customer) { return $this->person->newQuery()->where('title', $customer['consNo'])->first(); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Services/KelinMeterService.php b/src/backend/packages/inensus/kelin-meter/src/Services/KelinMeterService.php index 61308863b..2927d07d6 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Services/KelinMeterService.php +++ b/src/backend/packages/inensus/kelin-meter/src/Services/KelinMeterService.php @@ -22,23 +22,35 @@ use Inensus\KelinMeter\Models\KelinMeter; use Inensus\KelinMeter\Models\SyncStatus; -class KelinMeterService implements ISynchronizeService -{ +class KelinMeterService implements ISynchronizeService { private $meter; + private $rootUrl = '/listMeter'; + private $kelinMeter; + private $kelinApiClient; + private $apiHelpers; + private $syncSettingService; + private $syncActionService; + private $kelinCustomer; + private $meterParameter; + private $manufacturer; private $connectionGroup; + private $connectionType; + private $meterTariff; + private $city; + private $earlyRegisteredMeters; public function __construct( @@ -51,7 +63,6 @@ public function __construct( KelinCustomer $kelinCustomer, MeterParameter $meterParameter, Manufacturer $manufacturer, - ConnectionGroup $connectionGroup, ConnectionType $connectionType, MeterTariff $meterTariff, @@ -73,8 +84,7 @@ public function __construct( $this->city = $city; } - public function getMeters($request) - { + public function getMeters($request) { $perPage = $request->input('per_page') ?? 15; return $this->kelinMeter->newQuery()->with([ @@ -83,8 +93,7 @@ public function getMeters($request) ])->paginate($perPage); } - public function sync() - { + public function sync() { $synSetting = $this->syncSettingService->getSyncSettingsByActionName('Meters'); $syncAction = $this->syncActionService->getSyncActionBySynSettingId($synSetting->id); try { @@ -105,8 +114,10 @@ public function sync() $syncCheck['data']->filter(function ($value) { return $value['syncStatus'] === SyncStatus::EARLY_REGISTERED; })->each(function ($meter) { - $updatedMeter = $this->updateRelatedMeter($meter, - $meter['relatedMeter']); + $updatedMeter = $this->updateRelatedMeter( + $meter, + $meter['relatedMeter'] + ); $this->kelinMeter->newQuery()->create([ 'meter_name' => $meter['meterName'], 'meter_address' => $meter['meterAddr'], @@ -141,8 +152,7 @@ public function sync() } } - public function syncCheck($returnData = false) - { + public function syncCheck($returnData = false) { try { $url = $this->rootUrl; $result = $this->kelinApiClient->get($url); @@ -200,8 +210,7 @@ public function syncCheck($returnData = false) return $returnData ? ['data' => $metersCollection, 'result' => true] : ['result' => true]; } - private function kelinMeterHasher($kelinMeter) - { + private function kelinMeterHasher($kelinMeter) { return $this->apiHelpers->makeHash([ $kelinMeter['consNo'], $kelinMeter['meterAddr'], @@ -215,8 +224,7 @@ private function kelinMeterHasher($kelinMeter) ]); } - public function createRelatedMeter($kelinMeter) - { + public function createRelatedMeter($kelinMeter) { try { DB::connection('shard')->beginTransaction(); $meterSerial = $this->generateMeterSerialNumberInFormat($kelinMeter['meterAddr']); @@ -300,8 +308,7 @@ public function createRelatedMeter($kelinMeter) } } - public function updateRelatedMeter($kelinMeter, $meter) - { + public function updateRelatedMeter($kelinMeter, $meter) { $kelinCustomer = $this->kelinCustomer->newQuery()->with('mpmPerson')->where( 'customer_no', $kelinMeter['consNo'] @@ -323,8 +330,7 @@ public function updateRelatedMeter($kelinMeter, $meter) return $meter; } - private function findRegisteredMeter($kelinMeter) - { + private function findRegisteredMeter($kelinMeter) { $meter = collect($this->earlyRegisteredMeters)->where('meter_serial', $kelinMeter['meterAddr'])->first(); if (!$meter) { return $meter; @@ -333,8 +339,7 @@ private function findRegisteredMeter($kelinMeter) return $this->meter->newQuery()->find($meter['id']); } - private function getEarlyRegisteredMetersWithChangeSerialNumbersAsSimilarAsKalinMeterData() - { + private function getEarlyRegisteredMetersWithChangeSerialNumbersAsSimilarAsKalinMeterData() { $this->earlyRegisteredMeters = $this->meter->newQuery()->get()->map(function ($q) { $string = substr($q->serial_number, 0, -2); $array = explode('-', $string); @@ -347,8 +352,7 @@ private function getEarlyRegisteredMetersWithChangeSerialNumbersAsSimilarAsKalin }); } - private function generateMeterSerialNumberInFormat($meterAddress) - { + private function generateMeterSerialNumberInFormat($meterAddress) { $length = strlen($meterAddress); $newSerial = $meterAddress[0]; for ($i = 0; $i < $length; ++$i) { diff --git a/src/backend/packages/inensus/kelin-meter/src/Services/KelinMeterStatusService.php b/src/backend/packages/inensus/kelin-meter/src/Services/KelinMeterStatusService.php index 1506da96b..00f4c19a6 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Services/KelinMeterStatusService.php +++ b/src/backend/packages/inensus/kelin-meter/src/Services/KelinMeterStatusService.php @@ -7,18 +7,16 @@ use Inensus\KelinMeter\Exceptions\KelinApiResponseException; use Inensus\KelinMeter\Http\Clients\KelinMeterApiClient; -class KelinMeterStatusService -{ +class KelinMeterStatusService { private $rootUrl = '/getMeterStatus'; + private $kelinApiClient; - public function __construct(KelinMeterApiClient $kelinApiClient) - { + public function __construct(KelinMeterApiClient $kelinApiClient) { $this->kelinApiClient = $kelinApiClient; } - public function getStatusOfMeter($meter) - { + public function getStatusOfMeter($meter) { try { $queryParams = [ 'meterType' => 1, @@ -40,8 +38,7 @@ public function getStatusOfMeter($meter) } } - public function changeStatusOfMeter($meterAddress, $status) - { + public function changeStatusOfMeter($meterAddress, $status) { try { $rootUrl = '/meterRemoteControl'; $queryParams = [ diff --git a/src/backend/packages/inensus/kelin-meter/src/Services/KelinSettingService.php b/src/backend/packages/inensus/kelin-meter/src/Services/KelinSettingService.php index 3129723d9..f41ac2561 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Services/KelinSettingService.php +++ b/src/backend/packages/inensus/kelin-meter/src/Services/KelinSettingService.php @@ -4,17 +4,14 @@ use Inensus\KelinMeter\Models\KelinSetting; -class KelinSettingService -{ +class KelinSettingService { private $kelinSetting; - public function __construct(KelinSetting $kelinSetting) - { + public function __construct(KelinSetting $kelinSetting) { $this->kelinSetting = $kelinSetting; } - public function getSettings() - { + public function getSettings() { return $this->kelinSetting->newQuery()->with(['setting'])->get(); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Services/KelinSyncActionService.php b/src/backend/packages/inensus/kelin-meter/src/Services/KelinSyncActionService.php index 2e192df61..92880cdcf 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Services/KelinSyncActionService.php +++ b/src/backend/packages/inensus/kelin-meter/src/Services/KelinSyncActionService.php @@ -6,32 +6,26 @@ use Carbon\CarbonInterval; use Inensus\KelinMeter\Models\KelinSyncAction; -class KelinSyncActionService -{ +class KelinSyncActionService { private $syncAction; - public function __construct(KelinSyncAction $syncAction) - { + public function __construct(KelinSyncAction $syncAction) { $this->syncAction = $syncAction; } - public function createSyncAction($syncAction) - { + public function createSyncAction($syncAction) { return $this->syncAction->newQuery()->create($syncAction); } - public function getSyncActionBySynSettingId($settingId) - { + public function getSyncActionBySynSettingId($settingId) { return $this->syncAction->newQuery()->where('sync_setting_id', $settingId)->first(); } - public function getActionsNeedsToSync() - { + public function getActionsNeedsToSync() { return $this->syncAction->newQuery()->where('next_sync', '<=', Carbon::now())->orderBy('next_sync')->get(); } - public function updateSyncAction($syncAction, $syncSetting, $syncResult) - { + public function updateSyncAction($syncAction, $syncSetting, $syncResult) { if (!$syncResult) { return $syncAction->update([ 'attempts' => $syncAction->attempts + 1, diff --git a/src/backend/packages/inensus/kelin-meter/src/Services/KelinSyncSettingService.php b/src/backend/packages/inensus/kelin-meter/src/Services/KelinSyncSettingService.php index 936c5581f..be75a5813 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Services/KelinSyncSettingService.php +++ b/src/backend/packages/inensus/kelin-meter/src/Services/KelinSyncSettingService.php @@ -8,10 +8,11 @@ use Inensus\KelinMeter\Models\KelinSetting; use Inensus\KelinMeter\Models\KelinSyncSetting; -class KelinSyncSettingService -{ +class KelinSyncSettingService { private $syncSetting; + private $setting; + private $syncActionService; public function __construct( @@ -24,8 +25,7 @@ public function __construct( $this->syncActionService = $syncActionService; } - public function createDefaultSettings() - { + public function createDefaultSettings() { $dayInterval = CarbonInterval::make('1day'); $fiveMinInterval = CarbonInterval::make('5minute'); @@ -66,8 +66,7 @@ public function createDefaultSettings() } } - public function updateSyncSettings($syncSettings) - { + public function updateSyncSettings($syncSettings) { foreach ($syncSettings as $setting) { $syncSetting = $this->syncSetting->newQuery()->find($setting['id']); $intervalStr = $setting['sync_in_value_num'].$setting['sync_in_value_str']; @@ -92,13 +91,11 @@ public function updateSyncSettings($syncSettings) return $this->syncSetting->newQuery()->get(); } - public function getSyncSettings() - { + public function getSyncSettings() { return $this->syncSetting->newQuery()->get(); } - public function getSyncSettingsByActionName($actionName) - { + public function getSyncSettingsByActionName($actionName) { try { return $this->syncSetting->newQuery()->where('action_name', $actionName)->firstOrFail(); } catch (\Exception $exception) { diff --git a/src/backend/packages/inensus/kelin-meter/src/Services/MinutelyConsumptionService.php b/src/backend/packages/inensus/kelin-meter/src/Services/MinutelyConsumptionService.php index 0fc90cb4d..e574c9c93 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Services/MinutelyConsumptionService.php +++ b/src/backend/packages/inensus/kelin-meter/src/Services/MinutelyConsumptionService.php @@ -7,10 +7,11 @@ use Inensus\KelinMeter\Http\Clients\KelinMeterApiClient; use Inensus\KelinMeter\Models\KelinMeterMinutelyData; -class MinutelyConsumptionService -{ +class MinutelyConsumptionService { private $rootUrl = '/getMinData'; + private $kelinApi; + private $kelinMeterMinutelyData; public function __construct( @@ -21,8 +22,7 @@ public function __construct( $this->kelinMeterMinutelyData = $kelinMeterMinutelyData; } - public function getMinutelyDataFromAPI() - { + public function getMinutelyDataFromAPI() { $today = Carbon::now()->format('Ymd'); $moment = Carbon::now()->format('His'); $pageNo = 1; @@ -79,8 +79,7 @@ public function getMinutelyDataFromAPI() } while ($result['data']['dataCount'] > 0); } - public function getDailyData($meterAddress, $perPage) - { + public function getDailyData($meterAddress, $perPage) { return $this->kelinMeterMinutelyData->newQuery()->where('address_of_meter', $meterAddress)->orderByDesc('id')->paginate($perPage); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Services/PackageInstallationService.php b/src/backend/packages/inensus/kelin-meter/src/Services/PackageInstallationService.php index 34ddee422..bb87d18e7 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Services/PackageInstallationService.php +++ b/src/backend/packages/inensus/kelin-meter/src/Services/PackageInstallationService.php @@ -2,15 +2,12 @@ namespace Inensus\KelinMeter\Services; -class PackageInstallationService -{ +class PackageInstallationService { public function __construct( private KelinSyncSettingService $syncSettingService, - ) { - } + ) {} - public function createDefaultSettingRecords() - { + public function createDefaultSettingRecords() { $this->syncSettingService->createDefaultSettings(); } } diff --git a/src/backend/packages/inensus/kelin-meter/src/Tests/Feature/RechargeMeterTest.php b/src/backend/packages/inensus/kelin-meter/src/Tests/Feature/RechargeMeterTest.php index 9cc76b8ce..10fa1c62a 100644 --- a/src/backend/packages/inensus/kelin-meter/src/Tests/Feature/RechargeMeterTest.php +++ b/src/backend/packages/inensus/kelin-meter/src/Tests/Feature/RechargeMeterTest.php @@ -23,13 +23,11 @@ use Inensus\KelinMeter\Models\KelinMeter; use Tests\TestCase; -class RechargeMeterTest extends TestCase -{ +class RechargeMeterTest extends TestCase { use RefreshDatabase; use WithFaker; - public function testTokenGeneration() - { + public function testTokenGeneration() { Queue::fake(); $this->initData(); $t = Transaction::create([ @@ -47,8 +45,7 @@ public function testTokenGeneration() $this->assertEquals(1, MeterToken::query()->get()->count()); } - private function initData() - { + private function initData() { KelinCredential::query()->create([ 'id' => 1, 'api_url' => 'http://222.222.60.178:62189/EI', diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Console/Commands/InstallPackage.php index 067533a60..80f745678 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Console/Commands/InstallPackage.php @@ -4,24 +4,21 @@ use Illuminate\Console\Command; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'mesomb-payment-provider:install'; + protected $description = 'Install MesombPaymentProvider Package'; - public function __construct() - { + public function __construct() { parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing MesombPaymentProvider Integration Package\n'); $this->info('Package installed successfully..'); } - private function publishMigrations() - { + private function publishMigrations() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\MesombPaymentProvider\Providers\MesombServiceProvider", @@ -29,14 +26,12 @@ private function publishMigrations() ]); } - private function createDatabaseTables() - { + private function createDatabaseTables() { $this->info('Creating database tables\n'); $this->call('migrate'); } - private function createPluginRecord() - { + private function createPluginRecord() { $this->call('plugin:add', [ 'name' => 'MesombPaymentProvider', 'composer_name' => 'inensus/mesomb-payment-provider', diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Console/Commands/UpdatePackage.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Console/Commands/UpdatePackage.php index 93114c7b1..90dade2e0 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Console/Commands/UpdatePackage.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Console/Commands/UpdatePackage.php @@ -6,9 +6,9 @@ use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Facades\DB; -class UpdatePackage extends Command -{ +class UpdatePackage extends Command { protected $signature = 'mesomb-payment-provider:update'; + protected $description = 'Update the Mesomb Payment Provider Integration Package'; public function __construct( @@ -20,8 +20,7 @@ public function __construct( /** * Execute the console command. */ - public function handle(): void - { + public function handle(): void { $this->info('Mesomb Payment Provider Integration Updating Started\n'); $this->removeOldVersionOfPackage(); $this->installNewVersionOfPackage(); @@ -31,20 +30,17 @@ public function handle(): void $this->info('Package updated successfully..'); } - private function removeOldVersionOfPackage() - { + private function removeOldVersionOfPackage() { $this->info('Removing former version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar remove inensus/mesomb-payment-provider'); } - private function installNewVersionOfPackage() - { + private function installNewVersionOfPackage() { $this->info('Installing last version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar require inensus/mesomb-payment-provider'); } - private function deleteMigration(Filesystem $filesystem) - { + private function deleteMigration(Filesystem $filesystem) { $migrationFile = $filesystem->glob(database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'*_create_mesomb_payment_provider_tables.php')[0]; $migration = DB::table('migrations') ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->first(); @@ -55,8 +51,7 @@ private function deleteMigration(Filesystem $filesystem) ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->delete(); } - private function publishMigrationsAgain() - { + private function publishMigrationsAgain() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\MesombPaymentProvider\Providers\MesombServiceProvider", @@ -64,8 +59,7 @@ private function publishMigrationsAgain() ]); } - private function updateDatabase() - { + private function updateDatabase() { $this->info('Updating database tables\n'); $this->call('migrate'); } diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Exceptions/MesombPayerMustHaveOnlyOneConnectedMeterException.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Exceptions/MesombPayerMustHaveOnlyOneConnectedMeterException.php index a2bf80122..c65894a50 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Exceptions/MesombPayerMustHaveOnlyOneConnectedMeterException.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Exceptions/MesombPayerMustHaveOnlyOneConnectedMeterException.php @@ -2,6 +2,4 @@ namespace Inensus\MesombPaymentProvider\Exceptions; -class MesombPayerMustHaveOnlyOneConnectedMeterException extends \Exception -{ -} +class MesombPayerMustHaveOnlyOneConnectedMeterException extends \Exception {} diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Exceptions/MesombPaymentPhoneNumberNotFoundException.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Exceptions/MesombPaymentPhoneNumberNotFoundException.php index 86cc53bd9..4e8cb327a 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Exceptions/MesombPaymentPhoneNumberNotFoundException.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Exceptions/MesombPaymentPhoneNumberNotFoundException.php @@ -2,6 +2,4 @@ namespace Inensus\MesombPaymentProvider\Exceptions; -class MesombPaymentPhoneNumberNotFoundException extends \Exception -{ -} +class MesombPaymentPhoneNumberNotFoundException extends \Exception {} diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Exceptions/MesombStatusFailedException.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Exceptions/MesombStatusFailedException.php index 40dc55a05..d16a9f826 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Exceptions/MesombStatusFailedException.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Exceptions/MesombStatusFailedException.php @@ -2,6 +2,4 @@ namespace Inensus\MesombPaymentProvider\Exceptions; -class MesombStatusFailedException extends \Exception -{ -} +class MesombStatusFailedException extends \Exception {} diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Controllers/MesombPaymentProviderController.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Controllers/MesombPaymentProviderController.php index 391796bfe..6c99bcff8 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Controllers/MesombPaymentProviderController.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Controllers/MesombPaymentProviderController.php @@ -6,10 +6,8 @@ use Illuminate\Routing\Controller; use Inensus\MesombPaymentProvider\Http\Resources\MesombTransactionProcessingResource; -class MesombPaymentProviderController extends Controller -{ - public function store() - { +class MesombPaymentProviderController extends Controller { + public function store() { $transactionProvider = resolve('MesombPaymentProvider'); $transactionProvider->saveTransaction(); // store common data diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Kernel.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Kernel.php index 5685569bb..3bf8a537a 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Kernel.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Kernel.php @@ -5,8 +5,7 @@ use Illuminate\Foundation\Http\Kernel as HttpKernel; use Inensus\MesombPaymentProvider\Http\Middleware\MesombTransactionRequest; -class Kernel extends HttpKernel -{ +class Kernel extends HttpKernel { protected $routeMiddleware = [ 'mesomb.transaction.request' => MesombTransactionRequest::class, ]; diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Middleware/MesombTransactionRequest.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Middleware/MesombTransactionRequest.php index f3fb52c0d..8674613e5 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Middleware/MesombTransactionRequest.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Middleware/MesombTransactionRequest.php @@ -8,10 +8,8 @@ use Inensus\MesombPaymentProvider\Exceptions\MesombPaymentPhoneNumberNotFoundException; use Inensus\MesombPaymentProvider\Exceptions\MesombStatusFailedException; -class MesombTransactionRequest -{ - public function handle(Request $request, \Closure $next) - { +class MesombTransactionRequest { + public function handle(Request $request, \Closure $next) { $transactionProvider = resolve('MesombPaymentProvider'); try { $transactionProvider->validateRequest($request); @@ -21,7 +19,8 @@ public function handle(Request $request, \Closure $next) [ 'message' => $request->input('message'), 'pk' => $request->input('pk'), - ]); + ] + ); return response()->json([ 'errors' => [ diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Resources/MesombTransactionProcessingResource.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Resources/MesombTransactionProcessingResource.php index ad3fa435c..ccec12c06 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Resources/MesombTransactionProcessingResource.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Http/Resources/MesombTransactionProcessingResource.php @@ -4,8 +4,7 @@ use Illuminate\Http\Resources\Json\JsonResource; -class MesombTransactionProcessingResource extends JsonResource -{ +class MesombTransactionProcessingResource extends JsonResource { /** * Transform the resource into an array. * @@ -13,8 +12,7 @@ class MesombTransactionProcessingResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return [ 'data' => [ 'type' => 'mesomb_transaction', diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Listeners/TransactionListener.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Listeners/TransactionListener.php index 3042096f8..49334f725 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Listeners/TransactionListener.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Listeners/TransactionListener.php @@ -6,10 +6,8 @@ use Illuminate\Events\Dispatcher; use Illuminate\Support\Facades\Log; -class TransactionListener -{ - public function onTransactionFailed(Transaction $transaction, $message = null): void - { +class TransactionListener { + public function onTransactionFailed(Transaction $transaction, $message = null): void { $transactionProvider = resolve('MesombPaymentProvider'); $transactionProvider->addConflict($message); if (config('app.debug')) { @@ -18,18 +16,18 @@ public function onTransactionFailed(Transaction $transaction, $message = null): $transactionProvider->sendResult(false, $transaction); } - public function onTransactionSuccess(Transaction $transaction) - { + public function onTransactionSuccess(Transaction $transaction) { $transactionProvider = resolve('MesombPaymentProvider'); $transactionProvider->sendResult(true, $transaction); } - public function subscribe(Dispatcher $events) - { - $events->listen('transaction.successful', + public function subscribe(Dispatcher $events) { + $events->listen( + 'transaction.successful', 'Inensus\MesombPaymentProvider\Listeners\TransactionListener@onTransactionSuccess' ); - $events->listen('transaction.failed', + $events->listen( + 'transaction.failed', 'Inensus\MesombPaymentProvider\Listeners\TransactionListener@onTransactionFailed' ); } diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Models/BaseModel.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Models/BaseModel.php index c83529006..9e2fc612c 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Models/BaseModel.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Models/BaseModel.php @@ -4,19 +4,17 @@ use Illuminate\Database\Eloquent\Model; -class BaseModel extends Model -{ +class BaseModel extends Model { protected $guarded = ['id']; + public static $rules = []; - public function __construct(array $attributes = []) - { + public function __construct(array $attributes = []) { parent::__construct($attributes); $this->setConnection('shard'); } - public function resolveChildRouteBinding($childType, $value, $field) - { + public function resolveChildRouteBinding($childType, $value, $field) { // TODO: Implement resolveChildRouteBinding() method. } } diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Models/MesombTransaction.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Models/MesombTransaction.php index 3fd108e1c..57ce27b58 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Models/MesombTransaction.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Models/MesombTransaction.php @@ -9,25 +9,18 @@ use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphTo; -class MesombTransaction extends BaseModel implements IRawTransaction -{ +class MesombTransaction extends BaseModel implements IRawTransaction { protected $table = 'mesomb_transactions'; - /** - * @return MorphOne - */ - public function transaction(): MorphOne - { + public function transaction(): MorphOne { return $this->morphOne(Transaction::class, 'original_transaction'); } - public function manufacturerTransaction(): MorphTo - { + public function manufacturerTransaction(): MorphTo { return $this->morphTo(); } - public function conflicts(): MorphMany - { + public function conflicts(): MorphMany { return $this->morphMany(TransactionConflicts::class, 'transaction'); } } diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/EventServiceProvider.php index aa29178ec..615f14087 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/EventServiceProvider.php @@ -5,8 +5,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Inensus\MesombPaymentProvider\Listeners\TransactionListener; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ // TransactionListener::class ]; @@ -16,8 +15,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/MesombServiceProvider.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/MesombServiceProvider.php index 07c7b3d69..5fe50b077 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/MesombServiceProvider.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/MesombServiceProvider.php @@ -10,10 +10,8 @@ use Inensus\MesombPaymentProvider\Console\Commands\UpdatePackage; use Inensus\MesombPaymentProvider\Models\MesombTransaction; -class MesombServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class MesombServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -27,30 +25,26 @@ public function boot(Filesystem $filesystem) ); } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/mesomb-payment-provider.php', 'mesomb-payment-provider'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->singleton('MesombPaymentProvider', MesombTransactionProvider::class); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/mesomb-payment-provider.php' => config_path('mesomb-payment-provider.php'), ]); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_mesomb_payment_provider_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) @@ -58,8 +52,10 @@ protected function getMigrationFileName(Filesystem $filesystem): string if (count($filesystem->glob($path.'*_create_mesomb_payment_provider_tables.php'))) { $file = $filesystem->glob($path.'*_create_mesomb_payment_provider_tables.php')[0]; - file_put_contents($file, - file_get_contents(__DIR__.'/../../database/migrations/create_mesomb_payment_provider_tables.php.stub')); + file_put_contents( + $file, + file_get_contents(__DIR__.'/../../database/migrations/create_mesomb_payment_provider_tables.php.stub') + ); } return $filesystem->glob($path.'*_create_mesomb_payment_provider_tables.php'); diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/MesombTransactionProvider.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/MesombTransactionProvider.php index db964ef9d..2a22eacb2 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/MesombTransactionProvider.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/MesombTransactionProvider.php @@ -17,12 +17,15 @@ use Inensus\MesombPaymentProvider\Services\MesomTransactionService; use MPM\Transaction\Provider\ITransactionProvider; -class MesombTransactionProvider implements ITransactionProvider -{ +class MesombTransactionProvider implements ITransactionProvider { private $transaction; + private $mesombTransaction; + private $mesombTransactionService; + private $validData = []; + private $address; public function __construct( @@ -37,8 +40,7 @@ public function __construct( $this->address = $address; } - public function validateRequest($request) - { + public function validateRequest($request) { $requestData = $request->all(); if ($requestData['status'] === 'FAILED') { throw new MesombStatusFailedException($requestData['status'].' Sender: '.$requestData['b_party']); @@ -49,20 +51,19 @@ public function validateRequest($request) $this->validData = array_merge($this->validData, $requestData); } - public function saveTransaction() - { + public function saveTransaction() { $this->mesombTransaction = $this->mesombTransactionService->assignIncomingDataToMesombTransaction($this->validData); $this->transaction = $this->mesombTransactionService->assignIncomingDataToTransaction($this->validData); } - public function saveCommonData(): Model - { - return $this->mesombTransactionService->associateMesombTransactionWithTransaction($this->mesombTransaction, - $this->transaction); + public function saveCommonData(): Model { + return $this->mesombTransactionService->associateMesombTransactionWithTransaction( + $this->mesombTransaction, + $this->transaction + ); } - public function sendResult(bool $requestType, Transaction $transaction) - { + public function sendResult(bool $requestType, Transaction $transaction) { $this->mesombTransaction = $transaction->originalTransaction()->first(); if ($requestType) { $this->mesombTransaction->status = 1; @@ -76,8 +77,7 @@ public function sendResult(bool $requestType, Transaction $transaction) } } - public function confirm(): void - { + public function confirm(): void { echo $xmlResponse = ''. ''. @@ -91,8 +91,7 @@ public function confirm(): void ''; } - private function checkPhoneIsExists($requestData): Model - { + private function checkPhoneIsExists($requestData): Model { $personAddresses = $this->address->newQuery() ->where('phone', $requestData['b_party']) ->orWhere('phone', '+'.$requestData['b_party'])->get(); @@ -104,10 +103,11 @@ private function checkPhoneIsExists($requestData): Model return $personAddresses->first(); } - private function checkSenderHasOnlyOneMeterRegistered($senderAddress): void - { + private function checkSenderHasOnlyOneMeterRegistered($senderAddress): void { $senderMeters = $senderAddress->newQuery()->whereHasMorph( - 'owner', [Person::class]) + 'owner', + [Person::class] + ) ->first()->owner()->first()->meters(); $senderMetersCount = $senderMeters->count(); if ($senderMetersCount > 1 || $senderMetersCount == 0) { @@ -117,33 +117,27 @@ private function checkSenderHasOnlyOneMeterRegistered($senderAddress): void $this->validData['meter'] = $senderMeters->first()->meter()->first()->serial_number; } - public function init($transaction): void - { + public function init($transaction): void { // TODO: Implement init() method. } - public function addConflict(?string $message): void - { + public function addConflict(?string $message): void { // TODO: Implement addConflict() method. } - public function getTransaction(): Transaction - { + public function getTransaction(): Transaction { // TODO: Implement getTransaction() method. } - public function getMessage(): string - { + public function getMessage(): string { // TODO: Implement getMessage() method. } - public function getAmount(): int - { + public function getAmount(): int { // TODO: Implement getAmount() method. } - public function getSender(): string - { + public function getSender(): string { // TODO: Implement getSender() method. } } diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/ObserverServiceProvider.php index cdbe9fcb6..05f5e7178 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/ObserverServiceProvider.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/RouteServiceProvider.php index 2835917cc..cad77292e 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\MesombPaymentProvider\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Services/MesomTransactionService.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Services/MesomTransactionService.php index 418ffbcf8..36229fec3 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Services/MesomTransactionService.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Services/MesomTransactionService.php @@ -5,21 +5,20 @@ use App\Models\Transaction\Transaction; use Inensus\MesombPaymentProvider\Models\MesombTransaction; -class MesomTransactionService -{ +class MesomTransactionService { private $mesombTransaction; + private $transaction; public function __construct( MesombTransaction $mesombTransaction, - Transaction $transaction) - { + Transaction $transaction, + ) { $this->mesombTransaction = $mesombTransaction; $this->transaction = $transaction; } - public function assignIncomingDataToMesombTransaction(array $data) - { + public function assignIncomingDataToMesombTransaction(array $data) { return $this->mesombTransaction->newQuery()->create([ 'pk' => $data['pk'], 'type' => $data['type'], @@ -32,8 +31,7 @@ public function assignIncomingDataToMesombTransaction(array $data) ]); } - public function assignIncomingDataToTransaction(array $data) - { + public function assignIncomingDataToTransaction(array $data) { return $this->transaction->newQuery()->make([ 'amount' => (int) $data['amount'], 'sender' => $data['b_party'], @@ -43,8 +41,7 @@ public function assignIncomingDataToTransaction(array $data) ]); } - public function associateMesombTransactionWithTransaction($mesombTransaction, $transaction) - { + public function associateMesombTransactionWithTransaction($mesombTransaction, $transaction) { return $mesombTransaction->transaction()->save($transaction); } } diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Tests/Feature/PaymentTests.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Tests/Feature/PaymentTests.php index 8c0b43933..e8786cf24 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Tests/Feature/PaymentTests.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Tests/Feature/PaymentTests.php @@ -17,13 +17,11 @@ use Tests\CreatesApplication; use Tests\TestCase; -class PaymentTests extends TestCase -{ - use RefreshDatabase; +class PaymentTests extends TestCase { use CreatesApplication; + use RefreshDatabase; - public function testOnlySuccessesPaymentsCanBeProcessed() - { + public function testOnlySuccessesPaymentsCanBeProcessed() { $data = [ 'status' => 'FAILED', 'type' => 'Payment', @@ -41,8 +39,7 @@ public function testOnlySuccessesPaymentsCanBeProcessed() ]); } - public function testOnlyOnePhoneNumberIsValidForOneCustomer() - { + public function testOnlyOnePhoneNumberIsValidForOneCustomer() { $data = [ 'status' => 'SUCCESS', 'type' => 'Payment', @@ -61,8 +58,7 @@ public function testOnlyOnePhoneNumberIsValidForOneCustomer() ]); } - public function testOnlyOneConnectingMeterIsValidForOneNumber() - { + public function testOnlyOneConnectingMeterIsValidForOneNumber() { // create person factory(Person::class)->create(); // associate meter with a person @@ -93,8 +89,7 @@ public function testOnlyOneConnectingMeterIsValidForOneNumber() ]); } - public function testValidTransactionStartsTransactionProcessing() - { + public function testValidTransactionStartsTransactionProcessing() { Queue::fake(); $this->withoutExceptionHandling(); $this->initializeData(); @@ -135,8 +130,7 @@ public function testValidTransactionStartsTransactionProcessing() Queue::assertPushed(ProcessPayment::class); } - private function initializeData() - { + private function initializeData() { // create person factory(Person::class)->create(); // create meter-tariff diff --git a/src/backend/packages/inensus/mesomb-payment-provider/src/Tests/Unit/PaymentProcessTests.php b/src/backend/packages/inensus/mesomb-payment-provider/src/Tests/Unit/PaymentProcessTests.php index 3ee0f5f0b..1c95fd443 100644 --- a/src/backend/packages/inensus/mesomb-payment-provider/src/Tests/Unit/PaymentProcessTests.php +++ b/src/backend/packages/inensus/mesomb-payment-provider/src/Tests/Unit/PaymentProcessTests.php @@ -21,12 +21,10 @@ use Inensus\MesombPaymentProvider\Services\MesomTransactionService; use Tests\TestCase; -class PaymentProcessTests extends TestCase -{ +class PaymentProcessTests extends TestCase { use RefreshDatabase; - public function testProcessPaymentStartsEnergyTransactionProcessor() - { + public function testProcessPaymentStartsEnergyTransactionProcessor() { Queue::fake(); $this->initializeData(); $transaction = $this->initializeTransaction(); @@ -34,8 +32,7 @@ public function testProcessPaymentStartsEnergyTransactionProcessor() Queue::assertPushed(EnergyTransactionProcessor::class); } - public function testEnergyTransactionProcessorStartsTokenProcessor() - { + public function testEnergyTransactionProcessorStartsTokenProcessor() { Queue::fake(); $this->initializeData(); $transaction = $this->initializeTransaction(); @@ -43,8 +40,7 @@ public function testEnergyTransactionProcessorStartsTokenProcessor() Queue::assertPushed(TokenProcessor::class); } - public function testTokenProcessorChargesMeter() - { + public function testTokenProcessorChargesMeter() { Queue::fake(); $this->initializeData(); $transaction = $this->initializeTransaction(); @@ -58,8 +54,7 @@ public function testTokenProcessorChargesMeter() $this->assertEquals(1, $mesombPaymentCount); } - private function initializeTransaction() - { + private function initializeTransaction() { $validData = [ 'pk' => 'ae58a073-2b76-4774-995b-3743d6793d53', 'type' => 'PAYMENT', @@ -76,12 +71,13 @@ private function initializeTransaction() $mesombTransaction = $mesombTransactionService->assignIncomingDataToMesombTransaction($validData); $transaction = $mesombTransactionService->assignIncomingDataToTransaction($validData); - return $mesombTransactionService->associateMesombTransactionWithTransaction($mesombTransaction, - $transaction); + return $mesombTransactionService->associateMesombTransactionWithTransaction( + $mesombTransaction, + $transaction + ); } - private function initializeData() - { + private function initializeData() { // create person factory(Person::class)->create(); // create meter-tariff diff --git a/src/backend/packages/inensus/micro-star-meter/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/micro-star-meter/src/Console/Commands/InstallPackage.php index 99855d3bf..561d381c5 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Console/Commands/InstallPackage.php @@ -6,9 +6,9 @@ use Inensus\MicroStarMeter\Services\ManufacturerService; use Inensus\MicroStarMeter\Services\MicroStarCredentialService; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'micro-star-meter:install'; + protected $description = 'Install MicroStarMeter Package'; public function __construct( @@ -18,16 +18,14 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing MicroStarMeter Integration Package\n'); $this->manufacturerService->register(); $this->credentialService->createCredentials(); $this->info('Package installed successfully..'); } - private function publishMigrations() - { + private function publishMigrations() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\MicroStarMeter\Providers\MicroStarMeterServiceProvider", @@ -35,14 +33,12 @@ private function publishMigrations() ]); } - private function createDatabaseTables() - { + private function createDatabaseTables() { $this->info('Creating database tables\n'); $this->call('migrate'); } - private function publishVueFiles() - { + private function publishVueFiles() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\MicroStarMeter\Providers\MicroStarMeterServiceProvider", @@ -50,8 +46,7 @@ private function publishVueFiles() ]); } - private function createPluginRecord() - { + private function createPluginRecord() { $this->call('plugin:add', [ 'name' => 'MicroStarMeter', 'composer_name' => 'inensus/micro-star-meter', diff --git a/src/backend/packages/inensus/micro-star-meter/src/Console/Commands/UpdatePackage.php b/src/backend/packages/inensus/micro-star-meter/src/Console/Commands/UpdatePackage.php index c1998cbbf..dad2b042d 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Console/Commands/UpdatePackage.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Console/Commands/UpdatePackage.php @@ -6,9 +6,9 @@ use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Facades\DB; -class UpdatePackage extends Command -{ +class UpdatePackage extends Command { protected $signature = 'micro-star-meter:update'; + protected $description = 'Update MicroStarMeter Package'; public function __construct( @@ -17,8 +17,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('MicroStar Meter Integration Updating Started\n'); $this->removeOldVersionOfPackage(); $this->installNewVersionOfPackage(); @@ -31,20 +30,17 @@ public function handle(): void $this->info('Package updated successfully..'); } - private function removeOldVersionOfPackage() - { + private function removeOldVersionOfPackage() { $this->info('Removing former version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar remove inensus/micro-star-meter'); } - private function installNewVersionOfPackage() - { + private function installNewVersionOfPackage() { $this->info('Installing last version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar require inensus/micro-star-meter'); } - private function deleteMigration(Filesystem $filesystem) - { + private function deleteMigration(Filesystem $filesystem) { $migrationFile = $filesystem->glob(database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR .'*_create_micro_star_tables.php')[0]; $migration = DB::table('migrations') @@ -57,8 +53,7 @@ private function deleteMigration(Filesystem $filesystem) ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->delete(); } - private function publishMigrationsAgain() - { + private function publishMigrationsAgain() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\MicroStarMeter\Providers\MicroStarMeterServiceProvider", @@ -66,14 +61,12 @@ private function publishMigrationsAgain() ]); } - private function updateDatabase() - { + private function updateDatabase() { $this->info('Updating database tables\n'); $this->call('migrate'); } - private function publishVueFilesAgain() - { + private function publishVueFilesAgain() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\MicroStarMeter\Providers\MicroStarMeterServiceProvider", diff --git a/src/backend/packages/inensus/micro-star-meter/src/Exceptions/MicroStarApiResponseException.php b/src/backend/packages/inensus/micro-star-meter/src/Exceptions/MicroStarApiResponseException.php index 530404553..b07884022 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Exceptions/MicroStarApiResponseException.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Exceptions/MicroStarApiResponseException.php @@ -2,10 +2,8 @@ namespace Inensus\MicroStarMeter\Exceptions; -class MicroStarApiResponseException extends \Exception -{ - public function __construct(string $responseMessage) - { +class MicroStarApiResponseException extends \Exception { + public function __construct(string $responseMessage) { $errorMessage = "MicroStar Meter Api Response Error: $responseMessage"; parent::__construct($errorMessage); diff --git a/src/backend/packages/inensus/micro-star-meter/src/Http/Controllers/MicroStarCertificateController.php b/src/backend/packages/inensus/micro-star-meter/src/Http/Controllers/MicroStarCertificateController.php index 372a45125..72017d82a 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Http/Controllers/MicroStarCertificateController.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Http/Controllers/MicroStarCertificateController.php @@ -9,23 +9,19 @@ use Inensus\MicroStarMeter\Services\MicroStarCertificateService; use Inensus\MicroStarMeter\Services\MicroStarCredentialService; -class MicroStarCertificateController extends Controller -{ +class MicroStarCertificateController extends Controller { public function __construct( private MicroStarCertificateService $certificateService, private MicroStarCredentialService $credentialService, - ) { - } + ) {} - public function store(ImportCertificateRequest $request) - { + public function store(ImportCertificateRequest $request) { $credentials = $this->credentialService->getCredentials(); return MicroStarResource::make($this->certificateService->upload($request, $credentials)); } - public function show(Request $request) - { + public function show(Request $request) { $credentials = $this->credentialService->getCredentials(); $certificateName = $this->certificateService->getUploadedCertificate($credentials); diff --git a/src/backend/packages/inensus/micro-star-meter/src/Http/Controllers/MicroStarCredentialController.php b/src/backend/packages/inensus/micro-star-meter/src/Http/Controllers/MicroStarCredentialController.php index 5d6f60622..5e886294f 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Http/Controllers/MicroStarCredentialController.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Http/Controllers/MicroStarCredentialController.php @@ -7,19 +7,14 @@ use Inensus\MicroStarMeter\Http\Resources\MicroStarResource; use Inensus\MicroStarMeter\Services\MicroStarCredentialService; -class MicroStarCredentialController extends Controller -{ - public function __construct(private MicroStarCredentialService $credentialService) - { - } +class MicroStarCredentialController extends Controller { + public function __construct(private MicroStarCredentialService $credentialService) {} - public function show(): MicroStarResource - { + public function show(): MicroStarResource { return MicroStarResource::make($this->credentialService->getCredentials()); } - public function update(MicroStarCredentialRequest $request): MicroStarResource - { + public function update(MicroStarCredentialRequest $request): MicroStarResource { $credentials = $this->credentialService->updateCredentials($request->only([ 'id', 'api_url', diff --git a/src/backend/packages/inensus/micro-star-meter/src/Http/Controllers/MicroStarTestController.php b/src/backend/packages/inensus/micro-star-meter/src/Http/Controllers/MicroStarTestController.php index 01d044421..ce3a25363 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Http/Controllers/MicroStarTestController.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Http/Controllers/MicroStarTestController.php @@ -5,14 +5,10 @@ use Illuminate\Routing\Controller; use Inensus\MicroStarMeter\Modules\Api\ApiRequests; -class MicroStarTestController extends Controller -{ - public function __construct(private ApiRequests $apiRequests) - { - } +class MicroStarTestController extends Controller { + public function __construct(private ApiRequests $apiRequests) {} - public function show() - { + public function show() { return $this->apiRequests->testGet(); } } diff --git a/src/backend/packages/inensus/micro-star-meter/src/Http/Requests/ImportCertificateRequest.php b/src/backend/packages/inensus/micro-star-meter/src/Http/Requests/ImportCertificateRequest.php index e5bb27391..d64fbe76a 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Http/Requests/ImportCertificateRequest.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Http/Requests/ImportCertificateRequest.php @@ -4,25 +4,20 @@ use Illuminate\Foundation\Http\FormRequest; -class ImportCertificateRequest extends FormRequest -{ +class ImportCertificateRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } /** * Get the validation rules that apply to the request. - * - * @return array */ - public function rules(): array - { + public function rules(): array { return ['cert' => 'required']; } } diff --git a/src/backend/packages/inensus/micro-star-meter/src/Http/Requests/MicroStarCredentialRequest.php b/src/backend/packages/inensus/micro-star-meter/src/Http/Requests/MicroStarCredentialRequest.php index b98eec107..49534b1bb 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Http/Requests/MicroStarCredentialRequest.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Http/Requests/MicroStarCredentialRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class MicroStarCredentialRequest extends FormRequest -{ +class MicroStarCredentialRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'api_url' => ['required'], 'certificate_password' => ['required'], diff --git a/src/backend/packages/inensus/micro-star-meter/src/Http/Resources/MicroStarResource.php b/src/backend/packages/inensus/micro-star-meter/src/Http/Resources/MicroStarResource.php index 6450670aa..6d1b40326 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Http/Resources/MicroStarResource.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Http/Resources/MicroStarResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class MicroStarResource extends JsonResource -{ +class MicroStarResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class MicroStarResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/packages/inensus/micro-star-meter/src/Models/MicroStarCredential.php b/src/backend/packages/inensus/micro-star-meter/src/Models/MicroStarCredential.php index 744ced8a8..26f425792 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Models/MicroStarCredential.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Models/MicroStarCredential.php @@ -4,17 +4,14 @@ use App\Models\Base\BaseModel; -class MicroStarCredential extends BaseModel -{ +class MicroStarCredential extends BaseModel { protected $table = 'micro_star_api_credentials'; - public function getApiKey() - { + public function getApiKey() { return $this->api_key; } - public function getApiUrl() - { + public function getApiUrl() { return $this->api_url; } } diff --git a/src/backend/packages/inensus/micro-star-meter/src/Models/MicroStarTransaction.php b/src/backend/packages/inensus/micro-star-meter/src/Models/MicroStarTransaction.php index 1c3b7b544..6ae180366 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Models/MicroStarTransaction.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Models/MicroStarTransaction.php @@ -12,42 +12,34 @@ use Inensus\SwiftaPaymentProvider\Models\SwiftaTransaction; use Inensus\WaveMoneyPaymentProvider\Models\WaveMoneyTransaction; -class MicroStarTransaction extends BaseModel implements ISubTransaction -{ +class MicroStarTransaction extends BaseModel implements ISubTransaction { protected $table = 'micro_star_transactions'; - public function agentTransaction() - { + public function agentTransaction() { return $this->morphOne(AgentTransaction::class, 'manufacturer_transaction'); } - public function vodacomTransaction() - { + public function vodacomTransaction() { return $this->morphOne(VodacomTransaction::class, 'manufacturer_transaction'); } - public function airtelTransaction() - { + public function airtelTransaction() { return $this->morphOne(AirtelTransaction::class, 'manufacturer_transaction'); } - public function thirdPartyTransaction() - { + public function thirdPartyTransaction() { return $this->morphOne(ThirdPartyTransaction::class, 'manufacturer_transaction'); } - public function mesombTransaction() - { + public function mesombTransaction() { return $this->morphOne(MesombTransaction::class, 'manufacturer_transaction'); } - public function swiftaTransaction() - { + public function swiftaTransaction() { return $this->morphOne(SwiftaTransaction::class, 'manufacturer_transaction'); } - public function waveMoneyTransaction() - { + public function waveMoneyTransaction() { return $this->morphOne(WaveMoneyTransaction::class, 'manufacturer_transaction'); } } diff --git a/src/backend/packages/inensus/micro-star-meter/src/Modules/Api/ApiRequests.php b/src/backend/packages/inensus/micro-star-meter/src/Modules/Api/ApiRequests.php index 863d1eda2..1d7404d9e 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Modules/Api/ApiRequests.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Modules/Api/ApiRequests.php @@ -9,16 +9,13 @@ use Inensus\MicroStarMeter\Models\MicroStarCredential; use Inensus\MicroStarMeter\Modules\Api\Utils\ResponseResolver; -class ApiRequests -{ +class ApiRequests { public function __construct( private Client $httpClient, private ResponseResolver $responseResolver, - ) { - } + ) {} - public function get(MicroStarCredential $credentials, array $params, string $slug) - { + public function get(MicroStarCredential $credentials, array $params, string $slug) { $url = $credentials->getApiUrl().$slug; foreach ($params as $key => $value) { $url .= $key.'='.$value.'&'; @@ -26,13 +23,15 @@ public function get(MicroStarCredential $credentials, array $params, string $slu $certificatePath = storage_path('app'.$credentials->certificate_path.'/'. $credentials->certificate_file_name); try { - $request = $this->httpClient->get($url, + $request = $this->httpClient->get( + $url, [ 'headers' => [ 'Accept' => 'application/json', ], 'cert' => [$certificatePath, $credentials->certificate_password], - ]); + ] + ); return $this->responseResolver->checkResponse(json_decode((string) $request->getBody(), true)); } catch (GuzzleException|MicroStarApiResponseException $exception) { @@ -43,8 +42,7 @@ public function get(MicroStarCredential $credentials, array $params, string $slu } } - public function testGet() - { + public function testGet() { // ti1 = 1 phase 2 = 3 phase $url = 'https://ympt.microstarelectric.com'; @@ -59,13 +57,15 @@ public function testGet() $t = '/TMRDataService/getStsVendingToken?deviceNo=0101189000116&sgc=600415&ti=2&rechargeAmount=1'; try { - $request = $this->httpClient->get($url.$t, + $request = $this->httpClient->get( + $url.$t, [ 'headers' => [ 'Accept' => 'application/json', ], 'cert' => [__DIR__.'/Certs/client.ympt.p12', 'U7i8o9p0'], - ]); + ] + ); return $this->responseResolver->checkResponse(json_decode((string) $request->getBody(), true)); } catch (GuzzleException|MicroStarApiResponseException $exception) { diff --git a/src/backend/packages/inensus/micro-star-meter/src/Modules/Api/MicroStarMeterApi.php b/src/backend/packages/inensus/micro-star-meter/src/Modules/Api/MicroStarMeterApi.php index 7c70656a3..269c36c59 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Modules/Api/MicroStarMeterApi.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Modules/Api/MicroStarMeterApi.php @@ -10,19 +10,16 @@ use Inensus\MicroStarMeter\Models\MicroStarTransaction; use Inensus\MicroStarMeter\Services\MicroStarCredentialService; -class MicroStarMeterApi implements IManufacturerAPI -{ +class MicroStarMeterApi implements IManufacturerAPI { public const API_CALL_CHARGE_METER = '/getStsVendingToken?'; public function __construct( private MicroStarCredentialService $credentialService, private MicroStarTransaction $microStarTransaction, private ApiRequests $apiRequests, - ) { - } + ) {} - public function chargeDevice(TransactionDataContainer $transactionContainer): array - { + public function chargeDevice(TransactionDataContainer $transactionContainer): array { $meter = $transactionContainer->device->device; $tariff = $transactionContainer->tariff; $transactionContainer->chargedEnergy += $transactionContainer->amount / $tariff->total_price; @@ -53,8 +50,7 @@ public function chargeDevice(TransactionDataContainer $transactionContainer): ar ]; } - public function clearDevice(Device $device) - { + public function clearDevice(Device $device) { throw new ApiCallDoesNotSupportedException('This api call does not supported'); } } diff --git a/src/backend/packages/inensus/micro-star-meter/src/Modules/Api/Utils/ResponseResolver.php b/src/backend/packages/inensus/micro-star-meter/src/Modules/Api/Utils/ResponseResolver.php index b5cb9187e..9cba68bfc 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Modules/Api/Utils/ResponseResolver.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Modules/Api/Utils/ResponseResolver.php @@ -4,13 +4,11 @@ use Inensus\MicroStarMeter\Exceptions\MicroStarApiResponseException; -class ResponseResolver -{ +class ResponseResolver { /** * @throws MicroStarApiResponseException */ - public function checkResponse($result) - { + public function checkResponse($result) { if (isset($result['errorCode'])) { if ($result['errorCode'] == 1000) { return $result; @@ -24,8 +22,7 @@ public function checkResponse($result) return $result; } - public function getMessage($statusCode): string - { + public function getMessage($statusCode): string { switch ($statusCode) { case 1000: return 'Success'; diff --git a/src/backend/packages/inensus/micro-star-meter/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/micro-star-meter/src/Providers/EventServiceProvider.php index 773cd06b6..979d9d44f 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Providers/EventServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ ]; @@ -14,8 +13,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/micro-star-meter/src/Providers/MicroStarMeterServiceProvider.php b/src/backend/packages/inensus/micro-star-meter/src/Providers/MicroStarMeterServiceProvider.php index 07e217276..200a7b46c 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Providers/MicroStarMeterServiceProvider.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Providers/MicroStarMeterServiceProvider.php @@ -9,10 +9,8 @@ use Inensus\MicroStarMeter\Console\Commands\UpdatePackage; use Inensus\MicroStarMeter\Modules\Api\MicroStarMeterApi; -class MicroStarMeterServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class MicroStarMeterServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -22,45 +20,42 @@ public function boot(Filesystem $filesystem) } } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/micro-star-meter.php', 'micro-star-meter'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->bind('MicroStarMeterApi', MicroStarMeterApi::class); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/micro-star-meter.php' => config_path('micro-star-meter.php'), ]); } - public function publishVueFiles() - { + public function publishVueFiles() { $this->publishes([ __DIR__.'/../resources/assets' => resource_path('assets/js/plugins/micro-star-meter'), ], 'vue-components'); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_micro_star_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) ->flatMap(function ($path) use ($filesystem) { if (count($filesystem->glob($path.'*_create_micro_star_tables.php'))) { $file = $filesystem->glob($path.'*_create_micro_star_tables.php')[0]; - file_put_contents($file, - file_get_contents(__DIR__.'/../../database/migrations/create_micro_star_tables.php.stub')); + file_put_contents( + $file, + file_get_contents(__DIR__.'/../../database/migrations/create_micro_star_tables.php.stub') + ); } return $filesystem->glob($path.'*_create_micro_star_tables.php'); diff --git a/src/backend/packages/inensus/micro-star-meter/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/micro-star-meter/src/Providers/ObserverServiceProvider.php index 6586d7032..ed9d38d80 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Providers/ObserverServiceProvider.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/micro-star-meter/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/micro-star-meter/src/Providers/RouteServiceProvider.php index 557fddb7c..12995aa50 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\MicroStarMeter\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/micro-star-meter/src/Services/ManufacturerService.php b/src/backend/packages/inensus/micro-star-meter/src/Services/ManufacturerService.php index 7915b77aa..cf4541959 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Services/ManufacturerService.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Services/ManufacturerService.php @@ -4,14 +4,10 @@ use App\Models\Manufacturer; -class ManufacturerService -{ - public function __construct(private Manufacturer $manufacturer) - { - } +class ManufacturerService { + public function __construct(private Manufacturer $manufacturer) {} - public function register() - { + public function register() { $api = $this->manufacturer->newQuery()->where('api_name', 'MicroStarMeterApi')->first(); if (!$api) { $this->manufacturer->newQuery()->create([ diff --git a/src/backend/packages/inensus/micro-star-meter/src/Services/MicroStarCertificateService.php b/src/backend/packages/inensus/micro-star-meter/src/Services/MicroStarCertificateService.php index f25ee9ac5..114b4bca5 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Services/MicroStarCertificateService.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Services/MicroStarCertificateService.php @@ -6,10 +6,8 @@ use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Storage; -class MicroStarCertificateService -{ - public function upload($request, $credentials) - { +class MicroStarCertificateService { + public function upload($request, $credentials) { $file = $request->file('cert'); $companyId = app()->make(UserService::class)->getCompanyId(); @@ -28,8 +26,7 @@ public function upload($request, $credentials) return $credentials; } - public function getUploadedCertificate($credentials) - { + public function getUploadedCertificate($credentials) { if (!$credentials->certificate_path || !$credentials->certificate_file_name) { return ''; } diff --git a/src/backend/packages/inensus/micro-star-meter/src/Services/MicroStarCredentialService.php b/src/backend/packages/inensus/micro-star-meter/src/Services/MicroStarCredentialService.php index 2cff47f14..85f6bf5e2 100644 --- a/src/backend/packages/inensus/micro-star-meter/src/Services/MicroStarCredentialService.php +++ b/src/backend/packages/inensus/micro-star-meter/src/Services/MicroStarCredentialService.php @@ -4,18 +4,15 @@ use Inensus\MicroStarMeter\Models\MicroStarCredential; -class MicroStarCredentialService -{ +class MicroStarCredentialService { public function __construct( private MicroStarCredential $credential, - ) { - } + ) {} /** * This function uses one time on installation of the package. */ - public function createCredentials() - { + public function createCredentials() { return $this->credential->newQuery()->firstOrCreate(['id' => 1], [ 'api_url' => null, 'certificate_password' => null, @@ -24,13 +21,11 @@ public function createCredentials() ]); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->first(); } - public function updateCredentials($data) - { + public function updateCredentials($data) { $credential = $this->getCredentials(); $credential->update([ 'certificate_password' => $data['certificate_password'], diff --git a/src/backend/packages/inensus/spark-meter/src/Console/Commands/InstallSparkMeterPackage.php b/src/backend/packages/inensus/spark-meter/src/Console/Commands/InstallSparkMeterPackage.php index 97b96f949..d782d977c 100644 --- a/src/backend/packages/inensus/spark-meter/src/Console/Commands/InstallSparkMeterPackage.php +++ b/src/backend/packages/inensus/spark-meter/src/Console/Commands/InstallSparkMeterPackage.php @@ -15,9 +15,9 @@ use Inensus\SparkMeter\Services\SmSmsVariableDefaultValueService; use Inensus\SparkMeter\Services\SmSyncSettingService; -class InstallSparkMeterPackage extends Command -{ +class InstallSparkMeterPackage extends Command { protected $signature = 'spark-meter:install'; + protected $description = 'Install the Spark Meter Integration Package'; public function __construct( @@ -36,8 +36,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing Spark Meter Integration Package\n'); $this->packageInstallationService->createDefaultSettingRecords(); $this->insertSparkMeterApi->registerSparkMeterManufacturer(); @@ -56,8 +55,7 @@ public function handle(): void } } - private function publishMigrations() - { + private function publishMigrations() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\SparkMeter\Providers\SparkMeterServiceProvider", @@ -65,14 +63,12 @@ private function publishMigrations() ]); } - private function createDatabaseTables() - { + private function createDatabaseTables() { $this->info('Creating database tables\n'); $this->call('migrate'); } - private function publishVueFiles() - { + private function publishVueFiles() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\SparkMeter\Providers\SparkMeterServiceProvider", @@ -81,8 +77,7 @@ private function publishVueFiles() ]); } - private function createPluginRecord() - { + private function createPluginRecord() { $this->call('plugin:add', [ 'name' => 'SparkMeter', 'composer_name' => 'inensus/spark-meter', diff --git a/src/backend/packages/inensus/spark-meter/src/Console/Commands/SparkMeterDataSynchronizer.php b/src/backend/packages/inensus/spark-meter/src/Console/Commands/SparkMeterDataSynchronizer.php index 1427d2212..22eedc446 100644 --- a/src/backend/packages/inensus/spark-meter/src/Console/Commands/SparkMeterDataSynchronizer.php +++ b/src/backend/packages/inensus/spark-meter/src/Console/Commands/SparkMeterDataSynchronizer.php @@ -20,12 +20,13 @@ use Inensus\SparkMeter\Services\TariffService; use Inensus\SparkMeter\Services\TransactionService; -class SparkMeterDataSynchronizer extends AbstractSharedCommand -{ +class SparkMeterDataSynchronizer extends AbstractSharedCommand { use ScheduledPluginCommand; + public const MPM_PLUGIN_ID = 2; protected $signature = 'spark-meter:dataSync'; + protected $description = 'Synchronize data that needs to be updated from Spark Meter.'; public function __construct( @@ -42,8 +43,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { if (!$this->checkForPluginStatusIsActive(self::MPM_PLUGIN_ID)) { return; } @@ -70,10 +70,13 @@ public function handle(): void return true; } $adminId = $cluster->manager->id; - $adminAddress = $this->address->whereHasMorph('owner', [Person::class], + $adminAddress = $this->address->whereHasMorph( + 'owner', + [Person::class], function ($q) use ($adminId) { $q->where('id', $adminId); - })->first(); + } + )->first(); if (!$adminAddress) { return true; diff --git a/src/backend/packages/inensus/spark-meter/src/Console/Commands/SparkMeterSmsNotifier.php b/src/backend/packages/inensus/spark-meter/src/Console/Commands/SparkMeterSmsNotifier.php index 5d8c015a8..ff669e33e 100644 --- a/src/backend/packages/inensus/spark-meter/src/Console/Commands/SparkMeterSmsNotifier.php +++ b/src/backend/packages/inensus/spark-meter/src/Console/Commands/SparkMeterSmsNotifier.php @@ -17,19 +17,25 @@ use Inensus\SparkMeter\Sms\Senders\SparkSmsConfig; use Inensus\SparkMeter\Sms\SparkSmsTypes; -class SparkMeterSmsNotifier extends AbstractSharedCommand -{ +class SparkMeterSmsNotifier extends AbstractSharedCommand { use ScheduledPluginCommand; + public const MPM_PLUGIN_ID = 2; protected $signature = 'spark-meter:smsNotifier'; + protected $description = 'Notifies customers on payments and low balance limits'; private $smsSettingsService; + private $sms; + private $smTransactionService; + private $smSmsNotifiedCustomerService; + private $smCustomerService; + private $smsService; public function __construct( @@ -49,8 +55,7 @@ public function __construct( $this->smsService = $smsService; } - private function sendTransactionNotifySms($transactionMin, $smsNotifiedCustomers, $customers) - { + private function sendTransactionNotifySms($transactionMin, $smsNotifiedCustomers, $customers) { $this->smTransactionService->getSparkTransactions($transactionMin) ->each(function ($smTransaction) use ( $smsNotifiedCustomers, @@ -77,9 +82,11 @@ private function sendTransactionNotifySms($transactionMin, $smsNotifiedCustomers ) { return true; } - $this->smsService->sendSms($smTransaction->thirdPartyTransaction->transaction, + $this->smsService->sendSms( + $smTransaction->thirdPartyTransaction->transaction, SmsTypes::TRANSACTION_CONFIRMATION, - SmsConfigs::class); + SmsConfigs::class + ); $this->smSmsNotifiedCustomerService->createTransactionSmsNotify( $notifyCustomer->customer_id, $smTransaction->id @@ -89,8 +96,7 @@ private function sendTransactionNotifySms($transactionMin, $smsNotifiedCustomers }); } - private function sendLowBalanceWarningNotifySms($customers, $smsNotifiedCustomers, $lowBalanceMin) - { + private function sendLowBalanceWarningNotifySms($customers, $smsNotifiedCustomers, $lowBalanceMin) { $customers->each(function ($customer) use ( $smsNotifiedCustomers ) { @@ -110,17 +116,18 @@ private function sendLowBalanceWarningNotifySms($customers, $smsNotifiedCustomer ) { return true; } - $this->smsService->sendSms($customer, + $this->smsService->sendSms( + $customer, SparkSmsTypes::LOW_BALANCE_LIMIT_NOTIFIER, - SparkSmsConfig::class); + SparkSmsConfig::class + ); $this->smSmsNotifiedCustomerService->createLowBalanceSmsNotify($customer->customer_id); return true; }); } - public function handle(): void - { + public function handle(): void { if (!$this->checkForPluginStatusIsActive(self::MPM_PLUGIN_ID)) { return; } diff --git a/src/backend/packages/inensus/spark-meter/src/Console/Commands/SparkMeterTransactionStatusCheck.php b/src/backend/packages/inensus/spark-meter/src/Console/Commands/SparkMeterTransactionStatusCheck.php index 495689299..fb70e0d9e 100644 --- a/src/backend/packages/inensus/spark-meter/src/Console/Commands/SparkMeterTransactionStatusCheck.php +++ b/src/backend/packages/inensus/spark-meter/src/Console/Commands/SparkMeterTransactionStatusCheck.php @@ -8,11 +8,11 @@ use Inensus\SparkMeter\Models\SmTransaction; use Inensus\SparkMeter\Services\TransactionService; -class SparkMeterTransactionStatusCheck extends AbstractSharedCommand -{ +class SparkMeterTransactionStatusCheck extends AbstractSharedCommand { use ScheduledPluginCommand; protected $signature = 'spark-meter:transactionStatusCheck'; + protected $description = 'Checks status of Spark Meter transactions'; public function __construct( @@ -22,8 +22,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { if (!$this->checkForPluginStatusIsActive(MpmPlugin::SPARK_METER)) { return; } diff --git a/src/backend/packages/inensus/spark-meter/src/Console/Commands/UpdateSparkMeterPackage.php b/src/backend/packages/inensus/spark-meter/src/Console/Commands/UpdateSparkMeterPackage.php index cabc131fd..82847a17a 100644 --- a/src/backend/packages/inensus/spark-meter/src/Console/Commands/UpdateSparkMeterPackage.php +++ b/src/backend/packages/inensus/spark-meter/src/Console/Commands/UpdateSparkMeterPackage.php @@ -17,9 +17,9 @@ use Inensus\SparkMeter\Services\SmSmsVariableDefaultValueService; use Inensus\SparkMeter\Services\SmSyncSettingService; -class UpdateSparkMeterPackage extends Command -{ +class UpdateSparkMeterPackage extends Command { protected $signature = 'spark-meter:update'; + protected $description = 'Update the Spark Meter Integration Package'; public function __construct( @@ -42,8 +42,7 @@ public function __construct( /** * Execute the console command. */ - public function handle(): void - { + public function handle(): void { $this->info('Spark Meter Integration Updating Started\n'); $this->removeOldVersionOfPackage(); $this->installNewVersionOfPackage(); @@ -56,20 +55,17 @@ public function handle(): void $this->info('Package updated successfully..'); } - private function removeOldVersionOfPackage() - { + private function removeOldVersionOfPackage() { $this->info('Removing former version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar remove inensus/spark-meter'); } - private function installNewVersionOfPackage() - { + private function installNewVersionOfPackage() { $this->info('Installing last version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar require inensus/spark-meter'); } - private function deleteMigration(Filesystem $filesystem) - { + private function deleteMigration(Filesystem $filesystem) { $migrationFile = $filesystem->glob(database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'*_create_spark_tables.php')[0]; $migration = DB::table('migrations') ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->first(); @@ -81,8 +77,7 @@ private function deleteMigration(Filesystem $filesystem) ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->delete(); } - private function publishMigrationsAgain() - { + private function publishMigrationsAgain() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\SparkMeter\Providers\SparkMeterServiceProvider", @@ -90,14 +85,12 @@ private function publishMigrationsAgain() ]); } - private function updateDatabase() - { + private function updateDatabase() { $this->info('Updating database tables\n'); $this->call('migrate'); } - private function publishVueFilesAgain() - { + private function publishVueFilesAgain() { $this->info('Updating vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\SparkMeter\Providers\SparkMeterServiceProvider", diff --git a/src/backend/packages/inensus/spark-meter/src/Exceptions/CredentialsNotFoundException.php b/src/backend/packages/inensus/spark-meter/src/Exceptions/CredentialsNotFoundException.php index 09fc5a8a1..d6c86a011 100644 --- a/src/backend/packages/inensus/spark-meter/src/Exceptions/CredentialsNotFoundException.php +++ b/src/backend/packages/inensus/spark-meter/src/Exceptions/CredentialsNotFoundException.php @@ -2,6 +2,4 @@ namespace Inensus\SparkMeter\Exceptions; -class CredentialsNotFoundException extends \Exception -{ -} +class CredentialsNotFoundException extends \Exception {} diff --git a/src/backend/packages/inensus/spark-meter/src/Exceptions/CredentialsNotUpToDateException.php b/src/backend/packages/inensus/spark-meter/src/Exceptions/CredentialsNotUpToDateException.php index 0f55d90a5..6d18e9962 100644 --- a/src/backend/packages/inensus/spark-meter/src/Exceptions/CredentialsNotUpToDateException.php +++ b/src/backend/packages/inensus/spark-meter/src/Exceptions/CredentialsNotUpToDateException.php @@ -2,6 +2,4 @@ namespace Inensus\SparkMeter\Exceptions; -class CredentialsNotUpToDateException extends \Exception -{ -} +class CredentialsNotUpToDateException extends \Exception {} diff --git a/src/backend/packages/inensus/spark-meter/src/Exceptions/CronJobException.php b/src/backend/packages/inensus/spark-meter/src/Exceptions/CronJobException.php index cd08c1991..5b0686684 100644 --- a/src/backend/packages/inensus/spark-meter/src/Exceptions/CronJobException.php +++ b/src/backend/packages/inensus/spark-meter/src/Exceptions/CronJobException.php @@ -2,6 +2,4 @@ namespace Inensus\SparkMeter\Exceptions; -class CronJobException extends \Exception -{ -} +class CronJobException extends \Exception {} diff --git a/src/backend/packages/inensus/spark-meter/src/Exceptions/NoOnlineSiteRecordException.php b/src/backend/packages/inensus/spark-meter/src/Exceptions/NoOnlineSiteRecordException.php index 8c58c8a07..485b574ee 100644 --- a/src/backend/packages/inensus/spark-meter/src/Exceptions/NoOnlineSiteRecordException.php +++ b/src/backend/packages/inensus/spark-meter/src/Exceptions/NoOnlineSiteRecordException.php @@ -2,6 +2,4 @@ namespace Inensus\SparkMeter\Exceptions; -class NoOnlineSiteRecordException extends \Exception -{ -} +class NoOnlineSiteRecordException extends \Exception {} diff --git a/src/backend/packages/inensus/spark-meter/src/Exceptions/SitesNotUpToDateException.php b/src/backend/packages/inensus/spark-meter/src/Exceptions/SitesNotUpToDateException.php index 26b5d2ea2..9c8404b5c 100644 --- a/src/backend/packages/inensus/spark-meter/src/Exceptions/SitesNotUpToDateException.php +++ b/src/backend/packages/inensus/spark-meter/src/Exceptions/SitesNotUpToDateException.php @@ -2,6 +2,4 @@ namespace Inensus\SparkMeter\Exceptions; -class SitesNotUpToDateException extends \Exception -{ -} +class SitesNotUpToDateException extends \Exception {} diff --git a/src/backend/packages/inensus/spark-meter/src/Exceptions/SparkAPIResponseException.php b/src/backend/packages/inensus/spark-meter/src/Exceptions/SparkAPIResponseException.php index cd22db5b8..595c3a4e2 100644 --- a/src/backend/packages/inensus/spark-meter/src/Exceptions/SparkAPIResponseException.php +++ b/src/backend/packages/inensus/spark-meter/src/Exceptions/SparkAPIResponseException.php @@ -2,6 +2,4 @@ namespace Inensus\SparkMeter\Exceptions; -class SparkAPIResponseException extends \Exception -{ -} +class SparkAPIResponseException extends \Exception {} diff --git a/src/backend/packages/inensus/spark-meter/src/Exceptions/WrongCredentialsException.php b/src/backend/packages/inensus/spark-meter/src/Exceptions/WrongCredentialsException.php index ad5eca5af..06dab1b37 100644 --- a/src/backend/packages/inensus/spark-meter/src/Exceptions/WrongCredentialsException.php +++ b/src/backend/packages/inensus/spark-meter/src/Exceptions/WrongCredentialsException.php @@ -2,6 +2,4 @@ namespace Inensus\SparkMeter\Exceptions; -class WrongCredentialsException extends \Exception -{ -} +class WrongCredentialsException extends \Exception {} diff --git a/src/backend/packages/inensus/spark-meter/src/Helpers/InsertSparkMeterApi.php b/src/backend/packages/inensus/spark-meter/src/Helpers/InsertSparkMeterApi.php index 99bd7fd4e..7e376a080 100644 --- a/src/backend/packages/inensus/spark-meter/src/Helpers/InsertSparkMeterApi.php +++ b/src/backend/packages/inensus/spark-meter/src/Helpers/InsertSparkMeterApi.php @@ -4,8 +4,7 @@ use App\Models\Manufacturer; -class InsertSparkMeterApi -{ +class InsertSparkMeterApi { private $manufacturer; public function __construct( @@ -14,8 +13,7 @@ public function __construct( $this->manufacturer = $manufacturer; } - public function registerSparkMeterManufacturer() - { + public function registerSparkMeterManufacturer() { $api = $this->manufacturer->newQuery()->where('api_name', 'SparkMeterApi')->first(); if (!$api) { $this->manufacturer->newQuery()->create([ diff --git a/src/backend/packages/inensus/spark-meter/src/Helpers/ResultStatusChecker.php b/src/backend/packages/inensus/spark-meter/src/Helpers/ResultStatusChecker.php index b2865decd..cf3c02392 100644 --- a/src/backend/packages/inensus/spark-meter/src/Helpers/ResultStatusChecker.php +++ b/src/backend/packages/inensus/spark-meter/src/Helpers/ResultStatusChecker.php @@ -4,10 +4,8 @@ use Inensus\SparkMeter\Exceptions\SparkAPIResponseException; -class ResultStatusChecker -{ - public function checkApiResult($result) - { +class ResultStatusChecker { + public function checkApiResult($result) { if ($result['error'] !== false && $result['error'] !== null) { throw new SparkAPIResponseException($result['error']); } diff --git a/src/backend/packages/inensus/spark-meter/src/Helpers/SmTableEncryption.php b/src/backend/packages/inensus/spark-meter/src/Helpers/SmTableEncryption.php index d9ead7b63..cf4d37896 100644 --- a/src/backend/packages/inensus/spark-meter/src/Helpers/SmTableEncryption.php +++ b/src/backend/packages/inensus/spark-meter/src/Helpers/SmTableEncryption.php @@ -2,10 +2,8 @@ namespace Inensus\SparkMeter\Helpers; -class SmTableEncryption -{ - public function makeHash($data) - { +class SmTableEncryption { + public function makeHash($data) { return md5(implode('', $data)); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/IBaseController.php b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/IBaseController.php index 61126292d..26ae5bbea 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/IBaseController.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/IBaseController.php @@ -2,8 +2,7 @@ namespace Inensus\SparkMeter\Http\Controllers; -interface IBaseController -{ +interface IBaseController { public function sync(); public function checkSync(); diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmCredentialController.php b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmCredentialController.php index 208d0ef83..03c3bff3c 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmCredentialController.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmCredentialController.php @@ -8,22 +8,18 @@ use Inensus\SparkMeter\Http\Resources\SparkResource; use Inensus\SparkMeter\Services\CredentialService; -class SmCredentialController extends Controller -{ +class SmCredentialController extends Controller { private $credentialService; - public function __construct(CredentialService $credentialService) - { + public function __construct(CredentialService $credentialService) { $this->credentialService = $credentialService; } - public function show(): SparkResource - { + public function show(): SparkResource { return new SparkResource($this->credentialService->getCredentials()); } - public function update(SmCredentialRequest $request): SparkMeterCredentialResource - { + public function update(SmCredentialRequest $request): SparkMeterCredentialResource { $credentials = $this->credentialService->updateCredentials($request->only([ 'id', 'api_key', diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmCustomerController.php b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmCustomerController.php index 00641cb71..be0e0809a 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmCustomerController.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmCustomerController.php @@ -8,8 +8,7 @@ use Inensus\SparkMeter\Models\SmCustomer; use Inensus\SparkMeter\Services\CustomerService; -class SmCustomerController implements IBaseController -{ +class SmCustomerController implements IBaseController { private $customerService; public function __construct( @@ -18,42 +17,35 @@ public function __construct( $this->customerService = $customerService; } - public function index(Request $request): SparkResource - { + public function index(Request $request): SparkResource { $customers = $this->customerService->getSmCustomers($request); return new SparkResource($customers); } - public function sync(): SparkResource - { + public function sync(): SparkResource { return new SparkResource($this->customerService->sync()); } - public function checkSync(): SparkResource - { + public function checkSync(): SparkResource { return new SparkResource($this->customerService->syncCheck()); } - public function count() - { + public function count() { return $this->customerService->getSmCustomersCount(); } - public function connection(): SparkResource - { + public function connection(): SparkResource { return new SparkResource($this->customerService->checkConnectionAvailability()); } - public function update(SmCustomer $customer, SmCustomerRequest $request): SparkResource - { + public function update(SmCustomer $customer, SmCustomerRequest $request): SparkResource { return new SparkResource($this->customerService->updateCustomerLowBalanceLimit($customer->id, $request->only([ 'low_balance_limit', ]))); } - public function search() - { + public function search() { $term = request('term'); $paginate = request('paginate') ?? 1; diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmMeterModelController.php b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmMeterModelController.php index f16f38d09..5de1c8404 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmMeterModelController.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmMeterModelController.php @@ -7,8 +7,7 @@ use Inensus\SparkMeter\Http\Resources\SparkResource; use Inensus\SparkMeter\Services\MeterModelService; -class SmMeterModelController extends Controller implements IBaseController -{ +class SmMeterModelController extends Controller implements IBaseController { private $meterModelService; public function __construct( @@ -17,25 +16,21 @@ public function __construct( $this->meterModelService = $meterModelService; } - public function index(Request $request): SparkResource - { + public function index(Request $request): SparkResource { $meterModels = $this->meterModelService->getSmMeterModels($request); return new SparkResource($meterModels); } - public function sync(): SparkResource - { + public function sync(): SparkResource { return new SparkResource($this->meterModelService->sync()); } - public function checkSync(): SparkResource - { + public function checkSync(): SparkResource { return new SparkResource($this->meterModelService->syncCheck()); } - public function count() - { + public function count() { return $this->meterModelService->getSmMeterModelsCount(); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSalesAccountController.php b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSalesAccountController.php index caf5e4535..84f2a3104 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSalesAccountController.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSalesAccountController.php @@ -6,34 +6,28 @@ use Inensus\SparkMeter\Http\Resources\SparkResource; use Inensus\SparkMeter\Services\SmSalesAccoutService; -class SmSalesAccountController implements IBaseController -{ +class SmSalesAccountController implements IBaseController { private $smSalesAccountService; - public function __construct(SmSalesAccoutService $salesAccountService) - { + public function __construct(SmSalesAccoutService $salesAccountService) { $this->smSalesAccountService = $salesAccountService; } - public function index(Request $request): SparkResource - { + public function index(Request $request): SparkResource { $salesAccounts = $this->smSalesAccountService->getSmSalesAccounts($request); return new SparkResource($salesAccounts); } - public function sync(): SparkResource - { + public function sync(): SparkResource { return new SparkResource($this->smSalesAccountService->sync()); } - public function checkSync(): SparkResource - { + public function checkSync(): SparkResource { return new SparkResource($this->smSalesAccountService->syncCheck()); } - public function count() - { + public function count() { return $this->smSalesAccountService->getSmSalesAccountsCount(); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSettingController.php b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSettingController.php index 468dad1bf..269fb73d8 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSettingController.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSettingController.php @@ -6,17 +6,14 @@ use Inensus\SparkMeter\Http\Resources\SparkResource; use Inensus\SparkMeter\Services\SmSettingService; -class SmSettingController extends Controller -{ +class SmSettingController extends Controller { private $settingService; - public function __construct(SmSettingService $settingService) - { + public function __construct(SmSettingService $settingService) { $this->settingService = $settingService; } - public function index(): SparkResource - { + public function index(): SparkResource { return new SparkResource($this->settingService->getSettings()); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSiteController.php b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSiteController.php index 2f23cea75..953498b3c 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSiteController.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSiteController.php @@ -8,8 +8,7 @@ use Inensus\SparkMeter\Models\SmSite; use Inensus\SparkMeter\Services\SiteService; -class SmSiteController implements IBaseController -{ +class SmSiteController implements IBaseController { private $siteService; public function __construct( @@ -18,35 +17,29 @@ public function __construct( $this->siteService = $siteService; } - public function index(Request $request): SparkResource - { + public function index(Request $request): SparkResource { $customers = $this->siteService->getSmSites($request); return new SparkResource($customers); } - public function sync(): SparkResource - { + public function sync(): SparkResource { return new SparkResource($this->siteService->sync()); } - public function checkSync(): SparkResource - { + public function checkSync(): SparkResource { return new SparkResource($this->siteService->syncCheck()); } - public function count() - { + public function count() { return $this->siteService->getSmSitesCount(); } - public function location(): SparkResource - { + public function location(): SparkResource { return new SparkResource($this->siteService->checkLocationAvailability()); } - public function update(SmSite $site, SmSiteRequest $request): SparkResource - { + public function update(SmSite $site, SmSiteRequest $request): SparkResource { return new SparkResource($this->siteService->update($site->id, $request->only([ 'id', 'thundercloud_url', diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsBodyController.php b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsBodyController.php index b0138971f..a12208f9d 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsBodyController.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsBodyController.php @@ -7,22 +7,18 @@ use Inensus\SparkMeter\Http\Resources\SparkResource; use Inensus\SparkMeter\Services\SmSmsBodyService; -class SmSmsBodyController extends Controller -{ +class SmSmsBodyController extends Controller { private $smsBodyService; - public function __construct(SmSmsBodyService $smsBodyService) - { + public function __construct(SmSmsBodyService $smsBodyService) { $this->smsBodyService = $smsBodyService; } - public function index(): SparkResource - { + public function index(): SparkResource { return new SparkResource($this->smsBodyService->getSmsBodies()); } - public function update(Request $request): SparkResource - { + public function update(Request $request): SparkResource { return new SparkResource($this->smsBodyService->updateSmsBodies($request->all())); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsFeedbackController.php b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsFeedbackController.php index e33d72b7d..c580647fa 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsFeedbackController.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsFeedbackController.php @@ -8,22 +8,18 @@ use Inensus\SparkMeter\Models\SmSmsFeedbackWord; use Inensus\SparkMeter\Services\SmSmsFeedbackWordService; -class SmSmsFeedbackController extends Controller -{ +class SmSmsFeedbackController extends Controller { private $smsFeedbackWorkService; - public function __construct(SmSmsFeedbackWordService $smsFeedbackWordService) - { + public function __construct(SmSmsFeedbackWordService $smsFeedbackWordService) { $this->smsFeedbackWorkService = $smsFeedbackWordService; } - public function index(): SparkResource - { + public function index(): SparkResource { return new SparkResource($this->smsFeedbackWorkService->getSmsFeedbackWords()); } - public function update(SmSmsFeedbackWord $smsFeedbackWord, Request $request): SparkResource - { + public function update(SmSmsFeedbackWord $smsFeedbackWord, Request $request): SparkResource { return new SparkResource($this->smsFeedbackWorkService->updateSmsFeedbackWord($smsFeedbackWord, $request->all())); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsSettingController.php b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsSettingController.php index 51c9688ee..0c5ed94eb 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsSettingController.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsSettingController.php @@ -6,17 +6,14 @@ use Inensus\SparkMeter\Http\Resources\SparkResource; use Inensus\SparkMeter\Services\SmSmsSettingService; -class SmSmsSettingController -{ +class SmSmsSettingController { private $smsSettingService; - public function __construct(SmSmsSettingService $smsSettingService) - { + public function __construct(SmSmsSettingService $smsSettingService) { $this->smsSettingService = $smsSettingService; } - public function update(Request $request): SparkResource - { + public function update(Request $request): SparkResource { return new SparkResource($this->smsSettingService->updateSmsSettings($request->all())); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsVariableDefaultValueController.php b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsVariableDefaultValueController.php index 8400b1f65..c09faf78f 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsVariableDefaultValueController.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSmsVariableDefaultValueController.php @@ -6,17 +6,14 @@ use Inensus\SparkMeter\Services\SmSmsVariableDefaultValueService; use Inensus\Ticket\Http\Controllers\Controller; -class SmSmsVariableDefaultValueController extends Controller -{ +class SmSmsVariableDefaultValueController extends Controller { private $smsVariableDefaultSValueService; - public function __construct(SmSmsVariableDefaultValueService $smsVariableDefaultSValueService) - { + public function __construct(SmSmsVariableDefaultValueService $smsVariableDefaultSValueService) { $this->smsVariableDefaultSValueService = $smsVariableDefaultSValueService; } - public function index(): SparkResource - { + public function index(): SparkResource { return new SparkResource($this->smsVariableDefaultSValueService->getSmsVariableDefaultValues()); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSyncSettingController.php b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSyncSettingController.php index c4cf5bb0f..d3ab6dc95 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSyncSettingController.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmSyncSettingController.php @@ -6,17 +6,14 @@ use Inensus\SparkMeter\Http\Resources\SparkResource; use Inensus\SparkMeter\Services\SmSyncSettingService; -class SmSyncSettingController -{ +class SmSyncSettingController { private $syncSettingService; - public function __construct(SmSyncSettingService $syncSettingService) - { + public function __construct(SmSyncSettingService $syncSettingService) { $this->syncSettingService = $syncSettingService; } - public function update(Request $request): SparkResource - { + public function update(Request $request): SparkResource { return new SparkResource($this->syncSettingService->updateSyncSettings($request->all())); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmTariffController.php b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmTariffController.php index 4c0feccd2..24c70cb15 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmTariffController.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Controllers/SmTariffController.php @@ -8,27 +8,22 @@ use Inensus\SparkMeter\Http\Resources\SparkResource; use Inensus\SparkMeter\Services\TariffService; -class SmTariffController extends Controller implements IBaseController -{ +class SmTariffController extends Controller implements IBaseController { private $tariffService; - public function __construct(TariffService $tariffService) - { + public function __construct(TariffService $tariffService) { $this->tariffService = $tariffService; } - public function index(Request $request): SparkResource - { + public function index(Request $request): SparkResource { return new SparkResource($this->tariffService->getSmTariffs($request)); } - public function getInfo($tariffId): SparkResource - { + public function getInfo($tariffId): SparkResource { return new SparkResource($this->tariffService->getSparkTariffInfo($tariffId)); } - public function updateInfo(SmTariffRequest $request) - { + public function updateInfo(SmTariffRequest $request) { $tariffData = [ 'id' => $request->input('id'), 'name' => $request->input('name'), @@ -48,18 +43,15 @@ public function updateInfo(SmTariffRequest $request) return new SparkResource($this->tariffService->updateSparkTariffInfo($tariffData)); } - public function sync(): SparkResource - { + public function sync(): SparkResource { return new SparkResource($this->tariffService->sync()); } - public function checkSync(): SparkResource - { + public function checkSync(): SparkResource { return new SparkResource($this->tariffService->syncCheck()); } - public function count() - { + public function count() { return $this->tariffService->getSmTariffsCount(); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmCredentialRequest.php b/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmCredentialRequest.php index 0598b5100..fdcfacc64 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmCredentialRequest.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmCredentialRequest.php @@ -5,15 +5,13 @@ use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; -class SmCredentialRequest extends FormRequest -{ +class SmCredentialRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -22,8 +20,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'api_key' => ['required', Rule::unique('shard.sm_api_credentials')->ignore($this->id)], 'api_secret' => 'required', diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmCustomerRequest.php b/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmCustomerRequest.php index 6f2c82c7d..9d1659718 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmCustomerRequest.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmCustomerRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class SmCustomerRequest extends FormRequest -{ +class SmCustomerRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'low_balance_limit' => 'required', ]; diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmSiteRequest.php b/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmSiteRequest.php index e0213b98a..f3a34a765 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmSiteRequest.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmSiteRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class SmSiteRequest extends FormRequest -{ +class SmSiteRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -21,8 +19,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { return [ 'thundercloud_url' => 'required', 'thundercloud_token' => 'required', diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmTariffRequest.php b/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmTariffRequest.php index 834d4b92e..1af2ab250 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmTariffRequest.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Requests/SmTariffRequest.php @@ -6,15 +6,13 @@ use Illuminate\Validation\Rule; use Inensus\SparkMeter\Models\SmTariff; -class SmTariffRequest extends FormRequest -{ +class SmTariffRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ - public function authorize() - { + public function authorize() { return true; } @@ -23,8 +21,7 @@ public function authorize() * * @return array */ - public function rules() - { + public function rules() { $meterTariff = SmTariff::with('mpmTariff')->where('tariff_id', $this->id)->firstOrFail(); return [ diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Requests/SparkMeterApiRequests.php b/src/backend/packages/inensus/spark-meter/src/Http/Requests/SparkMeterApiRequests.php index d2abb5be8..5efd9aec1 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Requests/SparkMeterApiRequests.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Requests/SparkMeterApiRequests.php @@ -9,12 +9,15 @@ use Inensus\SparkMeter\Models\SmCredential; use Inensus\SparkMeter\Models\SmSite; -class SparkMeterApiRequests -{ +class SparkMeterApiRequests { private $client; + private $resultStatusChecker; + private $credential; + private $site; + private $smCredentail; public function __construct( @@ -31,8 +34,7 @@ public function __construct( $this->smCredentail = $smCredential; } - public function get($url, $siteId) - { + public function get($url, $siteId) { $smSite = $this->getThunderCloudInformation($siteId); try { $request = $this->client->get( @@ -51,8 +53,7 @@ public function get($url, $siteId) return $this->resultStatusChecker->checkApiResult(json_decode((string) $request->getBody(), true)); } - public function post($url, $postParams, $siteId) - { + public function post($url, $postParams, $siteId) { $smSite = $this->getThunderCloudInformation($siteId); try { $request = $this->client->post( @@ -72,8 +73,7 @@ public function post($url, $postParams, $siteId) return $this->resultStatusChecker->checkApiResult(json_decode((string) $request->getBody(), true)); } - public function put($url, $putParams, $siteId) - { + public function put($url, $putParams, $siteId) { $smSite = $this->getThunderCloudInformation($siteId); try { $request = $this->client->put( @@ -93,8 +93,7 @@ public function put($url, $putParams, $siteId) return $this->resultStatusChecker->checkApiResult(json_decode((string) $request->getBody(), true)); } - public function getByParams($url, $params, $siteId) - { + public function getByParams($url, $params, $siteId) { try { $smSite = $this->getThunderCloudInformation($siteId); $apiUrl = $smSite->thundercloud_url.$url.'?'; @@ -121,8 +120,7 @@ public function getByParams($url, $params, $siteId) } } - public function getInfo($url, $id, $siteId) - { + public function getInfo($url, $id, $siteId) { $smSite = $this->getThunderCloudInformation($siteId); $apiUrl = $smSite->thundercloud_url.$url.$id; try { @@ -142,8 +140,7 @@ public function getInfo($url, $id, $siteId) return $this->resultStatusChecker->checkApiResult(json_decode((string) $request->getBody(), true)); } - public function getFromKoios($url) - { + public function getFromKoios($url) { $smCredential = $this->getCredentials(); try { $request = $this->client->get( @@ -163,8 +160,7 @@ public function getFromKoios($url) return $this->resultStatusChecker->checkApiResult(json_decode((string) $request->getBody(), true)); } - public function postToKoios($url, $postParams) - { + public function postToKoios($url, $postParams) { $smCredential = $this->getCredentials(); try { $request = $this->client->post( @@ -185,13 +181,11 @@ public function postToKoios($url, $postParams) return $this->resultStatusChecker->checkApiResult(json_decode((string) $request->getBody(), true)); } - private function getCredentials() - { + private function getCredentials() { return $this->smCredentail->newQuery()->first(); } - private function getThunderCloudInformation($siteId) - { + private function getThunderCloudInformation($siteId) { return $this->site->newQuery()->where('site_id', $siteId)->first(); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Resources/SparkMeterCredentialResource.php b/src/backend/packages/inensus/spark-meter/src/Http/Resources/SparkMeterCredentialResource.php index 891e090a1..1cc6ce741 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Resources/SparkMeterCredentialResource.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Resources/SparkMeterCredentialResource.php @@ -6,10 +6,8 @@ use Illuminate\Http\Resources\Json\JsonResource; use Inensus\SparkMeter\Models\SmCredential; -class SparkMeterCredentialResource extends JsonResource -{ - public function __construct(SmCredential $smCredential) - { +class SparkMeterCredentialResource extends JsonResource { + public function __construct(SmCredential $smCredential) { parent::__construct($smCredential); } @@ -20,16 +18,14 @@ public function __construct(SmCredential $smCredential) * * @return Request */ - public function toArray($request) - { + public function toArray($request) { $credentials = $this->resource->toArray(); $credentials['alert'] = $this->alertType($this->resource->is_authenticated); return $credentials; } - private function alertType($authenticationStatus) - { + private function alertType($authenticationStatus) { switch ($authenticationStatus) { case true: return [ diff --git a/src/backend/packages/inensus/spark-meter/src/Http/Resources/SparkResource.php b/src/backend/packages/inensus/spark-meter/src/Http/Resources/SparkResource.php index d28e1c463..3e9f5f9b4 100644 --- a/src/backend/packages/inensus/spark-meter/src/Http/Resources/SparkResource.php +++ b/src/backend/packages/inensus/spark-meter/src/Http/Resources/SparkResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class SparkResource extends JsonResource -{ +class SparkResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class SparkResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Listeners/MeterParameterListener.php b/src/backend/packages/inensus/spark-meter/src/Listeners/MeterParameterListener.php index a233c4f14..633dc6c1b 100644 --- a/src/backend/packages/inensus/spark-meter/src/Listeners/MeterParameterListener.php +++ b/src/backend/packages/inensus/spark-meter/src/Listeners/MeterParameterListener.php @@ -13,15 +13,21 @@ use Inensus\SparkMeter\Services\CustomerService; use Inensus\SparkMeter\Services\TariffService; -class MeterParameterListener -{ +class MeterParameterListener { private $tariffService; + private $customerService; + private $meterParameter; + private $smTariff; + private $smCustomer; + private $miniGrid; + private $smSite; + private $city; public function __construct( @@ -46,11 +52,8 @@ public function __construct( /** * Sets the in_use to true. - * - * @param int $meter_id */ - public function onParameterSaved(int $meter_id) - { + public function onParameterSaved(int $meter_id) { Log::debug('Meter Parameter listener Spark Meter Package', []); $meterInfo = $this->meterParameter->newQuery()->with([ 'tariff.tou', @@ -93,8 +96,7 @@ function ($q) use ($customerId) { } } - public function subscribe(Dispatcher $events) - { + public function subscribe(Dispatcher $events) { $events->listen('meterparameter.saved', 'Inensus\SparkMeter\Listeners\MeterParameterListener@onParameterSaved'); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Listeners/SmsListener.php b/src/backend/packages/inensus/spark-meter/src/Listeners/SmsListener.php index 55c71a642..862dad230 100644 --- a/src/backend/packages/inensus/spark-meter/src/Listeners/SmsListener.php +++ b/src/backend/packages/inensus/spark-meter/src/Listeners/SmsListener.php @@ -11,11 +11,13 @@ use Inensus\SparkMeter\Sms\Senders\SparkSmsConfig; use Inensus\SparkMeter\Sms\SparkSmsTypes; -class SmsListener -{ +class SmsListener { private $smsFeedbackWordService; + private $customerService; + private $meter; + private $smsService; public function __construct( @@ -30,8 +32,7 @@ public function __construct( $this->smsService = $smsService; } - public function onSmsStored($sender, $message) - { + public function onSmsStored($sender, $message) { $sparkCustomer = $this->customerService->getSparkCustomerWithPhone($sender); if (!$sparkCustomer) { return; @@ -42,29 +43,34 @@ public function onSmsStored($sender, $message) if ($meterReset !== false) { try { $this->customerService->resetMeter($sparkCustomer); - $this->smsService->sendSms($meter, + $this->smsService->sendSms( + $meter, SparkSmsTypes::METER_RESET_FEEDBACK, - SparkSmsConfig::class); + SparkSmsConfig::class + ); return; } catch (SparkAPIResponseException $exception) { - $this->smsService->sendSms(['meter' => $meter['serial_number'], 'phone' => $sender], + $this->smsService->sendSms( + ['meter' => $meter['serial_number'], 'phone' => $sender], SparkSmsTypes::METER_RESET_FEEDBACK, - SparkSmsConfig::class); + SparkSmsConfig::class + ); } } $meterBalance = strpos(strtolower($message), strtolower($smsFeedbackWords[0]->meter_balance)); if ($meterBalance !== false) { - $this->smsService->sendSms($sparkCustomer, + $this->smsService->sendSms( + $sparkCustomer, SparkSmsTypes::BALANCE_FEEDBACK, - SparkSmsConfig::class); + SparkSmsConfig::class + ); return; } } - public function subscribe(Dispatcher $events) - { + public function subscribe(Dispatcher $events) { $events->listen('sms.stored', 'Inensus\SparkMeter\Listeners\SmsListener@onSmsStored'); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Listeners/TransactionListener.php b/src/backend/packages/inensus/spark-meter/src/Listeners/TransactionListener.php index c36fc1adf..3141106cb 100644 --- a/src/backend/packages/inensus/spark-meter/src/Listeners/TransactionListener.php +++ b/src/backend/packages/inensus/spark-meter/src/Listeners/TransactionListener.php @@ -7,9 +7,9 @@ use Inensus\SparkMeter\Models\SmTransaction; use Inensus\SparkMeter\Services\TransactionService; -class TransactionListener -{ +class TransactionListener { private $transactionService; + private $smTransaction; public function __construct( @@ -22,19 +22,15 @@ public function __construct( /** * Sets the in_use to true. - * - * @param Transaction $transaction */ - public function onTransactionSuccess(Transaction $transaction) - { + public function onTransactionSuccess(Transaction $transaction) { $smTransaction = $this->smTransaction->newQuery()->where('mpm_transaction_id', $transaction->id)->first(); if ($smTransaction) { $this->transactionService->updateTransactionStatus($smTransaction); } } - public function subscribe(Dispatcher $events) - { + public function subscribe(Dispatcher $events) { $events->listen( 'transaction.successful', 'Inensus\SparkMeter\Listeners\TransactionListener@onTransactionSuccess' diff --git a/src/backend/packages/inensus/spark-meter/src/Models/BaseModel.php b/src/backend/packages/inensus/spark-meter/src/Models/BaseModel.php index 427cf464a..e2372f8f2 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/BaseModel.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/BaseModel.php @@ -4,19 +4,17 @@ use Illuminate\Database\Eloquent\Model; -class BaseModel extends Model -{ +class BaseModel extends Model { protected $guarded = ['id']; + public static $rules = []; - public function __construct(array $attributes = []) - { + public function __construct(array $attributes = []) { parent::__construct($attributes); $this->setConnection('shard'); } - public function resolveChildRouteBinding($childType, $value, $field) - { + public function resolveChildRouteBinding($childType, $value, $field) { // TODO: Implement resolveChildRouteBinding() method. } } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmCredential.php b/src/backend/packages/inensus/spark-meter/src/Models/SmCredential.php index a3241afe0..eb8e89e5d 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmCredential.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmCredential.php @@ -2,7 +2,6 @@ namespace Inensus\SparkMeter\Models; -class SmCredential extends BaseModel -{ +class SmCredential extends BaseModel { protected $table = 'sm_api_credentials'; } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmCustomer.php b/src/backend/packages/inensus/spark-meter/src/Models/SmCustomer.php index b7ed5c87d..62729c954 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmCustomer.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmCustomer.php @@ -4,17 +4,14 @@ use App\Models\Person\Person; -class SmCustomer extends BaseModel -{ +class SmCustomer extends BaseModel { protected $table = 'sm_customers'; - public function mpmPerson() - { + public function mpmPerson() { return $this->belongsTo(Person::class, 'mpm_customer_id'); } - public function site() - { + public function site() { return $this->belongsTo(SmSite::class, 'site_id', 'site_id'); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmMeterModel.php b/src/backend/packages/inensus/spark-meter/src/Models/SmMeterModel.php index fada89e03..f6ac4cc2d 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmMeterModel.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmMeterModel.php @@ -4,17 +4,14 @@ use App\Models\Meter\MeterType; -class SmMeterModel extends BaseModel -{ +class SmMeterModel extends BaseModel { protected $table = 'sm_meter_models'; - public function meterType() - { + public function meterType() { return $this->belongsTo(MeterType::class, 'mpm_meter_type_id'); } - public function site() - { + public function site() { return $this->belongsTo(SmSite::class, 'site_id', 'site_id'); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmOrganization.php b/src/backend/packages/inensus/spark-meter/src/Models/SmOrganization.php index 2b5b2e25d..71cfa5277 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmOrganization.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmOrganization.php @@ -2,7 +2,6 @@ namespace Inensus\SparkMeter\Models; -class SmOrganization extends BaseModel -{ +class SmOrganization extends BaseModel { protected $table = 'sm_organizations'; } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmSalesAccount.php b/src/backend/packages/inensus/spark-meter/src/Models/SmSalesAccount.php index a7794efab..d3f6f5019 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmSalesAccount.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmSalesAccount.php @@ -2,12 +2,10 @@ namespace Inensus\SparkMeter\Models; -class SmSalesAccount extends BaseModel -{ +class SmSalesAccount extends BaseModel { protected $table = 'sm_sales_accounts'; - public function site() - { + public function site() { return $this->belongsTo(SmSite::class, 'site_id', 'site_id'); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmSetting.php b/src/backend/packages/inensus/spark-meter/src/Models/SmSetting.php index 52f5639c7..9d0178bc8 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmSetting.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmSetting.php @@ -5,32 +5,24 @@ use App\Relations\BelongsToMorph; use Illuminate\Database\Eloquent\Relations\MorphTo; -class SmSetting extends BaseModel -{ +class SmSetting extends BaseModel { protected $table = 'sm_settings'; - public function setting(): MorphTo - { + public function setting(): MorphTo { return $this->morphTo(); } /** * A work-around for querying the polymorphic relation with whereHas. - * - * @return BelongsToMorph */ - public function settingSms(): BelongsToMorph - { + public function settingSms(): BelongsToMorph { return BelongsToMorph::build($this, SmSmsSetting::class, 'setting'); } /** * A work-around for querying the polymorphic relation with whereHas. - * - * @return BelongsToMorph */ - public function settingSync(): BelongsToMorph - { + public function settingSync(): BelongsToMorph { return BelongsToMorph::build($this, SmSyncSetting::class, 'setting'); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmSite.php b/src/backend/packages/inensus/spark-meter/src/Models/SmSite.php index 81379a7e8..dc7bc43fc 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmSite.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmSite.php @@ -4,12 +4,10 @@ use App\Models\MiniGrid; -class SmSite extends BaseModel -{ +class SmSite extends BaseModel { protected $table = 'sm_sites'; - public function mpmMiniGrid() - { + public function mpmMiniGrid() { return $this->belongsTo(MiniGrid::class, 'mpm_mini_grid_id'); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmSmsBody.php b/src/backend/packages/inensus/spark-meter/src/Models/SmSmsBody.php index dca5e7baa..b3d4e0b9a 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmSmsBody.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmSmsBody.php @@ -2,7 +2,6 @@ namespace Inensus\SparkMeter\Models; -class SmSmsBody extends BaseModel -{ +class SmSmsBody extends BaseModel { protected $table = 'sm_sms_bodies'; } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmSmsFeedbackWord.php b/src/backend/packages/inensus/spark-meter/src/Models/SmSmsFeedbackWord.php index da438d20c..98f34eeb2 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmSmsFeedbackWord.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmSmsFeedbackWord.php @@ -2,7 +2,6 @@ namespace Inensus\SparkMeter\Models; -class SmSmsFeedbackWord extends BaseModel -{ +class SmSmsFeedbackWord extends BaseModel { protected $table = 'sm_sms_feedback_words'; } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmSmsNotifiedCustomer.php b/src/backend/packages/inensus/spark-meter/src/Models/SmSmsNotifiedCustomer.php index f91293c6a..439b4461d 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmSmsNotifiedCustomer.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmSmsNotifiedCustomer.php @@ -4,12 +4,10 @@ use Illuminate\Database\Eloquent\Relations\MorphTo; -class SmSmsNotifiedCustomer extends BaseModel -{ +class SmSmsNotifiedCustomer extends BaseModel { protected $table = 'sm_sms_notified_customers'; - public function notify(): MorphTo - { + public function notify(): MorphTo { return $this->morphTo(); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmSmsSetting.php b/src/backend/packages/inensus/spark-meter/src/Models/SmSmsSetting.php index a1059649b..97efbe937 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmSmsSetting.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmSmsSetting.php @@ -2,12 +2,10 @@ namespace Inensus\SparkMeter\Models; -class SmSmsSetting extends BaseModel -{ +class SmSmsSetting extends BaseModel { protected $table = 'sm_sms_settings'; - public function setting() - { + public function setting() { return $this->morphOne(SmSetting::class, 'setting'); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmSmsVariableDefaultValue.php b/src/backend/packages/inensus/spark-meter/src/Models/SmSmsVariableDefaultValue.php index 6858b4aa3..231bac378 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmSmsVariableDefaultValue.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmSmsVariableDefaultValue.php @@ -2,7 +2,6 @@ namespace Inensus\SparkMeter\Models; -class SmSmsVariableDefaultValue extends BaseModel -{ +class SmSmsVariableDefaultValue extends BaseModel { protected $table = 'sm_sms_variable_default_values'; } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmSyncAction.php b/src/backend/packages/inensus/spark-meter/src/Models/SmSyncAction.php index 5e8678e52..006d53159 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmSyncAction.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmSyncAction.php @@ -2,12 +2,10 @@ namespace Inensus\SparkMeter\Models; -class SmSyncAction extends BaseModel -{ +class SmSyncAction extends BaseModel { protected $table = 'sm_sync_actions'; - public function synSetting() - { + public function synSetting() { return $this->belongsTo(SmSyncSetting::class, 'sync_setting_id'); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmSyncSetting.php b/src/backend/packages/inensus/spark-meter/src/Models/SmSyncSetting.php index ac3a08ec4..2067eedd8 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmSyncSetting.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmSyncSetting.php @@ -2,17 +2,14 @@ namespace Inensus\SparkMeter\Models; -class SmSyncSetting extends BaseModel -{ +class SmSyncSetting extends BaseModel { protected $table = 'sm_sync_settings'; - public function syncAction() - { + public function syncAction() { return $this->hasOne(SmSyncAction::class); } - public function setting() - { + public function setting() { return $this->morphOne(SmSetting::class, 'setting'); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmTariff.php b/src/backend/packages/inensus/spark-meter/src/Models/SmTariff.php index 5ca299b22..9a7ad5c6b 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmTariff.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmTariff.php @@ -4,17 +4,14 @@ use App\Models\Meter\MeterTariff; -class SmTariff extends BaseModel -{ +class SmTariff extends BaseModel { protected $table = 'sm_tariffs'; - public function mpmTariff() - { + public function mpmTariff() { return $this->belongsTo(MeterTariff::class, 'mpm_tariff_id'); } - public function site() - { + public function site() { return $this->belongsTo(SmSite::class, 'site_id', 'site_id'); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SmTransaction.php b/src/backend/packages/inensus/spark-meter/src/Models/SmTransaction.php index 345dba8ac..dc1bc5a40 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SmTransaction.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SmTransaction.php @@ -12,52 +12,42 @@ use Inensus\SwiftaPaymentProvider\Models\SwiftaTransaction; use Inensus\WaveMoneyPaymentProvider\Models\WaveMoneyTransaction; -class SmTransaction extends BaseModel implements ISubTransaction -{ +class SmTransaction extends BaseModel implements ISubTransaction { protected $table = 'sm_transactions'; - public function mpmTransaction() - { + public function mpmTransaction() { return $this->belongsTo(Transaction::class, 'mpm_transaction_id'); } - public function site() - { + public function site() { return $this->belongsTo(SmSite::class, 'site_id', 'site_id'); } - public function agentTransaction() - { + public function agentTransaction() { return $this->morphOne(AgentTransaction::class, 'manufacturer_transaction'); } - public function vodacomTransaction() - { + public function vodacomTransaction() { return $this->morphOne(VodacomTransaction::class, 'manufacturer_transaction'); } - public function airtelTransaction() - { + public function airtelTransaction() { return $this->morphOne(AirtelTransaction::class, 'manufacturer_transaction'); } - public function thirdPartyTransaction() - { + public function thirdPartyTransaction() { return $this->morphOne(ThirdPartyTransaction::class, 'manufacturer_transaction'); } - public function mesombTransaction() - { + public function mesombTransaction() { return $this->morphOne(MesombTransaction::class, 'manufacturer_transaction'); } - public function swiftaTransaction() - { + public function swiftaTransaction() { return $this->morphOne(SwiftaTransaction::class, 'manufacturer_transaction'); } - public function waveMoneyTransaction() - { + public function waveMoneyTransaction() { return $this->morphOne(WaveMoneyTransaction::class, 'manufacturer_transaction'); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Models/SyncStatus.php b/src/backend/packages/inensus/spark-meter/src/Models/SyncStatus.php index 1ab44cace..dbdd1dd7c 100644 --- a/src/backend/packages/inensus/spark-meter/src/Models/SyncStatus.php +++ b/src/backend/packages/inensus/spark-meter/src/Models/SyncStatus.php @@ -2,9 +2,10 @@ namespace Inensus\SparkMeter\Models; -abstract class SyncStatus -{ +abstract class SyncStatus { public const SYNCED = 1; + public const MODIFIED = 2; + public const NOT_REGISTERED_YET = 3; } diff --git a/src/backend/packages/inensus/spark-meter/src/Observers/GeographicalInformationObserver.php b/src/backend/packages/inensus/spark-meter/src/Observers/GeographicalInformationObserver.php index e0e69db02..c717121c8 100644 --- a/src/backend/packages/inensus/spark-meter/src/Observers/GeographicalInformationObserver.php +++ b/src/backend/packages/inensus/spark-meter/src/Observers/GeographicalInformationObserver.php @@ -10,19 +10,16 @@ use Inensus\SparkMeter\Models\SmCustomer; use Inensus\SparkMeter\Services\CustomerService; -class GeographicalInformationObserver -{ +class GeographicalInformationObserver { public function __construct( private CustomerService $customerService, private SmTableEncryption $smTableEncryption, private Person $person, private SmCustomer $smCustomer, private PluginsService $pluginsService, - ) { - } + ) {} - public function updated(GeographicalInformation $geographicalInformation) - { + public function updated(GeographicalInformation $geographicalInformation) { if ($this->pluginsService->isPluginActive(MpmPlugin::SPARK_METER) && $geographicalInformation->owner_type === 'meter_parameter') { $meterParameterId = $geographicalInformation->owner_id; $customer = $this->person->newQuery()->with(['meters.tariff', 'meters.geo', 'meters.meter']) diff --git a/src/backend/packages/inensus/spark-meter/src/Observers/MeterTariffObserver.php b/src/backend/packages/inensus/spark-meter/src/Observers/MeterTariffObserver.php index 9403d8743..19667fc71 100644 --- a/src/backend/packages/inensus/spark-meter/src/Observers/MeterTariffObserver.php +++ b/src/backend/packages/inensus/spark-meter/src/Observers/MeterTariffObserver.php @@ -8,11 +8,13 @@ use Inensus\SparkMeter\Models\SmTariff; use Inensus\SparkMeter\Services\TariffService; -class MeterTariffObserver -{ +class MeterTariffObserver { private $tariffService; + private $smTableEncryption; + private $smTariff; + private $accessRate; public function __construct( @@ -27,8 +29,7 @@ public function __construct( $this->accessRate = $accessRate; } - public function updated(MeterTariff $tariff) - { + public function updated(MeterTariff $tariff) { $smTariff = $this->smTariff->newQuery()->where('mpm_tariff_id', $tariff->id)->first(); if ($smTariff) { $sparkTariff = $this->tariffService->getSparkTariffInfo($smTariff->tariff_id); @@ -60,7 +61,7 @@ public function updated(MeterTariff $tariff) $updatedTariff = $this->tariffService->updateSparkTariffInfo($tariffData); $modelTouString = ''; foreach ($updatedTariff['tous'] as $item) { - $modelTouString .= $item['start'].$item['end'].doubleval($item['value']); + $modelTouString .= $item['start'].$item['end'].floatval($item['value']); } $modelHash = $this->smTableEncryption->makeHash([ $updatedTariff['name'], diff --git a/src/backend/packages/inensus/spark-meter/src/Observers/PersonObserver.php b/src/backend/packages/inensus/spark-meter/src/Observers/PersonObserver.php index cc44b9a4d..90fcf6040 100644 --- a/src/backend/packages/inensus/spark-meter/src/Observers/PersonObserver.php +++ b/src/backend/packages/inensus/spark-meter/src/Observers/PersonObserver.php @@ -7,11 +7,13 @@ use Inensus\SparkMeter\Models\SmCustomer; use Inensus\SparkMeter\Services\CustomerService; -class PersonObserver -{ +class PersonObserver { private $customerService; + private $smTableEncryption; + private $person; + private $smCustomer; public function __construct( @@ -26,8 +28,7 @@ public function __construct( $this->smCustomer = $smCustomer; } - public function updated(Person $person) - { + public function updated(Person $person) { $smCustomer = $this->smCustomer->newQuery()->with('site') ->where('mpm_customer_id', $person->id)->first(); diff --git a/src/backend/packages/inensus/spark-meter/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/spark-meter/src/Providers/EventServiceProvider.php index 035781318..76c267275 100644 --- a/src/backend/packages/inensus/spark-meter/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/spark-meter/src/Providers/EventServiceProvider.php @@ -7,8 +7,7 @@ use Inensus\SparkMeter\Listeners\SmsListener; use Inensus\SparkMeter\Listeners\TransactionListener; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ // MeterParameterListener::class, // TransactionListener::class, @@ -20,8 +19,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/spark-meter/src/Providers/ObserverServiceProvider.php index dadf7cac1..8acd6378f 100644 --- a/src/backend/packages/inensus/spark-meter/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/spark-meter/src/Providers/ObserverServiceProvider.php @@ -10,15 +10,13 @@ use Inensus\SparkMeter\Observers\MeterTariffObserver; use Inensus\SparkMeter\Observers\PersonObserver; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); Person::observe(PersonObserver::class); GeographicalInformation::observe(GeographicalInformationObserver::class); diff --git a/src/backend/packages/inensus/spark-meter/src/Providers/SparkMeterRouteServiceProvider.php b/src/backend/packages/inensus/spark-meter/src/Providers/SparkMeterRouteServiceProvider.php index c406b4add..5d5aca4a7 100644 --- a/src/backend/packages/inensus/spark-meter/src/Providers/SparkMeterRouteServiceProvider.php +++ b/src/backend/packages/inensus/spark-meter/src/Providers/SparkMeterRouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class SparkMeterRouteServiceProvider extends ServiceProvider -{ +class SparkMeterRouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\SparkMeter\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/spark-meter/src/Providers/SparkMeterServiceProvider.php b/src/backend/packages/inensus/spark-meter/src/Providers/SparkMeterServiceProvider.php index d3e380dfe..c1ed656cb 100644 --- a/src/backend/packages/inensus/spark-meter/src/Providers/SparkMeterServiceProvider.php +++ b/src/backend/packages/inensus/spark-meter/src/Providers/SparkMeterServiceProvider.php @@ -17,13 +17,11 @@ use Inensus\SparkMeter\Models\SmTransaction; use Inensus\SparkMeter\SparkMeterApi; -class SparkMeterServiceProvider extends ServiceProvider -{ +class SparkMeterServiceProvider extends ServiceProvider { /** * Bootstrap the application services. */ - public function boot(Filesystem $filesystem) - { + public function boot(Filesystem $filesystem) { $this->app->register(SparkMeterRouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -53,37 +51,32 @@ public function boot(Filesystem $filesystem) ); } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/spark-meter-integration.php', 'spark'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->bind('SparkMeterApi', SparkMeterApi::class); } - public function publishVueFiles() - { + public function publishVueFiles() { $this->publishes([ __DIR__.'/../resources/assets' => resource_path('assets/js/plugins/spark-meter'), ], 'vue-components'); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/spark-meter-integration.php' => config_path('spark-meter-integration.php'), ]); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_spark_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) diff --git a/src/backend/packages/inensus/spark-meter/src/Services/CredentialService.php b/src/backend/packages/inensus/spark-meter/src/Services/CredentialService.php index 2848cf4e6..89613a0d9 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/CredentialService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/CredentialService.php @@ -7,12 +7,15 @@ use Inensus\SparkMeter\Http\Requests\SparkMeterApiRequests; use Inensus\SparkMeter\Models\SmCredential; -class CredentialService -{ +class CredentialService { private $sparkMeterApiRequests; + private $smCredential; + private $smTableEncryption; + private $rootUrl = '/organizations'; + private $organizationService; public function __construct( @@ -25,13 +28,11 @@ public function __construct( $this->organizationService = $organizationService; } - public function getCredentials() - { + public function getCredentials() { return $this->smCredential->newQuery()->latest()->take(1)->get()->first(); } - public function createSmCredentials() - { + public function createSmCredentials() { return $this->smCredential->newQuery()->firstOrCreate(['id' => 1], [ 'api_key' => null, 'api_secret' => null, @@ -39,8 +40,7 @@ public function createSmCredentials() ]); } - public function updateCredentials($data) - { + public function updateCredentials($data) { $smCredentials = $this->smCredential->newQuery()->find($data['id']); $smCredentials->update([ 'api_key' => $data['api_key'], diff --git a/src/backend/packages/inensus/spark-meter/src/Services/CustomerService.php b/src/backend/packages/inensus/spark-meter/src/Services/CustomerService.php index 98f8273b2..cc5b2aeab 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/CustomerService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/CustomerService.php @@ -26,25 +26,41 @@ use Inensus\SparkMeter\Models\SmTariff; use Inensus\SparkMeter\Models\SyncStatus; -class CustomerService implements ISynchronizeService -{ +class CustomerService implements ISynchronizeService { private $sparkMeterApiRequests; + private $rootUrl = '/customer/'; + private $smTableEncryption; + private $person; + private $smCustomer; + private $smMeterModel; + private $smTariff; + private $smSite; + private $meter; + private $manufacturer; + private $meterParameter; + private $connectionType; + private $connectionGroup; + private $city; + private $cluster; + private $smSyncSettingService; + private $smSyncActionService; + private $smSmsNotifiedCustomerService; public function __construct( @@ -85,8 +101,7 @@ public function __construct( $this->smSmsNotifiedCustomerService = $smSmsNotifiedCustomerService; } - public function createCustomer($meterInfo, $siteId) - { + public function createCustomer($meterInfo, $siteId) { $params = [ 'meter_serial' => $meterInfo->meter->serial_number, ]; @@ -132,28 +147,24 @@ public function createCustomer($meterInfo, $siteId) } } - public function getSmCustomers($request) - { + public function getSmCustomers($request) { $perPage = $request->input('per_page') ?? 15; return $this->smCustomer->newQuery()->with(['mpmPerson', 'site.mpmMiniGrid'])->paginate($perPage); } - public function getSmCustomersCount() - { + public function getSmCustomersCount() { return count($this->smCustomer->newQuery()->get()); } - public function getSmCustomerByCustomerId($customerId) - { + public function getSmCustomerByCustomerId($customerId) { return $this->smCustomer->newQuery()->with([ 'mpmPerson.meters.meter', 'mpmPerson.addresses', ])->where('customer_id', $customerId)->first(); } - public function updateSparkCustomerInfo($customerData, $siteId) - { + public function updateSparkCustomerInfo($customerData, $siteId) { try { $customerId = $customerData['id']; $putParams = [ @@ -175,8 +186,7 @@ public function updateSparkCustomerInfo($customerData, $siteId) } } - public function createRelatedPerson($customer, $site_id) - { + public function createRelatedPerson($customer, $site_id) { try { DB::connection('shard')->beginTransaction(); $sparkCustomerMeterSerial = $customer['meters'][0]['serial']; @@ -261,8 +271,7 @@ function ($q) use ($currentTariffName) { } } - public function createPerson($data) - { + public function createPerson($data) { $person = $this->person->newQuery()->create([ 'name' => $data['name'], 'is_customer' => 1, @@ -280,8 +289,7 @@ public function createPerson($data) return $person; } - public function updateRelatedPerson($customer, $person, $site_id) - { + public function updateRelatedPerson($customer, $person, $site_id) { $sparkCustomerMeterSerial = $customer['meters'][0]['serial']; $currentTariffName = $customer['meters'][0]['current_tariff_name']; $site = $this->smSite->newQuery()->with('mpmMiniGrid')->where('site_id', $site_id)->firstOrFail(); @@ -328,8 +336,7 @@ function ($q) use ($currentTariffName) { ]); } - public function checkConnectionAvailability() - { + public function checkConnectionAvailability() { $connectionType = $this->connectionType->newQuery()->first(); $connectionGroup = $this->connectionGroup->newQuery()->first(); @@ -345,8 +352,7 @@ public function checkConnectionAvailability() return $result; } - public function hashCustomerWithMeterSerial($meterSerial, $siteId) - { + public function hashCustomerWithMeterSerial($meterSerial, $siteId) { try { $params = [ 'meter_serial' => $meterSerial, @@ -360,8 +366,7 @@ public function hashCustomerWithMeterSerial($meterSerial, $siteId) } } - public function updateCustomerLowBalanceLimit($customerId, $data) - { + public function updateCustomerLowBalanceLimit($customerId, $data) { $customer = $this->smCustomer->newQuery()->find($customerId); $customer->update([ 'low_balance_limit' => $data['low_balance_limit'], @@ -370,8 +375,7 @@ public function updateCustomerLowBalanceLimit($customerId, $data) return $customer->fresh(); } - public function searchCustomer($searchTerm, $paginate) - { + public function searchCustomer($searchTerm, $paginate) { if ($paginate === 1) { return $this->smCustomer->newQuery()->with(['mpmPerson', 'site.mpmMiniGrid']) ->WhereHas('site.mpmMiniGrid', function ($q) use ($searchTerm) { @@ -389,8 +393,7 @@ public function searchCustomer($searchTerm, $paginate) })->get(); } - public function getLowBalancedCustomers() - { + public function getLowBalancedCustomers() { return $this->smCustomer->newQuery()->with([ 'mpmPerson.addresses' => function ($q) { return $q->where('is_primary', 1); @@ -401,8 +404,7 @@ public function getLowBalancedCustomers() ->where('low_balance_limit', '>', 'credit_balance')->get(); } - public function sync() - { + public function sync() { $synSetting = $this->smSyncSettingService->getSyncSettingsByActionName('Customers'); $syncAction = $this->smSyncActionService->getSyncActionBySynSettingId($synSetting->id); try { @@ -455,8 +457,7 @@ public function sync() } } - public function syncCheck($returnData = false) - { + public function syncCheck($returnData = false) { $returnArray = ['available_site_count' => 0]; $sites = $this->smSite->newQuery()->where('is_authenticated', 1)->where('is_online', 1)->get(); foreach ($sites as $key => $site) { @@ -519,8 +520,7 @@ public function syncCheck($returnData = false) return $returnArray; } - public function modelHasher($model, ...$params): string - { + public function modelHasher($model, ...$params): string { return $this->smTableEncryption->makeHash([ trim($model['name']), $params[0], @@ -530,8 +530,7 @@ public function modelHasher($model, ...$params): string ]); } - public function getSparkCustomersWithAddress() - { + public function getSparkCustomersWithAddress() { return $this->smCustomer->newQuery()->with([ 'mpmPerson.addresses', ])->whereHas('mpmPerson.addresses', function ($q) { @@ -539,8 +538,7 @@ public function getSparkCustomersWithAddress() })->get(); } - public function syncCheckBySite($siteId) - { + public function syncCheckBySite($siteId) { try { $sparkCustomers = $this->sparkMeterApiRequests->get('/customers', $siteId); } catch (SparkAPIResponseException $e) { @@ -581,8 +579,7 @@ public function syncCheckBySite($siteId) } } - public function resetMeter($customer) - { + public function resetMeter($customer) { $rootUrl = '/customers/'.$customer->customer_id.'/reset-meter'; try { $this->sparkMeterApiRequests->post($rootUrl, null, $customer->site->site_id); @@ -592,15 +589,18 @@ public function resetMeter($customer) } } - public function getSparkCustomerWithPhone($phoneNumber) - { + public function getSparkCustomerWithPhone($phoneNumber) { $person = $this->person::with(['addresses']) - ->whereHas('addresses', static function ($q) use ($phoneNumber) { - $q->where('phone', $phoneNumber); - } + ->whereHas( + 'addresses', + static function ($q) use ($phoneNumber) { + $q->where('phone', $phoneNumber); + } )->first(); - return $this->smCustomer->newQuery()->with(['site', 'mpmPerson.meters.meter'])->where('mpm_customer_id', - $person->id)->first(); + return $this->smCustomer->newQuery()->with(['site', 'mpmPerson.meters.meter'])->where( + 'mpm_customer_id', + $person->id + )->first(); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Services/ISynchronizeService.php b/src/backend/packages/inensus/spark-meter/src/Services/ISynchronizeService.php index 8ba77ea6a..427da8cbe 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/ISynchronizeService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/ISynchronizeService.php @@ -2,8 +2,7 @@ namespace Inensus\SparkMeter\Services; -interface ISynchronizeService -{ +interface ISynchronizeService { public function sync(); public function syncCheck(); diff --git a/src/backend/packages/inensus/spark-meter/src/Services/MeterModelService.php b/src/backend/packages/inensus/spark-meter/src/Services/MeterModelService.php index a75cb8734..2f335f8bc 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/MeterModelService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/MeterModelService.php @@ -11,15 +11,21 @@ use Inensus\SparkMeter\Models\SmSite; use Inensus\SparkMeter\Models\SyncStatus; -class MeterModelService implements ISynchronizeService -{ +class MeterModelService implements ISynchronizeService { private $sparkMeterApiRequests; + private $rootUrl = '/meters'; + private $smTableEncryption; + private $smMeterModel; + private $smSite; + private $meterType; + private $smSyncSettingService; + private $smSyncActionService; public function __construct( @@ -40,20 +46,17 @@ public function __construct( $this->smSyncActionService = $smSyncActionService; } - public function getSmMeterModels($request) - { + public function getSmMeterModels($request) { $perPage = $request->input('per_page') ?? 15; return $this->smMeterModel->newQuery()->with(['meterType', 'site.mpmMiniGrid'])->paginate($perPage); } - public function getSmMeterModelsCount() - { + public function getSmMeterModelsCount() { return count($this->smMeterModel->newQuery()->get()); } - public function sync() - { + public function sync() { $synSetting = $this->smSyncSettingService->getSyncSettingsByActionName('MeterModels'); $syncAction = $this->smSyncActionService->getSyncActionBySynSettingId($synSetting->id); try { @@ -108,8 +111,7 @@ public function sync() } } - public function syncCheck($returnData = false) - { + public function syncCheck($returnData = false) { $returnArray = ['available_site_count' => 0]; $sites = $this->smSite->newQuery()->where('is_authenticated', 1)->where('is_online', 1)->get(); foreach ($sites as $key => $site) { @@ -170,8 +172,7 @@ public function syncCheck($returnData = false) return $returnArray; } - public function modelHasher($model, ...$params): string - { + public function modelHasher($model, ...$params): string { return $smModelHash = $this->smTableEncryption->makeHash([ $model['name'], $model['phase_count'], @@ -180,8 +181,7 @@ public function modelHasher($model, ...$params): string ]); } - public function syncCheckBySite($siteId) - { + public function syncCheckBySite($siteId) { try { $url = $this->rootUrl.'/models'; $sparkMeterModels = $this->sparkMeterApiRequests->get($url, $siteId); @@ -221,8 +221,7 @@ public function syncCheckBySite($siteId) } } - public function createRelatedMeterModel($meterModel) - { + public function createRelatedMeterModel($meterModel) { return $this->meterType->newQuery()->create([ 'online' => 1, 'phase' => $meterModel['phase_count'], @@ -230,8 +229,7 @@ public function createRelatedMeterModel($meterModel) ]); } - public function updateRelatedMeterModel($meterModel, $relatedMeterModel) - { + public function updateRelatedMeterModel($meterModel, $relatedMeterModel) { return $meterModel['relatedMeterModel']->update([ 'phase' => $meterModel['phase_count'], 'max_current' => $meterModel['continuous_limit'], diff --git a/src/backend/packages/inensus/spark-meter/src/Services/OrganizationService.php b/src/backend/packages/inensus/spark-meter/src/Services/OrganizationService.php index 8cdaa098c..fe42a4667 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/OrganizationService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/OrganizationService.php @@ -4,8 +4,7 @@ use Inensus\SparkMeter\Models\SmOrganization; -class OrganizationService -{ +class OrganizationService { private $organization; public function __construct( @@ -14,13 +13,11 @@ public function __construct( $this->organization = $organization; } - public function getOrganizations() - { + public function getOrganizations() { return $this->organization->newQuery()->where('id', '>', 0)->get(); } - public function createOrganization($organizationData) - { + public function createOrganization($organizationData) { $organization = $this->organization->newQuery()->first(); if (!$organization) { return $this->organization->newQuery()->create([ @@ -39,8 +36,7 @@ public function createOrganization($organizationData) } } - public function deleteOrganization() - { + public function deleteOrganization() { $organization = $this->organization->newQuery()->first(); $organization->delete(); } diff --git a/src/backend/packages/inensus/spark-meter/src/Services/PackageInstallationService.php b/src/backend/packages/inensus/spark-meter/src/Services/PackageInstallationService.php index 8c513d2f5..fa09878b3 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/PackageInstallationService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/PackageInstallationService.php @@ -2,12 +2,15 @@ namespace Inensus\SparkMeter\Services; -class PackageInstallationService -{ +class PackageInstallationService { private $smsSettingService; + private $syncSettingService; + private $smsBodyService; + private $defaultValueService; + private $smSmsFeedbackWordService; public function __construct( @@ -24,8 +27,7 @@ public function __construct( $this->smSmsFeedbackWordService = $smSmsFeedbackWordService; } - public function createDefaultSettingRecords() - { + public function createDefaultSettingRecords() { $this->smsBodyService->createSmsBodies(); $this->defaultValueService->createSmsVariableDefaultValues(); $this->syncSettingService->createDefaultSettings(); diff --git a/src/backend/packages/inensus/spark-meter/src/Services/SiteService.php b/src/backend/packages/inensus/spark-meter/src/Services/SiteService.php index cfda00541..5c2ca03c8 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/SiteService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/SiteService.php @@ -14,18 +14,27 @@ use Inensus\SparkMeter\Models\SmSite; use Inensus\SparkMeter\Models\SyncStatus; -class SiteService implements ISynchronizeService -{ +class SiteService implements ISynchronizeService { private $site; + private $sparkMeterApiRequests; + private $rootUrl = '/organizations'; + private $smTableEncryption; + private $organizationService; + private $cluster; + private $miniGrid; + private $city; + private $geographicalInformation; + private $smSyncSettingService; + private $smSyncActionService; public function __construct( @@ -52,8 +61,7 @@ public function __construct( $this->smSyncActionService = $smSyncActionService; } - public function getSmSites($request) - { + public function getSmSites($request) { $perPage = $request->input('per_page') ?? 15; $sites = $this->site->newQuery()->with('mpmMiniGrid')->paginate($perPage); @@ -69,13 +77,11 @@ public function getSmSites($request) return $sites; } - public function getSmSitesCount() - { + public function getSmSitesCount() { return count($this->site->newQuery()->get()); } - public function creteRelatedMiniGrid($site) - { + public function creteRelatedMiniGrid($site) { $cluster = $this->cluster->newQuery()->latest('created_at')->first(); $miniGrid = $this->miniGrid->newQuery()->create([ 'name' => $site['name'], @@ -92,8 +98,7 @@ public function creteRelatedMiniGrid($site) return $miniGrid; } - public function updateGeographicalInformation($miniGridId) - { + public function updateGeographicalInformation($miniGridId) { $geographicalInformation = $this->geographicalInformation->newQuery()->whereHasMorph( 'owner', [MiniGrid::class], @@ -102,23 +107,21 @@ static function ($q) use ($miniGridId) { } )->first(); $points = explode(',', config('spark.geoLocation')); - $latitude = strval(doubleval($points[0]) + (mt_rand(10, 10000) / 10000)); - $longitude = strval(doubleval($points[1]) + (mt_rand(10, 10000) / 10000)); + $latitude = strval(floatval($points[0]) + (mt_rand(10, 10000) / 10000)); + $longitude = strval(floatval($points[1]) + (mt_rand(10, 10000) / 10000)); $points = $latitude.','.$longitude; $geographicalInformation->update([ 'points' => $points, ]); } - public function updateRelatedMiniGrid($site, $miniGrid) - { + public function updateRelatedMiniGrid($site, $miniGrid) { return $miniGrid->newQuery()->update([ 'name' => $site['name'], ]); } - public function update($siteId, $data) - { + public function update($siteId, $data) { $site = $this->site->newQuery()->find($siteId); $site->update([ 'thundercloud_token' => $data['thundercloud_token'], @@ -132,8 +135,8 @@ public function update($siteId, $data) $site->is_authenticated = true; $site->is_online = Carbon::parse($system['last_sync_date']) - ->toDateTimeString() > Carbon::now()->utc() - ->subMinutes(15)->toDateTimeString(); + ->toDateTimeString() > Carbon::now()->utc() + ->subMinutes(15)->toDateTimeString(); } catch (\Exception $e) { $site->is_authenticated = false; $site->is_online = false; @@ -143,18 +146,15 @@ public function update($siteId, $data) return $site->fresh(); } - public function getThunderCloudInformation($siteId) - { + public function getThunderCloudInformation($siteId) { return $this->site->newQuery()->where('site_id', $siteId)->first(); } - public function checkLocationAvailability() - { + public function checkLocationAvailability() { return $this->cluster->newQuery()->latest('created_at')->first(); } - public function sync() - { + public function sync() { $synSetting = $this->smSyncSettingService->getSyncSettingsByActionName('Sites'); $syncAction = $this->smSyncActionService->getSyncActionBySynSettingId($synSetting->id); try { @@ -198,8 +198,7 @@ public function sync() } } - public function syncCheck($returnData = false) - { + public function syncCheck($returnData = false) { $organizations = $this->organizationService->getOrganizations(); $sites = []; try { @@ -247,8 +246,7 @@ public function syncCheck($returnData = false) return $returnData ? ['data' => $sitesCollection, 'result' => true] : ['result' => true]; } - public function modelHasher($model, ...$params): string - { + public function modelHasher($model, ...$params): string { return $this->smTableEncryption->makeHash([ $model['name'], $model['display_name'], @@ -256,8 +254,7 @@ public function modelHasher($model, ...$params): string ]); } - public function syncCheckBySite($siteId) - { + public function syncCheckBySite($siteId) { // This function is not using for sites } } diff --git a/src/backend/packages/inensus/spark-meter/src/Services/SmSalesAccoutService.php b/src/backend/packages/inensus/spark-meter/src/Services/SmSalesAccoutService.php index 5574d7cce..8b054a64f 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/SmSalesAccoutService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/SmSalesAccoutService.php @@ -10,14 +10,19 @@ use Inensus\SparkMeter\Models\SmSite; use Inensus\SparkMeter\Models\SyncStatus; -class SmSalesAccoutService implements ISynchronizeService -{ +class SmSalesAccoutService implements ISynchronizeService { private $sparkMeterApiRequests; + private $rootUrl = '/sales-accounts'; + private $smTableEncryption; + private $smSalesAccount; + private $smSite; + private $smSyncSettingService; + private $smSyncActionService; public function __construct( @@ -36,20 +41,17 @@ public function __construct( $this->smSyncActionService = $smSyncActionService; } - public function getSmSalesAccounts($request) - { + public function getSmSalesAccounts($request) { $perPage = $request->input('per_page') ?? 15; return $this->smSalesAccount->newQuery()->with(['site.mpmMiniGrid'])->paginate($perPage); } - public function getSmSalesAccountsCount() - { + public function getSmSalesAccountsCount() { return count($this->smSalesAccount->newQuery()->get()); } - public function sync() - { + public function sync() { $synSetting = $this->smSyncSettingService->getSyncSettingsByActionName('SalesAccounts'); $syncAction = $this->smSyncActionService->getSyncActionBySynSettingId($synSetting->id); try { @@ -97,8 +99,7 @@ public function sync() } } - public function syncCheck($returnData = false) - { + public function syncCheck($returnData = false) { $returnArray = ['available_site_count' => 0]; $sites = $this->smSite->newQuery()->where('is_authenticated', 1)->where('is_online', 1)->get(); @@ -153,8 +154,7 @@ public function syncCheck($returnData = false) return $returnArray; } - public function syncCheckBySite($siteId) - { + public function syncCheckBySite($siteId) { try { $url = $this->rootUrl; $sparkMeterModels = $this->sparkMeterApiRequests->get($url, $siteId); @@ -190,8 +190,7 @@ public function syncCheckBySite($siteId) } } - public function modelHasher($model, ...$params): string - { + public function modelHasher($model, ...$params): string { return $smModelHash = $this->smTableEncryption->makeHash([ $model['account_type'], $model['active'], diff --git a/src/backend/packages/inensus/spark-meter/src/Services/SmSettingService.php b/src/backend/packages/inensus/spark-meter/src/Services/SmSettingService.php index f24536d3c..43fda9fa4 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/SmSettingService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/SmSettingService.php @@ -4,17 +4,14 @@ use Inensus\SparkMeter\Models\SmSetting; -class SmSettingService -{ +class SmSettingService { private $smSetting; - public function __construct(SmSetting $smSetting) - { + public function __construct(SmSetting $smSetting) { $this->smSetting = $smSetting; } - public function getSettings() - { + public function getSettings() { return $this->smSetting->newQuery()->with(['settingSms', 'settingSync'])->whereHasMorph('setting', '*')->get(); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Services/SmSmsBodyService.php b/src/backend/packages/inensus/spark-meter/src/Services/SmSmsBodyService.php index d2627e98d..5e4af91c7 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/SmSmsBodyService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/SmSmsBodyService.php @@ -4,27 +4,22 @@ use Inensus\SparkMeter\Models\SmSmsBody; -class SmSmsBodyService -{ +class SmSmsBodyService { private $smsBody; - public function __construct(SmSmsBody $smsBody) - { + public function __construct(SmSmsBody $smsBody) { $this->smsBody = $smsBody; } - public function getSmsBodyByReference($reference) - { + public function getSmsBodyByReference($reference) { return $this->smsBody->newQuery()->where('reference', $reference)->firstOrFail(); } - public function getSmsBodies() - { + public function getSmsBodies() { return $this->smsBody->newQuery()->get(); } - public function updateSmsBodies($smsBodiesData) - { + public function updateSmsBodies($smsBodiesData) { $smsBodies = $this->smsBody->newQuery()->get(); collect($smsBodiesData)->each(function ($smsBody) use ($smsBodies) { $smsBodies->filter(function ($body) use ($smsBody) { @@ -37,13 +32,11 @@ public function updateSmsBodies($smsBodiesData) return $smsBodies; } - public function getNullBodies() - { + public function getNullBodies() { return $this->smsBody->newQuery()->whereNull('body')->get(); } - public function createSmsBodies() - { + public function createSmsBodies() { $smsBodies = [ [ 'reference' => 'SparkSmsLowBalanceHeader', @@ -108,7 +101,8 @@ public function createSmsBodies() ], ]; collect($smsBodies)->each(function ($smsBody) { - $this->smsBody->newQuery()->firstOrCreate(['reference' => $smsBody['reference']], + $this->smsBody->newQuery()->firstOrCreate( + ['reference' => $smsBody['reference']], $smsBody ); }); diff --git a/src/backend/packages/inensus/spark-meter/src/Services/SmSmsFeedbackWordService.php b/src/backend/packages/inensus/spark-meter/src/Services/SmSmsFeedbackWordService.php index f140fc758..3f5a9eed3 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/SmSmsFeedbackWordService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/SmSmsFeedbackWordService.php @@ -4,30 +4,25 @@ use Inensus\SparkMeter\Models\SmSmsFeedbackWord; -class SmSmsFeedbackWordService -{ +class SmSmsFeedbackWordService { private $smsFeedbackWord; - public function __construct(SmSmsFeedbackWord $smsFeedbackWord) - { + public function __construct(SmSmsFeedbackWord $smsFeedbackWord) { $this->smsFeedbackWord = $smsFeedbackWord; } - public function getSmsFeedbackWords() - { + public function getSmsFeedbackWords() { return $this->smsFeedbackWord->newQuery()->get(); } - public function createSmsFeedbackWord() - { + public function createSmsFeedbackWord() { return $this->smsFeedbackWord->newQuery()->firstOrCreate(['id' => 1], [ 'meter_reset' => null, 'meter_balance' => null, ]); } - public function updateSmsFeedbackWord($smsFeedbackWord, $smsFeedbackWordData) - { + public function updateSmsFeedbackWord($smsFeedbackWord, $smsFeedbackWordData) { $smsFeedbackWord->update([ 'meter_reset' => $smsFeedbackWordData['meter_reset'], 'meter_balance' => $smsFeedbackWordData['meter_balance'], diff --git a/src/backend/packages/inensus/spark-meter/src/Services/SmSmsNotifiedCustomerService.php b/src/backend/packages/inensus/spark-meter/src/Services/SmSmsNotifiedCustomerService.php index 814e101f5..91f7e07a8 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/SmSmsNotifiedCustomerService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/SmSmsNotifiedCustomerService.php @@ -4,8 +4,7 @@ use Inensus\SparkMeter\Models\SmSmsNotifiedCustomer; -class SmSmsNotifiedCustomerService -{ +class SmSmsNotifiedCustomerService { private $smSmsNotifiedCustomer; public function __construct( @@ -14,13 +13,11 @@ public function __construct( $this->smSmsNotifiedCustomer = $smSmsNotifiedCustomer; } - public function getSmsNotifiedCustomers() - { + public function getSmsNotifiedCustomers() { return $this->smSmsNotifiedCustomer->newQuery()->get(); } - public function createTransactionSmsNotify($customerId, $transactionId) - { + public function createTransactionSmsNotify($customerId, $transactionId) { return $this->smSmsNotifiedCustomer->newQuery()->create([ 'customer_id' => $customerId, 'notify_type' => 'transaction', @@ -28,16 +25,14 @@ public function createTransactionSmsNotify($customerId, $transactionId) ]); } - public function createLowBalanceSmsNotify($customerId) - { + public function createLowBalanceSmsNotify($customerId) { return $this->smSmsNotifiedCustomer->newQuery()->create([ 'customer_id' => $customerId, 'notify_type' => 'low_balance', ]); } - public function removeLowBalancedCustomer($customer) - { + public function removeLowBalancedCustomer($customer) { if ($customer['low_balance_limit'] >= $customer['credit_balance']) { return false; } diff --git a/src/backend/packages/inensus/spark-meter/src/Services/SmSmsSettingService.php b/src/backend/packages/inensus/spark-meter/src/Services/SmSmsSettingService.php index 1544f1401..794d60973 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/SmSmsSettingService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/SmSmsSettingService.php @@ -5,19 +5,17 @@ use Inensus\SparkMeter\Models\SmSetting; use Inensus\SparkMeter\Models\SmSmsSetting; -class SmSmsSettingService -{ +class SmSmsSettingService { private $smsSetting; + private $setting; - public function __construct(SmSmsSetting $smsSetting, SmSetting $setting) - { + public function __construct(SmSmsSetting $smsSetting, SmSetting $setting) { $this->smsSetting = $smsSetting; $this->setting = $setting; } - public function createDefaultSettings() - { + public function createDefaultSettings() { $smsTransaction = $this->smsSetting->newQuery()->where('state', 'Transactions')->first(); if (!$smsTransaction) { $smsSetting = $this->setting->newQuery()->make(); @@ -40,8 +38,7 @@ public function createDefaultSettings() } } - public function updateSmsSettings($smsSettings) - { + public function updateSmsSettings($smsSettings) { foreach ($smsSettings as $key => $setting) { $smsSetting = $this->smsSetting->newQuery()->find($setting['id']); if ($smsSetting) { @@ -55,8 +52,7 @@ public function updateSmsSettings($smsSettings) return $this->smsSetting->newQuery()->get(); } - public function getSmsSettings() - { + public function getSmsSettings() { return $this->smsSetting->newQuery()->get(); } } diff --git a/src/backend/packages/inensus/spark-meter/src/Services/SmSmsVariableDefaultValueService.php b/src/backend/packages/inensus/spark-meter/src/Services/SmSmsVariableDefaultValueService.php index 581f77729..dab2b8afd 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/SmSmsVariableDefaultValueService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/SmSmsVariableDefaultValueService.php @@ -4,22 +4,18 @@ use Inensus\SparkMeter\Models\SmSmsVariableDefaultValue; -class SmSmsVariableDefaultValueService -{ +class SmSmsVariableDefaultValueService { private $smsVariableDefaultValue; - public function __construct(SmSmsVariableDefaultValue $smsVariableDefaultValue) - { + public function __construct(SmSmsVariableDefaultValue $smsVariableDefaultValue) { $this->smsVariableDefaultValue = $smsVariableDefaultValue; } - public function getSmsVariableDefaultValues() - { + public function getSmsVariableDefaultValues() { return $this->smsVariableDefaultValue->newQuery()->get(); } - public function createSmsVariableDefaultValues() - { + public function createSmsVariableDefaultValues() { $smsVariableDefaultValues = [ [ 'variable' => 'name', @@ -43,7 +39,8 @@ public function createSmsVariableDefaultValues() ], ]; collect($smsVariableDefaultValues)->each(function ($variable) { - $this->smsVariableDefaultValue->newQuery()->firstOrCreate(['variable' => $variable['variable']], + $this->smsVariableDefaultValue->newQuery()->firstOrCreate( + ['variable' => $variable['variable']], $variable ); }); diff --git a/src/backend/packages/inensus/spark-meter/src/Services/SmSyncActionService.php b/src/backend/packages/inensus/spark-meter/src/Services/SmSyncActionService.php index f2de4658a..f3dbc24b6 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/SmSyncActionService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/SmSyncActionService.php @@ -6,32 +6,26 @@ use Carbon\CarbonInterval; use Inensus\SparkMeter\Models\SmSyncAction; -class SmSyncActionService -{ +class SmSyncActionService { private $syncAction; - public function __construct(SmSyncAction $syncAction) - { + public function __construct(SmSyncAction $syncAction) { $this->syncAction = $syncAction; } - public function createSyncAction($syncAction) - { + public function createSyncAction($syncAction) { return $this->syncAction->newQuery()->create($syncAction); } - public function getSyncActionBySynSettingId($settingId) - { + public function getSyncActionBySynSettingId($settingId) { return $this->syncAction->newQuery()->where('sync_setting_id', $settingId)->first(); } - public function getActionsNeedsToSync() - { + public function getActionsNeedsToSync() { return $this->syncAction->newQuery()->where('next_sync', '<=', Carbon::now())->orderBy('next_sync')->get(); } - public function updateSyncAction($syncAction, $syncSetting, $syncResult) - { + public function updateSyncAction($syncAction, $syncSetting, $syncResult) { if (!$syncResult) { return $syncAction->update([ 'attempts' => $syncAction->attempts + 1, diff --git a/src/backend/packages/inensus/spark-meter/src/Services/SmSyncSettingService.php b/src/backend/packages/inensus/spark-meter/src/Services/SmSyncSettingService.php index 8858a20ab..9a4bcaaa5 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/SmSyncSettingService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/SmSyncSettingService.php @@ -8,21 +8,20 @@ use Inensus\SparkMeter\Models\SmSetting; use Inensus\SparkMeter\Models\SmSyncSetting; -class SmSyncSettingService -{ +class SmSyncSettingService { private $syncSetting; + private $setting; + private $syncActionService; - public function __construct(SmSyncSetting $syncSetting, SmSetting $setting, SmSyncActionService $syncActionService) - { + public function __construct(SmSyncSetting $syncSetting, SmSetting $setting, SmSyncActionService $syncActionService) { $this->syncSetting = $syncSetting; $this->setting = $setting; $this->syncActionService = $syncActionService; } - public function createDefaultSettings() - { + public function createDefaultSettings() { $dayInterval = CarbonInterval::make('1day'); $fiveMinInterval = CarbonInterval::make('5minute'); @@ -136,8 +135,7 @@ public function createDefaultSettings() } } - public function updateSyncSettings($syncSettings) - { + public function updateSyncSettings($syncSettings) { foreach ($syncSettings as $setting) { $syncSetting = $this->syncSetting->newQuery()->find($setting['id']); $intervalStr = $setting['sync_in_value_num'].$setting['sync_in_value_str']; @@ -162,13 +160,11 @@ public function updateSyncSettings($syncSettings) return $this->syncSetting->newQuery()->get(); } - public function getSyncSettings() - { + public function getSyncSettings() { return $this->syncSetting->newQuery()->get(); } - public function getSyncSettingsByActionName($actionName) - { + public function getSyncSettingsByActionName($actionName) { try { return $this->syncSetting->newQuery()->where('action_name', $actionName)->firstOrFail(); } catch (ModelNotFoundException $exception) { diff --git a/src/backend/packages/inensus/spark-meter/src/Services/TariffService.php b/src/backend/packages/inensus/spark-meter/src/Services/TariffService.php index 19c98b9f2..3eccae474 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/TariffService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/TariffService.php @@ -14,18 +14,27 @@ use Inensus\SparkMeter\Models\SmTariff; use Inensus\SparkMeter\Models\SyncStatus; -class TariffService implements ISynchronizeService -{ +class TariffService implements ISynchronizeService { private $sparkMeterApiRequests; + private $rootUrl = '/tariffs'; + private $smTableEncryption; + private $smMeterModel; + private $smSite; + private $smTariff; + private $meterTariff; + private $timeOfUsage; + private $accessRate; + private $smSyncSettingService; + private $smSyncActionService; public function __construct( @@ -52,8 +61,7 @@ public function __construct( $this->smSyncActionService = $smSyncActionService; } - public function createSmTariff($tariff, $siteId) - { + public function createSmTariff($tariff, $siteId) { $touEnabled = count($tariff->tou) > 0; $maxValue = $this->smMeterModel->newQuery()->max('continuous_limit'); $tous = []; @@ -88,7 +96,7 @@ public function createSmTariff($tariff, $siteId) if (!$tariffExists) { $modelTouString = ''; foreach ($tariff->tou as $key => $value) { - $modelTouString .= $value->start.$value->end.doubleval($value->value); + $modelTouString .= $value->start.$value->end.floatval($value->value); $tous[$key] = [ 'start' => $value->start, 'end' => $value->end, @@ -127,20 +135,17 @@ public function createSmTariff($tariff, $siteId) } } - public function getSmTariffs($request) - { + public function getSmTariffs($request) { $perPage = $request->input('per_page') ?? 15; return $this->smTariff->newQuery()->with(['mpmTariff', 'site.mpmMiniGrid'])->paginate($perPage); } - public function getSmTariffsCount() - { + public function getSmTariffsCount() { return count($this->smTariff->newQuery()->get()); } - public function createRelatedTariff($tariff) - { + public function createRelatedTariff($tariff) { $meterTariff = $this->meterTariff->newQuery()->create([ 'name' => $tariff['name'], 'price' => $tariff['flat_price'] * 100, @@ -152,7 +157,7 @@ public function createRelatedTariff($tariff) 'tariff_id' => $meterTariff->id, 'start' => $tou['start'], 'end' => $tou['end'], - 'value' => doubleval($tou['value']), + 'value' => floatval($tou['value']), ]); } if ($tariff['plan_enabled'] && $tariff['plan_fixed_fee'] > 0) { @@ -162,13 +167,12 @@ public function createRelatedTariff($tariff) return $meterTariff; } - public function updateRelatedTariff($model, $tariff) - { + public function updateRelatedTariff($model, $tariff) { if (count($model['tous']) === count($tariff->tou)) { foreach ($model['tous'] as $key => $tou) { $tariff->tou[$key]->start = $tou['start']; $tariff->tou[$key]->end = $tou['end']; - $tariff->tou[$key]->value = doubleval($tou['value']); + $tariff->tou[$key]->value = floatval($tou['value']); $tariff->tou[$key]->update(); } } else { @@ -180,7 +184,7 @@ public function updateRelatedTariff($model, $tariff) 'tariff_id' => $tariff->id, 'start' => $tou['start'], 'end' => $tou['end'], - 'value' => doubleval($tou['value']), + 'value' => floatval($tou['value']), ]); } } @@ -206,8 +210,7 @@ public function updateRelatedTariff($model, $tariff) } } - private function setAccessRate($model, $tariffId, $planEnabled) - { + private function setAccessRate($model, $tariffId, $planEnabled) { $accessRate = $this->accessRate->newQuery()->where('tariff_id', $tariffId)->first(); $duration = array_key_exists('plan_duration', $model) ? $model['plan_duration'] : '1m'; if ($accessRate) { @@ -231,8 +234,7 @@ private function setAccessRate($model, $tariffId, $planEnabled) } } - public function getSparkTariffInfo($tariffId) - { + public function getSparkTariffInfo($tariffId) { try { $smTariff = $this->smTariff->newQuery()->with(['mpmTariff.accessRate', 'site'])->where( 'tariff_id', @@ -247,8 +249,7 @@ public function getSparkTariffInfo($tariffId) } } - public function updateSparkTariffInfo($tariffData) - { + public function updateSparkTariffInfo($tariffData) { try { $tariffId = $tariffData['id']; $smTariff = $this->smTariff->newQuery()->where('tariff_id', $tariffId)->first(); @@ -282,8 +283,7 @@ public function updateSparkTariffInfo($tariffData) } } - public function singleSync($smTariff) - { + public function singleSync($smTariff) { $tariff = $this->getSparkTariffInfo($smTariff->tariff_id); $modelHash = $this->modelHasher($tariff, null); @@ -315,8 +315,7 @@ public function singleSync($smTariff) return $relatedTariff; } - public function sync() - { + public function sync() { $synSetting = $this->smSyncSettingService->getSyncSettingsByActionName('Tariffs'); $syncAction = $this->smSyncActionService->getSyncActionBySynSettingId($synSetting->id); try { @@ -387,8 +386,7 @@ public function sync() } } - public function syncCheck($returnData = false) - { + public function syncCheck($returnData = false) { $returnArray = ['available_site_count' => 0]; $sites = $this->smSite->newQuery()->where('is_authenticated', 1)->where('is_online', 1)->get(); @@ -448,11 +446,10 @@ public function syncCheck($returnData = false) return $returnArray; } - public function modelHasher($model, ...$params): string - { + public function modelHasher($model, ...$params): string { $modelTouString = ''; foreach ($model['tous'] as $item) { - $modelTouString .= $item['start'].$item['end'].doubleval($item['value']); + $modelTouString .= $item['start'].$item['end'].floatval($item['value']); } return $this->smTableEncryption->makeHash([ @@ -462,8 +459,7 @@ public function modelHasher($model, ...$params): string ]); } - public function syncCheckBySite($siteId) - { + public function syncCheckBySite($siteId) { try { $tariffs = $this->sparkMeterApiRequests->get($this->rootUrl, $siteId); } catch (SparkAPIResponseException $e) { diff --git a/src/backend/packages/inensus/spark-meter/src/Services/TransactionService.php b/src/backend/packages/inensus/spark-meter/src/Services/TransactionService.php index 835d6c211..5b5b61a90 100644 --- a/src/backend/packages/inensus/spark-meter/src/Services/TransactionService.php +++ b/src/backend/packages/inensus/spark-meter/src/Services/TransactionService.php @@ -19,24 +19,39 @@ use Inensus\SparkMeter\Models\SmTariff; use Inensus\SparkMeter\Models\SmTransaction; -class TransactionService -{ +class TransactionService { private $sparkMeterApiRequests; + private $sparkOrganization; + private $sparkCredentialService; + private $sparkSiteService; + private $sparkCustomerService; + private $sparkMeterModelService; + private $sparkTariffService; + private $sparkTransaction; + private $sparkTariff; + private $thirdPartyTransaction; + private $transaction; + private $meterToken; + private $sparkSite; + private $smCustomer; + private $rootUrl = '/transaction/'; + private $smSyncSettingService; + private $smSyncActionService; public function __construct( @@ -75,8 +90,7 @@ public function __construct( $this->smSyncActionService = $smSyncActionService; } - public function updateTransactionStatus($smTransaction) - { + public function updateTransactionStatus($smTransaction) { try { $smTransactionResult = $this->sparkMeterApiRequests->getInfo( $this->rootUrl, @@ -136,8 +150,7 @@ public function updateTransactionStatus($smTransaction) ]); } - public function sync() - { + public function sync() { $synSetting = $this->smSyncSettingService->getSyncSettingsByActionName('Transactions'); $syncAction = $this->smSyncActionService->getSyncActionBySynSettingId($synSetting->id); $syncCheck = []; @@ -295,8 +308,7 @@ public function sync() $this->smSyncActionService->updateSyncAction($syncAction, $synSetting, true); } - public function syncCheck() - { + public function syncCheck() { $credentials = $this->sparkCredentialService->getCredentials(); $sparkSites = $this->sparkSite->newQuery()->where('is_authenticated', 1)->where('is_online', 1)->get(); @@ -331,8 +343,7 @@ public function syncCheck() }); } - private function createSparkTransaction($transaction) - { + private function createSparkTransaction($transaction) { return $this->sparkTransaction->newQuery()->create([ 'site_id' => $transaction['site'], 'customer_id' => $transaction['to']['customer']['id'], @@ -343,8 +354,7 @@ private function createSparkTransaction($transaction) ]); } - public function getSparkTransactions($transactionMin) - { + public function getSparkTransactions($transactionMin) { $transactions = $this->sparkTransaction->newQuery()->with(['thirdPartyTransaction.transaction'])->where( 'status', 'processed' @@ -355,8 +365,7 @@ public function getSparkTransactions($transactionMin) }); } - private function createThirdPartyTransaction($transaction, $sparkTransaction, $status) - { + private function createThirdPartyTransaction($transaction, $sparkTransaction, $status) { $thirdPartyTransaction = $this->thirdPartyTransaction->newQuery()->make([ 'transaction_id' => $transaction['transaction_id'], 'status' => $status, @@ -367,8 +376,7 @@ private function createThirdPartyTransaction($transaction, $sparkTransaction, $s return $thirdPartyTransaction; } - private function createTransaction($transaction, $thirdPartyTransaction, $meterParameter) - { + private function createTransaction($transaction, $thirdPartyTransaction, $meterParameter) { $transaction = $this->transaction->newQuery()->make([ 'amount' => (int) $transaction['amount'], 'sender' => $sparkCustomer->mpmPerson->addresses[0]->phone ?? '-', @@ -384,8 +392,7 @@ private function createTransaction($transaction, $thirdPartyTransaction, $meterP return $transaction; } - private function createToken($sparkTariff, $mainTransaction, $transaction, $sparkTransaction, $meterParameter) - { + private function createToken($sparkTariff, $mainTransaction, $transaction, $sparkTransaction, $meterParameter) { try { $tariff = $this->sparkTariffService->singleSync($sparkTariff); } catch (SparkAPIResponseException $exception) { @@ -407,8 +414,7 @@ private function createToken($sparkTariff, $mainTransaction, $transaction, $spar return $token; } - private function createPayment($meterParameter, $mainTransaction, $token) - { + private function createPayment($meterParameter, $mainTransaction, $token) { $owner = $meterParameter->owner; event('payment.successful', [ 'amount' => $mainTransaction->amount, diff --git a/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsBalanceFeedbackBody.php b/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsBalanceFeedbackBody.php index d13e3821f..af6a17a65 100644 --- a/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsBalanceFeedbackBody.php +++ b/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsBalanceFeedbackBody.php @@ -5,18 +5,16 @@ use App\Sms\BodyParsers\SmsBodyParser; use Inensus\SparkMeter\Models\SmCustomer; -class SparkSmsBalanceFeedbackBody extends SmsBodyParser -{ +class SparkSmsBalanceFeedbackBody extends SmsBodyParser { protected $variables = ['credit_balance']; + protected $sparkCustomer; - public function __construct(SmCustomer $sparkCustomer) - { + public function __construct(SmCustomer $sparkCustomer) { $this->sparkCustomer = $sparkCustomer; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'credit_balance': $variable = $this->sparkCustomer->credit_balance; diff --git a/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsBalanceFeedbackHeader.php b/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsBalanceFeedbackHeader.php index d6d651e1c..0d428afaa 100644 --- a/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsBalanceFeedbackHeader.php +++ b/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsBalanceFeedbackHeader.php @@ -5,18 +5,16 @@ use App\Sms\BodyParsers\SmsBodyParser; use Inensus\SparkMeter\Models\SmCustomer; -class SparkSmsBalanceFeedbackHeader extends SmsBodyParser -{ +class SparkSmsBalanceFeedbackHeader extends SmsBodyParser { protected $variables = ['name', 'surname']; + protected $sparkCustomer; - public function __construct(SmCustomer $sparkCustomer) - { + public function __construct(SmCustomer $sparkCustomer) { $this->sparkCustomer = $sparkCustomer; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'name': $variable = $this->sparkCustomer->mpmPerson->name; diff --git a/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsLowBalanceBody.php b/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsLowBalanceBody.php index ee283e93d..9d00e1f79 100644 --- a/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsLowBalanceBody.php +++ b/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsLowBalanceBody.php @@ -5,18 +5,16 @@ use App\Sms\BodyParsers\SmsBodyParser; use Inensus\SparkMeter\Models\SmCustomer; -class SparkSmsLowBalanceBody extends SmsBodyParser -{ +class SparkSmsLowBalanceBody extends SmsBodyParser { protected $variables = ['low_balance_limit', 'credit_balance']; + protected $sparkCustomer; - public function __construct(SmCustomer $sparkCustomer) - { + public function __construct(SmCustomer $sparkCustomer) { $this->sparkCustomer = $sparkCustomer; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'low_balance_limit': $variable = $this->sparkCustomer->low_balance_limit; diff --git a/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsLowBalanceHeader.php b/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsLowBalanceHeader.php index a22b495c0..742061be0 100644 --- a/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsLowBalanceHeader.php +++ b/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsLowBalanceHeader.php @@ -5,18 +5,16 @@ use App\Sms\BodyParsers\SmsBodyParser; use Inensus\SparkMeter\Models\SmCustomer; -class SparkSmsLowBalanceHeader extends SmsBodyParser -{ +class SparkSmsLowBalanceHeader extends SmsBodyParser { protected $variables = ['name', 'surname']; + protected $sparkCustomer; - public function __construct(SmCustomer $sparkCustomer) - { + public function __construct(SmCustomer $sparkCustomer) { $this->sparkCustomer = $sparkCustomer; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'name': $variable = $this->sparkCustomer->mpmPerson->name; diff --git a/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsMeterResetFailedFeedbackBody.php b/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsMeterResetFailedFeedbackBody.php index fad4ff32a..27544a302 100644 --- a/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsMeterResetFailedFeedbackBody.php +++ b/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsMeterResetFailedFeedbackBody.php @@ -4,18 +4,16 @@ use App\Sms\BodyParsers\SmsBodyParser; -class SparkSmsMeterResetFailedFeedbackBody extends SmsBodyParser -{ +class SparkSmsMeterResetFailedFeedbackBody extends SmsBodyParser { protected $variables = ['meter_serial']; + protected $data; - public function __construct($data) - { + public function __construct($data) { $this->data = $data; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'meter_serial': $variable = $this->data['meter']; diff --git a/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsMeterResetFeedbackBody.php b/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsMeterResetFeedbackBody.php index 26bb60b8a..57990d9df 100644 --- a/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsMeterResetFeedbackBody.php +++ b/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsMeterResetFeedbackBody.php @@ -4,18 +4,16 @@ use App\Sms\BodyParsers\SmsBodyParser; -class SparkSmsMeterResetFeedbackBody extends SmsBodyParser -{ +class SparkSmsMeterResetFeedbackBody extends SmsBodyParser { protected $variables = ['meter_serial']; + protected $meter; - public function __construct($meter) - { + public function __construct($meter) { $this->meter = $meter; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'meter_serial': $variable = $this->meter->serial_number; diff --git a/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsMeterResetFeedbackHeader.php b/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsMeterResetFeedbackHeader.php index 0b086cdd5..1bcba6201 100644 --- a/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsMeterResetFeedbackHeader.php +++ b/src/backend/packages/inensus/spark-meter/src/Sms/BodyParsers/SparkSmsMeterResetFeedbackHeader.php @@ -5,18 +5,16 @@ use App\Models\Person\Person; use App\Sms\BodyParsers\SmsBodyParser; -class SparkSmsMeterResetFeedbackHeader extends SmsBodyParser -{ +class SparkSmsMeterResetFeedbackHeader extends SmsBodyParser { protected $variables = ['name', 'surname']; + protected $data; - public function __construct($data) - { + public function __construct($data) { $this->data = $data; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { if (!is_array($this->data)) { $person = $this->data->meterParameter->whereHasMorph('owner', [Person::class])->first()->owner()->first(); } else { diff --git a/src/backend/packages/inensus/spark-meter/src/Sms/Senders/BalanceFeedback.php b/src/backend/packages/inensus/spark-meter/src/Sms/Senders/BalanceFeedback.php index 339b44955..15e1d0ebe 100644 --- a/src/backend/packages/inensus/spark-meter/src/Sms/Senders/BalanceFeedback.php +++ b/src/backend/packages/inensus/spark-meter/src/Sms/Senders/BalanceFeedback.php @@ -4,8 +4,7 @@ use App\Sms\Senders\SmsSender; -class BalanceFeedback extends SmsSender -{ +class BalanceFeedback extends SmsSender { protected $references = [ 'header' => 'SparkSmsBalanceFeedbackHeader', 'body' => 'SparkSmsBalanceFeedbackBody', diff --git a/src/backend/packages/inensus/spark-meter/src/Sms/Senders/LowBalanceLimitNotifier.php b/src/backend/packages/inensus/spark-meter/src/Sms/Senders/LowBalanceLimitNotifier.php index d1b3b44af..4b3f1a42f 100644 --- a/src/backend/packages/inensus/spark-meter/src/Sms/Senders/LowBalanceLimitNotifier.php +++ b/src/backend/packages/inensus/spark-meter/src/Sms/Senders/LowBalanceLimitNotifier.php @@ -4,8 +4,7 @@ use App\Sms\Senders\SmsSender; -class LowBalanceLimitNotifier extends SmsSender -{ +class LowBalanceLimitNotifier extends SmsSender { protected $references = [ 'header' => 'SparkSmsLowBalanceHeader', 'body' => 'SparkSmsLowBalanceBody', diff --git a/src/backend/packages/inensus/spark-meter/src/Sms/Senders/MeterResetFeedback.php b/src/backend/packages/inensus/spark-meter/src/Sms/Senders/MeterResetFeedback.php index 8d94e29f6..f0932375c 100644 --- a/src/backend/packages/inensus/spark-meter/src/Sms/Senders/MeterResetFeedback.php +++ b/src/backend/packages/inensus/spark-meter/src/Sms/Senders/MeterResetFeedback.php @@ -9,18 +9,18 @@ use Inensus\SparkMeter\Sms\BodyParsers\SparkSmsMeterResetFailedFeedbackBody; use Inensus\SparkMeter\Sms\BodyParsers\SparkSmsMeterResetFeedbackBody; -class MeterResetFeedback extends SmsSender -{ +class MeterResetFeedback extends SmsSender { protected $data; + public $body = ''; + protected $references = [ 'header' => 'SparkSmsMeterResetFeedbackHeader', 'body' => 'SparkSmsMeterResetFeedbackBody', 'footer' => 'SparkSmsMeterResetFeedbackFooter', ]; - public function prepareBody() - { + public function prepareBody() { if (!is_array($this->data)) { try { $smsBody = $this->smsBodyService->getSmsBodyByReference('SparkSmsMeterResetFeedbackBody'); diff --git a/src/backend/packages/inensus/spark-meter/src/Sms/Senders/SparkSmsConfig.php b/src/backend/packages/inensus/spark-meter/src/Sms/Senders/SparkSmsConfig.php index e7ee3cad9..d4b8970f3 100644 --- a/src/backend/packages/inensus/spark-meter/src/Sms/Senders/SparkSmsConfig.php +++ b/src/backend/packages/inensus/spark-meter/src/Sms/Senders/SparkSmsConfig.php @@ -5,13 +5,14 @@ use App\Sms\Senders\SmsConfigsCore; use Inensus\SparkMeter\Sms\SparkSmsTypes; -class SparkSmsConfig extends SmsConfigsCore -{ +class SparkSmsConfig extends SmsConfigsCore { public $smsTypes = [ SparkSmsTypes::LOW_BALANCE_LIMIT_NOTIFIER => 'Inensus\SparkMeter\Sms\Senders\LowBalanceLimitNotifier', SparkSmsTypes::BALANCE_FEEDBACK => 'Inensus\SparkMeter\Sms\Senders\BalanceFeedback', SparkSmsTypes::METER_RESET_FEEDBACK => 'Inensus\SparkMeter\Sms\Senders\MeterResetFeedback', ]; + public $bodyParsersPath = 'Inensus\\SparkMeter\\Sms\\BodyParsers\\'; + public $servicePath = 'Inensus\SparkMeter\Services\SmSmsBodyService'; } diff --git a/src/backend/packages/inensus/spark-meter/src/Sms/SparkSmsTypes.php b/src/backend/packages/inensus/spark-meter/src/Sms/SparkSmsTypes.php index c7b1a1fd1..3fc5d3d8c 100644 --- a/src/backend/packages/inensus/spark-meter/src/Sms/SparkSmsTypes.php +++ b/src/backend/packages/inensus/spark-meter/src/Sms/SparkSmsTypes.php @@ -2,9 +2,10 @@ namespace Inensus\SparkMeter\Sms; -class SparkSmsTypes -{ +class SparkSmsTypes { public const LOW_BALANCE_LIMIT_NOTIFIER = 1; + public const BALANCE_FEEDBACK = 2; + public const METER_RESET_FEEDBACK = 3; } diff --git a/src/backend/packages/inensus/spark-meter/src/SparkMeterApi.php b/src/backend/packages/inensus/spark-meter/src/SparkMeterApi.php index 24fa81a6a..b825faa73 100644 --- a/src/backend/packages/inensus/spark-meter/src/SparkMeterApi.php +++ b/src/backend/packages/inensus/spark-meter/src/SparkMeterApi.php @@ -14,9 +14,9 @@ use Inensus\SparkMeter\Models\SmTransaction; use Inensus\SparkMeter\Services\TariffService; -class SparkMeterApi implements IManufacturerAPI -{ +class SparkMeterApi implements IManufacturerAPI { protected $api; + private $rootUrl = '/transaction/'; public function __construct( @@ -30,8 +30,7 @@ public function __construct( $this->api = $httpClient; } - public function chargeDevice($transactionContainer): array - { + public function chargeDevice($transactionContainer): array { $meter = $transactionContainer->device->device; $tariff = $transactionContainer->tariff; $owner = $transactionContainer->device->person; @@ -131,8 +130,7 @@ public function chargeDevice($transactionContainer): array } } - public function clearDevice(Device $device) - { + public function clearDevice(Device $device) { // TODO: Implement clearDevice() method. } } diff --git a/src/backend/packages/inensus/spark-meter/src/Tests/Feature/SendSms.php b/src/backend/packages/inensus/spark-meter/src/Tests/Feature/SendSms.php index 3ec916662..21735a317 100644 --- a/src/backend/packages/inensus/spark-meter/src/Tests/Feature/SendSms.php +++ b/src/backend/packages/inensus/spark-meter/src/Tests/Feature/SendSms.php @@ -21,13 +21,11 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class SendSms extends TestCase -{ +class SendSms extends TestCase { use RefreshDatabase; /** @test */ - public function isMeterResetFeedbackSend() - { + public function isMeterResetFeedbackSend() { Queue::fake(); $this->withoutExceptionHandling(); $person = $this->initializeData()['customer']; @@ -44,8 +42,7 @@ public function isMeterResetFeedbackSend() } /** @test */ - public function isMeterBalanceFeedbackSend() - { + public function isMeterBalanceFeedbackSend() { Queue::fake(); $this->withoutExceptionHandling(); $person = $this->initializeData()['customer']; @@ -60,8 +57,7 @@ public function isMeterBalanceFeedbackSend() $this->assertEquals(2, $smsCount); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); @@ -69,8 +65,7 @@ public function actingAs($user, $driver = null) return $this; } - private function initializeData() - { + private function initializeData() { $this->addSmsBodies(); $this->addFeedBackKeys(); factory(MainSettings::class)->create(); @@ -141,8 +136,7 @@ private function initializeData() return ['customer' => $p]; } - private function addSmsBodies() - { + private function addSmsBodies() { $bodies = [ [ 'reference' => 'SmsTransactionHeader', @@ -316,8 +310,7 @@ private function addSmsBodies() return SmsBody::query()->get(); } - private function addFeedBackKeys() - { + private function addFeedBackKeys() { SmSmsFeedbackWord::query()->create([ 'meter_reset' => 'Reset', 'meter_balance' => 'Balance', diff --git a/src/backend/packages/inensus/spark-meter/src/Tests/Unit/SmsNotifyTest.php b/src/backend/packages/inensus/spark-meter/src/Tests/Unit/SmsNotifyTest.php index 81eb04602..50c22b1a8 100644 --- a/src/backend/packages/inensus/spark-meter/src/Tests/Unit/SmsNotifyTest.php +++ b/src/backend/packages/inensus/spark-meter/src/Tests/Unit/SmsNotifyTest.php @@ -32,13 +32,11 @@ use Inensus\SparkMeter\Sms\SparkSmsTypes; use Tests\TestCase; -class SmsNotifyTest extends TestCase -{ +class SmsNotifyTest extends TestCase { use RefreshDatabase; /** @test */ - public function isLowBalanceNotifySend() - { + public function isLowBalanceNotifySend() { Queue::fake(); $this->initializeData(); $lowBalanceMin = SmSmsSetting::query()->where( @@ -91,8 +89,7 @@ public function isLowBalanceNotifySend() } /** @test */ - public function isTransactionNotifySend() - { + public function isTransactionNotifySend() { Queue::fake(); $data = $this->initializeData(); $this->initializeSparkTransaction($data['customer']); @@ -148,8 +145,7 @@ public function isTransactionNotifySend() } /** @test */ - public function isMaxAttemptNotifySend() - { + public function isMaxAttemptNotifySend() { Queue::fake(); $this->addSyncSettings(); $this->initializeAdminData(); @@ -188,8 +184,7 @@ public function isMaxAttemptNotifySend() $this->assertLessThan($oldNextSync, $newNextSync); } - private function initializeData() - { + private function initializeData() { $this->addSmsSettings(); $this->addSmsBodies(); // create person @@ -251,8 +246,7 @@ private function initializeData() return ['customer' => $p]; } - private function initializeSparkTransaction($customer) - { + private function initializeSparkTransaction($customer) { $sparkTransaction = SmTransaction::query()->create([ 'site_id' => 1, 'customer_id' => $customer->id, @@ -282,8 +276,7 @@ private function initializeSparkTransaction($customer) $transaction->save(); } - private function initializeAdminData() - { + private function initializeAdminData() { $user = factory(User::class)->create(); $address = Address::query()->make([ 'phone' => '+905494322161', @@ -294,8 +287,7 @@ private function initializeAdminData() $address->save(); } - private function addSmsSettings() - { + private function addSmsSettings() { $smsSetting = SmSetting::query()->make(); $smsTransaction = SmSmsSetting::query()->create([ @@ -319,8 +311,7 @@ private function addSmsSettings() $balanceSetting->save(); } - private function addSyncSettings() - { + private function addSyncSettings() { $minInterval = CarbonInterval::make('1minute'); $now = Carbon::now(); $siteSetting = SmSetting::query()->make(); @@ -340,8 +331,7 @@ private function addSyncSettings() SmSyncAction::query()->create($syncAction); } - private function addSmsBodies() - { + private function addSmsBodies() { $bodies = [ [ 'reference' => 'SmsTransactionHeader', diff --git a/src/backend/packages/inensus/steama-meter/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/steama-meter/src/Console/Commands/InstallPackage.php index eaab478b6..260f956f4 100644 --- a/src/backend/packages/inensus/steama-meter/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/steama-meter/src/Console/Commands/InstallPackage.php @@ -17,9 +17,9 @@ use Inensus\SteamaMeter\Services\SteamaTariffService; use Inensus\SteamaMeter\Services\SteamaUserTypeService; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'steama-meter:install'; + protected $description = 'Install Steamaco Meter Package'; public function __construct( @@ -40,8 +40,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing Steamaco Meter Integration Package\n'); // $this->publishMigrations(); @@ -65,8 +64,7 @@ public function handle(): void } } - private function publishMigrations() - { + private function publishMigrations() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\SteamaMeter\Providers\SteamaMeterServiceProvider", @@ -74,14 +72,12 @@ private function publishMigrations() ]); } - private function createDatabaseTables() - { + private function createDatabaseTables() { $this->info('Creating database tables\n'); $this->call('migrate'); } - private function publishVueFiles() - { + private function publishVueFiles() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\SteamaMeter\Providers\SteamaMeterServiceProvider", @@ -90,8 +86,7 @@ private function publishVueFiles() ]); } - private function createPluginRecord() - { + private function createPluginRecord() { $this->call('plugin:add', [ 'name' => 'SteamaMeter', 'composer_name' => 'inensus/steama-meter', diff --git a/src/backend/packages/inensus/steama-meter/src/Console/Commands/ReadHourlyMeterReadings.php b/src/backend/packages/inensus/steama-meter/src/Console/Commands/ReadHourlyMeterReadings.php index 84eb8a00a..1e2f1f466 100644 --- a/src/backend/packages/inensus/steama-meter/src/Console/Commands/ReadHourlyMeterReadings.php +++ b/src/backend/packages/inensus/steama-meter/src/Console/Commands/ReadHourlyMeterReadings.php @@ -7,21 +7,20 @@ use Carbon\Carbon; use Inensus\SteamaMeter\Services\SteamaMeterReadingService; -class ReadHourlyMeterReadings extends AbstractSharedCommand -{ +class ReadHourlyMeterReadings extends AbstractSharedCommand { use ScheduledPluginCommand; + public const MPM_PLUGIN_ID = 2; protected $signature = 'steama-meter:hourlyReadings'; + protected $description = 'Reads hourly meter readings.'; - public function __construct(private SteamaMeterReadingService $steamaMeterReadingService) - { + public function __construct(private SteamaMeterReadingService $steamaMeterReadingService) { parent::__construct(); } - public function handle(): void - { + public function handle(): void { if (!$this->checkForPluginStatusIsActive(self::MPM_PLUGIN_ID)) { return; } diff --git a/src/backend/packages/inensus/steama-meter/src/Console/Commands/SteamaMeterDataSynchronizer.php b/src/backend/packages/inensus/steama-meter/src/Console/Commands/SteamaMeterDataSynchronizer.php index b4f0a0721..73b143b6f 100644 --- a/src/backend/packages/inensus/steama-meter/src/Console/Commands/SteamaMeterDataSynchronizer.php +++ b/src/backend/packages/inensus/steama-meter/src/Console/Commands/SteamaMeterDataSynchronizer.php @@ -20,22 +20,31 @@ use Inensus\SteamaMeter\Services\SteamaTransactionsService; use Inensus\SteamaMeter\Services\StemaSyncActionService; -class SteamaMeterDataSynchronizer extends AbstractSharedCommand -{ +class SteamaMeterDataSynchronizer extends AbstractSharedCommand { use ScheduledPluginCommand; + public const MPM_PLUGIN_ID = 2; protected $signature = 'steama-meter:dataSync'; + protected $description = 'Synchronize data that needs to be updated from Steamaco Meter.'; private $steamaTransactionsService; + private $steamaSyncSettingservice; + private $stemaMeterService; + private $steamaCustomerService; + private $steamaSiteService; + private $steamaAgentService; + private $steamaSyncActionService; + private $address; + private $cluster; public function __construct( @@ -61,8 +70,7 @@ public function __construct( $this->cluster = $cluster; } - public function handle(): void - { + public function handle(): void { if (!$this->checkForPluginStatusIsActive(self::MPM_PLUGIN_ID)) { return; } @@ -89,10 +97,13 @@ public function handle(): void return true; } $adminId = $cluster->manager->id; - $adminAddress = $this->address->whereHasMorph('owner', [Person::class], + $adminAddress = $this->address->whereHasMorph( + 'owner', + [Person::class], function ($q) use ($adminId) { $q->where('id', $adminId); - })->first(); + } + )->first(); if (!$adminAddress) { return true; } diff --git a/src/backend/packages/inensus/steama-meter/src/Console/Commands/SteamaSmsNotifier.php b/src/backend/packages/inensus/steama-meter/src/Console/Commands/SteamaSmsNotifier.php index 90427bfc2..d378d6c5d 100644 --- a/src/backend/packages/inensus/steama-meter/src/Console/Commands/SteamaSmsNotifier.php +++ b/src/backend/packages/inensus/steama-meter/src/Console/Commands/SteamaSmsNotifier.php @@ -17,19 +17,25 @@ use Inensus\SteamaMeter\Sms\Senders\SteamaSmsConfig; use Inensus\SteamaMeter\Sms\SteamaSmsTypes; -class SteamaSmsNotifier extends AbstractSharedCommand -{ +class SteamaSmsNotifier extends AbstractSharedCommand { use ScheduledPluginCommand; + public const MPM_PLUGIN_ID = 2; protected $signature = 'steama-meter:smsNotifier'; + protected $description = ''; private $smsSettingsService; + private $sms; + private $steamaTransactionService; + private $steamaSmsNotifiedCustomerService; + private $steamaCustomerService; + private $smsService; public function __construct( @@ -49,8 +55,7 @@ public function __construct( $this->smsService = $smsService; } - private function sendTransactionNotifySms($transactionMin, $smsNotifiedCustomers, $customers) - { + private function sendTransactionNotifySms($transactionMin, $smsNotifiedCustomers, $customers) { $this->steamaTransactionService->getSteamaTransactions($transactionMin) ->each(function ($steamaTransaction) use ($smsNotifiedCustomers, $customers) { $smsNotifiedCustomers = $smsNotifiedCustomers->where( @@ -75,9 +80,11 @@ private function sendTransactionNotifySms($transactionMin, $smsNotifiedCustomers ) { return true; } - $this->smsService->sendSms($steamaTransaction->thirdPartyTransaction->transaction, + $this->smsService->sendSms( + $steamaTransaction->thirdPartyTransaction->transaction, SmsTypes::TRANSACTION_CONFIRMATION, - SmsConfigs::class); + SmsConfigs::class + ); $this->steamaSmsNotifiedCustomerService->createTransactionSmsNotify( $notifyCustomer->customer_id, @@ -88,8 +95,7 @@ private function sendTransactionNotifySms($transactionMin, $smsNotifiedCustomers }); } - private function sendLowBalanceWarningNotifySms($customers, $smsNotifiedCustomers, $lowBalanceMin) - { + private function sendLowBalanceWarningNotifySms($customers, $smsNotifiedCustomers, $lowBalanceMin) { $customers->each(function ($customer) use ( $smsNotifiedCustomers ) { @@ -109,9 +115,11 @@ private function sendLowBalanceWarningNotifySms($customers, $smsNotifiedCustomer ) { return true; } - $this->smsService->sendSms($customer, + $this->smsService->sendSms( + $customer, SteamaSmsTypes::LOW_BALANCE_LIMIT_NOTIFIER, - SteamaSmsConfig::class); + SteamaSmsConfig::class + ); $this->steamaSmsNotifiedCustomerService->createLowBalanceSmsNotify($customer->customer_id); @@ -119,8 +127,7 @@ private function sendLowBalanceWarningNotifySms($customers, $smsNotifiedCustomer }); } - public function handle(): void - { + public function handle(): void { if (!$this->checkForPluginStatusIsActive(self::MPM_PLUGIN_ID)) { return; } diff --git a/src/backend/packages/inensus/steama-meter/src/Console/Commands/UpdatePackage.php b/src/backend/packages/inensus/steama-meter/src/Console/Commands/UpdatePackage.php index e6a2a4f99..e2303c614 100644 --- a/src/backend/packages/inensus/steama-meter/src/Console/Commands/UpdatePackage.php +++ b/src/backend/packages/inensus/steama-meter/src/Console/Commands/UpdatePackage.php @@ -19,9 +19,9 @@ use Inensus\SteamaMeter\Services\SteamaTariffService; use Inensus\SteamaMeter\Services\SteamaUserTypeService; -class UpdatePackage extends Command -{ +class UpdatePackage extends Command { protected $signature = 'steama-meter:update'; + protected $description = 'Install Steamaco Meter Package'; public function __construct( @@ -43,8 +43,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Steamaco Meter Integration Updating Started\n'); $this->removeOldVersionOfPackage(); @@ -58,20 +57,17 @@ public function handle(): void $this->info('Package updated successfully..'); } - private function removeOldVersionOfPackage() - { + private function removeOldVersionOfPackage() { $this->info('Removing former version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar remove inensus/steama-meter'); } - private function installNewVersionOfPackage() - { + private function installNewVersionOfPackage() { $this->info('Installing last version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar require inensus/steama-meter'); } - private function deleteMigration(Filesystem $filesystem) - { + private function deleteMigration(Filesystem $filesystem) { $migrationFile = $filesystem->glob(database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'*_create_steama_tables.php')[0]; $migration = DB::table('migrations') ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->first(); @@ -83,8 +79,7 @@ private function deleteMigration(Filesystem $filesystem) ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->delete(); } - private function publishMigrationsAgain() - { + private function publishMigrationsAgain() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\SteamaMeter\Providers\SteamaMeterServiceProvider", @@ -92,14 +87,12 @@ private function publishMigrationsAgain() ]); } - private function updateDatabase() - { + private function updateDatabase() { $this->info('Updating database tables\n'); $this->call('migrate'); } - private function publishVueFilesAgain() - { + private function publishVueFilesAgain() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\SteamaMeter\Providers\SteamaMeterServiceProvider", diff --git a/src/backend/packages/inensus/steama-meter/src/Exceptions/CronJobException.php b/src/backend/packages/inensus/steama-meter/src/Exceptions/CronJobException.php index 4ef8e9804..b64feba19 100644 --- a/src/backend/packages/inensus/steama-meter/src/Exceptions/CronJobException.php +++ b/src/backend/packages/inensus/steama-meter/src/Exceptions/CronJobException.php @@ -2,6 +2,4 @@ namespace Inensus\SteamaMeter\Exceptions; -class CronJobException extends \Exception -{ -} +class CronJobException extends \Exception {} diff --git a/src/backend/packages/inensus/steama-meter/src/Exceptions/ModelNotFoundException.php b/src/backend/packages/inensus/steama-meter/src/Exceptions/ModelNotFoundException.php index 609220536..2a743e2f9 100644 --- a/src/backend/packages/inensus/steama-meter/src/Exceptions/ModelNotFoundException.php +++ b/src/backend/packages/inensus/steama-meter/src/Exceptions/ModelNotFoundException.php @@ -2,6 +2,4 @@ namespace Inensus\SteamaMeter\Exceptions; -class ModelNotFoundException extends \Exception -{ -} +class ModelNotFoundException extends \Exception {} diff --git a/src/backend/packages/inensus/steama-meter/src/Exceptions/SteamaApiResponseException.php b/src/backend/packages/inensus/steama-meter/src/Exceptions/SteamaApiResponseException.php index 409427086..219f7d6c7 100644 --- a/src/backend/packages/inensus/steama-meter/src/Exceptions/SteamaApiResponseException.php +++ b/src/backend/packages/inensus/steama-meter/src/Exceptions/SteamaApiResponseException.php @@ -2,6 +2,4 @@ namespace Inensus\SteamaMeter\Exceptions; -class SteamaApiResponseException extends \Exception -{ -} +class SteamaApiResponseException extends \Exception {} diff --git a/src/backend/packages/inensus/steama-meter/src/Exceptions/WrongCredentialsException.php b/src/backend/packages/inensus/steama-meter/src/Exceptions/WrongCredentialsException.php index 8d4b366a8..c77d42a6c 100644 --- a/src/backend/packages/inensus/steama-meter/src/Exceptions/WrongCredentialsException.php +++ b/src/backend/packages/inensus/steama-meter/src/Exceptions/WrongCredentialsException.php @@ -2,6 +2,4 @@ namespace Inensus\SteamaMeter\Exceptions; -class WrongCredentialsException extends \Exception -{ -} +class WrongCredentialsException extends \Exception {} diff --git a/src/backend/packages/inensus/steama-meter/src/Helpers/ApiHelpers.php b/src/backend/packages/inensus/steama-meter/src/Helpers/ApiHelpers.php index 82fdd6d3d..aa3cd417c 100644 --- a/src/backend/packages/inensus/steama-meter/src/Helpers/ApiHelpers.php +++ b/src/backend/packages/inensus/steama-meter/src/Helpers/ApiHelpers.php @@ -5,17 +5,14 @@ use App\Models\Manufacturer; use Inensus\SteamaMeter\Exceptions\SteamaApiResponseException; -class ApiHelpers -{ +class ApiHelpers { private $manufacturer; - public function __construct(Manufacturer $manufacturerModel) - { + public function __construct(Manufacturer $manufacturerModel) { $this->manufacturer = $manufacturerModel; } - public function registerSparkMeterManufacturer() - { + public function registerSparkMeterManufacturer() { $api = $this->manufacturer->newQuery()->where('api_name', 'SteamaMeterApi')->first(); if (!$api) { $this->manufacturer->newQuery()->create([ @@ -26,8 +23,7 @@ public function registerSparkMeterManufacturer() } } - public function checkApiResult($result) - { + public function checkApiResult($result) { if (array_key_exists('detail', $result)) { throw new SteamaApiResponseException($result['detail']); } @@ -38,8 +34,7 @@ public function checkApiResult($result) return $result; } - public function makeHash($data) - { + public function makeHash($data) { return md5(implode('', $data)); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Clients/SteamaMeterApiClient.php b/src/backend/packages/inensus/steama-meter/src/Http/Clients/SteamaMeterApiClient.php index a001a688a..075f68353 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Clients/SteamaMeterApiClient.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Clients/SteamaMeterApiClient.php @@ -9,10 +9,11 @@ use Inensus\SteamaMeter\Helpers\ApiHelpers; use Inensus\SteamaMeter\Models\SteamaCredential; -class SteamaMeterApiClient -{ +class SteamaMeterApiClient { private $client; + private $apiHelpers; + private $credential; public function __construct( @@ -25,8 +26,7 @@ public function __construct( $this->credential = $credentialModel; } - public function get($url) - { + public function get($url) { try { $credential = $this->getCredentials(); } catch (\Exception $e) { @@ -49,8 +49,7 @@ public function get($url) return $this->apiHelpers->checkApiResult(json_decode((string) $request->getBody(), true)); } - public function token($url, $postParams) - { + public function token($url, $postParams) { try { $credential = $this->getCredentials(); } catch (\Exception $e) { @@ -73,8 +72,7 @@ public function token($url, $postParams) return $this->apiHelpers->checkApiResult(json_decode((string) $request->getBody(), true)); } - public function post($url, $postParams) - { + public function post($url, $postParams) { try { $credential = $this->getCredentials(); } catch (ModelNotFoundException $e) { @@ -98,8 +96,7 @@ public function post($url, $postParams) return $this->apiHelpers->checkApiResult(json_decode((string) $request->getBody(), true)); } - public function put($url, $putParams) - { + public function put($url, $putParams) { try { $credential = $this->getCredentials(); } catch (\Exception $e) { @@ -124,8 +121,7 @@ public function put($url, $putParams) return $this->apiHelpers->checkApiResult(json_decode((string) $request->getBody(), true)); } - public function patch($url, $putParams) - { + public function patch($url, $putParams) { try { $credential = $this->getCredentials(); } catch (\Exception $e) { @@ -149,8 +145,7 @@ public function patch($url, $putParams) return $this->apiHelpers->checkApiResult(json_decode((string) $request->getBody(), true)); } - public function getByParams($url, $params) - { + public function getByParams($url, $params) { try { $credential = $this->getCredentials(); } catch (\Exception $e) { @@ -179,8 +174,7 @@ public function getByParams($url, $params) return json_decode((string) $request->getBody(), true); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->firstOrFail(); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/IBaseController.php b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/IBaseController.php index 85bc0ce15..083fcc304 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/IBaseController.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/IBaseController.php @@ -2,8 +2,7 @@ namespace Inensus\SteamaMeter\Http\Controllers; -interface IBaseController -{ +interface IBaseController { public function sync(); public function checkSync(); diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaAgentController.php b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaAgentController.php index 2170c3d5e..8418909e7 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaAgentController.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaAgentController.php @@ -7,34 +7,28 @@ use Inensus\SteamaMeter\Http\Resources\SteamaResource; use Inensus\SteamaMeter\Services\SteamaAgentService; -class SteamaAgentController extends Controller implements IBaseController -{ +class SteamaAgentController extends Controller implements IBaseController { private $agentService; - public function __construct(SteamaAgentService $agentService) - { + public function __construct(SteamaAgentService $agentService) { $this->agentService = $agentService; } - public function index(Request $request): SteamaResource - { + public function index(Request $request): SteamaResource { $customers = $this->agentService->getAgents($request); return new SteamaResource($customers); } - public function sync(): SteamaResource - { + public function sync(): SteamaResource { return new SteamaResource($this->agentService->sync()); } - public function checkSync(): SteamaResource - { + public function checkSync(): SteamaResource { return new SteamaResource($this->agentService->syncCheck()); } - public function count() - { + public function count() { return $this->agentService->getAgentsCount(); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaCredentialController.php b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaCredentialController.php index bfdd592f0..88f2360cc 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaCredentialController.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaCredentialController.php @@ -8,22 +8,18 @@ use Inensus\SteamaMeter\Http\Resources\SteamaResource; use Inensus\SteamaMeter\Services\SteamaCredentialService; -class SteamaCredentialController extends Controller -{ +class SteamaCredentialController extends Controller { private $credentialService; - public function __construct(SteamaCredentialService $credentialService) - { + public function __construct(SteamaCredentialService $credentialService) { $this->credentialService = $credentialService; } - public function show(): SteamaResource - { + public function show(): SteamaResource { return new SteamaResource($this->credentialService->getCredentials()); } - public function update(SteamaCredentialRequest $request): SteamaCredentialResource - { + public function update(SteamaCredentialRequest $request): SteamaCredentialResource { $credentials = $this->credentialService->updateCredentials($request->only([ 'id', 'username', diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaCustomerController.php b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaCustomerController.php index 0169f3645..1f4938f0a 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaCustomerController.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaCustomerController.php @@ -9,44 +9,36 @@ use Inensus\SteamaMeter\Models\SteamaCustomer; use Inensus\SteamaMeter\Services\SteamaCustomerService; -class SteamaCustomerController extends Controller implements IBaseController -{ +class SteamaCustomerController extends Controller implements IBaseController { private $customerService; - public function __construct(SteamaCustomerService $steamaCustomerService) - { + public function __construct(SteamaCustomerService $steamaCustomerService) { $this->customerService = $steamaCustomerService; } - public function index(Request $request): SteamaResource - { + public function index(Request $request): SteamaResource { $customers = $this->customerService->getCustomers($request); return new SteamaResource($customers); } - public function get($customerId): SteamaResource - { + public function get($customerId): SteamaResource { return new SteamaResource($this->customerService->getSteamaCustomerName($customerId)); } - public function sync(): SteamaResource - { + public function sync(): SteamaResource { return new SteamaResource($this->customerService->sync()); } - public function checkSync(): SteamaResource - { + public function checkSync(): SteamaResource { return new SteamaResource($this->customerService->syncCheck()); } - public function count() - { + public function count() { return $this->customerService->getCustomersCount(); } - public function update(SteamaCustomer $stmCustomer, SteamaCustomerRequest $request): SteamaResource - { + public function update(SteamaCustomer $stmCustomer, SteamaCustomerRequest $request): SteamaResource { $customerData = [ 'id' => $stmCustomer->customer_id, 'low_balance_warning' => $request->input('low_balance_warning'), @@ -56,8 +48,7 @@ public function update(SteamaCustomer $stmCustomer, SteamaCustomerRequest $reque return new SteamaResource($this->customerService->updateSteamaCustomerInfo($stmCustomer, $customerData)); } - public function search(): SteamaResource - { + public function search(): SteamaResource { $term = request('term'); $paginate = request('paginate') ?? 1; diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaMeterController.php b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaMeterController.php index 6fad3b77e..9bd9a97fd 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaMeterController.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaMeterController.php @@ -7,34 +7,28 @@ use Inensus\SteamaMeter\Http\Resources\SteamaResource; use Inensus\SteamaMeter\Services\SteamaMeterService; -class SteamaMeterController extends Controller implements IBaseController -{ +class SteamaMeterController extends Controller implements IBaseController { private $meterService; - public function __construct(SteamaMeterService $meterService) - { + public function __construct(SteamaMeterService $meterService) { $this->meterService = $meterService; } - public function index(Request $request): SteamaResource - { + public function index(Request $request): SteamaResource { $customers = $this->meterService->getMeters($request); return new SteamaResource($customers); } - public function sync(): SteamaResource - { + public function sync(): SteamaResource { return new SteamaResource($this->meterService->sync()); } - public function checkSync(): SteamaResource - { + public function checkSync(): SteamaResource { return new SteamaResource($this->meterService->syncCheck()); } - public function count() - { + public function count() { return $this->meterService->getMetersCount(); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSettingController.php b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSettingController.php index 56a247c64..307b424af 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSettingController.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSettingController.php @@ -6,17 +6,14 @@ use Inensus\SteamaMeter\Http\Resources\SteamaResource; use Inensus\SteamaMeter\Services\SteamaSettingService; -class SteamaSettingController extends Controller -{ +class SteamaSettingController extends Controller { private $settingService; - public function __construct(SteamaSettingService $settingService) - { + public function __construct(SteamaSettingService $settingService) { $this->settingService = $settingService; } - public function index(): SteamaResource - { + public function index(): SteamaResource { return new SteamaResource($this->settingService->getSettings()); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSiteController.php b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSiteController.php index 3c28c6a8e..21712be96 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSiteController.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSiteController.php @@ -7,39 +7,32 @@ use Inensus\SteamaMeter\Http\Resources\SteamaResource; use Inensus\SteamaMeter\Services\SteamaSiteService; -class SteamaSiteController extends Controller implements IBaseController -{ +class SteamaSiteController extends Controller implements IBaseController { private $siteService; - public function __construct(SteamaSiteService $siteService) - { + public function __construct(SteamaSiteService $siteService) { $this->siteService = $siteService; } - public function index(Request $request): SteamaResource - { + public function index(Request $request): SteamaResource { $sites = $this->siteService->getSites($request); return new SteamaResource($sites); } - public function sync(): SteamaResource - { + public function sync(): SteamaResource { return new SteamaResource($this->siteService->sync()); } - public function checkSync(): SteamaResource - { + public function checkSync(): SteamaResource { return new SteamaResource($this->siteService->syncCheck()); } - public function count() - { + public function count() { return $this->siteService->getSitesCount(); } - public function location(): SteamaResource - { + public function location(): SteamaResource { return new SteamaResource($this->siteService->checkLocationAvailability()); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsBodyController.php b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsBodyController.php index 65fd4c2c7..1efb090c3 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsBodyController.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsBodyController.php @@ -7,22 +7,18 @@ use Inensus\SteamaMeter\Http\Resources\SteamaResource; use Inensus\SteamaMeter\Services\SteamaSmsBodyService; -class SteamaSmsBodyController extends Controller -{ +class SteamaSmsBodyController extends Controller { private $smsBodyService; - public function __construct(SteamaSmsBodyService $smsBodyService) - { + public function __construct(SteamaSmsBodyService $smsBodyService) { $this->smsBodyService = $smsBodyService; } - public function index(): SteamaResource - { + public function index(): SteamaResource { return new SteamaResource($this->smsBodyService->getSmsBodies()); } - public function update(Request $request): SteamaResource - { + public function update(Request $request): SteamaResource { return new SteamaResource($this->smsBodyService->updateSmsBodies($request->all())); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsFeedbackController.php b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsFeedbackController.php index f899e28b3..b1ee215dd 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsFeedbackController.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsFeedbackController.php @@ -8,22 +8,18 @@ use Inensus\SteamaMeter\Models\SteamaSmsFeedbackWord; use Inensus\SteamaMeter\Services\SteamaSmsFeedbackWordService; -class SteamaSmsFeedbackController extends Controller -{ +class SteamaSmsFeedbackController extends Controller { private $smsFeedbackWorkService; - public function __construct(SteamaSmsFeedbackWordService $smsFeedbackWordService) - { + public function __construct(SteamaSmsFeedbackWordService $smsFeedbackWordService) { $this->smsFeedbackWorkService = $smsFeedbackWordService; } - public function index(): SteamaResource - { + public function index(): SteamaResource { return new SteamaResource($this->smsFeedbackWorkService->getSmsFeedbackWords()); } - public function update(SteamaSmsFeedbackWord $smsFeedbackWord, Request $request): SteamaResource - { + public function update(SteamaSmsFeedbackWord $smsFeedbackWord, Request $request): SteamaResource { return new SteamaResource($this->smsFeedbackWorkService->updateSmsFeedbackWord($smsFeedbackWord, $request->all())); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsSettingController.php b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsSettingController.php index 38344aaba..680ca4e96 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsSettingController.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsSettingController.php @@ -7,17 +7,14 @@ use Inensus\SteamaMeter\Http\Resources\SteamaResource; use Inensus\SteamaMeter\Services\SteamaSmsSettingService; -class SteamaSmsSettingController extends Controller -{ +class SteamaSmsSettingController extends Controller { private $smsSettingService; - public function __construct(SteamaSmsSettingService $smsSettingService) - { + public function __construct(SteamaSmsSettingService $smsSettingService) { $this->smsSettingService = $smsSettingService; } - public function update(Request $request): SteamaResource - { + public function update(Request $request): SteamaResource { return new SteamaResource($this->smsSettingService->updateSmsSettings($request->all())); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsVariableDefaultValueController.php b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsVariableDefaultValueController.php index c7fa08c4c..e33415d85 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsVariableDefaultValueController.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSmsVariableDefaultValueController.php @@ -6,17 +6,14 @@ use Inensus\SteamaMeter\Services\SteamaSmsVariableDefaultValueService; use Inensus\Ticket\Http\Controllers\Controller; -class SteamaSmsVariableDefaultValueController extends Controller -{ +class SteamaSmsVariableDefaultValueController extends Controller { private $smsVariableDefaultSValueService; - public function __construct(SteamaSmsVariableDefaultValueService $smsVariableDefaultSValueService) - { + public function __construct(SteamaSmsVariableDefaultValueService $smsVariableDefaultSValueService) { $this->smsVariableDefaultSValueService = $smsVariableDefaultSValueService; } - public function index(): SteamaResource - { + public function index(): SteamaResource { return new SteamaResource($this->smsVariableDefaultSValueService->getSmsVariableDefaultValues()); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSyncSettingController.php b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSyncSettingController.php index 240c03a2c..560404b72 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSyncSettingController.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaSyncSettingController.php @@ -7,17 +7,14 @@ use Inensus\SteamaMeter\Http\Resources\SteamaResource; use Inensus\SteamaMeter\Services\SteamaSyncSettingService; -class SteamaSyncSettingController extends Controller -{ +class SteamaSyncSettingController extends Controller { private $syncSettingService; - public function __construct(SteamaSyncSettingService $syncSettingService) - { + public function __construct(SteamaSyncSettingService $syncSettingService) { $this->syncSettingService = $syncSettingService; } - public function update(Request $request): SteamaResource - { + public function update(Request $request): SteamaResource { return new SteamaResource($this->syncSettingService->updateSyncSettings($request->all())); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaTransactionController.php b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaTransactionController.php index 8a2b46f69..39663a841 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaTransactionController.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Controllers/SteamaTransactionController.php @@ -7,17 +7,14 @@ use Inensus\SteamaMeter\Http\Resources\SteamaResource; use Inensus\SteamaMeter\Services\SteamaTransactionsService; -class SteamaTransactionController extends Controller -{ +class SteamaTransactionController extends Controller { private $steamaTransactionsService; - public function __construct(SteamaTransactionsService $steamaTransactionsService) - { + public function __construct(SteamaTransactionsService $steamaTransactionsService) { $this->steamaTransactionsService = $steamaTransactionsService; } - public function index($customer, Request $request): SteamaResource - { + public function index($customer, Request $request): SteamaResource { return new SteamaResource($this->steamaTransactionsService->getTransactionsByCustomer($customer, $request)); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Requests/SteamaCredentialRequest.php b/src/backend/packages/inensus/steama-meter/src/Http/Requests/SteamaCredentialRequest.php index f904fea6f..b5398ad4c 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Requests/SteamaCredentialRequest.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Requests/SteamaCredentialRequest.php @@ -5,15 +5,13 @@ use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; -class SteamaCredentialRequest extends FormRequest -{ +class SteamaCredentialRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'username' => ['required', Rule::unique('shard.steama_credentials')->ignore($this->id)], 'password' => 'required', diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Requests/SteamaCustomerRequest.php b/src/backend/packages/inensus/steama-meter/src/Http/Requests/SteamaCustomerRequest.php index 476be1a6c..20de3877c 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Requests/SteamaCustomerRequest.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Requests/SteamaCustomerRequest.php @@ -5,15 +5,13 @@ use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; -class SteamaCustomerRequest extends FormRequest -{ +class SteamaCustomerRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'id' => ['required', Rule::unique('shard.steama_customers')->ignore($this->id)], 'low_balance_warning' => 'required', diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Resources/SteamaCredentialResource.php b/src/backend/packages/inensus/steama-meter/src/Http/Resources/SteamaCredentialResource.php index ad7259755..2cb74b363 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Resources/SteamaCredentialResource.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Resources/SteamaCredentialResource.php @@ -6,10 +6,8 @@ use Illuminate\Http\Resources\Json\JsonResource; use Inensus\SteamaMeter\Models\SteamaCredential; -class SteamaCredentialResource extends JsonResource -{ - public function __construct(SteamaCredential $steamaCredential) - { +class SteamaCredentialResource extends JsonResource { + public function __construct(SteamaCredential $steamaCredential) { parent::__construct($steamaCredential); } @@ -20,16 +18,14 @@ public function __construct(SteamaCredential $steamaCredential) * * @return Request */ - public function toArray($request) - { + public function toArray($request) { $credentials = $this->resource->toArray(); $credentials['alert'] = $this->alertType($this->resource->is_authenticated); return $credentials; } - private function alertType($authenticationStatus) - { + private function alertType($authenticationStatus) { switch ($authenticationStatus) { case true: return [ diff --git a/src/backend/packages/inensus/steama-meter/src/Http/Resources/SteamaResource.php b/src/backend/packages/inensus/steama-meter/src/Http/Resources/SteamaResource.php index 84df4c453..6df8a2b5e 100644 --- a/src/backend/packages/inensus/steama-meter/src/Http/Resources/SteamaResource.php +++ b/src/backend/packages/inensus/steama-meter/src/Http/Resources/SteamaResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class SteamaResource extends JsonResource -{ +class SteamaResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class SteamaResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Listeners/MeterParameterListener.php b/src/backend/packages/inensus/steama-meter/src/Listeners/MeterParameterListener.php index f31d95f11..775bec09f 100644 --- a/src/backend/packages/inensus/steama-meter/src/Listeners/MeterParameterListener.php +++ b/src/backend/packages/inensus/steama-meter/src/Listeners/MeterParameterListener.php @@ -12,15 +12,21 @@ use Inensus\SteamaMeter\Services\SteamaCustomerService; use Inensus\SteamaMeter\Services\SteamaMeterService; -class MeterParameterListener -{ +class MeterParameterListener { private $apiHelpers; + private $stmCustomerService; + private $stmMeterService; + private $person; + private $meterParameter; + private $stmTariff; + private $stmCustomer; + private $stmMeter; public function __construct( @@ -43,8 +49,7 @@ public function __construct( $this->stmMeter = $stmMeter; } - public function onParameterSaved(int $meterId) - { + public function onParameterSaved(int $meterId) { $meterInfo = $this->meterParameter->newQuery()->with(['meter.manufacturer', 'geo', 'owner.addresses' => static function ($q) { $q->where('is_primary', 1); }])->whereHas('meter', function ($q) use ($meterId) { @@ -83,8 +88,7 @@ public function onParameterSaved(int $meterId) } } - public function subscribe(Dispatcher $events) - { + public function subscribe(Dispatcher $events) { $events->listen( 'meterparameter.saved', 'Inensus\SteamaMeter\Listeners\MeterParameterListener@onParameterSaved' diff --git a/src/backend/packages/inensus/steama-meter/src/Listeners/SmsListener.php b/src/backend/packages/inensus/steama-meter/src/Listeners/SmsListener.php index 3e6aaccd4..1e325d768 100644 --- a/src/backend/packages/inensus/steama-meter/src/Listeners/SmsListener.php +++ b/src/backend/packages/inensus/steama-meter/src/Listeners/SmsListener.php @@ -10,11 +10,13 @@ use Inensus\SteamaMeter\Sms\Senders\SteamaSmsConfig; use Inensus\SteamaMeter\Sms\SteamaSmsTypes; -class SmsListener -{ +class SmsListener { private $smsFeedbackWordService; + private $customerService; + private $meter; + private $smsService; public function __construct( @@ -29,8 +31,7 @@ public function __construct( $this->smsService = $smsService; } - public function onSmsStored($sender, $message) - { + public function onSmsStored($sender, $message) { $steamaCustomer = $this->customerService->getSteamaCustomerWithPhone($sender); if (!$steamaCustomer) { return; @@ -39,16 +40,17 @@ public function onSmsStored($sender, $message) $meterBalance = strpos(strtolower($message), strtolower($smsFeedbackWords[0]->meter_balance)); if ($meterBalance !== false) { - $this->smsService->sendSms($steamaCustomer, + $this->smsService->sendSms( + $steamaCustomer, SteamaSmsTypes::BALANCE_FEEDBACK, - SteamaSmsConfig::class); + SteamaSmsConfig::class + ); return; } } - public function subscribe(Dispatcher $events) - { + public function subscribe(Dispatcher $events) { $events->listen('sms.stored', 'Inensus\SteamaMeter\Listeners\SmsListener@onSmsStored'); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/BaseModel.php b/src/backend/packages/inensus/steama-meter/src/Models/BaseModel.php index da4ac23a5..c38475951 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/BaseModel.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/BaseModel.php @@ -4,19 +4,17 @@ use Illuminate\Database\Eloquent\Model; -class BaseModel extends Model -{ +class BaseModel extends Model { protected $guarded = ['id']; + public static $rules = []; - public function __construct(array $attributes = []) - { + public function __construct(array $attributes = []) { parent::__construct($attributes); $this->setConnection('shard'); } - public function resolveChildRouteBinding($childType, $value, $field) - { + public function resolveChildRouteBinding($childType, $value, $field) { // TODO: Implement resolveChildRouteBinding() method. } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaAgent.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaAgent.php index be39b612c..bbcd1dff2 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaAgent.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaAgent.php @@ -4,17 +4,14 @@ use App\Models\Agent; -class SteamaAgent extends BaseModel -{ +class SteamaAgent extends BaseModel { protected $table = 'steama_agents'; - public function mpmAgent() - { + public function mpmAgent() { return $this->belongsTo(Agent::class, 'mpm_agent_id'); } - public function site() - { + public function site() { return $this->belongsTo(SteamaSite::class, 'site_id', 'site_id'); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaAssetRatesPaymentPlan.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaAssetRatesPaymentPlan.php index 52a1fba2c..42b522ba5 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaAssetRatesPaymentPlan.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaAssetRatesPaymentPlan.php @@ -2,7 +2,6 @@ namespace Inensus\SteamaMeter\Models; -class SteamaAssetRatesPaymentPlan extends BaseModel -{ +class SteamaAssetRatesPaymentPlan extends BaseModel { protected $table = 'steama_asset_rates_payment_plans'; } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaCredential.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaCredential.php index 91a3b7058..e96ad22d6 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaCredential.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaCredential.php @@ -2,7 +2,6 @@ namespace Inensus\SteamaMeter\Models; -class SteamaCredential extends BaseModel -{ +class SteamaCredential extends BaseModel { protected $table = 'steama_credentials'; } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaCustomer.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaCustomer.php index cce8ccd80..3f33073d5 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaCustomer.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaCustomer.php @@ -4,32 +4,26 @@ use App\Models\Person\Person; -class SteamaCustomer extends BaseModel -{ +class SteamaCustomer extends BaseModel { protected $table = 'steama_customers'; - public function mpmPerson() - { + public function mpmPerson() { return $this->belongsTo(Person::class, 'mpm_customer_id'); } - public function site() - { + public function site() { return $this->belongsTo(SteamaSite::class, 'site_id', 'site_id'); } - public function userType() - { + public function userType() { return $this->belongsTo(SteamaUserType::class, 'user_type_id'); } - public function paymentPlans() - { + public function paymentPlans() { return $this->hasOne(SteamaCustomerBasisPaymentPlan::class); } - public function stmMeters() - { + public function stmMeters() { return $this->hasMany(SteamaMeter::class, 'customer_id', 'customer_id'); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaCustomerBasisPaymentPlan.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaCustomerBasisPaymentPlan.php index a3a5f5bd1..8b6a73505 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaCustomerBasisPaymentPlan.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaCustomerBasisPaymentPlan.php @@ -5,17 +5,14 @@ use App\Relations\BelongsToMorph; use Illuminate\Database\Eloquent\Relations\BelongsTo; -class SteamaCustomerBasisPaymentPlan extends BaseModel -{ +class SteamaCustomerBasisPaymentPlan extends BaseModel { protected $table = 'steama_customer_basis_payment_plans'; - public function customer() - { + public function customer() { return $this->belongsTo(SteamaCustomer::class, 'customer_id'); } - public function paymentPlan() - { + public function paymentPlan() { return $this->morphTo(); } @@ -24,8 +21,7 @@ public function paymentPlan() * * @return BelongsTo */ - public function paymentPlanFlatRate() - { + public function paymentPlanFlatRate() { return BelongsToMorph::build($this, SteamaFlatRatePaymentPlan::class, 'paymentPlan'); } @@ -34,8 +30,7 @@ public function paymentPlanFlatRate() * * @return BelongsTo */ - public function paymentPlanHybrid() - { + public function paymentPlanHybrid() { return BelongsToMorph::build($this, SteamaHybridPaymentPlan::class, 'paymentPlan'); } @@ -44,8 +39,7 @@ public function paymentPlanHybrid() * * @return BelongsTo */ - public function paymentPlanSubscription() - { + public function paymentPlanSubscription() { return BelongsToMorph::build($this, SteamaSubscriptionPaymentPlan::class, 'paymentPlan'); } @@ -54,8 +48,7 @@ public function paymentPlanSubscription() * * @return BelongsTo */ - public function paymentPlanMinimumTopUp() - { + public function paymentPlanMinimumTopUp() { return BelongsToMorph::build($this, SteamaMinimumTopUpRequirementsPaymentPlan::class, 'paymentPlan'); } @@ -64,8 +57,7 @@ public function paymentPlanMinimumTopUp() * * @return BelongsTo */ - public function paymentPlanAssetRates() - { + public function paymentPlanAssetRates() { return BelongsToMorph::build($this, SteamaAssetRatesPaymentPlan::class, 'paymentPlan'); } @@ -74,8 +66,7 @@ public function paymentPlanAssetRates() * * @return BelongsTo */ - public function paymentPlanPerKwh() - { + public function paymentPlanPerKwh() { return BelongsToMorph::build($this, SteamaPerKwhPaymentPlan::class, 'paymentPlan'); } @@ -84,8 +75,7 @@ public function paymentPlanPerKwh() * * @return BelongsTo */ - public function paymentPlanTariffOverride() - { + public function paymentPlanTariffOverride() { return BelongsToMorph::build($this, SteamaTariffOverridePaymentPlan::class, 'paymentPlan'); } @@ -94,8 +84,7 @@ public function paymentPlanTariffOverride() * * @return BelongsTo */ - public function paymentPlanCustomerBasisTimeOfUsage() - { + public function paymentPlanCustomerBasisTimeOfUsage() { return BelongsToMorph::build($this, SteamaCustomerBasisTimeOfUsage::class, 'paymentPlan'); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaCustomerBasisTimeOfUsage.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaCustomerBasisTimeOfUsage.php index 9a6cd3907..7fdd53bca 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaCustomerBasisTimeOfUsage.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaCustomerBasisTimeOfUsage.php @@ -2,7 +2,6 @@ namespace Inensus\SteamaMeter\Models; -class SteamaCustomerBasisTimeOfUsage extends BaseModel -{ +class SteamaCustomerBasisTimeOfUsage extends BaseModel { protected $table = 'create_steama_customer_basis_time_of_usages'; } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaFlatRatePaymentPlan.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaFlatRatePaymentPlan.php index 2587082fb..cdaffcaf3 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaFlatRatePaymentPlan.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaFlatRatePaymentPlan.php @@ -2,7 +2,6 @@ namespace Inensus\SteamaMeter\Models; -class SteamaFlatRatePaymentPlan extends BaseModel -{ +class SteamaFlatRatePaymentPlan extends BaseModel { protected $table = 'steama_flat_rate_payment_plans'; } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaHybridPaymentPlan.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaHybridPaymentPlan.php index d1f2531d8..997b252a3 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaHybridPaymentPlan.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaHybridPaymentPlan.php @@ -2,7 +2,6 @@ namespace Inensus\SteamaMeter\Models; -class SteamaHybridPaymentPlan extends BaseModel -{ +class SteamaHybridPaymentPlan extends BaseModel { protected $table = 'steama_hybrid_payment_plans'; } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaMeter.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaMeter.php index 740de9872..4e5beb1a8 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaMeter.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaMeter.php @@ -4,17 +4,14 @@ use App\Models\Meter\Meter; -class SteamaMeter extends BaseModel -{ +class SteamaMeter extends BaseModel { protected $table = 'steama_meters'; - public function mpmMeter() - { + public function mpmMeter() { return $this->belongsTo(Meter::class, 'mpm_meter_id'); } - public function stmCustomer() - { + public function stmCustomer() { return $this->belongsTo(SteamaCustomer::class, 'customer_id', 'customer_id'); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaMeterType.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaMeterType.php index 3550930c5..498226b5c 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaMeterType.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaMeterType.php @@ -4,12 +4,10 @@ use App\Models\Meter\MeterType; -class SteamaMeterType extends BaseModel -{ +class SteamaMeterType extends BaseModel { protected $table = 'steama_meter_types'; - public function mpmMeterType() - { + public function mpmMeterType() { return $this->belongsTo(MeterType::class, 'mpm_meter_type_id'); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaMinimumTopUpRequirementsPaymentPlan.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaMinimumTopUpRequirementsPaymentPlan.php index 6753edf8b..2c9e73d8a 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaMinimumTopUpRequirementsPaymentPlan.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaMinimumTopUpRequirementsPaymentPlan.php @@ -2,7 +2,6 @@ namespace Inensus\SteamaMeter\Models; -class SteamaMinimumTopUpRequirementsPaymentPlan extends BaseModel -{ +class SteamaMinimumTopUpRequirementsPaymentPlan extends BaseModel { protected $table = 'steama_minimum_top_up_requirements_payment_plans'; } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaPerKwhPaymentPlan.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaPerKwhPaymentPlan.php index 6f5da9964..236534f08 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaPerKwhPaymentPlan.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaPerKwhPaymentPlan.php @@ -2,7 +2,6 @@ namespace Inensus\SteamaMeter\Models; -class SteamaPerKwhPaymentPlan extends BaseModel -{ +class SteamaPerKwhPaymentPlan extends BaseModel { protected $table = 'steama_per_kwh_payment_plans'; } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSetting.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSetting.php index 86e97f02b..b546bfb4a 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSetting.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSetting.php @@ -6,32 +6,24 @@ use App\Relations\BelongsToMorph; use Illuminate\Database\Eloquent\Relations\MorphTo; -class SteamaSetting extends BaseModel -{ +class SteamaSetting extends BaseModel { protected $table = 'steama_settings'; - public function setting(): MorphTo - { + public function setting(): MorphTo { return $this->morphTo(); } /** * A work-around for querying the polymorphic relation with whereHas. - * - * @return BelongsToMorph */ - public function settingSms(): BelongsToMorph - { + public function settingSms(): BelongsToMorph { return BelongsToMorph::build($this, SteamaSmsSetting::class, 'setting'); } /** * A work-around for querying the polymorphic relation with whereHas. - * - * @return BelongsToMorph */ - public function settingSync(): BelongsToMorph - { + public function settingSync(): BelongsToMorph { return BelongsToMorph::build($this, SteamaSyncSetting::class, 'setting'); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSite.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSite.php index a20abfd43..79518f312 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSite.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSite.php @@ -4,22 +4,18 @@ use App\Models\MiniGrid; -class SteamaSite extends BaseModel -{ +class SteamaSite extends BaseModel { protected $table = 'steama_sites'; - public function mpmMiniGrid() - { + public function mpmMiniGrid() { return $this->belongsTo(MiniGrid::class, 'mpm_mini_grid_id'); } - public function paymentPlans() - { + public function paymentPlans() { return $this->hasMany(SteamaSiteLevelPaymentPlan::class); } - public function agents() - { + public function agents() { return $this->hasMany(SteamaAgent::class); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSiteLevelPaymentPlan.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSiteLevelPaymentPlan.php index 701c751ba..57a114ff4 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSiteLevelPaymentPlan.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSiteLevelPaymentPlan.php @@ -2,17 +2,14 @@ namespace Inensus\SteamaMeter\Models; -class SteamaSiteLevelPaymentPlan extends BaseModel -{ +class SteamaSiteLevelPaymentPlan extends BaseModel { protected $table = 'steama_site_level_payment_plans'; - public function site() - { + public function site() { return $this->belongsTo(SteamaSite::class, 'site_id'); } - public function planType() - { + public function planType() { return $this->belongsTo(SteamaSiteLevelPaymentPlanType::class, 'payment_plan_type_id'); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSiteLevelPaymentPlanType.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSiteLevelPaymentPlanType.php index 1170bca64..5e0f2e669 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSiteLevelPaymentPlanType.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSiteLevelPaymentPlanType.php @@ -2,7 +2,6 @@ namespace Inensus\SteamaMeter\Models; -class SteamaSiteLevelPaymentPlanType extends BaseModel -{ +class SteamaSiteLevelPaymentPlanType extends BaseModel { protected $table = 'steama_site_level_payment_plan_types'; } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsBody.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsBody.php index a14b6ef61..f75082f2c 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsBody.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsBody.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class SteamaSmsBody extends BaseModel -{ +class SteamaSmsBody extends BaseModel { protected $table = 'steama_sms_bodies'; } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsFeedbackWord.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsFeedbackWord.php index 86526e00a..c3e7c699d 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsFeedbackWord.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsFeedbackWord.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class SteamaSmsFeedbackWord extends BaseModel -{ +class SteamaSmsFeedbackWord extends BaseModel { protected $table = 'steama_sms_feedback_words'; } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsNotifiedCustomer.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsNotifiedCustomer.php index d28b16ff7..ba301bff7 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsNotifiedCustomer.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsNotifiedCustomer.php @@ -4,12 +4,10 @@ use Illuminate\Database\Eloquent\Relations\MorphTo; -class SteamaSmsNotifiedCustomer extends BaseModel -{ +class SteamaSmsNotifiedCustomer extends BaseModel { protected $table = 'steama_sms_notified_customers'; - public function notify(): MorphTo - { + public function notify(): MorphTo { return $this->morphTo(); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsSetting.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsSetting.php index 0565af1fe..d7311450e 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsSetting.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsSetting.php @@ -4,12 +4,10 @@ use App\Models\Base\BaseModel; -class SteamaSmsSetting extends BaseModel -{ +class SteamaSmsSetting extends BaseModel { protected $table = 'steama_sms_settings'; - public function setting() - { + public function setting() { return $this->morphOne(SteamaSetting::class, 'setting'); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsVariableDefaultValue.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsVariableDefaultValue.php index 47d5b438e..468eae61d 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsVariableDefaultValue.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSmsVariableDefaultValue.php @@ -2,7 +2,6 @@ namespace Inensus\SteamaMeter\Models; -class SteamaSmsVariableDefaultValue extends BaseModel -{ +class SteamaSmsVariableDefaultValue extends BaseModel { protected $table = 'steama_sms_variable_default_values'; } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSubscriptionPaymentPlan.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSubscriptionPaymentPlan.php index 39f2c6a9a..b3e8aa1b9 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSubscriptionPaymentPlan.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSubscriptionPaymentPlan.php @@ -2,7 +2,6 @@ namespace Inensus\SteamaMeter\Models; -class SteamaSubscriptionPaymentPlan extends BaseModel -{ +class SteamaSubscriptionPaymentPlan extends BaseModel { protected $table = 'steama_subscription_payment_plans'; } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSyncAction.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSyncAction.php index 4c379bd26..b69edeb2d 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSyncAction.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSyncAction.php @@ -2,12 +2,10 @@ namespace Inensus\SteamaMeter\Models; -class SteamaSyncAction extends BaseModel -{ +class SteamaSyncAction extends BaseModel { protected $table = 'steama_sync_actions'; - public function synSetting() - { + public function synSetting() { return $this->belongsTo(SteamaSyncSetting::class, 'sync_setting_id'); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSyncSetting.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSyncSetting.php index e15bf6af3..25c57d525 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaSyncSetting.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaSyncSetting.php @@ -2,17 +2,14 @@ namespace Inensus\SteamaMeter\Models; -class SteamaSyncSetting extends BaseModel -{ +class SteamaSyncSetting extends BaseModel { protected $table = 'steama_sync_settings'; - public function syncAction() - { + public function syncAction() { return $this->hasOne(SteamaSyncAction::class); } - public function setting() - { + public function setting() { return $this->morphOne(SteamaSetting::class, 'setting'); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaTariff.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaTariff.php index 06c5303bc..3ed6fe7a0 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaTariff.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaTariff.php @@ -4,12 +4,10 @@ use App\Models\Meter\MeterTariff; -class SteamaTariff extends BaseModel -{ +class SteamaTariff extends BaseModel { protected $table = 'steama_tariffs'; - public function mpmTariff() - { + public function mpmTariff() { return $this->belongsTo(MeterTariff::class, 'mpm_tariff_id'); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaTariffOverridePaymentPlan.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaTariffOverridePaymentPlan.php index 6d040a2d7..ec13116dc 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaTariffOverridePaymentPlan.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaTariffOverridePaymentPlan.php @@ -2,7 +2,6 @@ namespace Inensus\SteamaMeter\Models; -class SteamaTariffOverridePaymentPlan extends BaseModel -{ +class SteamaTariffOverridePaymentPlan extends BaseModel { protected $table = 'steama_tariff_override_payment_plans'; } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaTransaction.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaTransaction.php index fb9b5fddf..9a5281fa9 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaTransaction.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaTransaction.php @@ -11,47 +11,38 @@ use Inensus\SwiftaPaymentProvider\Models\SwiftaTransaction; use Inensus\WaveMoneyPaymentProvider\Models\WaveMoneyTransaction; -class SteamaTransaction extends BaseModel implements ISubTransaction -{ +class SteamaTransaction extends BaseModel implements ISubTransaction { protected $table = 'steama_transactions'; - public function site() - { + public function site() { return $this->belongsTo(SteamaSite::class, 'site_id', 'site_id'); } - public function agentTransaction() - { + public function agentTransaction() { return $this->morphOne(AgentTransaction::class, 'manufacturer_transaction'); } - public function vodacomTransaction() - { + public function vodacomTransaction() { return $this->morphOne(VodacomTransaction::class, 'manufacturer_transaction'); } - public function airtelTransaction() - { + public function airtelTransaction() { return $this->morphOne(AirtelTransaction::class, 'manufacturer_transaction'); } - public function thirdPartyTransaction() - { + public function thirdPartyTransaction() { return $this->morphOne(ThirdPartyTransaction::class, 'manufacturer_transaction'); } - public function mesombTransaction() - { + public function mesombTransaction() { return $this->morphOne(MesombTransaction::class, 'manufacturer_transaction'); } - public function swiftaTransaction() - { + public function swiftaTransaction() { return $this->morphOne(SwiftaTransaction::class, 'manufacturer_transaction'); } - public function waveMoneyTransaction() - { + public function waveMoneyTransaction() { return $this->morphOne(WaveMoneyTransaction::class, 'manufacturer_transaction'); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SteamaUserType.php b/src/backend/packages/inensus/steama-meter/src/Models/SteamaUserType.php index 58b148a9a..7f2c7663e 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SteamaUserType.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SteamaUserType.php @@ -4,12 +4,10 @@ use App\Models\ConnectionType; -class SteamaUserType extends BaseModel -{ +class SteamaUserType extends BaseModel { protected $table = 'steama_user_types'; - public function mpmConnectionType() - { + public function mpmConnectionType() { return $this->belongsTo(ConnectionType::class, 'mpm_connection_type_id'); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Models/SyncStatus.php b/src/backend/packages/inensus/steama-meter/src/Models/SyncStatus.php index 9140e7eb3..0f376fb20 100644 --- a/src/backend/packages/inensus/steama-meter/src/Models/SyncStatus.php +++ b/src/backend/packages/inensus/steama-meter/src/Models/SyncStatus.php @@ -2,9 +2,10 @@ namespace Inensus\SteamaMeter\Models; -abstract class SyncStatus -{ +abstract class SyncStatus { public const SYNCED = 1; + public const MODIFIED = 2; + public const NOT_REGISTERED_YET = 3; } diff --git a/src/backend/packages/inensus/steama-meter/src/Observers/GeographicalInformationObserver.php b/src/backend/packages/inensus/steama-meter/src/Observers/GeographicalInformationObserver.php index bf2d820d7..161f4a786 100644 --- a/src/backend/packages/inensus/steama-meter/src/Observers/GeographicalInformationObserver.php +++ b/src/backend/packages/inensus/steama-meter/src/Observers/GeographicalInformationObserver.php @@ -9,12 +9,15 @@ use Inensus\SteamaMeter\Models\SteamaMeter; use Inensus\SteamaMeter\Services\SteamaMeterService; -class GeographicalInformationObserver -{ +class GeographicalInformationObserver { private $stmMeterService; + private $stmMeter; + private $person; + private $stmCustomer; + private $meterParameter; public function __construct( @@ -31,8 +34,7 @@ public function __construct( $this->meterParameter = $meterParameter; } - public function updated(GeographicalInformation $geographicalInformation) - { + public function updated(GeographicalInformation $geographicalInformation) { if ($geographicalInformation->owner_type === 'meter_parameter') { $meterParameter = $this->meterParameter->newQuery()->find($geographicalInformation->owner_id); $stmMeter = $this->stmMeter->newQuery()->where('mpm_meter_id', $meterParameter->meter_id)->first(); diff --git a/src/backend/packages/inensus/steama-meter/src/Observers/PersonObserver.php b/src/backend/packages/inensus/steama-meter/src/Observers/PersonObserver.php index 397fd2ab6..2b65496ed 100644 --- a/src/backend/packages/inensus/steama-meter/src/Observers/PersonObserver.php +++ b/src/backend/packages/inensus/steama-meter/src/Observers/PersonObserver.php @@ -9,13 +9,17 @@ use Inensus\SteamaMeter\Services\SteamaCustomerService; use Inensus\SteamaMeter\Services\SteamaMeterService; -class PersonObserver -{ +class PersonObserver { private $apiHelpers; + private $stmCustomerService; + private $stmMeterService; + private $stmCustomer; + private $person; + private $steamaApi; public function __construct( @@ -34,8 +38,7 @@ public function __construct( $this->steamaApi = $steamaApi; } - public function updated(Person $person) - { + public function updated(Person $person) { $stmCustomer = $this->stmCustomer->newQuery()->with('site')->where('mpm_customer_id', $person->id)->first(); if ($stmCustomer) { diff --git a/src/backend/packages/inensus/steama-meter/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/steama-meter/src/Providers/EventServiceProvider.php index 9a2381dfa..2d8b2192a 100644 --- a/src/backend/packages/inensus/steama-meter/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/steama-meter/src/Providers/EventServiceProvider.php @@ -6,8 +6,7 @@ use Inensus\SteamaMeter\Listeners\MeterParameterListener; use Inensus\SteamaMeter\Listeners\SmsListener; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ // MeterParameterListener::class, SmsListener::class, @@ -18,8 +17,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/steama-meter/src/Providers/ObserverServiceProvider.php index 1a712485b..ad233f652 100644 --- a/src/backend/packages/inensus/steama-meter/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/steama-meter/src/Providers/ObserverServiceProvider.php @@ -8,15 +8,13 @@ use Inensus\SteamaMeter\Observers\GeographicalInformationObserver; use Inensus\SteamaMeter\Observers\PersonObserver; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); Person::observe(PersonObserver::class); GeographicalInformation::observe(GeographicalInformationObserver::class); diff --git a/src/backend/packages/inensus/steama-meter/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/steama-meter/src/Providers/RouteServiceProvider.php index b493105df..67094d743 100644 --- a/src/backend/packages/inensus/steama-meter/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/steama-meter/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\SteamaMeter\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/steama-meter/src/Providers/SteamaMeterServiceProvider.php b/src/backend/packages/inensus/steama-meter/src/Providers/SteamaMeterServiceProvider.php index 09a19e5b0..b4e9841dc 100644 --- a/src/backend/packages/inensus/steama-meter/src/Providers/SteamaMeterServiceProvider.php +++ b/src/backend/packages/inensus/steama-meter/src/Providers/SteamaMeterServiceProvider.php @@ -24,10 +24,8 @@ use Inensus\SteamaMeter\Models\SteamaTransaction; use Inensus\SteamaMeter\SteamaMeterApi; -class SteamaMeterServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class SteamaMeterServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -47,7 +45,7 @@ public function boot(Filesystem $filesystem) $app->make(Schedule::class)->command('steama-meter:smsNotifier')->withoutOverlapping(50) ->appendOutputTo(storage_path('logs/cron.log')); $app->make(Schedule::class)->command('steama-meter:hourlyReadings')->hourlyAt(1)->withoutOverlapping(50) - ->appendOutputTo(storage_path('logs/cron.log')); + ->appendOutputTo(storage_path('logs/cron.log')); }); Relation::morphMap( [ @@ -65,37 +63,32 @@ public function boot(Filesystem $filesystem) ); } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/steama-meter.php', 'steama'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->bind('SteamaMeterApi', SteamaMeterApi::class); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/steama-meter.php' => config_path('steama-meter.php'), ]); } - public function publishVueFiles() - { + public function publishVueFiles() { $this->publishes([ __DIR__.'/../resources/assets' => resource_path('assets/js/plugins/steama-meter'), ], 'vue-components'); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_steama_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) @@ -103,8 +96,10 @@ protected function getMigrationFileName(Filesystem $filesystem): string if (count($filesystem->glob($path.'*_create_steama_tables.php'))) { $file = $filesystem->glob($path.'*_create_steama_tables.php')[0]; - file_put_contents($file, - file_get_contents(__DIR__.'/../../database/migrations/create_steama_tables.php.stub')); + file_put_contents( + $file, + file_get_contents(__DIR__.'/../../database/migrations/create_steama_tables.php.stub') + ); } return $filesystem->glob($path.'*_create_steama_tables.php'); diff --git a/src/backend/packages/inensus/steama-meter/src/Services/ISynchronizeService.php b/src/backend/packages/inensus/steama-meter/src/Services/ISynchronizeService.php index ef7233423..6492c300a 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/ISynchronizeService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/ISynchronizeService.php @@ -2,8 +2,7 @@ namespace Inensus\SteamaMeter\Services; -interface ISynchronizeService -{ +interface ISynchronizeService { public function sync(); public function syncCheck(); diff --git a/src/backend/packages/inensus/steama-meter/src/Services/PackageInstallationService.php b/src/backend/packages/inensus/steama-meter/src/Services/PackageInstallationService.php index 62cb4f3af..e63ccdd9c 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/PackageInstallationService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/PackageInstallationService.php @@ -4,8 +4,7 @@ use Inensus\SteamaMeter\Helpers\ApiHelpers; -class PackageInstallationService -{ +class PackageInstallationService { public function __construct( private SteamaAgentService $agentService, private SteamaCredentialService $credentialService, @@ -19,11 +18,9 @@ public function __construct( private SteamaSmsBodyService $smsBodyService, private SteamaSmsVariableDefaultValueService $defaultValueService, private SteamaSmsFeedbackWordService $steamaSmsFeedbackWordService, - ) { - } + ) {} - public function createDefaultSettingRecords() - { + public function createDefaultSettingRecords() { $this->smsBodyService->createSmsBodies(); $this->defaultValueService->createSmsVariableDefaultValues(); $this->syncSettingService->createDefaultSettings(); diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaAgentService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaAgentService.php index 1be7e4499..e89962357 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaAgentService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaAgentService.php @@ -16,19 +16,29 @@ use Inensus\SteamaMeter\Models\SteamaSite; use Inensus\SteamaMeter\Models\SyncStatus; -class SteamaAgentService implements ISynchronizeService -{ +class SteamaAgentService implements ISynchronizeService { private $agentCommission; + private $agent; + private $stmAgent; + private $steamaApi; + private $apiHelpers; + private $rootUrl = '/agents'; + private $person; + private $addressService; + private $site; + private $address; + private $steamaSyncSettingService; + private $steamaSyncActionService; public function __construct( @@ -57,23 +67,20 @@ public function __construct( $this->steamaSyncActionService = $steamaSyncActionService; } - public function getAgents($request) - { + public function getAgents($request) { $perPage = $request->input('per_page') ?? 15; return $this->stmAgent->newQuery()->with(['mpmAgent.person.addresses', 'site.mpmMiniGrid'])->paginate($perPage); } - public function getAgentsCount() - { + public function getAgentsCount() { return count($this->agent->newQuery()->get()); } /** * This function uses one time on installation of the package. */ - public function createSteamaAgentCommission() - { + public function createSteamaAgentCommission() { $agentCommission = $this->agentCommission->newQuery()->where('name', 'Steama Agent Comission')->first(); if (!$agentCommission) { $agentCommission = $this->agentCommission->newQuery()->create([ @@ -87,8 +94,7 @@ public function createSteamaAgentCommission() return $agentCommission; } - public function sync() - { + public function sync() { $synSetting = $this->steamaSyncSettingService->getSyncSettingsByActionName('Agents'); $syncAction = $this->steamaSyncActionService->getSyncActionBySynSettingId($synSetting->id); try { @@ -136,8 +142,7 @@ public function sync() } } - public function syncCheck($returnData = false) - { + public function syncCheck($returnData = false) { try { $url = $this->rootUrl.'?page=1&page_size=100'; $result = $this->steamaApi->get($url); @@ -185,8 +190,7 @@ public function syncCheck($returnData = false) return $returnData ? ['data' => $agentsCollection, 'result' => true] : ['result' => true]; } - public function createRelatedAgent($stmAgent) - { + public function createRelatedAgent($stmAgent) { $person = $this->person->newQuery()->create([ 'name' => $stmAgent['first_name'], 'surname' => $stmAgent['last_name'], @@ -222,8 +226,7 @@ public function createRelatedAgent($stmAgent) return $agent; } - public function updateRelatedAgent($stmAgent, $agent) - { + public function updateRelatedAgent($stmAgent, $agent) { $relatedPerson = $agent->person; $relatedPerson->update([ 'name' => $stmAgent['first_name'], @@ -259,8 +262,7 @@ function ($q) use ($personId) { return $agent; } - private function steamaAgentHasher($steamaAgent) - { + private function steamaAgentHasher($steamaAgent) { return $this->apiHelpers->makeHash([ $steamaAgent['first_name'], $steamaAgent['last_name'], diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaBitharvesterService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaBitharvesterService.php index 09f1dbea9..f23729f86 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaBitharvesterService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaBitharvesterService.php @@ -4,9 +4,9 @@ use Inensus\SteamaMeter\Http\Clients\SteamaMeterApiClient; -class SteamaBitharvesterService -{ +class SteamaBitharvesterService { private $steamaApi; + private $rootUrl = '/bitharvesters'; public function __construct( @@ -15,8 +15,7 @@ public function __construct( $this->steamaApi = $steamaApi; } - public function getBitharvester($siteId) - { + public function getBitharvester($siteId) { $result = $this->steamaApi->get($this->rootUrl); $bitHarvesters = $result['results']; diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaCredentialService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaCredentialService.php index d828bcbd0..e59f5e5b8 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaCredentialService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaCredentialService.php @@ -7,10 +7,11 @@ use Inensus\SteamaMeter\Http\Clients\SteamaMeterApiClient; use Inensus\SteamaMeter\Models\SteamaCredential; -class SteamaCredentialService -{ +class SteamaCredentialService { private $rootUrl = '/get-token/'; + private $credential; + private $steamaApi; public function __construct( @@ -24,8 +25,7 @@ public function __construct( /** * This function uses one time on installation of the package. */ - public function createCredentials() - { + public function createCredentials() { return $this->credential->newQuery()->firstOrCreate(['id' => 1], [ 'username' => null, 'password' => null, @@ -35,13 +35,11 @@ public function createCredentials() ]); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->first(); } - public function updateCredentials($data) - { + public function updateCredentials($data) { $credential = $this->credential->newQuery()->find($data['id']); $credential->update([ diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaCustomerService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaCustomerService.php index e50587ff9..1becf260c 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaCustomerService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaCustomerService.php @@ -23,27 +23,45 @@ use Inensus\SteamaMeter\Models\SteamaUserType; use Inensus\SteamaMeter\Models\SyncStatus; -class SteamaCustomerService implements ISynchronizeService -{ +class SteamaCustomerService implements ISynchronizeService { private $customer; + private $steamaApi; + private $apiHelpers; + private $rootUrl = '/customers'; + private $person; + private $customerBasisPaymentPlan; + private $flatRatePaymentPlan; + private $subscriptionPaymentPlan; + private $hybridPaymentPlan; + private $minimumTopUpPaymentPlan; + private $perKwhPaymentPlan; + private $userType; + private $connectionType; + private $steamaSite; + private $bitharvesterService; + private $stmSite; + private $city; + private $steamaSyncSettingService; + private $steamaSyncActionService; + private $steamaSmsNotifiedCustomerService; public function __construct( @@ -88,20 +106,17 @@ public function __construct( $this->steamaSmsNotifiedCustomerService = $steamaSmsNotifiedCustomerService; } - public function getCustomers($request) - { + public function getCustomers($request) { $perPage = $request->input('per_page') ?? 15; return $this->customer->newQuery()->with(['mpmPerson.addresses', 'site.mpmMiniGrid'])->paginate($perPage); } - public function getCustomersCount() - { + public function getCustomersCount() { return count($this->customer->newQuery()->get()); } - public function sync() - { + public function sync() { $synSetting = $this->steamaSyncSettingService->getSyncSettingsByActionName('Customers'); $syncAction = $this->steamaSyncActionService->getSyncActionBySynSettingId($synSetting->id); try { @@ -160,8 +175,7 @@ public function sync() } } - public function syncCheck($returnData = false) - { + public function syncCheck($returnData = false) { try { $url = $this->rootUrl.'?page=1&page_size=100'; $result = $this->steamaApi->get($url); @@ -208,8 +222,7 @@ public function syncCheck($returnData = false) return $returnData ? ['data' => $customersCollection, 'result' => true] : ['result' => true]; } - public function createRelatedPerson($customer) - { + public function createRelatedPerson($customer) { $personData = [ 'name' => $customer['first_name'] ? $customer['first_name'] : '', 'surname' => $customer['last_name'] ? $customer['last_name'] : '', @@ -237,8 +250,7 @@ public function createRelatedPerson($customer) return $person; } - public function updateRelatedPerson($customer, $person) - { + public function updateRelatedPerson($customer, $person) { $person->update([ 'name' => $customer['first_name'] ? $customer['first_name'] : '', 'surname' => $customer['last_name'] ? $customer['last_name'] : '', @@ -256,8 +268,7 @@ public function updateRelatedPerson($customer, $person) return $person; } - public function createSteamaCustomer($meterInfo) - { + public function createSteamaCustomer($meterInfo) { $miniGrid = $meterInfo->address->city->miniGrid; $steamaSite = $this->steamaSite->newQuery()->where('mpm_mini_grid_id', $miniGrid->id)->first(); $person = $meterInfo->owner; @@ -291,8 +302,7 @@ public function createSteamaCustomer($meterInfo) ]); } - public function syncTransactionCustomer($stmCustomerId) - { + public function syncTransactionCustomer($stmCustomerId) { $url = $this->rootUrl.'/'.strval($stmCustomerId); $customer = $this->steamaApi->get($url); try { @@ -317,8 +327,7 @@ public function syncTransactionCustomer($stmCustomerId) } } - public function updateSteamaCustomerInfo($stmCustomer, $putData) - { + public function updateSteamaCustomerInfo($stmCustomer, $putData) { try { $url = $this->rootUrl.'/'.strval($stmCustomer->customer_id); $updatedSteamaCustomer = $this->steamaApi->patch($url, $putData); @@ -333,8 +342,7 @@ public function updateSteamaCustomerInfo($stmCustomer, $putData) } } - public function searchCustomer($searchTerm, $paginate) - { + public function searchCustomer($searchTerm, $paginate) { if ($paginate === 1) { return $this->customer->newQuery()->with(['mpmPerson.addresses', 'site.mpmMiniGrid']) ->WhereHas('site.mpmMiniGrid', function ($q) use ($searchTerm) { @@ -356,8 +364,7 @@ public function searchCustomer($searchTerm, $paginate) })->get(); } - public function setStmCustomerPaymentPlan($customer) - { + public function setStmCustomerPaymentPlan($customer) { $plan = explode(',', $customer['payment_plan'])[0]; switch ($plan) { @@ -425,8 +432,7 @@ public function setStmCustomerPaymentPlan($customer) } } - public function setFlatRatePlan($customer) - { + public function setFlatRatePlan($customer) { $customerBasisPlan = $this->customerBasisPaymentPlan->newQuery()->make([ 'customer_id' => $customer['id'], ]); @@ -438,8 +444,7 @@ public function setFlatRatePlan($customer) $customerBasisPlan->save(); } - public function setPerKwhPlan($customer) - { + public function setPerKwhPlan($customer) { $customerBasisPlan = $this->customerBasisPaymentPlan->newQuery()->make([ 'customer_id' => $customer['id'], ]); @@ -450,8 +455,7 @@ public function setPerKwhPlan($customer) $customerBasisPlan->save(); } - public function setMinimumTopUpPlan($customer) - { + public function setMinimumTopUpPlan($customer) { $plan = explode(',', $customer['payment_plan']); $threshold = $plan[1]; @@ -465,8 +469,7 @@ public function setMinimumTopUpPlan($customer) $customerBasisPlan->save(); } - public function setSubscriptionPlan($customer) - { + public function setSubscriptionPlan($customer) { $plan = explode(',', $customer['payment_plan']); $fee = $plan[1]; $duration = $plan[2]; @@ -487,8 +490,7 @@ public function setSubscriptionPlan($customer) $customerBasisPlan->save(); } - public function setHybridPlan($customer) - { + public function setHybridPlan($customer) { $plan = explode(',', $customer['payment_plan']); $connectionFee = $plan[1]; $subscriptionCost = $plan[2]; @@ -507,15 +509,13 @@ public function setHybridPlan($customer) $customerBasisPlan->save(); } - public function getSteamaCustomerName($customerId) - { + public function getSteamaCustomerName($customerId) { $stmCustomer = $this->customer->newQuery()->with('mpmPerson')->where('customer_id', $customerId)->first(); return ['name' => $stmCustomer->mpmPerson->name.' '.$stmCustomer->mpmPerson->surname]; } - public function getSteamaCustomersWithAddress() - { + public function getSteamaCustomersWithAddress() { return $this->customer->newQuery()->with([ 'mpmPerson.addresses', ])->whereHas('mpmPerson.addresses', function ($q) { @@ -523,8 +523,7 @@ public function getSteamaCustomersWithAddress() }); } - private function steamaCustomerHasher($steamaCustomer) - { + private function steamaCustomerHasher($steamaCustomer) { return $this->apiHelpers->makeHash([ $steamaCustomer['user_type'], $steamaCustomer['control_type'], @@ -541,12 +540,13 @@ private function steamaCustomerHasher($steamaCustomer) ]); } - public function getSteamaCustomerWithPhone($phoneNumber) - { + public function getSteamaCustomerWithPhone($phoneNumber) { $person = $this->person::with(['addresses']) - ->whereHas('addresses', static function ($q) use ($phoneNumber) { - $q->where('phone', $phoneNumber); - } + ->whereHas( + 'addresses', + static function ($q) use ($phoneNumber) { + $q->where('phone', $phoneNumber); + } )->first(); return $this->customer->newQuery()->with(['site', 'mpmPerson.meters.meter'])->where('mpm_customer_id', $person->id)->first(); diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaMeterReadingService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaMeterReadingService.php index 788f7e6dc..3905cf83f 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaMeterReadingService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaMeterReadingService.php @@ -9,16 +9,16 @@ use Inensus\SteamaMeter\Http\Clients\SteamaMeterApiClient; use Inensus\SteamaMeter\Models\SteamaMeter; -class SteamaMeterReadingService -{ +class SteamaMeterReadingService { private $steamaMeter; + private $steamaApi; + private $meterConsumtion; public function __construct( SteamaMeter $steamaMeter, SteamaMeterApiClient $steamaApi, - MeterConsumption $meterConsumption, ) { $this->steamaMeter = $steamaMeter; @@ -26,8 +26,7 @@ public function __construct( $this->meterConsumtion = $meterConsumption; } - public function getMeterReadingsThroughHourlyWorkingJob() - { + public function getMeterReadingsThroughHourlyWorkingJob() { $now = Carbon::now()->toIso8601ZuluString(); $oneHourEarlier = Carbon::now()->subHours(10)->toIso8601ZuluString(); $this->steamaMeter->newQuery()->get()->each(function ($meter) use ($now, $oneHourEarlier) { @@ -42,7 +41,8 @@ public function getMeterReadingsThroughHourlyWorkingJob() [ 'meter_id' => $meter->mpm_meter_id, 'reading_date' => Carbon::parse($reading['timestamp'])->format('Y-m-d H:i:s'), - ], [ + ], + [ 'meter_id' => $meter->mpm_meter_id, 'total_consumption' => $reading['reading'], 'consumption' => $reading['usage_amount'], diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaMeterService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaMeterService.php index 993a7c394..56366320f 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaMeterService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaMeterService.php @@ -23,8 +23,7 @@ use Inensus\SteamaMeter\Models\SteamaTariff; use Inensus\SteamaMeter\Models\SyncStatus; -class SteamaMeterService implements ISynchronizeService -{ +class SteamaMeterService implements ISynchronizeService { private $rootUrl = '/meters'; public function __construct( @@ -43,11 +42,9 @@ public function __construct( private SteamaTariff $tariff, private SteamaSyncSettingService $steamaSyncSettingService, private StemaSyncActionService $steamaSyncActionService, - ) { - } + ) {} - public function getMeters($request) - { + public function getMeters($request) { $perPage = $request->input('per_page') ?? 15; return $this->stmMeter->newQuery()->with([ @@ -57,13 +54,11 @@ public function getMeters($request) ])->paginate($perPage); } - public function getMetersCount() - { + public function getMetersCount() { return count($this->stmMeter->newQuery()->get()); } - public function sync(): LengthAwarePaginator - { + public function sync(): LengthAwarePaginator { $synSetting = $this->steamaSyncSettingService->getSyncSettingsByActionName('Meters'); $syncAction = $this->steamaSyncActionService->getSyncActionBySynSettingId($synSetting->id); try { @@ -107,8 +102,7 @@ public function sync(): LengthAwarePaginator } } - public function syncCheck($returnData = false) - { + public function syncCheck($returnData = false) { try { $url = $this->rootUrl.'?page=1&page_size=100'; $result = $this->steamaApi->get($url); @@ -156,8 +150,7 @@ public function syncCheck($returnData = false) return $returnData ? ['data' => $metersCollection, 'result' => true] : ['result' => true]; } - public function createRelatedMeter($stmMeter) - { + public function createRelatedMeter($stmMeter) { try { DB::connection('shard')->beginTransaction(); $meterSerial = $stmMeter['reference']; @@ -188,8 +181,8 @@ public function createRelatedMeter($stmMeter) $points = $stmMeter['latitude'].','.$stmMeter['longitude']; } else { $points = explode(',', config('steama.geoLocation')); - $latitude = strval(doubleval($points[0]) - (mt_rand(10, 1000) / 10000)); - $longitude = strval(doubleval($points[1]) - (mt_rand(10, 1000) / 10000)); + $latitude = strval(floatval($points[0]) - (mt_rand(10, 1000) / 10000)); + $longitude = strval(floatval($points[1]) - (mt_rand(10, 1000) / 10000)); $points = $latitude.','.$longitude; } @@ -236,8 +229,7 @@ public function createRelatedMeter($stmMeter) } } - public function updateRelatedMeter($stmMeter, $meter) - { + public function updateRelatedMeter($stmMeter, $meter) { $meterSerial = $stmMeter['reference']; $meter->serial_number = $meterSerial; $meter->meterType()->associate($this->getMeterType($stmMeter)); @@ -260,8 +252,7 @@ public function updateRelatedMeter($stmMeter, $meter) return $meter; } - public function getMeterType($stmMeter) - { + public function getMeterType($stmMeter) { $version = $stmMeter['version']; $usageSpikeThreshold = $stmMeter['usage_spike_threshold']; $stmMeterType = $this->stmMeterType->newQuery()->with('mpmMeterType')->where( @@ -294,8 +285,7 @@ public function getMeterType($stmMeter) } } - public function creteSteamaMeter($meterInfo, $stmCustomer) - { + public function creteSteamaMeter($meterInfo, $stmCustomer) { $geographicalInformation = $meterInfo->address->geo; $points = explode(',', $geographicalInformation); $postParams = [ @@ -316,8 +306,7 @@ public function creteSteamaMeter($meterInfo, $stmCustomer) ]); } - public function updateSteamaMeterInfo($stmMeter, $putParams) - { + public function updateSteamaMeterInfo($stmMeter, $putParams) { $url = '/bitharvesters/'.$stmMeter->bit_harvester_id.$this->rootUrl.'/'.$stmMeter->meter_id.'/'; $meter = $this->steamaApi->patch($url, $putParams); $stmMeterHash = $this->steamaMeterHasher($meter); @@ -328,8 +317,7 @@ public function updateSteamaMeterInfo($stmMeter, $putParams) return $stmMeter->fresh(); } - private function steamaMeterHasher($steamaMeter) - { + private function steamaMeterHasher($steamaMeter) { return $this->apiHelpers->makeHash([ $steamaMeter['reference'], $steamaMeter['version'], diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSettingService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSettingService.php index ba3669eb2..85dbc2abe 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSettingService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSettingService.php @@ -4,17 +4,14 @@ use Inensus\SteamaMeter\Models\SteamaSetting; -class SteamaSettingService -{ +class SteamaSettingService { private $steamaSetting; - public function __construct(SteamaSetting $steamaSetting) - { + public function __construct(SteamaSetting $steamaSetting) { $this->steamaSetting = $steamaSetting; } - public function getSettings() - { + public function getSettings() { return $this->steamaSetting->newQuery()->with(['settingSms', 'settingSync'])->whereHasMorph('setting', '*')->get(); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSiteLevelPaymentPlanTypeService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSiteLevelPaymentPlanTypeService.php index b93ee0489..15b271ca2 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSiteLevelPaymentPlanTypeService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSiteLevelPaymentPlanTypeService.php @@ -4,20 +4,17 @@ use Inensus\SteamaMeter\Models\SteamaSiteLevelPaymentPlanType; -class SteamaSiteLevelPaymentPlanTypeService -{ +class SteamaSiteLevelPaymentPlanTypeService { private $paymentPlanType; - public function __construct(SteamaSiteLevelPaymentPlanType $paymentPlanTypeModel) - { + public function __construct(SteamaSiteLevelPaymentPlanType $paymentPlanTypeModel) { $this->paymentPlanType = $paymentPlanTypeModel; } /** * This function uses one time on installation of the package. */ - public function createPaymentPlans() - { + public function createPaymentPlans() { $paymentPlans = [ 'Credit Bundles', 'Time-of-use Pricing', diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSiteService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSiteService.php index 538ebf33a..83540c232 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSiteService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSiteService.php @@ -13,17 +13,25 @@ use Inensus\SteamaMeter\Models\SteamaSite; use Inensus\SteamaMeter\Models\SyncStatus; -class SteamaSiteService implements ISynchronizeService -{ +class SteamaSiteService implements ISynchronizeService { private $site; + private $steamaApi; + private $apiHelpers; + private $rootUrl = '/sites'; + private $miniGrid; + private $cluster; + private $geographicalInformation; + private $city; + private $steamaSyncSettingService; + private $steamaSyncActionService; public function __construct( @@ -48,20 +56,17 @@ public function __construct( $this->steamaSyncActionService = $steamaSyncActionService; } - public function getSites($request) - { + public function getSites($request) { $perPage = $request->input('per_page') ?? 15; return $this->site->newQuery()->with('mpmMiniGrid.location')->paginate($perPage); } - public function getSitesCount() - { + public function getSitesCount() { return count($this->site->newQuery()->get()); } - public function sync() - { + public function sync() { $synSetting = $this->steamaSyncSettingService->getSyncSettingsByActionName('Sites'); $syncAction = $this->steamaSyncActionService->getSyncActionBySynSettingId($synSetting->id); try { @@ -100,8 +105,7 @@ public function sync() } } - public function syncCheck($returnData = false) - { + public function syncCheck($returnData = false) { try { $url = $this->rootUrl.'?page=1&page_size=100'; $result = $this->steamaApi->get($url); @@ -151,8 +155,7 @@ public function syncCheck($returnData = false) return $returnData ? ['data' => $sitesCollection, 'result' => true] : ['result' => true]; } - public function creteRelatedMiniGrid($site) - { + public function creteRelatedMiniGrid($site) { $cluster = $this->cluster->newQuery()->latest('created_at')->first(); $miniGrid = $this->miniGrid->newQuery()->create([ 'name' => $site['name'], @@ -167,8 +170,7 @@ public function creteRelatedMiniGrid($site) return $miniGrid; } - public function updateRelatedMiniGrid($site, $miniGrid) - { + public function updateRelatedMiniGrid($site, $miniGrid) { $miniGrid->update([ 'name' => $site['name'], ]); @@ -176,8 +178,7 @@ public function updateRelatedMiniGrid($site, $miniGrid) return $miniGrid->fresh(); } - public function createOrUpdateGeographicalInformation($miniGridId, $site) - { + public function createOrUpdateGeographicalInformation($miniGridId, $site) { $geographicalInformation = $this->geographicalInformation->newQuery()->whereHasMorph( 'owner', [MiniGrid::class], @@ -201,13 +202,11 @@ static function ($q) use ($miniGridId) { } } - public function checkLocationAvailability() - { + public function checkLocationAvailability() { return $this->cluster->newQuery()->latest('created_at')->first(); } - private function steamaSiteHasher($steamaSite) - { + private function steamaSiteHasher($steamaSite) { return $this->apiHelpers->makeHash([ $steamaSite['name'], $steamaSite['latitude'], diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsBodyService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsBodyService.php index acebec7e9..56d0b6584 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsBodyService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsBodyService.php @@ -4,27 +4,22 @@ use Inensus\SteamaMeter\Models\SteamaSmsBody; -class SteamaSmsBodyService -{ +class SteamaSmsBodyService { private $smsBody; - public function __construct(SteamaSmsBody $smsBody) - { + public function __construct(SteamaSmsBody $smsBody) { $this->smsBody = $smsBody; } - public function getSmsBodyByReference($reference) - { + public function getSmsBodyByReference($reference) { return $this->smsBody->newQuery()->where('reference', $reference)->firstOrFail(); } - public function getSmsBodies() - { + public function getSmsBodies() { return $this->smsBody->newQuery()->get(); } - public function updateSmsBodies($smsBodiesData) - { + public function updateSmsBodies($smsBodiesData) { $smsBodies = $this->smsBody->newQuery()->get(); collect($smsBodiesData)->each(function ($smsBody) use ($smsBodies) { $smsBodies->filter(function ($body) use ($smsBody) { @@ -37,13 +32,11 @@ public function updateSmsBodies($smsBodiesData) return $smsBodies; } - public function getNullBodies() - { + public function getNullBodies() { return $this->smsBody->newQuery()->whereNull('body')->get(); } - public function createSmsBodies() - { + public function createSmsBodies() { $smsBodies = [ [ 'reference' => 'SteamaSmsLowBalanceHeader', diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsFeedbackWordService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsFeedbackWordService.php index aea962ba9..e2d8a28e7 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsFeedbackWordService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsFeedbackWordService.php @@ -4,29 +4,24 @@ use Inensus\SteamaMeter\Models\SteamaSmsFeedbackWord; -class SteamaSmsFeedbackWordService -{ +class SteamaSmsFeedbackWordService { private $smsFeedbackWord; - public function __construct(SteamaSmsFeedbackWord $smsFeedbackWord) - { + public function __construct(SteamaSmsFeedbackWord $smsFeedbackWord) { $this->smsFeedbackWord = $smsFeedbackWord; } - public function getSmsFeedbackWords() - { + public function getSmsFeedbackWords() { return $this->smsFeedbackWord->newQuery()->get(); } - public function createSmsFeedbackWord() - { + public function createSmsFeedbackWord() { return $this->smsFeedbackWord->newQuery()->firstOrCreate(['id' => 1], [ 'meter_balance' => null, ]); } - public function updateSmsFeedbackWord($smsFeedbackWord, $smsFeedbackWordData) - { + public function updateSmsFeedbackWord($smsFeedbackWord, $smsFeedbackWordData) { $smsFeedbackWord->update([ 'meter_balance' => $smsFeedbackWordData['meter_balance'], ]); diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsNotifiedCustomerService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsNotifiedCustomerService.php index 6a7ed3367..3f6626dad 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsNotifiedCustomerService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsNotifiedCustomerService.php @@ -4,8 +4,7 @@ use Inensus\SteamaMeter\Models\SteamaSmsNotifiedCustomer; -class SteamaSmsNotifiedCustomerService -{ +class SteamaSmsNotifiedCustomerService { private $steamaSmsNotifiedCustomer; public function __construct( @@ -14,13 +13,11 @@ public function __construct( $this->steamaSmsNotifiedCustomer = $steamaSmsNotifiedCustomer; } - public function getSteamaSmsNotifiedCustomers() - { + public function getSteamaSmsNotifiedCustomers() { return $this->steamaSmsNotifiedCustomer->newQuery()->get(); } - public function createTransactionSmsNotify($customerId, $transactionId) - { + public function createTransactionSmsNotify($customerId, $transactionId) { return $this->steamaSmsNotifiedCustomer->newQuery()->create([ 'customer_id' => $customerId, 'notify_type' => 'transaction', @@ -28,16 +25,14 @@ public function createTransactionSmsNotify($customerId, $transactionId) ]); } - public function createLowBalanceSmsNotify($customerId) - { + public function createLowBalanceSmsNotify($customerId) { return $this->steamaSmsNotifiedCustomer->newQuery()->create([ 'customer_id' => $customerId, 'notify_type' => 'low_balance', ]); } - public function removeLowBalancedCustomer($customer) - { + public function removeLowBalancedCustomer($customer) { if ($customer['low_balance_warning'] >= $customer['account_balance']) { return false; } diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsSettingService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsSettingService.php index a74545a2d..dd3dd1cc4 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsSettingService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsSettingService.php @@ -5,19 +5,17 @@ use Inensus\SteamaMeter\Models\SteamaSetting; use Inensus\SteamaMeter\Models\SteamaSmsSetting; -class SteamaSmsSettingService -{ +class SteamaSmsSettingService { private $smsSetting; + private $setting; - public function __construct(SteamaSmsSetting $smsSetting, SteamaSetting $setting) - { + public function __construct(SteamaSmsSetting $smsSetting, SteamaSetting $setting) { $this->smsSetting = $smsSetting; $this->setting = $setting; } - public function createDefaultSettings() - { + public function createDefaultSettings() { $smsTransaction = $this->smsSetting->newQuery()->where('state', 'Transactions')->first(); if (!$smsTransaction) { $smsSetting = $this->setting->newQuery()->make(); @@ -40,8 +38,7 @@ public function createDefaultSettings() } } - public function updateSmsSettings($smsSettings) - { + public function updateSmsSettings($smsSettings) { foreach ($smsSettings as $key => $setting) { $smsSetting = $this->smsSetting->newQuery()->find($setting['id']); if ($smsSetting) { @@ -55,8 +52,7 @@ public function updateSmsSettings($smsSettings) return $this->smsSetting->newQuery()->get(); } - public function getSmsSettings() - { + public function getSmsSettings() { return $this->smsSetting->newQuery()->get(); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsVariableDefaultValueService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsVariableDefaultValueService.php index b770b2f0b..7d591be2d 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsVariableDefaultValueService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSmsVariableDefaultValueService.php @@ -4,22 +4,18 @@ use Inensus\SteamaMeter\Models\SteamaSmsVariableDefaultValue; -class SteamaSmsVariableDefaultValueService -{ +class SteamaSmsVariableDefaultValueService { private $smsVariableDefaultValue; - public function __construct(SteamaSmsVariableDefaultValue $smsVariableDefaultValue) - { + public function __construct(SteamaSmsVariableDefaultValue $smsVariableDefaultValue) { $this->smsVariableDefaultValue = $smsVariableDefaultValue; } - public function getSmsVariableDefaultValues() - { + public function getSmsVariableDefaultValues() { return $this->smsVariableDefaultValue->newQuery()->get(); } - public function createSmsVariableDefaultValues() - { + public function createSmsVariableDefaultValues() { $smsVariableDefaultValues = [ [ 'variable' => 'name', @@ -40,8 +36,10 @@ public function createSmsVariableDefaultValues() ]; collect($smsVariableDefaultValues)->each(function ($variable) { $this->smsVariableDefaultValue->newQuery() - ->firstOrCreate(['variable' => $variable['variable']], - $variable); + ->firstOrCreate( + ['variable' => $variable['variable']], + $variable + ); }); } } diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSyncSettingService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSyncSettingService.php index d109c6153..3be5657a7 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaSyncSettingService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaSyncSettingService.php @@ -8,10 +8,11 @@ use Inensus\SteamaMeter\Models\SteamaSetting; use Inensus\SteamaMeter\Models\SteamaSyncSetting; -class SteamaSyncSettingService -{ +class SteamaSyncSettingService { private $syncSetting; + private $setting; + private $syncActionService; public function __construct( @@ -24,8 +25,7 @@ public function __construct( $this->syncActionService = $syncActionService; } - public function createDefaultSettings() - { + public function createDefaultSettings() { $dayInterval = CarbonInterval::make('1day'); $fiveMinInterval = CarbonInterval::make('5minute'); @@ -121,8 +121,7 @@ public function createDefaultSettings() } } - public function updateSyncSettings($syncSettings) - { + public function updateSyncSettings($syncSettings) { foreach ($syncSettings as $setting) { $syncSetting = $this->syncSetting->newQuery()->find($setting['id']); $intervalStr = $setting['sync_in_value_num'].$setting['sync_in_value_str']; @@ -147,13 +146,11 @@ public function updateSyncSettings($syncSettings) return $this->syncSetting->newQuery()->get(); } - public function getSyncSettings() - { + public function getSyncSettings() { return $this->syncSetting->newQuery()->get(); } - public function getSyncSettingsByActionName($actionName) - { + public function getSyncSettingsByActionName($actionName) { try { return $this->syncSetting->newQuery()->where('action_name', $actionName)->firstOrFail(); } catch (\Exception $exception) { diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaTariffService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaTariffService.php index e0341571f..d925dbf2d 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaTariffService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaTariffService.php @@ -5,17 +5,13 @@ use App\Models\Meter\MeterTariff; use Inensus\SteamaMeter\Models\SteamaTariff; -class SteamaTariffService -{ - public function __construct(private readonly SteamaTariff $tariff, private readonly MeterTariff $meterTariff) - { - } +class SteamaTariffService { + public function __construct(private readonly SteamaTariff $tariff, private readonly MeterTariff $meterTariff) {} /** * This function uses one time on installation of the package. */ - public function createTariff() - { + public function createTariff() { $meterTariff = $this->meterTariff->newQuery()->where('name', 'Steama External Tariff')->first(); if (!$meterTariff) { $meterTariff = $this->meterTariff->newQuery()->create([ diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaTransactionsService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaTransactionsService.php index bd5824944..0550c83ec 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaTransactionsService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaTransactionsService.php @@ -13,22 +13,35 @@ use Inensus\SteamaMeter\Models\SteamaMeter; use Inensus\SteamaMeter\Models\SteamaTransaction; -class SteamaTransactionsService implements ISynchronizeService -{ +class SteamaTransactionsService implements ISynchronizeService { private $stemaMeterService; + private $steamaCustomerService; + private $steamaCredentialService; + private $steamaSiteService; + private $steamaAgentService; + private $steamaTransaction; + private $steamaMeter; + private $steamaApi; + private $thirdPartyTransaction; + private $rootUrl = '/transactions'; + private $transaction; + private $meterToken; + private $steamaCustomer; + private $steamaSyncSettingService; + private $steamaSyncActionService; public function __construct( @@ -63,8 +76,7 @@ public function __construct( $this->steamaSyncActionService = $steamaSyncActionService; } - public function sync() - { + public function sync() { $synSetting = $this->steamaSyncSettingService->getSyncSettingsByActionName('Transactions'); $syncAction = $this->steamaSyncActionService->getSyncActionBySynSettingId($synSetting->id); $syncCheck = $this->syncCheck(); @@ -132,8 +144,7 @@ public function sync() return $syncCheck['message']; } - public function syncCheck() - { + public function syncCheck() { $credentials = $this->steamaCredentialService->getCredentials(); if ($credentials) { if ($credentials->is_authenticated) { @@ -169,15 +180,13 @@ public function syncCheck() } } - public function getTransactionsByCustomer($customer, $request) - { + public function getTransactionsByCustomer($customer, $request) { $perPage = $request->input('per_page') ?? 15; return $this->steamaTransaction->newQuery()->where('customer_id', $customer)->paginate($perPage); } - public function getSteamaTransactions($transactionMin) - { + public function getSteamaTransactions($transactionMin) { return $this->steamaTransaction->newQuery()->with(['thirdPartyTransaction.transaction'])->where( 'timestamp', '>=', @@ -185,8 +194,7 @@ public function getSteamaTransactions($transactionMin) )->where('category', 'PAY')->get(); } - private function createSteamaTransaction($transaction) - { + private function createSteamaTransaction($transaction) { return $this->steamaTransaction->newQuery()->create([ 'transaction_id' => $transaction['id'], 'site_id' => $transaction['site_id'], @@ -199,8 +207,7 @@ private function createSteamaTransaction($transaction) ]); } - private function createThirdPartyTransaction($transaction, $steamaTransaction) - { + private function createThirdPartyTransaction($transaction, $steamaTransaction) { $thirdPartyTransaction = $this->thirdPartyTransaction->newQuery()->make([ 'transaction_id' => $transaction['id'], 'status' => $transaction['reversed_by_id'] !== null ? -1 : 1, @@ -213,8 +220,7 @@ private function createThirdPartyTransaction($transaction, $steamaTransaction) return $thirdPartyTransaction; } - private function createTransaction($transaction, $thirdPartyTransaction, $steamaMeter) - { + private function createTransaction($transaction, $thirdPartyTransaction, $steamaMeter) { $transaction = $this->transaction->newQuery()->make([ 'amount' => (int) $transaction['amount'], 'sender' => $transaction['customer_telephone'], @@ -229,8 +235,7 @@ private function createTransaction($transaction, $thirdPartyTransaction, $steama return $transaction; } - private function createToken($steamaMeter, $mainTransaction, $transaction) - { + private function createToken($steamaMeter, $mainTransaction, $transaction) { $stmCustomer = $steamaMeter->stmCustomer->first(); $customerEnergyPrice = $stmCustomer->energy_price; $chargedEnergy = $mainTransaction->amount / $customerEnergyPrice; @@ -252,8 +257,7 @@ private function createToken($steamaMeter, $mainTransaction, $transaction) return $token; } - private function createPayment($steamaMeter, $mainTransaction, $token) - { + private function createPayment($steamaMeter, $mainTransaction, $token) { $owner = $steamaMeter->mpmMeter->meterParameter->owner; if ($owner) { diff --git a/src/backend/packages/inensus/steama-meter/src/Services/SteamaUserTypeService.php b/src/backend/packages/inensus/steama-meter/src/Services/SteamaUserTypeService.php index 539c0edd5..211976f4a 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/SteamaUserTypeService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/SteamaUserTypeService.php @@ -6,10 +6,11 @@ use App\Models\SubConnectionType; use Inensus\SteamaMeter\Models\SteamaUserType; -class SteamaUserTypeService -{ +class SteamaUserTypeService { private $connectionType; + private $userType; + private $subConnectionType; public function __construct( @@ -25,8 +26,7 @@ public function __construct( /** * This function uses one time on installation of the package. */ - public function createUserTypes($tariff) - { + public function createUserTypes($tariff) { $connectionTypes = [ 'NA' => 'Not Specified', 'RES' => 'Residential', diff --git a/src/backend/packages/inensus/steama-meter/src/Services/StemaSyncActionService.php b/src/backend/packages/inensus/steama-meter/src/Services/StemaSyncActionService.php index f298b6146..2a2c50422 100644 --- a/src/backend/packages/inensus/steama-meter/src/Services/StemaSyncActionService.php +++ b/src/backend/packages/inensus/steama-meter/src/Services/StemaSyncActionService.php @@ -6,32 +6,26 @@ use Carbon\CarbonInterval; use Inensus\SteamaMeter\Models\SteamaSyncAction; -class StemaSyncActionService -{ +class StemaSyncActionService { private $syncAction; - public function __construct(SteamaSyncAction $syncAction) - { + public function __construct(SteamaSyncAction $syncAction) { $this->syncAction = $syncAction; } - public function createSyncAction($syncAction) - { + public function createSyncAction($syncAction) { return $this->syncAction->newQuery()->create($syncAction); } - public function getSyncActionBySynSettingId($settingId) - { + public function getSyncActionBySynSettingId($settingId) { return $this->syncAction->newQuery()->where('sync_setting_id', $settingId)->first(); } - public function getActionsNeedsToSync() - { + public function getActionsNeedsToSync() { return $this->syncAction->newQuery()->where('next_sync', '<=', Carbon::now())->orderBy('next_sync')->get(); } - public function updateSyncAction($syncAction, $syncSetting, $syncResult) - { + public function updateSyncAction($syncAction, $syncSetting, $syncResult) { if (!$syncResult) { return $syncAction->update([ 'attempts' => $syncAction->attempts + 1, diff --git a/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsBalanceFeedbackBody.php b/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsBalanceFeedbackBody.php index f15d7939d..e91626dda 100644 --- a/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsBalanceFeedbackBody.php +++ b/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsBalanceFeedbackBody.php @@ -5,18 +5,16 @@ use App\Sms\BodyParsers\SmsBodyParser; use Inensus\SteamaMeter\Models\SteamaCustomer; -class SteamaSmsBalanceFeedbackBody extends SmsBodyParser -{ +class SteamaSmsBalanceFeedbackBody extends SmsBodyParser { protected $variables = ['account_balance']; + protected $steamaCustomer; - public function __construct(SteamaCustomer $steamaCustomer) - { + public function __construct(SteamaCustomer $steamaCustomer) { $this->steamaCustomer = $steamaCustomer; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'account_balance': $variable = $this->steamaCustomer->account_balance; diff --git a/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsBalanceFeedbackHeader.php b/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsBalanceFeedbackHeader.php index 961ca39f6..2f0b68fa5 100644 --- a/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsBalanceFeedbackHeader.php +++ b/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsBalanceFeedbackHeader.php @@ -5,18 +5,16 @@ use App\Sms\BodyParsers\SmsBodyParser; use Inensus\SteamaMeter\Models\SteamaCustomer; -class SteamaSmsBalanceFeedbackHeader extends SmsBodyParser -{ +class SteamaSmsBalanceFeedbackHeader extends SmsBodyParser { protected $variables = ['name', 'surname']; + protected $steamaCustomer; - public function __construct(SteamaCustomer $steamaCustomer) - { + public function __construct(SteamaCustomer $steamaCustomer) { $this->steamaCustomer = $steamaCustomer; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'name': $variable = $this->steamaCustomer->mpmPerson->name; diff --git a/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsLowBalanceBody.php b/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsLowBalanceBody.php index 9c02dfcd0..652ad972e 100644 --- a/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsLowBalanceBody.php +++ b/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsLowBalanceBody.php @@ -5,18 +5,16 @@ use App\Sms\BodyParsers\SmsBodyParser; use Inensus\SteamaMeter\Models\SteamaCustomer; -class SteamaSmsLowBalanceBody extends SmsBodyParser -{ +class SteamaSmsLowBalanceBody extends SmsBodyParser { protected $variables = ['low_balance_warning', 'account_balance']; + protected $steamaCustomer; - public function __construct(SteamaCustomer $steamaCustomer) - { + public function __construct(SteamaCustomer $steamaCustomer) { $this->steamaCustomer = $steamaCustomer; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'low_balance_warning': $variable = $this->steamaCustomer->low_balance_warning; diff --git a/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsLowBalanceHeader.php b/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsLowBalanceHeader.php index 5c5fc5de3..22349118a 100644 --- a/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsLowBalanceHeader.php +++ b/src/backend/packages/inensus/steama-meter/src/Sms/BodyParsers/SteamaSmsLowBalanceHeader.php @@ -5,18 +5,16 @@ use App\Sms\BodyParsers\SmsBodyParser; use Inensus\SteamaMeter\Models\SteamaCustomer; -class SteamaSmsLowBalanceHeader extends SmsBodyParser -{ +class SteamaSmsLowBalanceHeader extends SmsBodyParser { protected $variables = ['name', 'surname']; + protected $steamaCustomer; - public function __construct(SteamaCustomer $steamaCustomer) - { + public function __construct(SteamaCustomer $steamaCustomer) { $this->steamaCustomer = $steamaCustomer; } - protected function getVariableValue($variable) - { + protected function getVariableValue($variable) { switch ($variable) { case 'name': $variable = $this->steamaCustomer->mpmPerson->name; diff --git a/src/backend/packages/inensus/steama-meter/src/Sms/Senders/BalanceFeedback.php b/src/backend/packages/inensus/steama-meter/src/Sms/Senders/BalanceFeedback.php index 444b3120d..0b80eba09 100644 --- a/src/backend/packages/inensus/steama-meter/src/Sms/Senders/BalanceFeedback.php +++ b/src/backend/packages/inensus/steama-meter/src/Sms/Senders/BalanceFeedback.php @@ -4,8 +4,7 @@ use App\Sms\Senders\SmsSender; -class BalanceFeedback extends SmsSender -{ +class BalanceFeedback extends SmsSender { protected $references = [ 'header' => 'SteamaSmsBalanceFeedbackHeader', 'body' => 'SteamaSmsBalanceFeedbackBody', diff --git a/src/backend/packages/inensus/steama-meter/src/Sms/Senders/LowBalanceLimitNotifier.php b/src/backend/packages/inensus/steama-meter/src/Sms/Senders/LowBalanceLimitNotifier.php index 6eacaef8d..f7ad4fe1f 100644 --- a/src/backend/packages/inensus/steama-meter/src/Sms/Senders/LowBalanceLimitNotifier.php +++ b/src/backend/packages/inensus/steama-meter/src/Sms/Senders/LowBalanceLimitNotifier.php @@ -4,8 +4,7 @@ use App\Sms\Senders\SmsSender; -class LowBalanceLimitNotifier extends SmsSender -{ +class LowBalanceLimitNotifier extends SmsSender { protected $references = [ 'header' => 'SteamaSmsLowBalanceHeader', 'body' => 'SteamaSmsLowBalanceBody', diff --git a/src/backend/packages/inensus/steama-meter/src/Sms/Senders/SteamaSmsConfig.php b/src/backend/packages/inensus/steama-meter/src/Sms/Senders/SteamaSmsConfig.php index 74bc11cae..29f98709d 100644 --- a/src/backend/packages/inensus/steama-meter/src/Sms/Senders/SteamaSmsConfig.php +++ b/src/backend/packages/inensus/steama-meter/src/Sms/Senders/SteamaSmsConfig.php @@ -5,12 +5,13 @@ use App\Sms\Senders\SmsConfigsCore; use Inensus\SteamaMeter\Sms\SteamaSmsTypes; -class SteamaSmsConfig extends SmsConfigsCore -{ +class SteamaSmsConfig extends SmsConfigsCore { public $smsTypes = [ SteamaSmsTypes::LOW_BALANCE_LIMIT_NOTIFIER => 'Inensus\SteamaMeter\Sms\Senders\LowBalanceLimitNotifier', SteamaSmsTypes::BALANCE_FEEDBACK => 'Inensus\SteamaMeter\Sms\Senders\BalanceFeedback', ]; + public $bodyParsersPath = 'Inensus\\SteamaMeter\\Sms\\BodyParsers\\'; + public $servicePath = 'Inensus\SteamaMeter\Services\SteamaSmsBodyService'; } diff --git a/src/backend/packages/inensus/steama-meter/src/Sms/SteamaSmsTypes.php b/src/backend/packages/inensus/steama-meter/src/Sms/SteamaSmsTypes.php index 27daf9c8a..63ff24721 100644 --- a/src/backend/packages/inensus/steama-meter/src/Sms/SteamaSmsTypes.php +++ b/src/backend/packages/inensus/steama-meter/src/Sms/SteamaSmsTypes.php @@ -2,8 +2,8 @@ namespace Inensus\SteamaMeter\Sms; -class SteamaSmsTypes -{ +class SteamaSmsTypes { public const LOW_BALANCE_LIMIT_NOTIFIER = 1; + public const BALANCE_FEEDBACK = 2; } diff --git a/src/backend/packages/inensus/steama-meter/src/SteamaMeterApi.php b/src/backend/packages/inensus/steama-meter/src/SteamaMeterApi.php index 0eca704df..649672abe 100644 --- a/src/backend/packages/inensus/steama-meter/src/SteamaMeterApi.php +++ b/src/backend/packages/inensus/steama-meter/src/SteamaMeterApi.php @@ -14,8 +14,7 @@ use Inensus\SteamaMeter\Services\SteamaCredentialService; use Inensus\SteamaMeter\Services\SteamaCustomerService; -class SteamaMeterApi implements IManufacturerAPI -{ +class SteamaMeterApi implements IManufacturerAPI { protected $api; public function __construct( @@ -28,8 +27,7 @@ public function __construct( $this->api = $httpClient; } - public function chargeDevice(TransactionDataContainer $transactionContainer): array - { + public function chargeDevice(TransactionDataContainer $transactionContainer): array { $owner = $transactionContainer->device->person; $stmCustomer = $this->steamaCustomer->newQuery()->with('paymentPlans')->where( @@ -107,7 +105,5 @@ public function chargeDevice(TransactionDataContainer $transactionContainer): ar } } - public function clearDevice(Device $device) - { - } + public function clearDevice(Device $device) {} } diff --git a/src/backend/packages/inensus/steama-meter/src/Tests/Feature/SendSms.php b/src/backend/packages/inensus/steama-meter/src/Tests/Feature/SendSms.php index 9ecf1d300..deade5706 100644 --- a/src/backend/packages/inensus/steama-meter/src/Tests/Feature/SendSms.php +++ b/src/backend/packages/inensus/steama-meter/src/Tests/Feature/SendSms.php @@ -18,13 +18,11 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class SendSms extends TestCase -{ +class SendSms extends TestCase { use RefreshDatabase; /** @test */ - public function isMeterBalanceFeedbackSend() - { + public function isMeterBalanceFeedbackSend() { Queue::fake(); Config::set('app.debug', false); $this->withoutExceptionHandling(); @@ -40,8 +38,7 @@ public function isMeterBalanceFeedbackSend() $this->assertEquals(2, $smsCount); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); @@ -49,8 +46,7 @@ public function actingAs($user, $driver = null) return $this; } - private function initializeData() - { + private function initializeData() { $this->addSmsBodies(); $this->addFeedBackKeys(); factory(MainSettings::class)->create(); @@ -89,8 +85,7 @@ private function initializeData() return ['customer' => $p]; } - private function addSmsBodies() - { + private function addSmsBodies() { $bodies = [ [ 'reference' => 'SmsTransactionHeader', @@ -240,8 +235,7 @@ private function addSmsBodies() return SmsBody::query()->get(); } - private function addFeedBackKeys() - { + private function addFeedBackKeys() { SteamaSmsFeedbackWord::query()->create([ 'meter_balance' => 'Balance', ]); diff --git a/src/backend/packages/inensus/steama-meter/src/Tests/Unit/SmsNotifyTest.php b/src/backend/packages/inensus/steama-meter/src/Tests/Unit/SmsNotifyTest.php index 04413f28d..707a850bb 100644 --- a/src/backend/packages/inensus/steama-meter/src/Tests/Unit/SmsNotifyTest.php +++ b/src/backend/packages/inensus/steama-meter/src/Tests/Unit/SmsNotifyTest.php @@ -33,13 +33,11 @@ use Inensus\SteamaMeter\Sms\SteamaSmsTypes; use Tests\TestCase; -class SmsNotifyTest extends TestCase -{ +class SmsNotifyTest extends TestCase { use RefreshDatabase; /** @test */ - public function isLowBalanceNotifySend() - { + public function isLowBalanceNotifySend() { Queue::fake(); $this->initializeData(); $lowBalanceMin = SteamaSmsSetting::query()->where( @@ -91,8 +89,7 @@ public function isLowBalanceNotifySend() } /** @test */ - public function isTransactionNotifySend() - { + public function isTransactionNotifySend() { Queue::fake(); $data = $this->initializeData(); $this->initializeSteamaTransaction($data['customer'], $data['meter']); @@ -148,8 +145,7 @@ public function isTransactionNotifySend() } /** @test */ - public function isMaxAttemptNotifySend() - { + public function isMaxAttemptNotifySend() { Queue::fake(); $this->addSyncSettings(); $this->initializeAdminData(); @@ -191,8 +187,7 @@ public function isMaxAttemptNotifySend() $this->assertLessThan($oldNextSync, $newNextSync); } - private function initializeData() - { + private function initializeData() { $this->addSmsSettings(); $this->addSmsBodies(); // create person @@ -262,8 +257,7 @@ private function initializeData() return ['customer' => $p, 'meter' => $steamaMeter]; } - private function initializeSteamaTransaction($customer, $steamaMeter) - { + private function initializeSteamaTransaction($customer, $steamaMeter) { $steamaTransaction = SteamaTransaction::query()->create([ 'transaction_id' => '1111', 'site_id' => 1, @@ -295,8 +289,7 @@ private function initializeSteamaTransaction($customer, $steamaMeter) $transaction->save(); } - private function initializeAdminData() - { + private function initializeAdminData() { $user = factory(User::class)->create(); $address = Address::query()->make([ 'phone' => '+905396398161', @@ -307,8 +300,7 @@ private function initializeAdminData() $address->save(); } - private function addSmsSettings() - { + private function addSmsSettings() { $smsSetting = SteamaSetting::query()->make(); $smsTransaction = SteamaSmsSetting::query()->create([ @@ -332,8 +324,7 @@ private function addSmsSettings() $balanceSetting->save(); } - private function addSyncSettings() - { + private function addSyncSettings() { $minInterval = CarbonInterval::make('1minute'); $now = Carbon::now(); $siteSetting = SteamaSetting::query()->make(); @@ -353,8 +344,7 @@ private function addSyncSettings() SteamaSyncAction::query()->create($syncAction); } - private function addSmsBodies() - { + private function addSmsBodies() { $bodies = [ [ 'reference' => 'SmsTransactionHeader', diff --git a/src/backend/packages/inensus/stron-meter/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/stron-meter/src/Console/Commands/InstallPackage.php index c4f510335..76ce6d5c5 100644 --- a/src/backend/packages/inensus/stron-meter/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/stron-meter/src/Console/Commands/InstallPackage.php @@ -6,9 +6,9 @@ use Inensus\StronMeter\Helpers\ApiHelpers; use Inensus\StronMeter\Services\StronCredentialService; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'stron-meter:install'; + protected $description = 'Install StronMeter Package'; public function __construct( @@ -18,16 +18,14 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing Stron Meter Integration Package\n'); $this->apiHelpers->registerStronMeterManufacturer(); $this->credentialService->createCredentials(); $this->info('Package installed successfully..'); } - private function publishMigrations() - { + private function publishMigrations() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\StronMeter\Providers\StronMeterServiceProvider", @@ -35,14 +33,12 @@ private function publishMigrations() ]); } - private function createDatabaseTables() - { + private function createDatabaseTables() { $this->info('Creating database tables\n'); $this->call('migrate'); } - private function publishVueFiles() - { + private function publishVueFiles() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\StronMeter\Providers\StronMeterServiceProvider", @@ -50,8 +46,7 @@ private function publishVueFiles() ]); } - private function createPluginRecord() - { + private function createPluginRecord() { $this->call('plugin:add', [ 'name' => 'StronMeter', 'composer_name' => 'inensus/stron-meter', diff --git a/src/backend/packages/inensus/stron-meter/src/Console/Commands/UpdatePackage.php b/src/backend/packages/inensus/stron-meter/src/Console/Commands/UpdatePackage.php index 2769774e6..a6fba8014 100644 --- a/src/backend/packages/inensus/stron-meter/src/Console/Commands/UpdatePackage.php +++ b/src/backend/packages/inensus/stron-meter/src/Console/Commands/UpdatePackage.php @@ -7,9 +7,9 @@ use Illuminate\Support\Facades\DB; use Inensus\StronMeter\Services\StronCredentialService; -class UpdatePackage extends Command -{ +class UpdatePackage extends Command { protected $signature = 'stron-meter:update'; + protected $description = 'Update StronMeter Package'; public function __construct( @@ -19,8 +19,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Stron Meter Integration Updating Started\n'); $this->removeOldVersionOfPackage(); $this->installNewVersionOfPackage(); @@ -32,20 +31,17 @@ public function handle(): void $this->info('Package updated successfully..'); } - private function removeOldVersionOfPackage() - { + private function removeOldVersionOfPackage() { $this->info('Removing former version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar remove inensus/stron-meter'); } - private function installNewVersionOfPackage() - { + private function installNewVersionOfPackage() { $this->info('Installing last version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar require inensus/stron-meter'); } - private function deleteMigration(Filesystem $filesystem) - { + private function deleteMigration(Filesystem $filesystem) { $migrationFile = $filesystem->glob(database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'*_create_calin_smart_tables.php')[0]; $migration = DB::table('migrations') ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->first(); @@ -57,8 +53,7 @@ private function deleteMigration(Filesystem $filesystem) ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->delete(); } - private function publishMigrationsAgain() - { + private function publishMigrationsAgain() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\StronMeter\Providers\StronMeterServiceProvider", @@ -66,14 +61,12 @@ private function publishMigrationsAgain() ]); } - private function updateDatabase() - { + private function updateDatabase() { $this->info('Updating database tables\n'); $this->call('migrate'); } - private function publishVueFilesAgain() - { + private function publishVueFilesAgain() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\StronMeter\Providers\StronMeterServiceProvider", diff --git a/src/backend/packages/inensus/stron-meter/src/Exceptions/StronApiResponseException.php b/src/backend/packages/inensus/stron-meter/src/Exceptions/StronApiResponseException.php index 22007d2aa..37808a756 100644 --- a/src/backend/packages/inensus/stron-meter/src/Exceptions/StronApiResponseException.php +++ b/src/backend/packages/inensus/stron-meter/src/Exceptions/StronApiResponseException.php @@ -2,6 +2,4 @@ namespace Inensus\StronMeter\Exceptions; -class StronApiResponseException extends \Exception -{ -} +class StronApiResponseException extends \Exception {} diff --git a/src/backend/packages/inensus/stron-meter/src/Helpers/ApiHelpers.php b/src/backend/packages/inensus/stron-meter/src/Helpers/ApiHelpers.php index 8592ca5db..bd897dfeb 100644 --- a/src/backend/packages/inensus/stron-meter/src/Helpers/ApiHelpers.php +++ b/src/backend/packages/inensus/stron-meter/src/Helpers/ApiHelpers.php @@ -5,17 +5,14 @@ use App\Models\Manufacturer; use Inensus\StronMeter\Exceptions\StronApiResponseException; -class ApiHelpers -{ +class ApiHelpers { private $manufacturer; - public function __construct(Manufacturer $manufacturerModel) - { + public function __construct(Manufacturer $manufacturerModel) { $this->manufacturer = $manufacturerModel; } - public function registerStronMeterManufacturer() - { + public function registerStronMeterManufacturer() { $api = $this->manufacturer->newQuery()->where('api_name', 'StronMeterApi')->first(); if (!$api) { $this->manufacturer->newQuery()->create([ @@ -26,8 +23,7 @@ public function registerStronMeterManufacturer() } } - public function checkApiResult($result) - { + public function checkApiResult($result) { if (is_array($result) && array_key_exists('Message', $result)) { throw new StronApiResponseException($result['Message']); } @@ -38,8 +34,7 @@ public function checkApiResult($result) return $result; } - public function makeHash($data) - { + public function makeHash($data) { return md5(implode($data, '')); } } diff --git a/src/backend/packages/inensus/stron-meter/src/Http/Controllers/StronCredentialController.php b/src/backend/packages/inensus/stron-meter/src/Http/Controllers/StronCredentialController.php index b72f89755..8d37a256c 100644 --- a/src/backend/packages/inensus/stron-meter/src/Http/Controllers/StronCredentialController.php +++ b/src/backend/packages/inensus/stron-meter/src/Http/Controllers/StronCredentialController.php @@ -8,22 +8,18 @@ use Inensus\StronMeter\Http\Resources\StronResource; use Inensus\StronMeter\Services\StronCredentialService; -class StronCredentialController extends Controller -{ +class StronCredentialController extends Controller { private $credentialService; - public function __construct(StronCredentialService $credentialService) - { + public function __construct(StronCredentialService $credentialService) { $this->credentialService = $credentialService; } - public function show(): StronResource - { + public function show(): StronResource { return new StronResource($this->credentialService->getCredentials()); } - public function update(StronCredentialRequest $request): StronCredentialResource - { + public function update(StronCredentialRequest $request): StronCredentialResource { $credentials = $this->credentialService->updateCredentials($request->only([ 'username', 'password', diff --git a/src/backend/packages/inensus/stron-meter/src/Http/Requests/StronCredentialRequest.php b/src/backend/packages/inensus/stron-meter/src/Http/Requests/StronCredentialRequest.php index acff5fdc3..99c9786d0 100644 --- a/src/backend/packages/inensus/stron-meter/src/Http/Requests/StronCredentialRequest.php +++ b/src/backend/packages/inensus/stron-meter/src/Http/Requests/StronCredentialRequest.php @@ -5,15 +5,13 @@ use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; -class StronCredentialRequest extends FormRequest -{ +class StronCredentialRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'company_name' => ['required', Rule::unique('shard.stron_api_credentials')->ignore($this->id)], 'username' => ['required', Rule::unique('shard.stron_api_credentials')->ignore($this->id)], diff --git a/src/backend/packages/inensus/stron-meter/src/Http/Requests/StronMeterApiRequests.php b/src/backend/packages/inensus/stron-meter/src/Http/Requests/StronMeterApiRequests.php index 09e0ca0c7..1e96767f4 100644 --- a/src/backend/packages/inensus/stron-meter/src/Http/Requests/StronMeterApiRequests.php +++ b/src/backend/packages/inensus/stron-meter/src/Http/Requests/StronMeterApiRequests.php @@ -7,10 +7,11 @@ use Inensus\StronMeter\Helpers\ApiHelpers; use Inensus\StronMeter\Models\StronCredential; -class StronMeterApiRequests -{ +class StronMeterApiRequests { private $client; + private $apiHelpers; + private $credential; public function __construct( @@ -23,8 +24,7 @@ public function __construct( $this->credential = $credentialModel; } - public function token($url, $postParams) - { + public function token($url, $postParams) { try { $credential = $this->getCredentials(); } catch (ModelNotFoundException $e) { @@ -43,8 +43,7 @@ public function token($url, $postParams) return $this->apiHelpers->checkApiResult(json_decode((string) $request->getBody(), true)); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->firstOrFail(); } } diff --git a/src/backend/packages/inensus/stron-meter/src/Http/Resources/StronCredentialResource.php b/src/backend/packages/inensus/stron-meter/src/Http/Resources/StronCredentialResource.php index 9dcee0599..697033608 100644 --- a/src/backend/packages/inensus/stron-meter/src/Http/Resources/StronCredentialResource.php +++ b/src/backend/packages/inensus/stron-meter/src/Http/Resources/StronCredentialResource.php @@ -6,10 +6,8 @@ use Illuminate\Http\Resources\Json\JsonResource; use Inensus\StronMeter\Models\StronCredential; -class StronCredentialResource extends JsonResource -{ - public function __construct(StronCredential $stronCredential) - { +class StronCredentialResource extends JsonResource { + public function __construct(StronCredential $stronCredential) { parent::__construct($stronCredential); } @@ -20,16 +18,14 @@ public function __construct(StronCredential $stronCredential) * * @return Request */ - public function toArray($request) - { + public function toArray($request) { $credentials = $this->resource->toArray(); $credentials['alert'] = $this->alertType($this->resource->is_authenticated); return $credentials; } - private function alertType($authenticationStatus) - { + private function alertType($authenticationStatus) { switch ($authenticationStatus) { case true: return [ diff --git a/src/backend/packages/inensus/stron-meter/src/Http/Resources/StronResource.php b/src/backend/packages/inensus/stron-meter/src/Http/Resources/StronResource.php index ccacc4bc8..35b077bfa 100644 --- a/src/backend/packages/inensus/stron-meter/src/Http/Resources/StronResource.php +++ b/src/backend/packages/inensus/stron-meter/src/Http/Resources/StronResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class StronResource extends JsonResource -{ +class StronResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class StronResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/packages/inensus/stron-meter/src/Models/StronCredential.php b/src/backend/packages/inensus/stron-meter/src/Models/StronCredential.php index 244ecdce5..b04093471 100644 --- a/src/backend/packages/inensus/stron-meter/src/Models/StronCredential.php +++ b/src/backend/packages/inensus/stron-meter/src/Models/StronCredential.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class StronCredential extends BaseModel -{ +class StronCredential extends BaseModel { protected $table = 'stron_api_credentials'; } diff --git a/src/backend/packages/inensus/stron-meter/src/Models/StronTransaction.php b/src/backend/packages/inensus/stron-meter/src/Models/StronTransaction.php index 06691f172..e6a455a7c 100644 --- a/src/backend/packages/inensus/stron-meter/src/Models/StronTransaction.php +++ b/src/backend/packages/inensus/stron-meter/src/Models/StronTransaction.php @@ -12,42 +12,34 @@ use Inensus\SwiftaPaymentProvider\Models\SwiftaTransaction; use Inensus\WaveMoneyPaymentProvider\Models\WaveMoneyTransaction; -class StronTransaction extends BaseModel implements ISubTransaction -{ +class StronTransaction extends BaseModel implements ISubTransaction { protected $table = 'stron_transactions'; - public function agentTransaction() - { + public function agentTransaction() { return $this->morphOne(AgentTransaction::class, 'manufacturer_transaction'); } - public function vodacomTransaction() - { + public function vodacomTransaction() { return $this->morphOne(VodacomTransaction::class, 'manufacturer_transaction'); } - public function airtelTransaction() - { + public function airtelTransaction() { return $this->morphOne(AirtelTransaction::class, 'manufacturer_transaction'); } - public function thirdPartyTransaction() - { + public function thirdPartyTransaction() { return $this->morphOne(ThirdPartyTransaction::class, 'manufacturer_transaction'); } - public function mesombTransaction() - { + public function mesombTransaction() { return $this->morphOne(MesombTransaction::class, 'manufacturer_transaction'); } - public function swiftaTransaction() - { + public function swiftaTransaction() { return $this->morphOne(SwiftaTransaction::class, 'manufacturer_transaction'); } - public function waveMoneyTransaction() - { + public function waveMoneyTransaction() { return $this->morphOne(WaveMoneyTransaction::class, 'manufacturer_transaction'); } } diff --git a/src/backend/packages/inensus/stron-meter/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/stron-meter/src/Providers/EventServiceProvider.php index eaa7770a7..611d0a567 100644 --- a/src/backend/packages/inensus/stron-meter/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/stron-meter/src/Providers/EventServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ ]; @@ -14,8 +13,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/stron-meter/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/stron-meter/src/Providers/ObserverServiceProvider.php index 4761a484a..37d0a9a8a 100644 --- a/src/backend/packages/inensus/stron-meter/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/stron-meter/src/Providers/ObserverServiceProvider.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/stron-meter/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/stron-meter/src/Providers/RouteServiceProvider.php index 868883c40..937a51e23 100644 --- a/src/backend/packages/inensus/stron-meter/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/stron-meter/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\StronMeter\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/stron-meter/src/Providers/StronMeterServiceProvider.php b/src/backend/packages/inensus/stron-meter/src/Providers/StronMeterServiceProvider.php index 2b278f384..d332a78a5 100644 --- a/src/backend/packages/inensus/stron-meter/src/Providers/StronMeterServiceProvider.php +++ b/src/backend/packages/inensus/stron-meter/src/Providers/StronMeterServiceProvider.php @@ -9,10 +9,8 @@ use Inensus\StronMeter\Console\Commands\UpdatePackage; use Inensus\StronMeter\StronMeterApi; -class StronMeterServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class StronMeterServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -22,37 +20,32 @@ public function boot(Filesystem $filesystem) } } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/stron-meter.php', 'stron-meter'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->bind('StronMeterApi', StronMeterApi::class); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/stron-meter.php' => config_path('stron-meter.php'), ]); } - public function publishVueFiles() - { + public function publishVueFiles() { $this->publishes([ __DIR__.'/../resources/assets' => resource_path('assets/js/plugins/stron-meter'), ], 'vue-components'); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_stron_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) diff --git a/src/backend/packages/inensus/stron-meter/src/Services/StronCredentialService.php b/src/backend/packages/inensus/stron-meter/src/Services/StronCredentialService.php index 0f2968ae7..e8e157080 100644 --- a/src/backend/packages/inensus/stron-meter/src/Services/StronCredentialService.php +++ b/src/backend/packages/inensus/stron-meter/src/Services/StronCredentialService.php @@ -7,10 +7,11 @@ use Inensus\StronMeter\Http\Requests\StronMeterApiRequests; use Inensus\StronMeter\Models\StronCredential; -class StronCredentialService -{ +class StronCredentialService { private $rootUrl = '/login/'; + private $credential; + private $stronApi; public function __construct( @@ -24,8 +25,7 @@ public function __construct( /** * This function uses one time on installation of the package. */ - public function createCredentials() - { + public function createCredentials() { return $this->credential->newQuery()->firstOrCreate(['id' => 1], [ 'username' => null, 'password' => null, @@ -35,13 +35,11 @@ public function createCredentials() ]); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->first(); } - public function updateCredentials($data) - { + public function updateCredentials($data) { $credential = $this->credential->newQuery()->firstOrFail(); $credential->update([ diff --git a/src/backend/packages/inensus/stron-meter/src/StronMeterApi.php b/src/backend/packages/inensus/stron-meter/src/StronMeterApi.php index 978b4d8e1..0023a682a 100644 --- a/src/backend/packages/inensus/stron-meter/src/StronMeterApi.php +++ b/src/backend/packages/inensus/stron-meter/src/StronMeterApi.php @@ -13,9 +13,9 @@ use Inensus\StronMeter\Models\StronCredential; use Inensus\StronMeter\Models\StronTransaction; -class StronMeterApi implements IManufacturerAPI -{ +class StronMeterApi implements IManufacturerAPI { protected $api; + private $rootUrl = '/vending/'; public function __construct( @@ -27,8 +27,7 @@ public function __construct( $this->api = $httpClient; } - public function chargeDevice(TransactionDataContainer $transactionContainer): array - { + public function chargeDevice(TransactionDataContainer $transactionContainer): array { $meter = $transactionContainer->device->device; $tariff = $transactionContainer->tariff; $owner = $transactionContainer->device->person; @@ -93,8 +92,7 @@ public function chargeDevice(TransactionDataContainer $transactionContainer): ar ]; } - public function clearDevice(Device $device) - { + public function clearDevice(Device $device) { // TODO: Implement clearDevice() method. } } diff --git a/src/backend/packages/inensus/stron-meter/src/Tests/Unit/TokenGenerationTest.php b/src/backend/packages/inensus/stron-meter/src/Tests/Unit/TokenGenerationTest.php index 01cfad53c..1bf522649 100644 --- a/src/backend/packages/inensus/stron-meter/src/Tests/Unit/TokenGenerationTest.php +++ b/src/backend/packages/inensus/stron-meter/src/Tests/Unit/TokenGenerationTest.php @@ -19,13 +19,11 @@ use Inensus\StronMeter\Models\StronCredential; use Tests\TestCase; -class TokenGenerationTest extends TestCase -{ +class TokenGenerationTest extends TestCase { use RefreshDatabase; /** @test */ - public function isTokenGenerated() - { + public function isTokenGenerated() { Queue::fake(); Config::set('app.debug', false); $transaction = $this->initializeData(); @@ -38,8 +36,7 @@ public function isTokenGenerated() Queue::assertPushed(TokenProcessor::class); } - private function initializeData() - { + private function initializeData() { // create person factory(MainSettings::class)->create(); diff --git a/src/backend/packages/inensus/sun-king-shs/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/sun-king-shs/src/Console/Commands/InstallPackage.php index e45cade62..63dfffc71 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Console/Commands/InstallPackage.php @@ -6,9 +6,9 @@ use Inensus\SunKingSHS\Services\ManufacturerService; use Inensus\SunKingSHS\Services\SunKingCredentialService; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'sun-king-shs:install'; + protected $description = 'Install SunKingSHS Package'; public function __construct( @@ -18,8 +18,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing SunKingSHS Integration Package\n'); $this->manufacturerService->register(); @@ -27,8 +26,7 @@ public function handle(): void $this->info('Package installed successfully..'); } - private function publishMigrations() - { + private function publishMigrations() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\SunKingSHS\Providers\SunKingSHSServiceProvider", @@ -36,14 +34,12 @@ private function publishMigrations() ]); } - private function createDatabaseTables() - { + private function createDatabaseTables() { $this->info('Creating database tables\n'); $this->call('migrate'); } - private function publishVueFiles() - { + private function publishVueFiles() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\SunKingSHS\Providers\SunKingSHSServiceProvider", @@ -51,8 +47,7 @@ private function publishVueFiles() ]); } - private function createPluginRecord() - { + private function createPluginRecord() { $this->call('plugin:add', [ 'name' => 'SunKingSHS', 'composer_name' => 'inensus/sun-king-shs', diff --git a/src/backend/packages/inensus/sun-king-shs/src/Exceptions/SunKingApiResponseException.php b/src/backend/packages/inensus/sun-king-shs/src/Exceptions/SunKingApiResponseException.php index 0f3fe33ea..4d19c4130 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Exceptions/SunKingApiResponseException.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Exceptions/SunKingApiResponseException.php @@ -2,10 +2,8 @@ namespace Inensus\SunKingSHS\Exceptions; -class SunKingApiResponseException extends \Exception -{ - public function __construct($message) - { +class SunKingApiResponseException extends \Exception { + public function __construct($message) { parent::__construct($message); } } diff --git a/src/backend/packages/inensus/sun-king-shs/src/Http/Controllers/SunKingCredentialController.php b/src/backend/packages/inensus/sun-king-shs/src/Http/Controllers/SunKingCredentialController.php index 8dea71db2..f3b66187d 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Http/Controllers/SunKingCredentialController.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Http/Controllers/SunKingCredentialController.php @@ -7,19 +7,14 @@ use Inensus\SunKingSHS\Http\Resources\SunKingResource; use Inensus\SunKingSHS\Services\SunKingCredentialService; -class SunKingCredentialController extends Controller -{ - public function __construct(private SunKingCredentialService $credentialService) - { - } +class SunKingCredentialController extends Controller { + public function __construct(private SunKingCredentialService $credentialService) {} - public function show(): SunKingResource - { + public function show(): SunKingResource { return SunKingResource::make($this->credentialService->getCredentials()); } - public function update(SunKingCredentialRequest $request): SunKingResource - { + public function update(SunKingCredentialRequest $request): SunKingResource { $credentials = $this->credentialService->getCredentials(); $updateData = $request->only([ 'client_id', diff --git a/src/backend/packages/inensus/sun-king-shs/src/Http/Requests/SunKingCredentialRequest.php b/src/backend/packages/inensus/sun-king-shs/src/Http/Requests/SunKingCredentialRequest.php index d155f844f..e117d0092 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Http/Requests/SunKingCredentialRequest.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Http/Requests/SunKingCredentialRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class SunKingCredentialRequest extends FormRequest -{ +class SunKingCredentialRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'client_id' => ['required'], 'client_secret' => ['required'], diff --git a/src/backend/packages/inensus/sun-king-shs/src/Http/Resources/SunKingResource.php b/src/backend/packages/inensus/sun-king-shs/src/Http/Resources/SunKingResource.php index e7a541476..d78c5f3dc 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Http/Resources/SunKingResource.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Http/Resources/SunKingResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class SunKingResource extends JsonResource -{ +class SunKingResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class SunKingResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/packages/inensus/sun-king-shs/src/Models/SunKingCredential.php b/src/backend/packages/inensus/sun-king-shs/src/Models/SunKingCredential.php index bcda551a3..379f01b75 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Models/SunKingCredential.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Models/SunKingCredential.php @@ -4,37 +4,30 @@ use App\Models\Base\BaseModel; -class SunKingCredential extends BaseModel -{ +class SunKingCredential extends BaseModel { protected $table = 'sun_king_api_credentials'; - public function getClientSecret() - { + public function getClientSecret() { return $this->client_secret; } - public function getClientId() - { + public function getClientId() { return $this->client_id; } - public function getApiUrl() - { + public function getApiUrl() { return $this->api_url; } - public function getAuthUrl() - { + public function getAuthUrl() { return $this->auth_url; } - public function getAccessToken() - { + public function getAccessToken() { return $this->access_token; } - public function getExpirationTime() - { + public function getExpirationTime() { return $this->token_expires_in; } } diff --git a/src/backend/packages/inensus/sun-king-shs/src/Models/SunKingTransaction.php b/src/backend/packages/inensus/sun-king-shs/src/Models/SunKingTransaction.php index 9451bb065..7ba7cba3c 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Models/SunKingTransaction.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Models/SunKingTransaction.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class SunKingTransaction extends BaseModel -{ +class SunKingTransaction extends BaseModel { protected $table = 'sun_king_transactions'; } diff --git a/src/backend/packages/inensus/sun-king-shs/src/Modules/Api/ApiRequests.php b/src/backend/packages/inensus/sun-king-shs/src/Modules/Api/ApiRequests.php index 54f502401..0ace3b98e 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Modules/Api/ApiRequests.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Modules/Api/ApiRequests.php @@ -8,15 +8,12 @@ use Inensus\SunKingSHS\Exceptions\SunKingApiResponseException; use Inensus\SunKingSHS\Models\SunKingCredential; -class ApiRequests -{ +class ApiRequests { public function __construct( private Client $httpClient, - ) { - } + ) {} - public function authentication($credential): array - { + public function authentication($credential): array { try { $response = $this->httpClient->post($credential->getAuthUrl(), [ @@ -44,20 +41,21 @@ public function authentication($credential): array } } - public function get(SunKingCredential $credentials, array $params, string $slug) - { + public function get(SunKingCredential $credentials, array $params, string $slug) { $url = $credentials->getApiUrl().$slug; foreach ($params as $key => $value) { $url .= $key.'='.$value.'&'; } try { - $request = $this->httpClient->get($url, + $request = $this->httpClient->get( + $url, [ 'headers' => [ 'Accept' => 'application/json', 'Authorization' => 'Bearer '.$credentials->getApiKey(), ], - ]); + ] + ); return json_decode((string) $request->getBody(), true); } catch (GuzzleException $e) { @@ -68,8 +66,7 @@ public function get(SunKingCredential $credentials, array $params, string $slug) } } - public function post(SunKingCredential $credentials, array $params, string $slug) - { + public function post(SunKingCredential $credentials, array $params, string $slug) { $url = $credentials->getApiUrl().$slug; try { $request = $this->httpClient->post( @@ -91,7 +88,8 @@ public function post(SunKingCredential $credentials, array $params, string $slug 'URL :' => $url, 'Body :' => json_encode($params), 'message :' => $e->getMessage(), - ]); + ] + ); throw new SunKingApiResponseException($e->getMessage()); } } diff --git a/src/backend/packages/inensus/sun-king-shs/src/Modules/Api/SunKingSHSApi.php b/src/backend/packages/inensus/sun-king-shs/src/Modules/Api/SunKingSHSApi.php index b16959461..94128cfe9 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Modules/Api/SunKingSHSApi.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Modules/Api/SunKingSHSApi.php @@ -11,20 +11,18 @@ use Inensus\SunKingSHS\Models\SunKingTransaction; use Inensus\SunKingSHS\Services\SunKingCredentialService; -class SunKingSHSApi implements IManufacturerAPI -{ +class SunKingSHSApi implements IManufacturerAPI { public const API_CALL_TOKEN_GENERATION = '/token'; + public const COMMAND_ADD_CREDIT = 'add_credit'; public function __construct( private SunKingCredentialService $credentialService, private SunKingTransaction $sunKingTransaction, private ApiRequests $apiRequests, - ) { - } + ) {} - public function chargeDevice(TransactionDataContainer $transactionContainer): array - { + public function chargeDevice(TransactionDataContainer $transactionContainer): array { $dayDifferenceBetweenTwoInstallments = $transactionContainer->dayDifferenceBetweenTwoInstallments; $minimumPurchaseAmount = $transactionContainer->installmentCost; $minimumPurchaseAmountPerDay = ($minimumPurchaseAmount / $dayDifferenceBetweenTwoInstallments); // This is for 1 day of energy @@ -50,8 +48,10 @@ public function chargeDevice(TransactionDataContainer $transactionContainer): ar $this->credentialService->updateCredentials($credentials, $authResponse); $response = $this->apiRequests->post($credentials, $params, self::API_CALL_TOKEN_GENERATION); } catch (SunKingApiResponseException $e) { - $this->credentialService->updateCredentials($credentials, - ['access_token' => null, 'token_expires_in' => null]); + $this->credentialService->updateCredentials( + $credentials, + ['access_token' => null, 'token_expires_in' => null] + ); throw new SunKingApiResponseException($e->getMessage()); } @@ -78,8 +78,7 @@ public function chargeDevice(TransactionDataContainer $transactionContainer): ar ]; } - public function clearDevice(Device $device) - { + public function clearDevice(Device $device) { throw new ApiCallDoesNotSupportedException('This api call does not supported'); } } diff --git a/src/backend/packages/inensus/sun-king-shs/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/sun-king-shs/src/Providers/EventServiceProvider.php index daecbfabe..9c31e8b10 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Providers/EventServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ ]; @@ -14,8 +13,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/sun-king-shs/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/sun-king-shs/src/Providers/ObserverServiceProvider.php index 54f1bde61..c1845156d 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Providers/ObserverServiceProvider.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/sun-king-shs/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/sun-king-shs/src/Providers/RouteServiceProvider.php index 6ca04edc8..202232d59 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\SunKingSHS\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/sun-king-shs/src/Providers/SunKingSHSServiceProvider.php b/src/backend/packages/inensus/sun-king-shs/src/Providers/SunKingSHSServiceProvider.php index 5d80f4609..7fe6ee7c0 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Providers/SunKingSHSServiceProvider.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Providers/SunKingSHSServiceProvider.php @@ -8,10 +8,8 @@ use Inensus\SunKingSHS\Console\Commands\InstallPackage; use Inensus\SunKingSHS\Modules\Api\SunKingSHSApi; -class SunKingSHSServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class SunKingSHSServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -21,45 +19,42 @@ public function boot(Filesystem $filesystem) } } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/sun-king-shs.php', 'sun-king-shs'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->bind('SunKingSHSApi', SunKingSHSApi::class); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/sun-king-shs.php' => config_path('sun-king-shs.php'), ]); } - public function publishVueFiles() - { + public function publishVueFiles() { $this->publishes([ __DIR__.'/../resources/assets' => resource_path('assets/js/plugins/sun-king-shs'), ], 'vue-components'); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_sun_king_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) ->flatMap(function ($path) use ($filesystem) { if (count($filesystem->glob($path.'*_create_sun_king_tables.php'))) { $file = $filesystem->glob($path.'*_create_sun_king_tables.php')[0]; - file_put_contents($file, - file_get_contents(__DIR__.'/../../database/migrations/create_sun_king_tables.php.stub')); + file_put_contents( + $file, + file_get_contents(__DIR__.'/../../database/migrations/create_sun_king_tables.php.stub') + ); } return $filesystem->glob($path.'*_create_sun_king_tables.php'); diff --git a/src/backend/packages/inensus/sun-king-shs/src/Services/ManufacturerService.php b/src/backend/packages/inensus/sun-king-shs/src/Services/ManufacturerService.php index 0948e4470..e0cd03f8a 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Services/ManufacturerService.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Services/ManufacturerService.php @@ -4,14 +4,10 @@ use App\Models\Manufacturer; -class ManufacturerService -{ - public function __construct(private Manufacturer $manufacturer) - { - } +class ManufacturerService { + public function __construct(private Manufacturer $manufacturer) {} - public function register() - { + public function register() { $api = $this->manufacturer->newQuery()->where('api_name', 'SunKingSHSApi')->first(); if (!$api) { $this->manufacturer->newQuery()->create([ diff --git a/src/backend/packages/inensus/sun-king-shs/src/Services/SunKingCredentialService.php b/src/backend/packages/inensus/sun-king-shs/src/Services/SunKingCredentialService.php index bc416a9b6..57e3be728 100644 --- a/src/backend/packages/inensus/sun-king-shs/src/Services/SunKingCredentialService.php +++ b/src/backend/packages/inensus/sun-king-shs/src/Services/SunKingCredentialService.php @@ -4,43 +4,36 @@ use Inensus\SunKingSHS\Models\SunKingCredential; -class SunKingCredentialService -{ +class SunKingCredentialService { public function __construct( private SunKingCredential $credential, - ) { - } + ) {} /** * This function uses one time on installation of the package. */ - public function createCredentials() - { + public function createCredentials() { return $this->credential->newQuery()->firstOrCreate(['id' => 1], [ 'client_id' => null, 'client_secret' => null, ]); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->first(); } - public function updateCredentials($credentials, $updateData) - { + public function updateCredentials($credentials, $updateData) { $credentials->update($updateData); return $credentials->fresh(); } - public function getById($id) - { + public function getById($id) { return $this->credential->newQuery()->findOrFail($id); } - public function isAccessTokenValid($credential) - { + public function isAccessTokenValid($credential) { $accessToken = $credential->getAccessToken(); if ($accessToken == null) { diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/swifta-payment-provider/src/Console/Commands/InstallPackage.php index 178326aea..bdb469d8d 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Console/Commands/InstallPackage.php @@ -12,9 +12,9 @@ use Inensus\SwiftaPaymentProvider\Models\SwiftaAuthentication; use Tymon\JWTAuth\Facades\JWTAuth; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'swifta-payment-provider:install'; + protected $description = 'Install SwiftaPaymentProvider Package'; public function __construct( @@ -27,16 +27,14 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing SwiftaPaymentProvider Integration Package\n'); $token = $this->generateAuthenticationToken(); $this->warn("Authentication token for swifta payments generated. token =>\n {$token}"); $this->info('Package installed successfully..'); } - private function publishConfigurations() - { + private function publishConfigurations() { $this->info('Copying configurations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\SwiftaPaymentProvider\Providers\SwiftaServiceProvider", @@ -44,8 +42,7 @@ private function publishConfigurations() ]); } - private function publishMigrations() - { + private function publishMigrations() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\SwiftaPaymentProvider\Providers\SwiftaServiceProvider", @@ -53,14 +50,12 @@ private function publishMigrations() ]); } - private function createDatabaseTables() - { + private function createDatabaseTables() { $this->info('Creating database tables\n'); $this->call('migrate'); } - private function createPluginRecord() - { + private function createPluginRecord() { $this->call('plugin:add', [ 'name' => 'SwiftaPaymentProvider', 'composer_name' => 'inensus/swifta-payment-provider', @@ -68,8 +63,7 @@ private function createPluginRecord() ]); } - private function generateAuthenticationToken() - { + private function generateAuthenticationToken() { $password = $this->generateRandomNumber(); $companyId = app()->make(UserService::class)->getCompanyId(); $company = $this->companyService->getById($companyId); @@ -98,8 +92,7 @@ private function generateAuthenticationToken() return $token; } - private function generateRandomNumber(): string - { + private function generateRandomNumber(): string { $length = random_int(1, 10); $number = ''; for ($i = 0; $i < $length; ++$i) { diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Console/Commands/TransactionStatusChecker.php b/src/backend/packages/inensus/swifta-payment-provider/src/Console/Commands/TransactionStatusChecker.php index bb4e74a9a..33bd9686d 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Console/Commands/TransactionStatusChecker.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Console/Commands/TransactionStatusChecker.php @@ -7,21 +7,20 @@ use Carbon\Carbon; use Inensus\SwiftaPaymentProvider\Services\SwiftaTransactionService; -class TransactionStatusChecker extends AbstractSharedCommand -{ +class TransactionStatusChecker extends AbstractSharedCommand { use ScheduledPluginCommand; + public const MPM_PLUGIN_ID = 7; protected $signature = 'swifta-payment-provider:transactionStatusCheck'; + protected $description = 'Update the Swifta Transaction status if still REQUESTED at 00:00'; - public function __construct(private SwiftaTransactionService $swiftaTransactionService) - { + public function __construct(private SwiftaTransactionService $swiftaTransactionService) { parent::__construct(); } - public function handle(): void - { + public function handle(): void { if (!$this->checkForPluginStatusIsActive(self::MPM_PLUGIN_ID)) { return; } diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Console/Commands/UpdatePackage.php b/src/backend/packages/inensus/swifta-payment-provider/src/Console/Commands/UpdatePackage.php index 093dda50f..e47857980 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Console/Commands/UpdatePackage.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Console/Commands/UpdatePackage.php @@ -10,9 +10,9 @@ use Inensus\SwiftaPaymentProvider\Models\SwiftaAuthentication; use Tymon\JWTAuth\Facades\JWTAuth; -class UpdatePackage extends Command -{ +class UpdatePackage extends Command { protected $signature = 'swifta-payment-provider:update'; + protected $description = 'Update the Swifta Payment Provider Integration Package'; public function __construct( @@ -26,8 +26,7 @@ public function __construct( /** * Execute the console command. */ - public function handle(): void - { + public function handle(): void { $this->info('Swifta Payment Provider Integration Updating Started\n'); $this->removeOldVersionOfPackage(); $this->installNewVersionOfPackage(); @@ -40,8 +39,7 @@ public function handle(): void $this->info('Package updated successfully..'); } - private function publishConfigurations() - { + private function publishConfigurations() { $this->info('Copying configurations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\SwiftaPaymentProvider\Providers\SwiftaServiceProvider", @@ -49,20 +47,17 @@ private function publishConfigurations() ]); } - private function removeOldVersionOfPackage() - { + private function removeOldVersionOfPackage() { $this->info('Removing former version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar remove inensus/swifta-payment-provider'); } - private function installNewVersionOfPackage() - { + private function installNewVersionOfPackage() { $this->info('Installing last version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar require inensus/swifta-payment-provider'); } - private function deleteMigration(Filesystem $filesystem) - { + private function deleteMigration(Filesystem $filesystem) { $migrationFile = $filesystem->glob(database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'*_create_swifta_payment_provider_tables.php')[0]; $migration = DB::table('migrations') ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->first(); @@ -73,8 +68,7 @@ private function deleteMigration(Filesystem $filesystem) ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->delete(); } - private function publishMigrationsAgain() - { + private function publishMigrationsAgain() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\SwiftaPaymentProvider\Providers\SwiftaServiceProvider", @@ -82,14 +76,12 @@ private function publishMigrationsAgain() ]); } - private function updateDatabase() - { + private function updateDatabase() { $this->info('Updating database tables\n'); $this->call('migrate'); } - private function generateAuthenticationTokenAgain() - { + private function generateAuthenticationTokenAgain() { $password = $this->generateRandomNumber(); $user = $this->user->newQuery()->firstOrCreate([ 'email' => 'swifta-user', @@ -111,8 +103,7 @@ private function generateAuthenticationTokenAgain() return $token; } - private function generateRandomNumber(): string - { + private function generateRandomNumber(): string { $length = random_int(1, 10); $number = ''; for ($i = 0; $i < $length; ++$i) { diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/CipherNotValidException.php b/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/CipherNotValidException.php index 954e9fd40..9e0bbbcd3 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/CipherNotValidException.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/CipherNotValidException.php @@ -2,6 +2,4 @@ namespace Inensus\SwiftaPaymentProvider\Exceptions; -class CipherNotValidException extends \Exception -{ -} +class CipherNotValidException extends \Exception {} diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/CustomerAddressNotFoundException.php b/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/CustomerAddressNotFoundException.php index 8c548c73f..36e415f33 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/CustomerAddressNotFoundException.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/CustomerAddressNotFoundException.php @@ -2,6 +2,4 @@ namespace Inensus\SwiftaPaymentProvider\Exceptions; -class CustomerAddressNotFoundException extends \Exception -{ -} +class CustomerAddressNotFoundException extends \Exception {} diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/SwiftaValidationFailedException.php b/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/SwiftaValidationFailedException.php index 1220242ac..ae16b3fb1 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/SwiftaValidationFailedException.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/SwiftaValidationFailedException.php @@ -2,6 +2,4 @@ namespace Inensus\SwiftaPaymentProvider\Exceptions; -class SwiftaValidationFailedException extends \Exception -{ -} +class SwiftaValidationFailedException extends \Exception {} diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/TransactionAmountDifferentException.php b/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/TransactionAmountDifferentException.php index 1b958300b..5ac2ad6a1 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/TransactionAmountDifferentException.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/TransactionAmountDifferentException.php @@ -2,6 +2,4 @@ namespace Inensus\SwiftaPaymentProvider\Exceptions; -class TransactionAmountDifferentException extends \Exception -{ -} +class TransactionAmountDifferentException extends \Exception {} diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/TransactionNotExistsException.php b/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/TransactionNotExistsException.php index 5be8a2415..6f45bda5f 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/TransactionNotExistsException.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Exceptions/TransactionNotExistsException.php @@ -2,6 +2,4 @@ namespace Inensus\SwiftaPaymentProvider\Exceptions; -class TransactionNotExistsException extends \Exception -{ -} +class TransactionNotExistsException extends \Exception {} diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Controllers/SwiftaAuthenticationController.php b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Controllers/SwiftaAuthenticationController.php index 99fee28a5..51aaed0be 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Controllers/SwiftaAuthenticationController.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Controllers/SwiftaAuthenticationController.php @@ -6,14 +6,10 @@ use Illuminate\Routing\Controller; use Inensus\SwiftaPaymentProvider\Services\SwiftaAuthenticationService; -class SwiftaAuthenticationController extends Controller -{ - public function __construct(private SwiftaAuthenticationService $swiftaAuthenticationService) - { - } +class SwiftaAuthenticationController extends Controller { + public function __construct(private SwiftaAuthenticationService $swiftaAuthenticationService) {} - public function show(): ApiResource - { + public function show(): ApiResource { return ApiResource::make($this->swiftaAuthenticationService->getSwiftaAuthentication()); } } diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Controllers/SwiftaPaymentProviderController.php b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Controllers/SwiftaPaymentProviderController.php index 300d77513..18d4b2f09 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Controllers/SwiftaPaymentProviderController.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Controllers/SwiftaPaymentProviderController.php @@ -9,14 +9,10 @@ use Inensus\SwiftaPaymentProvider\Models\SwiftaTransaction; use Inensus\SwiftaPaymentProvider\Services\SwiftaTransactionService; -class SwiftaPaymentProviderController extends Controller -{ - public function __construct(private SwiftaTransactionService $swiftaTransactionService) - { - } +class SwiftaPaymentProviderController extends Controller { + public function __construct(private SwiftaTransactionService $swiftaTransactionService) {} - public function validation(SwiftaValidationRequest $request) - { + public function validation(SwiftaValidationRequest $request) { $transactionId = $request->get('transactionId'); $customerName = $request->get('customerName'); $data = collect([ @@ -31,8 +27,7 @@ public function validation(SwiftaValidationRequest $request) return new Response($data, 200); } - public function transaction(SwiftaTransactionRequest $request) - { + public function transaction(SwiftaTransactionRequest $request) { $transaction = $request->get('transaction'); $reference = $request->get('reference'); $swiftaTransaction = $transaction->originalTransaction()->first(); diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Kernel.php b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Kernel.php index 45544c4fd..a7d75d8e8 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Kernel.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Kernel.php @@ -7,8 +7,7 @@ use Inensus\SwiftaPaymentProvider\Http\Middleware\SwiftaTransactionCallbackMiddleware; use Inensus\SwiftaPaymentProvider\Http\Middleware\SwiftaTransactionMiddleware; -class Kernel extends HttpKernel -{ +class Kernel extends HttpKernel { protected $routeMiddleware = [ 'swifta.transaction' => SwiftaTransactionCallbackMiddleware::class, 'swifta.validation' => SwiftaMiddleware::class, diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Middleware/SwiftaMiddleware.php b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Middleware/SwiftaMiddleware.php index 0e56bf9c0..df7b97af1 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Middleware/SwiftaMiddleware.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Middleware/SwiftaMiddleware.php @@ -6,10 +6,8 @@ use Illuminate\Http\Response; use Illuminate\Support\Facades\Log; -class SwiftaMiddleware -{ - public function handle(Request $request, \Closure $next) - { +class SwiftaMiddleware { + public function handle(Request $request, \Closure $next) { if (auth()->payload()->get('usr') !== 'swifta-token') { $data = collect([ 'success' => 0, @@ -32,8 +30,7 @@ public function handle(Request $request, \Closure $next) return $next($request); } - private function checkCipherIsValid(Request $request) - { + private function checkCipherIsValid(Request $request) { $hash = md5('Inensus'.$request->input('timestamp').$request->input('amount').'Swifta'); if ($request->input('cipher') != $hash) { Log::warning('Swifta Transaction Validation Failed', [ diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Middleware/SwiftaTransactionCallbackMiddleware.php b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Middleware/SwiftaTransactionCallbackMiddleware.php index ad9af1208..bf7940805 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Middleware/SwiftaTransactionCallbackMiddleware.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Middleware/SwiftaTransactionCallbackMiddleware.php @@ -7,14 +7,10 @@ use Illuminate\Http\Response; use Inensus\SwiftaPaymentProvider\Services\SwiftaTransactionService; -class SwiftaTransactionCallbackMiddleware -{ - public function __construct(private SwiftaTransactionService $swiftaTransactionService) - { - } +class SwiftaTransactionCallbackMiddleware { + public function __construct(private SwiftaTransactionService $swiftaTransactionService) {} - public function handle(Request $request, \Closure $next) - { + public function handle(Request $request, \Closure $next) { try { $transactionId = $request->input('transaction_id'); $amount = $request->input('amount'); diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Middleware/SwiftaTransactionMiddleware.php b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Middleware/SwiftaTransactionMiddleware.php index 89cca332a..2a7cd4e9e 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Middleware/SwiftaTransactionMiddleware.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Middleware/SwiftaTransactionMiddleware.php @@ -5,10 +5,8 @@ use Illuminate\Http\Request; use Illuminate\Http\Response; -class SwiftaTransactionMiddleware -{ - public function handle(Request $request, \Closure $next) - { +class SwiftaTransactionMiddleware { + public function handle(Request $request, \Closure $next) { $transactionProvider = resolve('SwiftaPaymentProvider'); try { diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Requests/SwiftaTransactionRequest.php b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Requests/SwiftaTransactionRequest.php index 34c913032..9564d8321 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Requests/SwiftaTransactionRequest.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Requests/SwiftaTransactionRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class SwiftaTransactionRequest extends FormRequest -{ +class SwiftaTransactionRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'transaction_id' => 'required', 'transaction_reference' => 'required', diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Requests/SwiftaValidationRequest.php b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Requests/SwiftaValidationRequest.php index 793699635..49d8841a0 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Http/Requests/SwiftaValidationRequest.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Http/Requests/SwiftaValidationRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class SwiftaValidationRequest extends FormRequest -{ +class SwiftaValidationRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'meter_number' => 'required', 'amount' => 'required', diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Listeners/TransactionListener.php b/src/backend/packages/inensus/swifta-payment-provider/src/Listeners/TransactionListener.php index 35011823b..7b0354ec5 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Listeners/TransactionListener.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Listeners/TransactionListener.php @@ -6,10 +6,8 @@ use Illuminate\Events\Dispatcher; use Illuminate\Support\Facades\Log; -class TransactionListener -{ - public function onTransactionFailed(Transaction $transaction, $message = null): void - { +class TransactionListener { + public function onTransactionFailed(Transaction $transaction, $message = null): void { $transactionProvider = resolve('SwiftaPaymentProvider'); $transactionProvider->conflict($message, $transaction); if (config('app.debug')) { @@ -18,18 +16,18 @@ public function onTransactionFailed(Transaction $transaction, $message = null): $transactionProvider->sendResult(false, $transaction); } - public function onTransactionSuccess(Transaction $transaction) - { + public function onTransactionSuccess(Transaction $transaction) { $transactionProvider = resolve('SwiftaPaymentProvider'); $transactionProvider->sendResult(true, $transaction); } - public function subscribe(Dispatcher $events) - { - $events->listen('transaction.successful', + public function subscribe(Dispatcher $events) { + $events->listen( + 'transaction.successful', 'Inensus\SwiftaPaymentProvider\Listeners\TransactionListener@onTransactionSuccess' ); - $events->listen('transaction.failed', + $events->listen( + 'transaction.failed', 'Inensus\SwiftaPaymentProvider\Listeners\TransactionListener@onTransactionFailed' ); } diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Models/SwiftaAuthentication.php b/src/backend/packages/inensus/swifta-payment-provider/src/Models/SwiftaAuthentication.php index 90fe117e3..7db6aa89a 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Models/SwiftaAuthentication.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Models/SwiftaAuthentication.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class SwiftaAuthentication extends BaseModel -{ +class SwiftaAuthentication extends BaseModel { protected $table = 'swifta_authentication'; } diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Models/SwiftaTransaction.php b/src/backend/packages/inensus/swifta-payment-provider/src/Models/SwiftaTransaction.php index 4fd09e6f7..9e05ad820 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Models/SwiftaTransaction.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Models/SwiftaTransaction.php @@ -11,41 +11,36 @@ use Illuminate\Database\Eloquent\Relations\MorphTo; use MPM\Transaction\FullySupportedTransactionInterface; -class SwiftaTransaction extends BaseModel implements IRawTransaction, FullySupportedTransactionInterface -{ +class SwiftaTransaction extends BaseModel implements FullySupportedTransactionInterface, IRawTransaction { public const RELATION_NAME = 'swifta_transaction'; + public const STATUS_SUCCESS = 1; + public const STATUS_PENDING = 0; + public const STATUS_FAILED = -1; + public const STATUS_REQUESTED = -2; protected $table = 'swifta_transactions'; - public function getAmount(): int - { + public function getAmount(): int { return $this->amount; } - /** - * @return MorphOne - */ - public function transaction(): MorphOne - { + public function transaction(): MorphOne { return $this->morphOne(Transaction::class, 'original_transaction'); } - public function manufacturerTransaction(): MorphTo - { + public function manufacturerTransaction(): MorphTo { return $this->morphTo(); } - public function conflicts(): MorphMany - { + public function conflicts(): MorphMany { return $this->morphMany(TransactionConflicts::class, 'transaction'); } - public static function getTransactionName(): string - { + public static function getTransactionName(): string { return self::RELATION_NAME; } } diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/swifta-payment-provider/src/Providers/EventServiceProvider.php index 327ad4bda..190b752c1 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Providers/EventServiceProvider.php @@ -5,8 +5,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Inensus\SwiftaPaymentProvider\Listeners\TransactionListener; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { // commended out because it is not used for cloud protected $subscribe = [ // TransactionListener::class @@ -17,8 +16,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/swifta-payment-provider/src/Providers/ObserverServiceProvider.php index c5907ab88..4c39c9f1f 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Providers/ObserverServiceProvider.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/swifta-payment-provider/src/Providers/RouteServiceProvider.php index f51124905..2a70f18ed 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\SwiftaPaymentProvider\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Providers/SwiftaServiceProvider.php b/src/backend/packages/inensus/swifta-payment-provider/src/Providers/SwiftaServiceProvider.php index f4ad9e680..c87b6b703 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Providers/SwiftaServiceProvider.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Providers/SwiftaServiceProvider.php @@ -12,10 +12,8 @@ use Inensus\SwiftaPaymentProvider\Console\Commands\UpdatePackage; use Inensus\SwiftaPaymentProvider\Models\SwiftaTransaction; -class SwiftaServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class SwiftaServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -31,30 +29,26 @@ public function boot(Filesystem $filesystem) ->appendOutputTo(storage_path('logs/cron.log')); } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/swifta-payment-provider.php', 'swifta-payment-provider'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->bind('SwiftaPaymentProvider', SwiftaTransactionProvider::class); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/swifta-payment-provider.php' => config_path('swifta-payment-provider.php'), ], 'configurations'); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_swifta_payment_provider_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) @@ -62,8 +56,10 @@ protected function getMigrationFileName(Filesystem $filesystem): string if (count($filesystem->glob($path.'*_create_swifta_payment_provider_tables.php'))) { $file = $filesystem->glob($path.'*_create_swifta_payment_provider_tables.php')[0]; - file_put_contents($file, - file_get_contents(__DIR__.'/../../database/migrations/create_swifta_payment_provider_tables.php.stub')); + file_put_contents( + $file, + file_get_contents(__DIR__.'/../../database/migrations/create_swifta_payment_provider_tables.php.stub') + ); } return $filesystem->glob($path.'*_create_swifta_payment_provider_tables.php'); diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Providers/SwiftaTransactionProvider.php b/src/backend/packages/inensus/swifta-payment-provider/src/Providers/SwiftaTransactionProvider.php index e1e58b33c..bb312770f 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Providers/SwiftaTransactionProvider.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Providers/SwiftaTransactionProvider.php @@ -13,8 +13,7 @@ use Inensus\SwiftaPaymentProvider\Services\SwiftaTransactionService; use MPM\Transaction\Provider\ITransactionProvider; -class SwiftaTransactionProvider implements ITransactionProvider -{ +class SwiftaTransactionProvider implements ITransactionProvider { private $validData = []; public function __construct( @@ -22,11 +21,9 @@ public function __construct( private Transaction $transaction, private SwiftaTransactionService $swiftaTransactionService, private TransactionConflicts $transactionConflicts, - ) { - } + ) {} - public function validateRequest($request) - { + public function validateRequest($request) { $meterSerial = $request->input('meter_number'); $amount = $request->input('amount'); @@ -43,13 +40,11 @@ public function validateRequest($request) $this->setValidData($swiftaTransactionData); } - public function saveTransaction() - { + public function saveTransaction() { $this->swiftaTransactionService->saveTransaction(); } - public function sendResult(bool $requestType, Transaction $transaction) - { + public function sendResult(bool $requestType, Transaction $transaction) { $swiftaTransaction = $transaction->originalTransaction()->first(); if ($requestType) { $updateData = [ @@ -63,8 +58,7 @@ public function sendResult(bool $requestType, Transaction $transaction) } } - public function addConflict(?string $message): void - { + public function addConflict(?string $message): void { $conflict = $this->transactionConflicts->newQuery()->make([ 'state' => $message, ]); @@ -72,49 +66,40 @@ public function addConflict(?string $message): void $conflict->save(); } - public function getTransaction(): Transaction - { + public function getTransaction(): Transaction { return $this->transaction; } - public function setValidData($swiftaTransactionData) - { + public function setValidData($swiftaTransactionData) { $this->validData = $swiftaTransactionData; } - public function getSubTransaction() - { + public function getSubTransaction() { return $this->swiftaTransactionService->getSwiftaTransaction(); } - public function init($transaction): void - { + public function init($transaction): void { $this->swiftaTransaction = $transaction; $this->transaction = $transaction->transaction()->first(); } - public function confirm(): void - { + public function confirm(): void { // TODO: Implement getMessage() method. } - public function getMessage(): string - { + public function getMessage(): string { // TODO: Implement getMessage() method. } - public function getAmount(): int - { + public function getAmount(): int { return $this->getTransaction()->amount; } - public function getSender(): string - { + public function getSender(): string { return $this->getTransaction()->message; } - public function saveCommonData(): Model - { + public function saveCommonData(): Model { // TODO: Implement getSender() method. } } diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Services/SwiftaAuthenticationService.php b/src/backend/packages/inensus/swifta-payment-provider/src/Services/SwiftaAuthenticationService.php index ced42711f..42d2fc212 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Services/SwiftaAuthenticationService.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Services/SwiftaAuthenticationService.php @@ -4,14 +4,10 @@ use Inensus\SwiftaPaymentProvider\Models\SwiftaAuthentication; -class SwiftaAuthenticationService -{ - public function __construct(private SwiftaAuthentication $swiftaAuthentication) - { - } +class SwiftaAuthenticationService { + public function __construct(private SwiftaAuthentication $swiftaAuthentication) {} - public function getSwiftaAuthentication() - { + public function getSwiftaAuthentication() { return $this->swiftaAuthentication->firstOrFail(); } } diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Services/SwiftaTransactionService.php b/src/backend/packages/inensus/swifta-payment-provider/src/Services/SwiftaTransactionService.php index 85970670c..87dfd941b 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Services/SwiftaTransactionService.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Services/SwiftaTransactionService.php @@ -18,8 +18,7 @@ /** * @implements IBaseService */ -class SwiftaTransactionService extends AbstractPaymentAggregatorTransactionService implements IBaseService -{ +class SwiftaTransactionService extends AbstractPaymentAggregatorTransactionService implements IBaseService { public function __construct( private Meter $meter, private Address $address, @@ -36,8 +35,7 @@ public function __construct( ); } - public function initializeTransactionData($data): array - { + public function initializeTransactionData($data): array { return [ 'amount' => $data['amount'], 'cipher' => $data['cipher'], @@ -46,8 +44,7 @@ public function initializeTransactionData($data): array ]; } - public function setRequestedTransactionsStatusFailed() - { + public function setRequestedTransactionsStatusFailed() { $this->swiftaTransaction->newQuery()->where('status', SwiftaTransaction::STATUS_REQUESTED)->get()->each(function ($transaction) { $transaction->update([ 'status' => SwiftaTransaction::STATUS_FAILED, @@ -61,13 +58,11 @@ public function setRequestedTransactionsStatusFailed() }); } - public function getSwiftaTransaction() - { + public function getSwiftaTransaction() { return $this->getPaymentAggregatorTransaction(); } - public function getTransactionById($transactionId) - { + public function getTransactionById($transactionId) { try { return $this->transaction->newQuery()->findOrFail($transactionId); } catch (ModelNotFoundException $exception) { @@ -75,38 +70,32 @@ public function getTransactionById($transactionId) } } - public function checkAmountIsSame($amount, $transaction) - { + public function checkAmountIsSame($amount, $transaction) { if ($amount != (int) $transaction->amount) { throw new \Exception('amount validation field.'); } } - public function getById(?int $id): SwiftaTransaction - { + public function getById(?int $id): SwiftaTransaction { return $this->swiftaTransaction->newQuery()->find($id); } - public function update($swiftaTransaction, $swiftaTransactionData): SwiftaTransaction - { + public function update($swiftaTransaction, $swiftaTransactionData): SwiftaTransaction { $swiftaTransaction->update($swiftaTransactionData); $swiftaTransaction->fresh(); return $swiftaTransaction; } - public function create(array $swiftaTransactionData): SwiftaTransaction - { + public function create(array $swiftaTransactionData): SwiftaTransaction { return $this->swiftaTransaction->newQuery()->create($swiftaTransactionData); } - public function delete($swiftaTransaction): ?bool - { + public function delete($swiftaTransaction): ?bool { return $swiftaTransaction->delete(); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { $query = $this->swiftaTransaction->newQuery(); if ($limit) { diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Tests/Feature/TransactionTests.php b/src/backend/packages/inensus/swifta-payment-provider/src/Tests/Feature/TransactionTests.php index 09bfb0bb4..08d212c57 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Tests/Feature/TransactionTests.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Tests/Feature/TransactionTests.php @@ -19,12 +19,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class TransactionTests extends TestCase -{ +class TransactionTests extends TestCase { use RefreshDatabase; - public function testWithNonExistingTransaction() - { + public function testWithNonExistingTransaction() { $data = [ 'transaction_id' => -1, 'transaction_reference' => 'ref', @@ -44,8 +42,7 @@ public function testWithNonExistingTransaction() ]); } - public function testWithDifferentTransactionAmountFromValidatedTransaction() - { + public function testWithDifferentTransactionAmountFromValidatedTransaction() { $this->initializeData(); $user = User::query()->create([ 'name' => 'test', @@ -74,8 +71,7 @@ public function testWithDifferentTransactionAmountFromValidatedTransaction() ]); } - public function testWithValidTransaction() - { + public function testWithValidTransaction() { Queue::fake(); $this->initializeData(); $user = User::query()->create([ @@ -115,8 +111,7 @@ public function testWithValidTransaction() ]); } - private function initializeData() - { + private function initializeData() { // create person factory(Person::class)->create(); // create meter-tariff @@ -167,8 +162,7 @@ private function initializeData() $address->save(); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $customClaims = ['usr' => 'swifta-token', 'exp' => Carbon::now()->addYears(1)->timestamp]; $token = JWTAuth::customClaims($customClaims)->fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Tests/Feature/ValidationTests.php b/src/backend/packages/inensus/swifta-payment-provider/src/Tests/Feature/ValidationTests.php index a9f213bd6..e20abd044 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Tests/Feature/ValidationTests.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Tests/Feature/ValidationTests.php @@ -18,12 +18,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class ValidationTests extends TestCase -{ +class ValidationTests extends TestCase { use RefreshDatabase; - public function testOnlyAuthenticatedSwiftaUserSendsTransaction() - { + public function testOnlyAuthenticatedSwiftaUserSendsTransaction() { $data = [ 'meter_number' => '478881899', 'amount' => 1000, @@ -42,8 +40,7 @@ public function testOnlyAuthenticatedSwiftaUserSendsTransaction() ]); } - public function testWithoutInvalidCipher() - { + public function testWithoutInvalidCipher() { $data = [ 'meter_number' => '478881899', 'amount' => 1000, @@ -62,8 +59,7 @@ public function testWithoutInvalidCipher() ]); } - public function testWithoutNonExistingMeterNumber() - { + public function testWithoutNonExistingMeterNumber() { $this->initializeData(); $data = [ 'meter_number' => '4700005610', @@ -84,8 +80,7 @@ public function testWithoutNonExistingMeterNumber() ]); } - public function testWithNonSenderAddress() - { + public function testWithNonSenderAddress() { $this->initializeData(); Address::query()->first()->delete(); $data = [ @@ -108,8 +103,7 @@ public function testWithNonSenderAddress() ]); } - public function testWithInvalidTransactionAmount() - { + public function testWithInvalidTransactionAmount() { $this->initializeData(); AccessRate::query()->where('id', 1)->update([ 'tariff_id' => 1, @@ -140,8 +134,7 @@ public function testWithInvalidTransactionAmount() ]); } - public function testWithValidTransactionAmount() - { + public function testWithValidTransactionAmount() { $this->initializeData(); $data = [ 'meter_number' => '4700005646', @@ -169,8 +162,7 @@ public function testWithValidTransactionAmount() ]); } - private function initializeData() - { + private function initializeData() { // create person factory(Person::class)->create(); // create meter-tariff @@ -221,8 +213,7 @@ private function initializeData() $address->save(); } - public function actingAsWrong($user, $driver = null) - { + public function actingAsWrong($user, $driver = null) { $customClaims = ['usr' => 'swifta-token-wrong', 'exp' => Carbon::now()->addYears(1)->timestamp]; $token = JWTAuth::customClaims($customClaims)->fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); @@ -231,8 +222,7 @@ public function actingAsWrong($user, $driver = null) return $this; } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $customClaims = ['usr' => 'swifta-token', 'exp' => Carbon::now()->addYears(1)->timestamp]; $token = JWTAuth::customClaims($customClaims)->fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); diff --git a/src/backend/packages/inensus/swifta-payment-provider/src/Tests/Unit/PaymentProcessTests.php b/src/backend/packages/inensus/swifta-payment-provider/src/Tests/Unit/PaymentProcessTests.php index a5af291bd..8371c7516 100644 --- a/src/backend/packages/inensus/swifta-payment-provider/src/Tests/Unit/PaymentProcessTests.php +++ b/src/backend/packages/inensus/swifta-payment-provider/src/Tests/Unit/PaymentProcessTests.php @@ -20,12 +20,10 @@ use Illuminate\Support\Facades\Queue; use Tests\TestCase; -class PaymentProcessTests extends TestCase -{ +class PaymentProcessTests extends TestCase { use RefreshDatabase; - public function testProcessPaymentStartsEnergyTransactionProcessor() - { + public function testProcessPaymentStartsEnergyTransactionProcessor() { Queue::fake(); $this->initializeData(); $transaction = $this->initializeTransaction(); @@ -33,8 +31,7 @@ public function testProcessPaymentStartsEnergyTransactionProcessor() Queue::assertPushed(EnergyTransactionProcessor::class); } - public function testEnergyTransactionProcessorStartsTokenProcessor() - { + public function testEnergyTransactionProcessorStartsTokenProcessor() { Queue::fake(); $this->initializeData(); $transaction = $this->initializeTransaction(); @@ -42,8 +39,7 @@ public function testEnergyTransactionProcessorStartsTokenProcessor() Queue::assertPushed(TokenProcessor::class); } - public function testTokenProcessorChargesMeter() - { + public function testTokenProcessorChargesMeter() { Queue::fake(); $this->initializeData(); $transaction = $this->initializeTransaction(); @@ -57,8 +53,7 @@ public function testTokenProcessorChargesMeter() $this->assertEquals(1, $mesombPaymentCount); } - private function initializeTransaction() - { + private function initializeTransaction() { $validData = [ 'pk' => 'ae58a073-2b76-4774-995b-3743d6793d53', 'type' => 'PAYMENT', @@ -75,12 +70,13 @@ private function initializeTransaction() $mesombTransaction = $mesombTransactionService->assignIncomingDataToMesombTransaction($validData); $transaction = $mesombTransactionService->assignIncomingDataToTransaction($validData); - return $mesombTransactionService->associateMesombTransactionWithTransaction($mesombTransaction, - $transaction); + return $mesombTransactionService->associateMesombTransactionWithTransaction( + $mesombTransaction, + $transaction + ); } - private function initializeData() - { + private function initializeData() { // create person factory(Person::class)->create(); // create meter-tariff diff --git a/src/backend/packages/inensus/ticket/src/Exceptions/ApiUserNotFound.php b/src/backend/packages/inensus/ticket/src/Exceptions/ApiUserNotFound.php index 081ae012e..28f351359 100644 --- a/src/backend/packages/inensus/ticket/src/Exceptions/ApiUserNotFound.php +++ b/src/backend/packages/inensus/ticket/src/Exceptions/ApiUserNotFound.php @@ -2,6 +2,4 @@ namespace Inensus\Ticket\Exceptions; -class ApiUserNotFound extends \Exception -{ -} +class ApiUserNotFound extends \Exception {} diff --git a/src/backend/packages/inensus/ticket/src/Exceptions/TicketOwnerNotFoundException.php b/src/backend/packages/inensus/ticket/src/Exceptions/TicketOwnerNotFoundException.php index 0cb518af5..c6ff994c0 100644 --- a/src/backend/packages/inensus/ticket/src/Exceptions/TicketOwnerNotFoundException.php +++ b/src/backend/packages/inensus/ticket/src/Exceptions/TicketOwnerNotFoundException.php @@ -2,6 +2,4 @@ namespace Inensus\Ticket\Exceptions; -class TicketOwnerNotFoundException extends \Exception -{ -} +class TicketOwnerNotFoundException extends \Exception {} diff --git a/src/backend/packages/inensus/ticket/src/Factories/TicketCategoryFactory.php b/src/backend/packages/inensus/ticket/src/Factories/TicketCategoryFactory.php index f0b4625a8..89ff52ab6 100644 --- a/src/backend/packages/inensus/ticket/src/Factories/TicketCategoryFactory.php +++ b/src/backend/packages/inensus/ticket/src/Factories/TicketCategoryFactory.php @@ -5,8 +5,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Inensus\Ticket\Models\TicketCategory; -class TicketCategoryFactory extends Factory -{ +class TicketCategoryFactory extends Factory { protected $model = TicketCategory::class; /** @@ -14,8 +13,7 @@ class TicketCategoryFactory extends Factory * * @return array */ - public function definition() - { + public function definition() { return [ 'label_name' => $this->faker->word, 'label_color' => $this->faker->colorName, diff --git a/src/backend/packages/inensus/ticket/src/Http/Controllers/Controller.php b/src/backend/packages/inensus/ticket/src/Http/Controllers/Controller.php index 9c572c7df..577736f13 100644 --- a/src/backend/packages/inensus/ticket/src/Http/Controllers/Controller.php +++ b/src/backend/packages/inensus/ticket/src/Http/Controllers/Controller.php @@ -7,8 +7,7 @@ use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Routing\Controller as BaseController; -class Controller extends BaseController -{ +class Controller extends BaseController { use AuthorizesRequests; use DispatchesJobs; use ValidatesRequests; diff --git a/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketAgentController.php b/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketAgentController.php index 52003b9f8..e5d4242a9 100644 --- a/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketAgentController.php +++ b/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketAgentController.php @@ -6,14 +6,10 @@ use Inensus\Ticket\Http\Resources\TicketResource; use Inensus\Ticket\Services\TicketService; -class TicketAgentController extends Controller -{ - public function __construct(private TicketService $ticketService) - { - } +class TicketAgentController extends Controller { + public function __construct(private TicketService $ticketService) {} - public function index($agentId, Request $request): TicketResource - { + public function index($agentId, Request $request): TicketResource { $limit = 5; $status = null; diff --git a/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketCategoryController.php b/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketCategoryController.php index 44e9c6f1d..a3af249bf 100644 --- a/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketCategoryController.php +++ b/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketCategoryController.php @@ -7,25 +7,20 @@ use Inensus\Ticket\Http\Resources\TicketResource; use Inensus\Ticket\Services\TicketCategoryService; -class TicketCategoryController extends Controller -{ - public function __construct(private TicketCategoryService $ticketCategoryService) - { - } +class TicketCategoryController extends Controller { + public function __construct(private TicketCategoryService $ticketCategoryService) {} /** * A list of all stored labels/categories. */ - public function index(Request $request): TicketResource - { + public function index(Request $request): TicketResource { $limit = $request->input('per_page'); $outsource = $request->get('outsource'); return TicketResource::make($this->ticketCategoryService->getAll($limit, $outsource)); } - public function store(TicketCategoryRequest $request): TicketResource - { + public function store(TicketCategoryRequest $request): TicketResource { $ticketCategoryData = [ 'label_name' => $request->input('labelName'), 'label_color' => $request->input('labelColor'), diff --git a/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketCommentController.php b/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketCommentController.php index f144a1a1b..319c32c5c 100644 --- a/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketCommentController.php +++ b/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketCommentController.php @@ -8,14 +8,10 @@ use Inensus\Ticket\Services\TicketCommentService; use Inensus\Ticket\Services\TicketUserService; -class TicketCommentController extends Controller -{ - public function __construct(private TicketCommentService $ticketCommentService, private TicketUserService $ticketUserService) - { - } +class TicketCommentController extends Controller { + public function __construct(private TicketCommentService $ticketCommentService, private TicketUserService $ticketUserService) {} - public function store(Request $request) - { + public function store(Request $request) { /** @var User $user */ $user = Auth::user(); $ticketId = (int) $request->input('cardId'); diff --git a/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketController.php b/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketController.php index 53962d162..0840d9678 100644 --- a/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketController.php +++ b/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketController.php @@ -6,16 +6,12 @@ use Inensus\Ticket\Http\Resources\TicketResource; use Inensus\Ticket\Services\TicketService; -class TicketController extends Controller -{ +class TicketController extends Controller { public const FOR_APP = false; - public function __construct(private TicketService $ticketService) - { - } + public function __construct(private TicketService $ticketService) {} - public function index(Request $request): TicketResource - { + public function index(Request $request): TicketResource { $assignedId = $request->input('person') ?? null; $categoryId = $request->input('category') ?? null; $status = $request->input('status') ?? null; @@ -23,20 +19,24 @@ public function index(Request $request): TicketResource $agentId = $request->input('agent') ?? null; $customerId = $request->input('customer') ?? null; - return TicketResource::make($this->ticketService->getAll($limit, $status, $agentId, $customerId, $assignedId, - $categoryId)); + return TicketResource::make($this->ticketService->getAll( + $limit, + $status, + $agentId, + $customerId, + $assignedId, + $categoryId + )); } - public function show(int $id): TicketResource - { + public function show(int $id): TicketResource { $ticket = $this->ticketService->getById($id); return TicketResource::make(collect($ticket)); } // TODO: change this on UI side with query parameter $ticketId - public function destroy(int $ticketId, Request $request) - { + public function destroy(int $ticketId, Request $request) { $closed = $this->ticketService->close($ticketId); return TicketResource::make(['data' => $closed]); diff --git a/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketCustomerController.php b/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketCustomerController.php index 48eec9212..e922d403d 100644 --- a/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketCustomerController.php +++ b/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketCustomerController.php @@ -14,8 +14,7 @@ use Inensus\Ticket\Services\TicketOutSourceService; use Inensus\Ticket\Services\TicketService; -class TicketCustomerController extends Controller -{ +class TicketCustomerController extends Controller { public function __construct( private TicketService $ticketService, private UserTicketService $userTicketService, @@ -25,11 +24,9 @@ public function __construct( private TicketOutSourceService $ticketOutSourceService, private MaintenanceUserService $maintenanceUserService, private MaintenanceUserTicketService $maintenanceUserTicketService, - ) { - } + ) {} - public function store(UserTicketCreateRequest $request): TicketResource - { + public function store(UserTicketCreateRequest $request): TicketResource { $ticketData = $request->getMappedArray(); $user = auth('api')->user(); $ticket = $this->ticketService->make($ticketData); @@ -62,8 +59,7 @@ public function store(UserTicketCreateRequest $request): TicketResource return TicketResource::make($ticket); } - public function index($customerId, Request $request) - { + public function index($customerId, Request $request) { $limit = 5; $agentId = null; $status = null; diff --git a/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketExportController.php b/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketExportController.php index 99f72b25e..d616609f6 100644 --- a/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketExportController.php +++ b/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketExportController.php @@ -8,21 +8,16 @@ use Inensus\Ticket\Services\TicketService; use Symfony\Component\HttpFoundation\BinaryFileResponse; -class TicketExportController -{ +class TicketExportController { public function __construct( private TicketOutsourceReportService $ticketOutsourceReportService, private TicketService $ticketService, - ) { - } + ) {} /** * A list of stored book keeping data. - * - * @return TicketResource */ - public function index(Request $request): TicketResource - { + public function index(Request $request): TicketResource { $limit = $request->input('per_page'); return TicketResource::make($this->ticketOutsourceReportService->getAll($limit)); @@ -31,14 +26,9 @@ public function index(Request $request): TicketResource /** * Generates a book keeping file and stores it. * - * @param Request $request - * - * @return TicketResource - * * @throws \PhpOffice\PhpSpreadsheet\Exception */ - public function outsource(Request $request): TicketResource - { + public function outsource(Request $request): TicketResource { $startDate = $request->input('startDate'); $endDate = $request->input('endDate'); $tickets = $this->ticketService->getForOutsourceReport($startDate, $endDate); @@ -51,8 +41,7 @@ public function outsource(Request $request): TicketResource return TicketResource::make($this->ticketOutsourceReportService->create($ticketOutsourceReportData)); } - public function download($id): BinaryFileResponse - { + public function download($id): BinaryFileResponse { return response()->download($this->ticketOutsourceReportService->getById($id)); } } diff --git a/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketUserController.php b/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketUserController.php index bd23a2f21..682a6965a 100644 --- a/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketUserController.php +++ b/src/backend/packages/inensus/ticket/src/Http/Controllers/TicketUserController.php @@ -9,24 +9,20 @@ use Inensus\Ticket\Http\Resources\TicketResource; use Inensus\Ticket\Services\TicketUserService; -class TicketUserController extends Controller -{ +class TicketUserController extends Controller { public function __construct( private TicketUserService $ticketUserService, private UserService $userService, - ) { - } + ) {} - public function index(Request $request): TicketResource - { + public function index(Request $request): TicketResource { $limit = $request->input('per_page'); $outSource = $request->input('outsource'); return TicketResource::make($this->ticketUserService->getAll($limit, $outSource)); } - public function storeExternal(TicketingUserExternalRequest $request) - { + public function storeExternal(TicketingUserExternalRequest $request) { $ticketUserData = [ 'user_name' => $request->getUserName(), 'phone' => $request->getPhone(), @@ -37,8 +33,7 @@ public function storeExternal(TicketingUserExternalRequest $request) $this->ticketUserService->create($ticketUserData); } - public function store(TicketingUserRequest $request): TicketResource - { + public function store(TicketingUserRequest $request): TicketResource { $user = $this->userService->get($request->getUserId()); $ticketUserData = [ diff --git a/src/backend/packages/inensus/ticket/src/Http/Controllers/WatcherController.php b/src/backend/packages/inensus/ticket/src/Http/Controllers/WatcherController.php index af2efce66..7a68ad27c 100644 --- a/src/backend/packages/inensus/ticket/src/Http/Controllers/WatcherController.php +++ b/src/backend/packages/inensus/ticket/src/Http/Controllers/WatcherController.php @@ -13,14 +13,14 @@ * The reason to storing the actions, is to make a timeline. * Class WatcherController. */ -class WatcherController -{ +class WatcherController { // TODO: fix for Saas. /** * The Trello action codes which are logged in our system. */ public const INTERESTING_ACTIONS = ['createCard', 'addMemberToCard', 'commentCard', 'updateCard']; + /** * @var Ticket */ @@ -28,16 +28,12 @@ class WatcherController /** * WatcherController constructor. - * - * @param Ticket $ticket */ - public function __construct(Ticket $ticket) - { + public function __construct(Ticket $ticket) { $this->ticket = $ticket; } - public function store(): void - { + public function store(): void { // convert the json string $content = json_decode(request()->getContent(), true); if ($content === null) { // request body is not a valid json string. @@ -62,11 +58,8 @@ public function store(): void * Checks if the request type is interesting or not. * * @param string $type the request type - * - * @return bool */ - private function filterRequest($type): bool - { + private function filterRequest($type): bool { return \in_array($type, self::INTERESTING_ACTIONS, false); } @@ -74,19 +67,13 @@ private function filterRequest($type): bool * Tries to match the given ticket id with an entry in the database * it should prevent, that any new ticket created directly in Trello. * - * @param string $ticketId - * - * @return Ticket - * * @throws ModelNotFoundException */ - private function ticketMatcher(string $ticketId): Ticket - { + private function ticketMatcher(string $ticketId): Ticket { return $this->ticket->where('ticket_id', $ticketId)->firstOrFail(); } - private function fetchAndStore($type, $action): void - { + private function fetchAndStore($type, $action): void { $text = ''; // initialize text $ticketId = $action['data']['card']['id']; // the affected card. $actionType = null; diff --git a/src/backend/packages/inensus/ticket/src/Http/Requests/TicketCategoryRequest.php b/src/backend/packages/inensus/ticket/src/Http/Requests/TicketCategoryRequest.php index 99a9b5ff2..936bc2155 100644 --- a/src/backend/packages/inensus/ticket/src/Http/Requests/TicketCategoryRequest.php +++ b/src/backend/packages/inensus/ticket/src/Http/Requests/TicketCategoryRequest.php @@ -4,10 +4,8 @@ use Illuminate\Foundation\Http\FormRequest; -class TicketCategoryRequest extends FormRequest -{ - public function rules(): array - { +class TicketCategoryRequest extends FormRequest { + public function rules(): array { return [ 'labelName' => 'required', 'labelColor' => 'sometimes|in:yellow,purple,blue,red,green,orange,black,sky,pink,lime,nocolor', diff --git a/src/backend/packages/inensus/ticket/src/Http/Requests/TicketingUserExternalRequest.php b/src/backend/packages/inensus/ticket/src/Http/Requests/TicketingUserExternalRequest.php index 1b99f2914..4d69785cd 100644 --- a/src/backend/packages/inensus/ticket/src/Http/Requests/TicketingUserExternalRequest.php +++ b/src/backend/packages/inensus/ticket/src/Http/Requests/TicketingUserExternalRequest.php @@ -4,28 +4,22 @@ use Illuminate\Foundation\Http\FormRequest; -class TicketingUserExternalRequest extends FormRequest -{ +class TicketingUserExternalRequest extends FormRequest { /** * Describes the rules which should be fulfilled by the request. - * - * @return array */ - public function rules(): array - { + public function rules(): array { return [ 'username' => 'required', 'phone' => 'required', ]; } - public function getUserName(): string - { + public function getUserName(): string { return $this->input('username'); } - public function getPhone(): string - { + public function getPhone(): string { return (int) $this->input('phone'); } } diff --git a/src/backend/packages/inensus/ticket/src/Http/Requests/TicketingUserRequest.php b/src/backend/packages/inensus/ticket/src/Http/Requests/TicketingUserRequest.php index 1a726cf21..586e53eec 100644 --- a/src/backend/packages/inensus/ticket/src/Http/Requests/TicketingUserRequest.php +++ b/src/backend/packages/inensus/ticket/src/Http/Requests/TicketingUserRequest.php @@ -4,22 +4,17 @@ use Illuminate\Foundation\Http\FormRequest; -class TicketingUserRequest extends FormRequest -{ +class TicketingUserRequest extends FormRequest { /** * Describes the rules which should be fulfilled by the request. - * - * @return array */ - public function rules(): array - { + public function rules(): array { return [ 'user_id' => 'required|numeric', ]; } - public function getUserId(): int - { + public function getUserId(): int { return (int) $this->input('user_id'); } } diff --git a/src/backend/packages/inensus/ticket/src/Http/Requests/UserTicketCreateRequest.php b/src/backend/packages/inensus/ticket/src/Http/Requests/UserTicketCreateRequest.php index aaa819478..585797d7e 100644 --- a/src/backend/packages/inensus/ticket/src/Http/Requests/UserTicketCreateRequest.php +++ b/src/backend/packages/inensus/ticket/src/Http/Requests/UserTicketCreateRequest.php @@ -5,30 +5,24 @@ use Illuminate\Foundation\Http\FormRequest; use Ramsey\Uuid\Uuid; -class UserTicketCreateRequest extends FormRequest -{ - public function rules(): array - { +class UserTicketCreateRequest extends FormRequest { + public function rules(): array { return []; } - public function getTitle(): string - { + public function getTitle(): string { return $this->input('title'); } - public function getOwnerId(): ?int - { + public function getOwnerId(): ?int { return $this->input('owner_id'); } - public function getOutsourcing(): bool - { + public function getOutsourcing(): bool { return $this->input('outsourcing'); } - public function getMappedArray(): array - { + public function getMappedArray(): array { return [ 'ticket_id' => Uuid::uuid4(), 'title' => $this->getTitle(), @@ -39,23 +33,19 @@ public function getMappedArray(): array ]; } - public function getLabel(): int - { + public function getLabel(): int { return $this->input('label'); } - private function getAssignedPerson(): ?int - { + private function getAssignedPerson(): ?int { return $this->input('assignedPerson'); } - private function getDescription(): string - { + private function getDescription(): string { return $this->input('description'); } - private function getDueDate(): ?string - { + private function getDueDate(): ?string { return $this->input('dueDate'); } } diff --git a/src/backend/packages/inensus/ticket/src/Http/Resources/TicketResource.php b/src/backend/packages/inensus/ticket/src/Http/Resources/TicketResource.php index 024d08f73..892137753 100644 --- a/src/backend/packages/inensus/ticket/src/Http/Resources/TicketResource.php +++ b/src/backend/packages/inensus/ticket/src/Http/Resources/TicketResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class TicketResource extends JsonResource -{ +class TicketResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class TicketResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/packages/inensus/ticket/src/Interfaces/ITicketProvider.php b/src/backend/packages/inensus/ticket/src/Interfaces/ITicketProvider.php index faf7f0a7e..d52500f7c 100644 --- a/src/backend/packages/inensus/ticket/src/Interfaces/ITicketProvider.php +++ b/src/backend/packages/inensus/ticket/src/Interfaces/ITicketProvider.php @@ -2,8 +2,7 @@ namespace Inensus\Ticket\Interfaces; -interface ITicketProvider -{ +interface ITicketProvider { // initializes the ticketing system public function initialize(); diff --git a/src/backend/packages/inensus/ticket/src/Jobs/OutputJob.php b/src/backend/packages/inensus/ticket/src/Jobs/OutputJob.php index 5dc8e3234..366ffc1a1 100644 --- a/src/backend/packages/inensus/ticket/src/Jobs/OutputJob.php +++ b/src/backend/packages/inensus/ticket/src/Jobs/OutputJob.php @@ -9,12 +9,12 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Log; -class OutputJob implements ShouldQueue -{ +class OutputJob implements ShouldQueue { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; + /** * @var integert */ @@ -25,14 +25,12 @@ class OutputJob implements ShouldQueue */ protected $queue_name; - public function __construct(string $queue_name, int $val) - { + public function __construct(string $queue_name, int $val) { $this->queue_name = $queue_name; $this->val = $val; } - public function handle(): void - { + public function handle(): void { Log::critical('redis', ['abc' => 'def', 'Val' => $this->val, 'queue' => $this->queue_name]); } } diff --git a/src/backend/packages/inensus/ticket/src/Models/BaseModel.php b/src/backend/packages/inensus/ticket/src/Models/BaseModel.php index 3097d4d06..c49f487c9 100644 --- a/src/backend/packages/inensus/ticket/src/Models/BaseModel.php +++ b/src/backend/packages/inensus/ticket/src/Models/BaseModel.php @@ -2,6 +2,4 @@ namespace Inensus\Ticket\Models; -class BaseModel extends \App\Models\Base\BaseModel -{ -} +class BaseModel extends \App\Models\Base\BaseModel {} diff --git a/src/backend/packages/inensus/ticket/src/Models/Ticket.php b/src/backend/packages/inensus/ticket/src/Models/Ticket.php index 470206ac1..6b5bdc359 100644 --- a/src/backend/packages/inensus/ticket/src/Models/Ticket.php +++ b/src/backend/packages/inensus/ticket/src/Models/Ticket.php @@ -8,8 +8,7 @@ use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Support\Facades\DB; -class Ticket extends BaseModel -{ +class Ticket extends BaseModel { protected $table = 'tickets'; public const STATUS = [ @@ -18,53 +17,44 @@ class Ticket extends BaseModel 'waiting' => 2, ]; - public function card() - { + public function card() { return $this->belongsTo(TicketCard::class); } - public function category(): BelongsTo - { + public function category(): BelongsTo { return $this->belongsTo(TicketCategory::class, 'category_id'); } - public function owner(): MorphTo - { + public function owner(): MorphTo { return $this->morphTo(); } - public function outsource(): HasOne - { + public function outsource(): HasOne { return $this->hasOne(TicketOutsource::class); } - public function assignedTo(): BelongsTo - { + public function assignedTo(): BelongsTo { return $this->belongsTo(TicketUser::class, 'assigned_id'); } - public function ticketsOpenedInPeriod($startDate, $endDate) - { + public function ticketsOpenedInPeriod($startDate, $endDate) { return $this->select(DB::raw('COUNT(id) as amount, YEARWEEK(created_at,3) as period')) ->whereBetween('created_at', [$startDate, $endDate]) ->groupBy(DB::raw('YEARWEEK(created_at,3)')); } - public function ticketsClosedInPeriod($startDate, $endDate) - { + public function ticketsClosedInPeriod($startDate, $endDate) { return $this->select(DB::raw('COUNT(id) as amount, YEARWEEK(updated_at,3) as period,avg(timestampdiff(SECOND, created_at, updated_at)) as avgdiff')) ->where('status', 1) ->whereBetween('updated_at', [$startDate, $endDate]) ->groupBy(DB::raw('YEARWEEK(updated_at,3)')); } - public function creator() - { + public function creator() { return $this->morphTo('creator'); } - public function ticketsOpenedWithCategories($miniGridId): bool|array - { + public function ticketsOpenedWithCategories($miniGridId): bool|array { $sql = 'SELECT ticket_categories.label_name, count(tickets.id) as new_tickets, YEARWEEK(tickets.created_at,3) as period FROM `tickets` '. 'LEFT join ticket_categories on tickets.category_id = ticket_categories.id '. 'left join addresses on addresses.owner_id = tickets.owner_id '. @@ -79,8 +69,7 @@ public function ticketsOpenedWithCategories($miniGridId): bool|array return $sth->fetchAll(\PDO::FETCH_ASSOC); } - public function ticketsClosedWithCategories($miniGridId): bool|array - { + public function ticketsClosedWithCategories($miniGridId): bool|array { $sql = 'SELECT ticket_categories.label_name, count(tickets.id) as closed_tickets, YEARWEEK(tickets.updated_at,3) as period FROM `tickets` '. 'LEFT join ticket_categories on tickets.category_id = ticket_categories.id '. 'left join addresses on addresses.owner_id = tickets.owner_id '. @@ -95,8 +84,7 @@ public function ticketsClosedWithCategories($miniGridId): bool|array return $sth->fetchAll(\PDO::FETCH_ASSOC); } - public function comments(): HasMany - { + public function comments(): HasMany { return $this->hasMany(TicketComment::class, 'ticket_id', 'id'); } } diff --git a/src/backend/packages/inensus/ticket/src/Models/TicketCategory.php b/src/backend/packages/inensus/ticket/src/Models/TicketCategory.php index eec1aaf5d..2f3b81a89 100644 --- a/src/backend/packages/inensus/ticket/src/Models/TicketCategory.php +++ b/src/backend/packages/inensus/ticket/src/Models/TicketCategory.php @@ -5,13 +5,11 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Inensus\Ticket\Factories\TicketCategoryFactory; -class TicketCategory extends BaseModel -{ +class TicketCategory extends BaseModel { /** * Create a new factory instance for the model. */ - protected static function newFactory(): Factory - { + protected static function newFactory(): Factory { return TicketCategoryFactory::new(); } diff --git a/src/backend/packages/inensus/ticket/src/Models/TicketComment.php b/src/backend/packages/inensus/ticket/src/Models/TicketComment.php index 70bfdd5f1..597817733 100644 --- a/src/backend/packages/inensus/ticket/src/Models/TicketComment.php +++ b/src/backend/packages/inensus/ticket/src/Models/TicketComment.php @@ -4,17 +4,14 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; -class TicketComment extends BaseModel -{ +class TicketComment extends BaseModel { protected $table = 'ticket_comments'; - public function ticket(): BelongsTo - { + public function ticket(): BelongsTo { return $this->belongsTo(Ticket::class, 'ticket_id', 'id'); } - public function ticketUser(): BelongsTo - { + public function ticketUser(): BelongsTo { return $this->belongsTo(TicketUser::class, 'ticket_user_id', 'id'); } } diff --git a/src/backend/packages/inensus/ticket/src/Models/TicketOutsource.php b/src/backend/packages/inensus/ticket/src/Models/TicketOutsource.php index e6ffd9fe8..0b2dd1c59 100644 --- a/src/backend/packages/inensus/ticket/src/Models/TicketOutsource.php +++ b/src/backend/packages/inensus/ticket/src/Models/TicketOutsource.php @@ -2,12 +2,10 @@ namespace Inensus\Ticket\Models; -class TicketOutsource extends BaseModel -{ +class TicketOutsource extends BaseModel { protected $table = 'ticket_outsources'; - public function ticket() - { + public function ticket() { return $this->belongsTo(Ticket::class); } } diff --git a/src/backend/packages/inensus/ticket/src/Models/TicketOutsourceReport.php b/src/backend/packages/inensus/ticket/src/Models/TicketOutsourceReport.php index 18f04c596..bdb122b80 100644 --- a/src/backend/packages/inensus/ticket/src/Models/TicketOutsourceReport.php +++ b/src/backend/packages/inensus/ticket/src/Models/TicketOutsourceReport.php @@ -9,7 +9,6 @@ * @property string $date * @property string $path */ -class TicketOutsourceReport extends BaseModel -{ +class TicketOutsourceReport extends BaseModel { protected $table = 'ticket_outsource_reports'; } diff --git a/src/backend/packages/inensus/ticket/src/Models/TicketUser.php b/src/backend/packages/inensus/ticket/src/Models/TicketUser.php index d82fba2d3..d406cb1d4 100644 --- a/src/backend/packages/inensus/ticket/src/Models/TicketUser.php +++ b/src/backend/packages/inensus/ticket/src/Models/TicketUser.php @@ -10,14 +10,14 @@ * @property int $out_source * @property int $id */ -class TicketUser extends BaseModel -{ +class TicketUser extends BaseModel { public const TABLE_NAME = 'ticket_users'; + public const COL_USER_ID = 'user_id'; + protected $table = self::TABLE_NAME; - public function getId(): int - { + public function getId(): int { return $this->id; } } diff --git a/src/backend/packages/inensus/ticket/src/Providers/TicketRootServiceProvider.php b/src/backend/packages/inensus/ticket/src/Providers/TicketRootServiceProvider.php index ba15e182e..ddacb811c 100644 --- a/src/backend/packages/inensus/ticket/src/Providers/TicketRootServiceProvider.php +++ b/src/backend/packages/inensus/ticket/src/Providers/TicketRootServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class TicketRootServiceProvider extends ServiceProvider -{ +class TicketRootServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\Ticket\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('tickets') ->namespace($this->namespace) ->group(__DIR__.'/../routes/web.php'); diff --git a/src/backend/packages/inensus/ticket/src/Providers/TicketServiceProvider.php b/src/backend/packages/inensus/ticket/src/Providers/TicketServiceProvider.php index f2fbd7e73..622a4105b 100644 --- a/src/backend/packages/inensus/ticket/src/Providers/TicketServiceProvider.php +++ b/src/backend/packages/inensus/ticket/src/Providers/TicketServiceProvider.php @@ -4,10 +4,8 @@ use Illuminate\Support\ServiceProvider; -class TicketServiceProvider extends ServiceProvider -{ - public function boot() - { +class TicketServiceProvider extends ServiceProvider { + public function boot() { $this->app->register(TicketRootServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -15,23 +13,20 @@ public function boot() } } - public function register() - { + public function register() { $this->mergeConfigFrom( __DIR__.'/../../config/tickets.php', 'tickets' ); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/tickets.php' => config_path('tickets.php'), ], 'config'); } - public function publishMigrations() - { + public function publishMigrations() { if (!class_exists('CreateTicketingTables')) { $timestamp = date('Y_m_d_His', time()); diff --git a/src/backend/packages/inensus/ticket/src/Services/TicketCategoryService.php b/src/backend/packages/inensus/ticket/src/Services/TicketCategoryService.php index 11278724c..23f1a8342 100644 --- a/src/backend/packages/inensus/ticket/src/Services/TicketCategoryService.php +++ b/src/backend/packages/inensus/ticket/src/Services/TicketCategoryService.php @@ -10,35 +10,28 @@ /** * @implements IBaseService */ -class TicketCategoryService implements IBaseService -{ +class TicketCategoryService implements IBaseService { public function __construct( private TicketCategory $ticketCategory, - ) { - } + ) {} - public function getById(int $categoryId): TicketCategory - { + public function getById(int $categoryId): TicketCategory { return $this->ticketCategory->newQuery()->find($categoryId); } - public function create(array $ticketCategoryData): TicketCategory - { + public function create(array $ticketCategoryData): TicketCategory { return $this->ticketCategory->newQuery()->create($ticketCategoryData); } - public function update($model, array $data): TicketCategory - { + public function update($model, array $data): TicketCategory { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null, ?bool $outsource = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null, ?bool $outsource = null): Collection|LengthAwarePaginator { $ticketCategories = $this->ticketCategory->newQuery(); if ($outsource) { diff --git a/src/backend/packages/inensus/ticket/src/Services/TicketCommentService.php b/src/backend/packages/inensus/ticket/src/Services/TicketCommentService.php index 20fae6e86..1dbdd966b 100644 --- a/src/backend/packages/inensus/ticket/src/Services/TicketCommentService.php +++ b/src/backend/packages/inensus/ticket/src/Services/TicketCommentService.php @@ -5,16 +5,14 @@ use App\Models\Person\Person; use Inensus\Ticket\Models\TicketComment; -class TicketCommentService -{ - public function __construct(private Person $person, +class TicketCommentService { + public function __construct( + private Person $person, private TicketComment $ticketComment, - private TicketUserService $ticketUserService) - { - } + private TicketUserService $ticketUserService, + ) {} - public function createComment(int $ticketId, string $comment, int $ticketUserId): TicketComment - { + public function createComment(int $ticketId, string $comment, int $ticketUserId): TicketComment { $commentData = [ 'comment' => $comment, 'ticket_id' => $ticketId, @@ -28,8 +26,7 @@ public function createComment(int $ticketId, string $comment, int $ticketUserId) } // store a comment if the sender is an maintenance guy and responds with sms to an open ticket. - public function storeComment($sender, $message) - { + public function storeComment($sender, $message) { $person = $this->person::with([ 'addresses', 'tickets' => static function ($q) { diff --git a/src/backend/packages/inensus/ticket/src/Services/TicketOutSourceService.php b/src/backend/packages/inensus/ticket/src/Services/TicketOutSourceService.php index e70bcb414..be9024f64 100644 --- a/src/backend/packages/inensus/ticket/src/Services/TicketOutSourceService.php +++ b/src/backend/packages/inensus/ticket/src/Services/TicketOutSourceService.php @@ -9,35 +9,28 @@ /** * @implements IBaseService */ -class TicketOutSourceService implements IBaseService -{ +class TicketOutSourceService implements IBaseService { public function __construct( private TicketOutsource $ticketOutsource, - ) { - } + ) {} - public function getById(int $ticketOutsourceId): TicketOutsource - { + public function getById(int $ticketOutsourceId): TicketOutsource { return $this->ticketOutsource->newQuery()->find($ticketOutsourceId); } - public function create(array $ticketOutsourceData): TicketOutsource - { + public function create(array $ticketOutsourceData): TicketOutsource { return $this->ticketOutsource->newQuery()->create($ticketOutsourceData); } - public function update($model, array $data): TicketOutsource - { + public function update($model, array $data): TicketOutsource { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } } diff --git a/src/backend/packages/inensus/ticket/src/Services/TicketOutsourceReportService.php b/src/backend/packages/inensus/ticket/src/Services/TicketOutsourceReportService.php index daa71de3a..1cf302203 100644 --- a/src/backend/packages/inensus/ticket/src/Services/TicketOutsourceReportService.php +++ b/src/backend/packages/inensus/ticket/src/Services/TicketOutsourceReportService.php @@ -13,16 +13,13 @@ /** * @implements IBaseService */ -class TicketOutsourceReportService implements IBaseService -{ +class TicketOutsourceReportService implements IBaseService { public function __construct( private TicketOutsourceReport $ticketOutsourceReport, - private Spreadsheet $spreadsheet) - { - } + private Spreadsheet $spreadsheet, + ) {} - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { if ($limit) { return $this->ticketOutsourceReport->newQuery()->paginate($limit); } @@ -30,8 +27,7 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->ticketOutsourceReport->newQuery()->get(); } - public function createExcelSheet($startDate, $endDate, $tickets) - { + public function createExcelSheet($startDate, $endDate, $tickets) { $fileName = 'Outsourcing-'.$startDate.'-'.$endDate.'.xlsx'; $sheet = $this->spreadsheet->getActiveSheet(); @@ -63,23 +59,19 @@ public function createExcelSheet($startDate, $endDate, $tickets) return $fileName; } - public function create(array $ticketOutsourceReportData): TicketOutsourceReport - { + public function create(array $ticketOutsourceReportData): TicketOutsourceReport { return $this->ticketOutsourceReport->newQuery()->create($ticketOutsourceReportData); } - public function getById(int $outsourceReportId): TicketOutsourceReport - { + public function getById(int $outsourceReportId): TicketOutsourceReport { return $this->ticketOutsourceReport->newQuery()->find($outsourceReportId); } - public function update($model, array $data): TicketOutsourceReport - { + public function update($model, array $data): TicketOutsourceReport { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } } diff --git a/src/backend/packages/inensus/ticket/src/Services/TicketService.php b/src/backend/packages/inensus/ticket/src/Services/TicketService.php index 9bba24c0f..29e03f970 100644 --- a/src/backend/packages/inensus/ticket/src/Services/TicketService.php +++ b/src/backend/packages/inensus/ticket/src/Services/TicketService.php @@ -10,12 +10,10 @@ /** * @implements IAssociative */ -class TicketService implements IAssociative -{ +class TicketService implements IAssociative { public function __construct( private Ticket $ticket, - ) { - } + ) {} public function create( string $title, @@ -41,8 +39,7 @@ public function create( return $ticket; } - public function close($ticketId): Ticket - { + public function close($ticketId): Ticket { $ticket = $this->getById($ticketId); $ticketData = ['status' => 1]; $this->update($ticket, $ticketData); @@ -50,8 +47,7 @@ public function close($ticketId): Ticket return $ticket->fresh(); } - public function getBatch($tickets) - { + public function getBatch($tickets) { foreach ($tickets as $index => $ticket) { $tickets[$index]['comments'] = $ticket->comments()->with('ticketUser')->get(); } @@ -59,13 +55,11 @@ public function getBatch($tickets) return $tickets; } - public function getById($ticketId) - { + public function getById($ticketId) { return $this->ticket->newQuery()->with(['category', 'owner'])->where('id', $ticketId)->first(); } - public function update($ticket, $ticketData) - { + public function update($ticket, $ticketData) { $ticket->update($ticketData); $ticket->fresh(); @@ -120,18 +114,15 @@ static function ($q) use ($agentId) { return $tickets; } - public function make(array $ticketData): Ticket - { + public function make(array $ticketData): Ticket { return $this->ticket->newQuery()->make($ticketData); } - public function save($ticket): bool - { + public function save($ticket): bool { return $ticket->save(); } - public function getForOutsourceReport($startDate, $endDate) - { + public function getForOutsourceReport($startDate, $endDate) { return $this->ticket->newQuery()->with(['outsource', 'assignedTo', 'category']) ->whereHas('category', static function ($q) { $q->where('out_source', 1); @@ -143,8 +134,7 @@ public function getForOutsourceReport($startDate, $endDate) ->get(); } - public function getForAgent($agentId, $customerId = null) - { + public function getForAgent($agentId, $customerId = null) { $query = $this->ticket->newQuery()->with(['category', 'owner', 'assignedTo', 'comments.ticketUser']); if ($agentId) { diff --git a/src/backend/packages/inensus/ticket/src/Services/TicketUserService.php b/src/backend/packages/inensus/ticket/src/Services/TicketUserService.php index 14f6c8153..41556151e 100644 --- a/src/backend/packages/inensus/ticket/src/Services/TicketUserService.php +++ b/src/backend/packages/inensus/ticket/src/Services/TicketUserService.php @@ -11,16 +11,13 @@ /** * @implements IBaseService */ -class TicketUserService implements IBaseService -{ +class TicketUserService implements IBaseService { public function __construct( private TicketUser $ticketUser, private User $user, - ) { - } + ) {} - public function getAll(?int $limit = null, ?bool $outsource = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null, ?bool $outsource = null): Collection|LengthAwarePaginator { $ticketUsers = $this->user::with('relationTicketUser'); if ($outsource) { @@ -34,28 +31,23 @@ public function getAll(?int $limit = null, ?bool $outsource = null): Collection| return $ticketUsers->get(); } - public function getById(int $externId): TicketUser - { + public function getById(int $externId): TicketUser { return $this->ticketUser->newQuery()->where('extern_id', $externId)->first(); } - public function create($ticketUserData): TicketUser - { + public function create($ticketUserData): TicketUser { return $this->ticketUser->newQuery()->create($ticketUserData); } - public function update($model, array $data): TicketUser - { + public function update($model, array $data): TicketUser { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function findByPhone(string $phone): TicketUser - { + public function findByPhone(string $phone): TicketUser { /** @var TicketUser $result */ $result = $this->ticketUser->newQuery()->where('phone', '=', $phone) ->firstOrFail(); @@ -63,8 +55,7 @@ public function findByPhone(string $phone): TicketUser return $result; } - public function findOrCreateByUser(User $user): TicketUser - { + public function findOrCreateByUser(User $user): TicketUser { try { /** @var TicketUser $result */ $result = $this->ticketUser->newQuery()->where('user_id', '=', $user->getId()) diff --git a/src/backend/packages/inensus/viber-messaging/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/viber-messaging/src/Console/Commands/InstallPackage.php index 90e344df2..5f45e8641 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/viber-messaging/src/Console/Commands/InstallPackage.php @@ -5,9 +5,9 @@ use Illuminate\Console\Command; use Inensus\ViberMessaging\Services\ViberCredentialService; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'viber-messaging:install'; + protected $description = 'Install ViberMessaging Package'; public function __construct( @@ -16,15 +16,13 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing ViberMessaging Integration Package\n'); $this->credentialService->createCredentials(); $this->info('Package installed successfully..'); } - private function publishMigrations() - { + private function publishMigrations() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\ViberMessaging\Providers\ViberMessagingServiceProvider", @@ -32,14 +30,12 @@ private function publishMigrations() ]); } - private function createDatabaseTables() - { + private function createDatabaseTables() { $this->info('Creating database tables\n'); $this->call('migrate'); } - private function publishVueFiles() - { + private function publishVueFiles() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\ViberMessaging\Providers\ViberMessagingServiceProvider", @@ -47,8 +43,7 @@ private function publishVueFiles() ]); } - private function createPluginRecord() - { + private function createPluginRecord() { $this->call('plugin:add', [ 'name' => 'ViberMessaging', 'composer_name' => 'inensus/viber-messaging', diff --git a/src/backend/packages/inensus/viber-messaging/src/Console/Commands/UpdatePackage.php b/src/backend/packages/inensus/viber-messaging/src/Console/Commands/UpdatePackage.php index 1c398b3e0..c3c6e30d0 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Console/Commands/UpdatePackage.php +++ b/src/backend/packages/inensus/viber-messaging/src/Console/Commands/UpdatePackage.php @@ -7,9 +7,9 @@ use Illuminate\Support\Facades\DB; use Inensus\ViberMessaging\Services\ViberCredentialService; -class UpdatePackage extends Command -{ +class UpdatePackage extends Command { protected $signature = 'viber-messaging:update'; + protected $description = 'Update ViberMessaging Package'; public function __construct( @@ -19,8 +19,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Viber Messaging Integration Updating Started\n'); $this->removeOldVersionOfPackage(); $this->installNewVersionOfPackage(); @@ -33,20 +32,17 @@ public function handle(): void $this->info('Package updated successfully..'); } - private function removeOldVersionOfPackage() - { + private function removeOldVersionOfPackage() { $this->info('Removing former version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar remove inensus/viber-messaging'); } - private function installNewVersionOfPackage() - { + private function installNewVersionOfPackage() { $this->info('Installing last version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar require inensus/viber-messaging'); } - private function deleteMigration(Filesystem $filesystem) - { + private function deleteMigration(Filesystem $filesystem) { $migrationFile = $filesystem->glob(database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR. '*_create_viber_tables.php')[0]; $migration = DB::table('migrations') @@ -59,8 +55,7 @@ private function deleteMigration(Filesystem $filesystem) ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->delete(); } - private function publishMigrationsAgain() - { + private function publishMigrationsAgain() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\ViberMessaging\Providers\ViberMessagingServiceProvider", @@ -68,14 +63,12 @@ private function publishMigrationsAgain() ]); } - private function updateDatabase() - { + private function updateDatabase() { $this->info('Updating database tables\n'); $this->call('migrate'); } - private function publishVueFilesAgain() - { + private function publishVueFilesAgain() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\ViberMessaging\Providers\ViberMessagingServiceProvider", diff --git a/src/backend/packages/inensus/viber-messaging/src/Exceptions/MessageNotSentException.php b/src/backend/packages/inensus/viber-messaging/src/Exceptions/MessageNotSentException.php index 774de2d69..6b51cfa7c 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Exceptions/MessageNotSentException.php +++ b/src/backend/packages/inensus/viber-messaging/src/Exceptions/MessageNotSentException.php @@ -2,6 +2,4 @@ namespace Inensus\ViberMessaging\Exceptions; -class MessageNotSentException extends \Exception -{ -} +class MessageNotSentException extends \Exception {} diff --git a/src/backend/packages/inensus/viber-messaging/src/Exceptions/WebhookNotCreatedException.php b/src/backend/packages/inensus/viber-messaging/src/Exceptions/WebhookNotCreatedException.php index 4837bd754..4522049ec 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Exceptions/WebhookNotCreatedException.php +++ b/src/backend/packages/inensus/viber-messaging/src/Exceptions/WebhookNotCreatedException.php @@ -2,6 +2,4 @@ namespace Inensus\ViberMessaging\Exceptions; -class WebhookNotCreatedException extends \Exception -{ -} +class WebhookNotCreatedException extends \Exception {} diff --git a/src/backend/packages/inensus/viber-messaging/src/Http/Controllers/ViberCredentialController.php b/src/backend/packages/inensus/viber-messaging/src/Http/Controllers/ViberCredentialController.php index 0dcde78ae..fdd76d6f4 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Http/Controllers/ViberCredentialController.php +++ b/src/backend/packages/inensus/viber-messaging/src/Http/Controllers/ViberCredentialController.php @@ -9,21 +9,17 @@ use Inensus\ViberMessaging\Services\ViberCredentialService; use MPM\DatabaseProxy\DatabaseProxyManagerService; -class ViberCredentialController extends Controller -{ +class ViberCredentialController extends Controller { public function __construct( private ViberCredentialService $credentialService, private DatabaseProxyManagerService $databaseProxyManagerService, - ) { - } + ) {} - public function show(): ViberResource - { + public function show(): ViberResource { return ViberResource::make($this->credentialService->getCredentials()); } - public function update(ViberCredentialRequest $request): ViberResource - { + public function update(ViberCredentialRequest $request): ViberResource { $databaseProxy = $this->databaseProxyManagerService->findByEmail(auth('api')->user()->email); $companyId = $databaseProxy->getCompanyId(); $apiToken = $request->input('api_token'); diff --git a/src/backend/packages/inensus/viber-messaging/src/Http/Controllers/WebhookController.php b/src/backend/packages/inensus/viber-messaging/src/Http/Controllers/WebhookController.php index 43e1cdf32..f4d5e1dd7 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Http/Controllers/WebhookController.php +++ b/src/backend/packages/inensus/viber-messaging/src/Http/Controllers/WebhookController.php @@ -15,9 +15,9 @@ use Viber\Api\Sender; use Viber\Bot; -class WebhookController extends Controller -{ +class WebhookController extends Controller { private $bot; + private $botSender; public function __construct( @@ -32,8 +32,7 @@ public function __construct( ]); } - public function index(string $slug) - { + public function index(string $slug) { Log::info('Webhook called'); $credential = $this->credentialService->getCredentials(); @@ -69,8 +68,12 @@ public function index(string $slug) $viberContact = $this->viberContactService->getByRegisteredMeterSerialNumber($meterSerialNumber); if ($viberContact) { - $this->answerToCustomer($bot, $botSender, $event, - $this->setAlreadyRegisteredMessage($meterSerialNumber)); + $this->answerToCustomer( + $bot, + $botSender, + $event, + $this->setAlreadyRegisteredMessage($meterSerialNumber) + ); return; } @@ -124,33 +127,27 @@ public function index(string $slug) return response()->json(['success' => 'success'], 200); } - private function setWrongFormatMessage(): string - { + private function setWrongFormatMessage(): string { return 'Please enter your meter serial number after register+'; } - private function setMeterNotFoundMessage(): string - { + private function setMeterNotFoundMessage(): string { return "We couldn't find your meter. Please check your meter serial number and try again."; } - private function setSuccessMessage(): string - { + private function setSuccessMessage(): string { return 'You have successfully registered with MicroPowerManager.'; } - private function setAlreadyRegisteredMessage($meterSerialNumber) - { + private function setAlreadyRegisteredMessage($meterSerialNumber) { return "$meterSerialNumber has already registered with MicroPowerManager."; } - private function setNoTransactionMessage($meterSerial) - { + private function setNoTransactionMessage($meterSerial) { return "No transaction found for meter serial: $meterSerial"; } - private function answerToCustomer($bot, $botSender, $event, $message) - { + private function answerToCustomer($bot, $botSender, $event, $message) { $bot->getClient()->sendMessage( (new \Viber\Api\Message\Text()) ->setSender($botSender) diff --git a/src/backend/packages/inensus/viber-messaging/src/Http/Requests/ViberCredentialRequest.php b/src/backend/packages/inensus/viber-messaging/src/Http/Requests/ViberCredentialRequest.php index 692612974..52bec1443 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Http/Requests/ViberCredentialRequest.php +++ b/src/backend/packages/inensus/viber-messaging/src/Http/Requests/ViberCredentialRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class ViberCredentialRequest extends FormRequest -{ +class ViberCredentialRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'api_token' => ['required'], ]; diff --git a/src/backend/packages/inensus/viber-messaging/src/Http/Resources/ViberResource.php b/src/backend/packages/inensus/viber-messaging/src/Http/Resources/ViberResource.php index 1f204d92d..418fa2837 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Http/Resources/ViberResource.php +++ b/src/backend/packages/inensus/viber-messaging/src/Http/Resources/ViberResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class ViberResource extends JsonResource -{ +class ViberResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class ViberResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/packages/inensus/viber-messaging/src/Models/ViberContact.php b/src/backend/packages/inensus/viber-messaging/src/Models/ViberContact.php index 770545573..3b6a6216d 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Models/ViberContact.php +++ b/src/backend/packages/inensus/viber-messaging/src/Models/ViberContact.php @@ -5,12 +5,10 @@ use App\Models\Base\BaseModel; use App\Models\Person\Person; -class ViberContact extends BaseModel -{ +class ViberContact extends BaseModel { protected $table = 'viber_contacts'; - public function mpmPerson() - { + public function mpmPerson() { return $this->belongsTo(Person::class, 'person_id'); } } diff --git a/src/backend/packages/inensus/viber-messaging/src/Models/ViberCredential.php b/src/backend/packages/inensus/viber-messaging/src/Models/ViberCredential.php index d83325e34..87988359e 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Models/ViberCredential.php +++ b/src/backend/packages/inensus/viber-messaging/src/Models/ViberCredential.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class ViberCredential extends BaseModel -{ +class ViberCredential extends BaseModel { protected $table = 'viber_credentials'; } diff --git a/src/backend/packages/inensus/viber-messaging/src/Models/ViberMessage.php b/src/backend/packages/inensus/viber-messaging/src/Models/ViberMessage.php index 1b57ee3a4..028e72bb0 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Models/ViberMessage.php +++ b/src/backend/packages/inensus/viber-messaging/src/Models/ViberMessage.php @@ -4,7 +4,6 @@ use App\Models\Base\BaseModel; -class ViberMessage extends BaseModel -{ +class ViberMessage extends BaseModel { protected $table = 'viber_messages'; } diff --git a/src/backend/packages/inensus/viber-messaging/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/viber-messaging/src/Providers/EventServiceProvider.php index 74a9ea6b4..47b952a1e 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/viber-messaging/src/Providers/EventServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ ]; @@ -14,8 +13,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/viber-messaging/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/viber-messaging/src/Providers/ObserverServiceProvider.php index 58fd63bb4..cd002637b 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/viber-messaging/src/Providers/ObserverServiceProvider.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/viber-messaging/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/viber-messaging/src/Providers/RouteServiceProvider.php index 5a0db19a9..33fa3a133 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/viber-messaging/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\ViberMessaging\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/viber-messaging/src/Providers/ViberMessagingServiceProvider.php b/src/backend/packages/inensus/viber-messaging/src/Providers/ViberMessagingServiceProvider.php index bb4a121e9..24e5bd653 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Providers/ViberMessagingServiceProvider.php +++ b/src/backend/packages/inensus/viber-messaging/src/Providers/ViberMessagingServiceProvider.php @@ -9,10 +9,8 @@ use Inensus\ViberMessaging\Console\Commands\UpdatePackage; use Inensus\ViberMessaging\ViberGateway; -class ViberMessagingServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class ViberMessagingServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -22,38 +20,34 @@ public function boot(Filesystem $filesystem) } } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/viber-messaging.php', 'viber-messaging'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->bind('ViberGateway', ViberGateway::class); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__.'/../../config/viber-messaging.php' => config_path('viber-messaging.php'), ]); } - public function publishVueFiles() - { + public function publishVueFiles() { $this->publishes([ - __DIR__.'/../resources/assets' => resource_path('assets/js/plugins/viber-messaging' + __DIR__.'/../resources/assets' => resource_path( + 'assets/js/plugins/viber-messaging' ), ], 'vue-components'); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_viber_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) diff --git a/src/backend/packages/inensus/viber-messaging/src/Services/AccountService.php b/src/backend/packages/inensus/viber-messaging/src/Services/AccountService.php index fcf72f944..f2b73c8eb 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Services/AccountService.php +++ b/src/backend/packages/inensus/viber-messaging/src/Services/AccountService.php @@ -5,10 +5,8 @@ use Illuminate\Support\Facades\Log; use Viber\Client; -class AccountService -{ - public function getAccountInfo($credential) - { +class AccountService { + public function getAccountInfo($credential) { $apiKey = $credential->api_token; try { diff --git a/src/backend/packages/inensus/viber-messaging/src/Services/ViberContactService.php b/src/backend/packages/inensus/viber-messaging/src/Services/ViberContactService.php index 109883cb8..96a798686 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Services/ViberContactService.php +++ b/src/backend/packages/inensus/viber-messaging/src/Services/ViberContactService.php @@ -10,47 +10,39 @@ /** * @implements IBaseService */ -class ViberContactService implements IBaseService -{ +class ViberContactService implements IBaseService { public function __construct( - private ViberContact $viberContact, private Person $person, - ) { - } + private ViberContact $viberContact, + private Person $person, + ) {} - public function createContact($personId, $viberId) - { + public function createContact($personId, $viberId) { return $this->viberContact->newQuery()->firstOrCreate(['person_id' => $personId], [ 'viber_id' => $viberId, ]); } - public function getById(int $id): ViberContact - { + public function getById(int $id): ViberContact { return $this->viberContact->newQuery()->find($id); } - public function create(array $data): ViberContact - { + public function create(array $data): ViberContact { return $this->viberContact->newQuery()->create($data); } - public function update($model, array $data): ViberContact - { + public function update($model, array $data): ViberContact { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } - public function getByReceiverPhoneNumber($receiver) - { + public function getByReceiverPhoneNumber($receiver) { return $this->viberContact->newQuery() ->whereHas('mpmPerson', function ($q) use ($receiver) { $q->whereHas('addresses', static function ($q) use ($receiver) { @@ -59,13 +51,11 @@ public function getByReceiverPhoneNumber($receiver) })->first(); } - public function getByRegisteredMeterSerialNumber($meterSerialNumber) - { + public function getByRegisteredMeterSerialNumber($meterSerialNumber) { return $this->viberContact->newQuery()->where('registered_meter_serial_number', $meterSerialNumber)->first(); } - public function getByViberId($viberId) - { + public function getByViberId($viberId) { return $this->viberContact->newQuery()->where('viber_id', $viberId)->first(); } } diff --git a/src/backend/packages/inensus/viber-messaging/src/Services/ViberCredentialService.php b/src/backend/packages/inensus/viber-messaging/src/Services/ViberCredentialService.php index f4995c7fa..c3c52a3bd 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Services/ViberCredentialService.php +++ b/src/backend/packages/inensus/viber-messaging/src/Services/ViberCredentialService.php @@ -4,20 +4,17 @@ use Inensus\ViberMessaging\Models\ViberCredential; -class ViberCredentialService -{ +class ViberCredentialService { public function __construct( private ViberCredential $credential, private WebhookService $webhookService, private AccountService $accountService, - ) { - } + ) {} /** * This function uses one time on installation of the package. */ - public function createCredentials() - { + public function createCredentials() { return $this->credential->newQuery()->firstOrCreate(['id' => 1], [ 'api_token' => null, 'webhook_url' => null, @@ -26,16 +23,14 @@ public function createCredentials() ]); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->first(); } /** * @throws \Inensus\ViberMessaging\Exceptions\WebhookNotCreatedException */ - public function updateCredentials($data) - { + public function updateCredentials($data) { $credential = $this->credential->newQuery()->find($data['id']); $credential->update([ diff --git a/src/backend/packages/inensus/viber-messaging/src/Services/ViberMessageService.php b/src/backend/packages/inensus/viber-messaging/src/Services/ViberMessageService.php index c480c60c9..a3cd64958 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Services/ViberMessageService.php +++ b/src/backend/packages/inensus/viber-messaging/src/Services/ViberMessageService.php @@ -9,35 +9,28 @@ /** * @implements IBaseService */ -class ViberMessageService implements IBaseService -{ +class ViberMessageService implements IBaseService { public function __construct( private ViberMessage $viberMessage, - ) { - } + ) {} - public function getById(int $id): ViberMessage - { + public function getById(int $id): ViberMessage { throw new \Exception('Method getById() not yet implemented.'); } - public function create(array $data): ViberMessage - { + public function create(array $data): ViberMessage { return $this->viberMessage->newQuery()->create($data); } - public function update($model, array $data): ViberMessage - { + public function update($model, array $data): ViberMessage { throw new \Exception('Method update() not yet implemented.'); } - public function delete($model): ?bool - { + public function delete($model): ?bool { throw new \Exception('Method delete() not yet implemented.'); } - public function getAll(?int $limit = null): Collection - { + public function getAll(?int $limit = null): Collection { throw new \Exception('Method getAll() not yet implemented.'); } } diff --git a/src/backend/packages/inensus/viber-messaging/src/Services/WebhookService.php b/src/backend/packages/inensus/viber-messaging/src/Services/WebhookService.php index d01be3993..73d739cb0 100644 --- a/src/backend/packages/inensus/viber-messaging/src/Services/WebhookService.php +++ b/src/backend/packages/inensus/viber-messaging/src/Services/WebhookService.php @@ -6,10 +6,8 @@ use Inensus\ViberMessaging\Exceptions\WebhookNotCreatedException; use Viber\Client; -class WebhookService -{ - public function createWebHook($credential) - { +class WebhookService { + public function createWebHook($credential) { $apiKey = $credential->api_token; $webhookUrl = $credential->webhook_url; diff --git a/src/backend/packages/inensus/viber-messaging/src/ViberGateway.php b/src/backend/packages/inensus/viber-messaging/src/ViberGateway.php index 0c338fa62..c81a83aba 100644 --- a/src/backend/packages/inensus/viber-messaging/src/ViberGateway.php +++ b/src/backend/packages/inensus/viber-messaging/src/ViberGateway.php @@ -10,9 +10,9 @@ use Viber\Api\Sender; use Viber\Bot; -class ViberGateway -{ +class ViberGateway { private $bot; + private $botSender; public function __construct( diff --git a/src/backend/packages/inensus/wave-money-payment-provider/database/migrations/create_wave_money_payment_provider_tables.php b/src/backend/packages/inensus/wave-money-payment-provider/database/migrations/create_wave_money_payment_provider_tables.php index 8cc6bc9e2..89132c6ef 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/database/migrations/create_wave_money_payment_provider_tables.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/database/migrations/create_wave_money_payment_provider_tables.php @@ -4,10 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreateWaveMoneyPaymentProviderTables extends Migration -{ - public function up() - { +class CreateWaveMoneyPaymentProviderTables extends Migration { + public function up() { if (!Schema::hasTable('wave_money_transactions')) { Schema::create('wave_money_transactions', static function (Blueprint $table) { $table->increments('id'); @@ -37,8 +35,7 @@ public function up() } } - public function down() - { + public function down() { Schema::dropIfExists('wave_money_transactions'); Schema::dropIfExists('wave_money_credentials'); } diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Console/Commands/InstallPackage.php index 69345d2f2..d6e4dabcd 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Console/Commands/InstallPackage.php @@ -5,26 +5,24 @@ use Illuminate\Console\Command; use Inensus\WaveMoneyPaymentProvider\Services\WaveMoneyCredentialService; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'wave-money-payment-provider:install'; + protected $description = 'Install WaveMoneyPaymentProvider Package'; public function __construct( - private WaveMoneyCredentialService $credentialService) - { + private WaveMoneyCredentialService $credentialService, + ) { parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('Installing WaveMoneyPaymentProvider Integration Package\n'); $this->credentialService->createCredentials(); $this->info('Package installed successfully..'); } - private function publishMigrations() - { + private function publishMigrations() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\WaveMoneyPaymentProvider\Providers\WaveMoneyPaymentProviderServiceProvider", @@ -32,14 +30,12 @@ private function publishMigrations() ]); } - private function createDatabaseTables() - { + private function createDatabaseTables() { $this->info('Creating database tables\n'); $this->call('migrate'); } - private function publishVueFiles() - { + private function publishVueFiles() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\WaveMoneyPaymentProvider\Providers\WaveMoneyPaymentProviderServiceProvider", @@ -47,8 +43,7 @@ private function publishVueFiles() ]); } - private function createPluginRecord() - { + private function createPluginRecord() { $this->call('plugin:add', [ 'name' => 'ViberMessaging', 'composer_name' => 'inensus/wave-money-payment-provider', diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Console/Commands/UpdatePackage.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Console/Commands/UpdatePackage.php index f44b7c9b7..ca8bd9b21 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Console/Commands/UpdatePackage.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Console/Commands/UpdatePackage.php @@ -7,9 +7,9 @@ use Illuminate\Support\Facades\DB; use Inensus\WaveMoneyPaymentProvider\Services\WaveMoneyCredentialService; -class UpdatePackage extends Command -{ +class UpdatePackage extends Command { protected $signature = 'wave-money-payment-provider:update'; + protected $description = 'Update WaveMoney Package'; public function __construct( @@ -19,8 +19,7 @@ public function __construct( parent::__construct(); } - public function handle(): void - { + public function handle(): void { $this->info('WaveMoney Integration Updating Started\n'); // $this->removeOldVersionOfPackage(); // $this->installNewVersionOfPackage(); @@ -33,20 +32,17 @@ public function handle(): void $this->info('Package updated successfully..'); } - private function removeOldVersionOfPackage() - { + private function removeOldVersionOfPackage() { $this->info('Removing former version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar remove inensus/wave-money-payment-provider'); } - private function installNewVersionOfPackage() - { + private function installNewVersionOfPackage() { $this->info('Installing last version of package\n'); echo shell_exec('COMPOSER_MEMORY_LIMIT=-1 ../composer.phar require inensus/wave-money-payment-provider'); } - private function deleteMigration(Filesystem $filesystem) - { + private function deleteMigration(Filesystem $filesystem) { $migrationFile = $filesystem->glob(database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR. '*_create_wave_money_payment_provider_tables.php')[0]; $migration = DB::table('migrations') @@ -59,8 +55,7 @@ private function deleteMigration(Filesystem $filesystem) ->where('migration', substr(explode('/migrations/', $migrationFile)[1], 0, -4))->delete(); } - private function publishMigrationsAgain() - { + private function publishMigrationsAgain() { $this->info('Copying migrations\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\WaveMoneyPaymentProvider\Providers\WaveMoneyPaymentProviderServiceProvider", @@ -68,14 +63,12 @@ private function publishMigrationsAgain() ]); } - private function updateDatabase() - { + private function updateDatabase() { $this->info('Updating database tables\n'); $this->call('migrate'); } - private function publishVueFilesAgain() - { + private function publishVueFilesAgain() { $this->info('Copying vue files\n'); $this->call('vendor:publish', [ '--provider' => "Inensus\WaveMoneyPaymentProvider\Providers\WaveMoneyPaymentProviderServiceProvider", diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Controllers/WaveMoneyController.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Controllers/WaveMoneyController.php index 3add2dc85..6960e3096 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Controllers/WaveMoneyController.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Controllers/WaveMoneyController.php @@ -11,23 +11,19 @@ use Inensus\WaveMoneyPaymentProvider\Modules\Api\WaveMoneyApiService; use Inensus\WaveMoneyPaymentProvider\Modules\Transaction\WaveMoneyTransactionService; -class WaveMoneyController extends Controller -{ +class WaveMoneyController extends Controller { public function __construct( private WaveMoneyTransactionService $transactionService, private WaveMoneyApiService $apiService, - ) { - } + ) {} - public function startTransaction(TransactionInitializeRequest $request): WaveMoneyResource - { + public function startTransaction(TransactionInitializeRequest $request): WaveMoneyResource { $transaction = $request->get('waveMoneyTransaction'); return WaveMoneyResource::make($this->apiService->requestPayment($transaction)); } - public function transactionCallBack(Request $request) - { + public function transactionCallBack(Request $request) { $transaction = $request->get('waveMoneyTransaction'); $status = $request->get('status'); diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Controllers/WaveMoneyCredentialController.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Controllers/WaveMoneyCredentialController.php index a0fa27144..3fbc67098 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Controllers/WaveMoneyCredentialController.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Controllers/WaveMoneyCredentialController.php @@ -10,22 +10,18 @@ use Inensus\WaveMoneyPaymentProvider\Services\WaveMoneyCredentialService; use MPM\DatabaseProxy\DatabaseProxyManagerService; -class WaveMoneyCredentialController extends Controller -{ +class WaveMoneyCredentialController extends Controller { public function __construct( private WaveMoneyCredentialService $credentialService, private DatabaseProxyManagerService $databaseProxyManagerService, private CompanyService $companyService, - ) { - } + ) {} - public function show(): WaveMoneyResource - { + public function show(): WaveMoneyResource { return WaveMoneyResource::make($this->credentialService->getCredentials()); } - public function update(WaveMoneyCredentialRequest $request): WaveMoneyResource - { + public function update(WaveMoneyCredentialRequest $request): WaveMoneyResource { $databaseProxy = $this->databaseProxyManagerService->findByEmail(auth('api')->user()->email); $companyId = $databaseProxy->getCompanyId(); $company = $this->companyService->getById($companyId); diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Middleware/WaveMoneyTransactionCallbackMiddleware.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Middleware/WaveMoneyTransactionCallbackMiddleware.php index 1a500b31f..d15f46e1a 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Middleware/WaveMoneyTransactionCallbackMiddleware.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Middleware/WaveMoneyTransactionCallbackMiddleware.php @@ -11,14 +11,10 @@ use Inensus\WaveMoneyPaymentProvider\Modules\Api\Data\TransactionCallbackData; use Inensus\WaveMoneyPaymentProvider\Modules\Transaction\WaveMoneyTransactionService; -class WaveMoneyTransactionCallbackMiddleware -{ - public function __construct(private WaveMoneyTransactionService $transactionService) - { - } +class WaveMoneyTransactionCallbackMiddleware { + public function __construct(private WaveMoneyTransactionService $transactionService) {} - public function handle(Request $request, \Closure $next) - { + public function handle(Request $request, \Closure $next) { $mapper = new TransactionCallbackRequestMapper(); $callbackData = $mapper->getMappedObject($request); try { diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Middleware/WaveMoneyTransactionMiddleware.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Middleware/WaveMoneyTransactionMiddleware.php index c943a3a23..58c6a580e 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Middleware/WaveMoneyTransactionMiddleware.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Middleware/WaveMoneyTransactionMiddleware.php @@ -5,10 +5,8 @@ use Illuminate\Http\Request; use Illuminate\Http\Response; -class WaveMoneyTransactionMiddleware -{ - public function handle(Request $request, \Closure $next) - { +class WaveMoneyTransactionMiddleware { + public function handle(Request $request, \Closure $next) { $transactionProvider = resolve('WaveMoneyPaymentProvider'); try { diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Requests/TransactionCallbackRequestMapper.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Requests/TransactionCallbackRequestMapper.php index 4ae30b3ab..f49c9c639 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Requests/TransactionCallbackRequestMapper.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Requests/TransactionCallbackRequestMapper.php @@ -7,31 +7,48 @@ use Illuminate\Http\Request; use Inensus\WaveMoneyPaymentProvider\Modules\Api\Data\TransactionCallbackData; -class TransactionCallbackRequestMapper -{ +class TransactionCallbackRequestMapper { private const BODY_PARAM_STATUS = 'status'; + private const BODY_PARAM_MERCHANT_ID = 'merchantId'; + private const BODY_PARAM_ORDER_ID = 'orderId'; + private const BODY_PARAM_MERCHANT_REFERENCE_ID = 'merchantReferenceId'; + private const BODY_PARAM_FRONTEND_RESULT_URL = 'frontendResultUrl'; + private const BODY_PARAM_BACKEND_RESULT_URL = 'backendResultUrl'; + private const BODY_PARAM_INITIATOR_MSISDN = 'initiatorMsisdn'; + private const BODY_PARAM_AMOUNT = 'amount'; + private const BODY_PARAM_TIME_TO_LIVE_SECONDS = 'timeToLiveSeconds'; + private const BODY_PARAM_PAYMENT_DESCRIPTION = 'paymentDescription'; + private const BODY_PARAM_CURRENCY = 'currency'; + private const BODY_PARAM_HASH_VALUE = 'hashValue'; + private const BODY_PARAM_TRANSACTION_ID = 'transactionId'; + private const BODY_PARAM_PAYMENT_REQUEST_ID = 'paymentRequestId'; + private const BODY_PARAM_REQUEST_TIME = 'requestTime'; + private const BODY_PARAM_ADDITIONAL_FIELD_1 = 'additionalField1'; + private const BODY_PARAM_ADDITIONAL_FIELD_2 = 'additionalField2'; + private const BODY_PARAM_ADDITIONAL_FIELD_3 = 'additionalField3'; + private const BODY_PARAM_ADDITIONAL_FIELD_4 = 'additionalField4'; + private const BODY_PARAM_ADDITIONAL_FIELD_5 = 'additionalField5'; - public function getMappedObject(Request $request): TransactionCallbackData - { + public function getMappedObject(Request $request): TransactionCallbackData { return new TransactionCallbackData( $request->input(self::BODY_PARAM_STATUS), $request->input(self::BODY_PARAM_MERCHANT_ID), diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Requests/TransactionInitializeRequest.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Requests/TransactionInitializeRequest.php index a8c51292a..d6bf757e6 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Requests/TransactionInitializeRequest.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Requests/TransactionInitializeRequest.php @@ -6,13 +6,12 @@ use Illuminate\Foundation\Http\FormRequest; -class TransactionInitializeRequest extends FormRequest -{ +class TransactionInitializeRequest extends FormRequest { private const BODY_PARAM_METER_SERIAL = 'meterSerial'; + private const BODY_PARAM_AMOUNT = 'amount'; - public function rules(): array - { + public function rules(): array { return [ self::BODY_PARAM_METER_SERIAL => 'required', self::BODY_PARAM_AMOUNT => 'required|numeric', diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Requests/WaveMoneyCredentialRequest.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Requests/WaveMoneyCredentialRequest.php index 3ec4a544e..1c27e94f2 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Requests/WaveMoneyCredentialRequest.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Requests/WaveMoneyCredentialRequest.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Http\FormRequest; -class WaveMoneyCredentialRequest extends FormRequest -{ +class WaveMoneyCredentialRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ - public function rules() - { + public function rules() { return [ 'merchant_id' => ['required'], 'secret_key' => ['required'], diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Resources/WaveMoneyResource.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Resources/WaveMoneyResource.php index c66114fea..8d7e80964 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Resources/WaveMoneyResource.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Http/Resources/WaveMoneyResource.php @@ -5,8 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class WaveMoneyResource extends JsonResource -{ +class WaveMoneyResource extends JsonResource { /** * Transform the resource into an array. * @@ -14,8 +13,7 @@ class WaveMoneyResource extends JsonResource * * @return array */ - public function toArray($request) - { + public function toArray($request) { return parent::toArray($request); } } diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Models/WaveMoneyCredential.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Models/WaveMoneyCredential.php index 87bf61186..0adff2123 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Models/WaveMoneyCredential.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Models/WaveMoneyCredential.php @@ -12,37 +12,30 @@ * @property string result_url * @property string merchant_name */ -class WaveMoneyCredential extends BaseModel -{ +class WaveMoneyCredential extends BaseModel { protected $table = 'wave_money_credentials'; - public function getMerchantId(): string - { + public function getMerchantId(): string { return $this->merchant_id; } - public function getSecretKey(): string - { + public function getSecretKey(): string { return $this->secret_key; } - public function getMerchantName(): string - { + public function getMerchantName(): string { return $this->merchant_name; } - public function getCallbackUrl(): string - { + public function getCallbackUrl(): string { return $this->callback_url; } - public function getPaymentUrl(): string - { + public function getPaymentUrl(): string { return $this->payment_url; } - public function getResultUrl(): string - { + public function getResultUrl(): string { return $this->result_url; } } diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Models/WaveMoneyTransaction.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Models/WaveMoneyTransaction.php index 92d204f8c..52692ccb9 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Models/WaveMoneyTransaction.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Models/WaveMoneyTransaction.php @@ -19,95 +19,82 @@ * @property int customer_id * @property string|null meter_serial */ -class WaveMoneyTransaction extends BaseModel implements IRawTransaction, FullySupportedTransactionInterface -{ +class WaveMoneyTransaction extends BaseModel implements FullySupportedTransactionInterface, IRawTransaction { public const RELATION_NAME = 'wave_money_transaction'; public const STATUS_REQUESTED = 0; + public const STATUS_FAILED = -1; + public const STATUS_SUCCESS = 1; + public const STATUS_COMPLETED_BY_WAVE_MONEY = 2; + public const MAX_ATTEMPTS = 5; protected $table = 'wave_money_transactions'; - public function getAmount(): int - { + public function getAmount(): int { return $this->amount; } - public function getCurrency(): string - { + public function getCurrency(): string { return $this->currency; } - public function getOrderId(): string - { + public function getOrderId(): string { return $this->order_id; } - public function getReferenceId(): string - { + public function getReferenceId(): string { return $this->reference_id; } - public function getId(): int - { + public function getId(): int { return $this->id; } - public function setStatus(int $status) - { + public function setStatus(int $status) { $this->status = $status; } - public function setExternalTransactionId(string $transactionId) - { + public function setExternalTransactionId(string $transactionId) { $this->external_transaction_id = $transactionId; } - public function setOrderId(string $orderId) - { + public function setOrderId(string $orderId) { $this->order_id = $orderId; } - public function setReferenceId(string $referenceId) - { + public function setReferenceId(string $referenceId) { $this->reference_id = $referenceId; } - public function setCustomerId(int $customerId) - { + public function setCustomerId(int $customerId) { $this->customer_id = $customerId; } - public function setMeterSerial(string $meterSerialNumber) - { + public function setMeterSerial(string $meterSerialNumber) { $this->meter_serial = $meterSerialNumber; } - public function setAmount(float $amount) - { + public function setAmount(float $amount) { $this->amount = $amount; } - public function transaction() - { + public function transaction() { return $this->morphOne(Transaction::class, 'original_transaction'); } - public function manufacturerTransaction() - { + public function manufacturerTransaction() { return $this->morphTo(); } - public function conflicts() - { + public function conflicts() { return $this->morphMany(TransactionConflicts::class, 'transaction'); } - public static function getTransactionName(): string - { + public static function getTransactionName(): string { return self::RELATION_NAME; } } diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/AbstractApi.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/AbstractApi.php index b59f46d74..c3af36207 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/AbstractApi.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/AbstractApi.php @@ -8,14 +8,10 @@ use Inensus\WaveMoneyPaymentProvider\Modules\Api\Exceptions\ApiRequestFailedException; use Inensus\WaveMoneyPaymentProvider\Modules\Api\Resources\AbstractApiResource; -abstract class AbstractApi -{ - public function __construct(private Client $client) - { - } +abstract class AbstractApi { + public function __construct(private Client $client) {} - public function doRequest(AbstractApiResource $resource): AbstractApiResource - { + public function doRequest(AbstractApiResource $resource): AbstractApiResource { if ($resource->getRequestMethod() === RequestMethod::POST) { $response = $this->client->post($resource->getPaymentUri(), [ 'form_params' => $resource->getBodyData(), diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Data/TransactionCallbackData.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Data/TransactionCallbackData.php index 0119f0e25..8745274d4 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Data/TransactionCallbackData.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Data/TransactionCallbackData.php @@ -4,14 +4,19 @@ namespace Inensus\WaveMoneyPaymentProvider\Modules\Api\Data; -class TransactionCallbackData -{ +class TransactionCallbackData { public const STATUS_PAYMENT_CONFIRMED = 'PAYMENT_CONFIRMED'; + public const STATUS_BILL_COLLECTION_FAILED = 'BILL_COLLECTION_FAILED'; + public const STATUS_INSUFFICIENT_BALANCE = 'INSUFFICIENT_BALANCE'; + public const STATUS_ACCOUNT_LOCKED = 'ACCOUNT_LOCKED'; + public const STATUS_SCHEDULER_TRANSACTION_TIMED_OUT = 'SCHEDULER_TRANSACTION_TIMED_OUT'; + public const STATUS_SUCCESS = 1; + public const STATUS_FAILURE = -1; public function __construct( @@ -35,86 +40,69 @@ public function __construct( private ?string $additional3, private ?string $additional4, private ?string $additional5, - ) { - } + ) {} - public function getStatus(): string - { + public function getStatus(): string { return $this->status; } - public function getMerchantId(): string - { + public function getMerchantId(): string { return $this->merchantId; } - public function getOrderId(): string - { + public function getOrderId(): string { return $this->orderId; } - public function getMerchantReferenceId(): string - { + public function getMerchantReferenceId(): string { return $this->merchantReferenceId; } - public function getFrontendResultUrl(): string - { + public function getFrontendResultUrl(): string { return $this->frontendResultUrl; } - public function getBackEndResultUrl(): string - { + public function getBackEndResultUrl(): string { return $this->backEndResultUrl; } - public function getInitiatorMsisdn(): ?string - { + public function getInitiatorMsisdn(): ?string { return $this->initiatorMsisdn; } - public function getAmount(): float - { + public function getAmount(): float { return $this->amount; } - public function getTimeToLiveSeconds(): int - { + public function getTimeToLiveSeconds(): int { return $this->timeToLiveSeconds; } - public function getPaymentDescription(): string - { + public function getPaymentDescription(): string { return $this->paymentDescription; } - public function getCurrency(): string - { + public function getCurrency(): string { return $this->currency; } - public function getHash(): string - { + public function getHash(): string { return $this->hash; } - public function getTransactionId(): ?string - { + public function getTransactionId(): ?string { return $this->transactionId; } - public function getPaymentRequestId(): string|int - { + public function getPaymentRequestId(): string|int { return $this->paymentRequestId; } - public function getRequestTime(): string - { + public function getRequestTime(): string { return $this->requestTime; } - public function getAdditionalFields(): array - { + public function getAdditionalFields(): array { return [ 'add1' => $this->additional1, 'add2' => $this->additional2, @@ -124,8 +112,7 @@ public function getAdditionalFields(): array ]; } - public function mapTransactionStatus(string $status): int - { + public function mapTransactionStatus(string $status): int { if ($status === self::STATUS_PAYMENT_CONFIRMED) { return self::STATUS_SUCCESS; } diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Exceptions/ApiRequestFailedException.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Exceptions/ApiRequestFailedException.php index 48a164114..3add4e54d 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Exceptions/ApiRequestFailedException.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Exceptions/ApiRequestFailedException.php @@ -4,10 +4,8 @@ namespace Inensus\WaveMoneyPaymentProvider\Modules\Api\Exceptions; -class ApiRequestFailedException extends \Exception -{ - public function __construct(int $statusCode, string $uri, string $body) - { +class ApiRequestFailedException extends \Exception { + public function __construct(int $statusCode, string $uri, string $body) { $message = ['statusCode' => $statusCode, 'uri' => $uri, 'body' => $body]; parent::__construct(json_encode($message)); diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/RequestMethod.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/RequestMethod.php index a675638c8..c74772da8 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/RequestMethod.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/RequestMethod.php @@ -2,10 +2,12 @@ namespace Inensus\WaveMoneyPaymentProvider\Modules\Api; -class RequestMethod -{ +class RequestMethod { public const POST = 'post'; + public const GET = 'get'; + public const PUT = 'put'; + public const DELETE = 'delete'; } diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Resources/AbstractApiResource.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Resources/AbstractApiResource.php index d98842b70..f18f6f218 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Resources/AbstractApiResource.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Resources/AbstractApiResource.php @@ -4,9 +4,9 @@ namespace Inensus\WaveMoneyPaymentProvider\Modules\Api\Resources; -abstract class AbstractApiResource -{ +abstract class AbstractApiResource { protected string $body; + protected const REQUEST_TIME_TO_LIVE_IN_SECS = 120; abstract public function getRequestMethod(): string; @@ -19,38 +19,31 @@ abstract public function getBackendCallback(): string; abstract public function getFrontendCallback(): string; - public function getUri(): string - { + public function getUri(): string { return config('wave-money-payment-provider.api_uri'); } - public function getPaymentUri(): string - { + public function getPaymentUri(): string { return config('wave-money-payment-provider.api_uri').'/payment'; } - public function getHeaders(): array - { + public function getHeaders(): array { return ['Accept' => 'application/json']; } - public function setBody(string $body): void - { + public function setBody(string $body): void { $this->body = $body; } - public function getBody(): string - { + public function getBody(): string { return $this->body; } - public function getBodyAsArray(): array - { + public function getBodyAsArray(): array { return json_decode($this->body, true); } - public function getAuthenticateUri(): string - { + public function getAuthenticateUri(): string { return config('wave-money-payment-provider.api_uri').'/authenticate?transaction_id='; } } diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Resources/StartTransactionResource.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Resources/StartTransactionResource.php index f25f1fd62..fb7b5cbbe 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Resources/StartTransactionResource.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/Resources/StartTransactionResource.php @@ -6,25 +6,23 @@ use Inensus\WaveMoneyPaymentProvider\Models\WaveMoneyTransaction; use Inensus\WaveMoneyPaymentProvider\Modules\Api\RequestMethod; -class StartTransactionResource extends AbstractApiResource -{ +class StartTransactionResource extends AbstractApiResource { public const RESPONSE_SUCCESS = 'success'; + public const RESPONSE_KEY_MESSAGE = 'transaction_id'; + public const RESPONSE_KEY_TRANSACTION_ID = 'transaction_id'; public function __construct( private WaveMoneyCredential $waveMoneyCredential, private WaveMoneyTransaction $waveMoneyTransaction, - ) { - } + ) {} - public function getRequestMethod(): string - { + public function getRequestMethod(): string { return RequestMethod::POST; } - public function getBodyData(): array - { + public function getBodyData(): array { return [ 'merchant_id' => $this->waveMoneyCredential->getMerchantId(), 'order_id' => $this->waveMoneyTransaction->getOrderId(), @@ -43,13 +41,11 @@ public function getBodyData(): array ]; } - public function getQueryParams(): array - { + public function getQueryParams(): array { return []; } - private function generatePayloadHash(): string - { + private function generatePayloadHash(): string { return hash_hmac('sha256', implode('', [ self::REQUEST_TIME_TO_LIVE_IN_SECS, $this->waveMoneyCredential->getMerchantId(), @@ -60,18 +56,15 @@ private function generatePayloadHash(): string ]), $this->waveMoneyCredential->getSecretKey()); } - public function getBackendCallback(): string - { + public function getBackendCallback(): string { return $this->waveMoneyCredential->getCallbackUrl(); } - public function getFrontendCallback(): string - { + public function getFrontendCallback(): string { return $this->waveMoneyCredential->getResultUrl(); } - public function getMerchantName(): string - { + public function getMerchantName(): string { return $this->waveMoneyCredential->getMerchantName(); } } diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/WaveMoneyApi.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/WaveMoneyApi.php index 37694efca..7e9d95d30 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/WaveMoneyApi.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/WaveMoneyApi.php @@ -2,6 +2,4 @@ namespace Inensus\WaveMoneyPaymentProvider\Modules\Api; -class WaveMoneyApi extends AbstractApi -{ -} +class WaveMoneyApi extends AbstractApi {} diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/WaveMoneyApiService.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/WaveMoneyApiService.php index 68db1b9e7..b870f112a 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/WaveMoneyApiService.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Api/WaveMoneyApiService.php @@ -8,16 +8,13 @@ use Inensus\WaveMoneyPaymentProvider\Modules\Api\Resources\StartTransactionResource; use Inensus\WaveMoneyPaymentProvider\Services\WaveMoneyCredentialService; -class WaveMoneyApiService -{ +class WaveMoneyApiService { public function __construct( private WaveMoneyApi $api, private WaveMoneyCredentialService $credentialService, - ) { - } + ) {} - public function requestPayment(WaveMoneyTransaction $transaction): array - { + public function requestPayment(WaveMoneyTransaction $transaction): array { $credential = $this->credentialService->getCredentials(); $transactionResource = new StartTransactionResource($credential, $transaction); try { diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Transaction/WaveMoneyTransactionService.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Transaction/WaveMoneyTransactionService.php index 03e4b487e..68072b78c 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Transaction/WaveMoneyTransactionService.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Modules/Transaction/WaveMoneyTransactionService.php @@ -19,12 +19,15 @@ /** * @implements IBaseService */ -class WaveMoneyTransactionService extends AbstractPaymentAggregatorTransactionService implements IBaseService -{ +class WaveMoneyTransactionService extends AbstractPaymentAggregatorTransactionService implements IBaseService { private Meter $meter; + private Address $address; + private Transaction $transaction; + private MeterParameter $meterParameter; + private WaveMoneyTransaction $waveMoneyTransaction; public function __construct( @@ -49,8 +52,7 @@ public function __construct( ); } - public function initializeTransactionData(): array - { + public function initializeTransactionData(): array { $orderId = Uuid::uuid4()->toString(); // need to store somewhere $referenceId = Uuid::uuid4()->toString(); // need to store somewhere @@ -65,49 +67,41 @@ public function initializeTransactionData(): array ]; } - public function getByOrderId(string $orderId) - { + public function getByOrderId(string $orderId) { return $this->waveMoneyTransaction->newQuery()->where('order_id', '=', $orderId) ->firstOrFail(); } - public function getByExternalTransactionId(string $externalTransactionId) - { + public function getByExternalTransactionId(string $externalTransactionId) { return $this->waveMoneyTransaction->newQuery()->where('external_transaction_id', '=', $externalTransactionId) ->firstOrFail(); } - public function getByStatus($status) - { + public function getByStatus($status) { return $this->waveMoneyTransaction->newQuery()->where('status', '=', $status) ->get(); } - public function getById(int $id): WaveComTransaction - { + public function getById(int $id): WaveComTransaction { return $this->waveMoneyTransaction->newQuery()->find($id); } - public function update($waveMoneyTransaction, array $waveMoneyTransactionData): WaveMoneyTransaction - { + public function update($waveMoneyTransaction, array $waveMoneyTransactionData): WaveMoneyTransaction { $waveMoneyTransaction->update($waveMoneyTransactionData); $waveMoneyTransaction->fresh(); return $waveMoneyTransaction; } - public function create($waveMoneyTransactionData): WaveMoneyTransaction - { + public function create($waveMoneyTransactionData): WaveMoneyTransaction { return $this->waveMoneyTransaction->newQuery()->create($waveMoneyTransactionData); } - public function delete($waveMoneyTransaction): ?bool - { + public function delete($waveMoneyTransaction): ?bool { return $waveMoneyTransaction->delete(); } - public function getAll(?int $limit = null): Collection|LengthAwarePaginator - { + public function getAll(?int $limit = null): Collection|LengthAwarePaginator { $query = $this->waveMoneyTransaction->newQuery(); if ($limit) { @@ -117,8 +111,7 @@ public function getAll(?int $limit = null): Collection|LengthAwarePaginator return $this->waveMoneyTransaction->newQuery()->get(); } - public function getWaveMoneyTransaction() - { + public function getWaveMoneyTransaction() { return $this->getPaymentAggregatorTransaction(); } } diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/EventServiceProvider.php index eca534b79..ef211c007 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/EventServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ ]; @@ -14,8 +13,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/ObserverServiceProvider.php index 71affce49..020f8fee5 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/ObserverServiceProvider.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/RouteServiceProvider.php index 71162d81d..3fc062622 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\WaveMoneyPaymentProvider\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/WaveMoneyPaymentProviderServiceProvider.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/WaveMoneyPaymentProviderServiceProvider.php index 5510558a6..094930c65 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/WaveMoneyPaymentProviderServiceProvider.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/WaveMoneyPaymentProviderServiceProvider.php @@ -10,10 +10,8 @@ use Inensus\WaveMoneyPaymentProvider\Console\Commands\UpdatePackage; use Inensus\WaveMoneyPaymentProvider\Models\WaveMoneyTransaction; -class WaveMoneyPaymentProviderServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class WaveMoneyPaymentProviderServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -28,40 +26,38 @@ public function boot(Filesystem $filesystem) ); } - public function register() - { - $this->mergeConfigFrom(__DIR__.'/../../config/wave-money-payment-provider.php', - 'wave-money-payment-provider'); + public function register() { + $this->mergeConfigFrom( + __DIR__.'/../../config/wave-money-payment-provider.php', + 'wave-money-payment-provider' + ); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->singleton('WaveMoneyPaymentProvider', WaveMoneyTransactionProvider::class); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes([ __DIR__. '/../../config/wave-money-payment-provider-integration.php' => config_path('wave-money-payment-provider.php'), ]); } - public function publishVueFiles() - { + public function publishVueFiles() { $this->publishes([ - __DIR__.'/../resources/assets' => resource_path('assets/js/plugins/wave-money-payment-provider' + __DIR__.'/../resources/assets' => resource_path( + 'assets/js/plugins/wave-money-payment-provider' ), ], 'vue-components'); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_viber_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/WaveMoneyTransactionProvider.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/WaveMoneyTransactionProvider.php index 8da7aada7..a4d8ad72d 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/WaveMoneyTransactionProvider.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Providers/WaveMoneyTransactionProvider.php @@ -13,8 +13,7 @@ use Inensus\WaveMoneyPaymentProvider\Modules\Transaction\WaveMoneyTransactionService; use MPM\Transaction\Provider\ITransactionProvider; -class WaveMoneyTransactionProvider implements ITransactionProvider -{ +class WaveMoneyTransactionProvider implements ITransactionProvider { private $validData = []; public function __construct( @@ -22,11 +21,9 @@ public function __construct( private Transaction $transaction, private WaveMoneyTransactionService $waveMoneyTransactionService, private TransactionConflicts $transactionConflicts, - ) { - } + ) {} - public function validateRequest($request) - { + public function validateRequest($request) { $meterSerial = $request->input('meterSerial'); $amount = $request->input('amount'); @@ -43,13 +40,11 @@ public function validateRequest($request) $this->setValidData($waveMoneyTransactionData); } - public function saveTransaction() - { + public function saveTransaction() { $this->waveMoneyTransactionService->saveTransaction(); } - public function sendResult(bool $requestType, Transaction $transaction) - { + public function sendResult(bool $requestType, Transaction $transaction) { if ($requestType) { $waveMoneyTransaction = $transaction->originalTransaction()->first(); $updateData = [ @@ -59,47 +54,42 @@ public function sendResult(bool $requestType, Transaction $transaction) $smsService = app()->make(SmsService::class); $smsService->sendSms($transaction, SmsTypes::TRANSACTION_CONFIRMATION, SmsConfigs::class); } else { - Log::critical('WaveMoney transaction is been cancelled from MicroPowerManager.', + Log::critical( + 'WaveMoney transaction is been cancelled from MicroPowerManager.', [ 'transaction_id' => $transaction->id, 'original_transaction_id' => $transaction->originalTransaction()->first()->id, - ]); + ] + ); } } - public function confirm(): void - { + public function confirm(): void { // TODO: Implement confirm() method. } - public function getMessage(): string - { + public function getMessage(): string { // TODO: Implement getMessage() method. } - public function getAmount(): int - { + public function getAmount(): int { return $this->getTransaction()->amount; } - public function getSender(): string - { + public function getSender(): string { return $this->getTransaction()->message; } - public function saveCommonData(): Model - { + public function saveCommonData(): Model { // TODO: Implement saveCommonData() method. } - public function init($transaction): void - { + public function init($transaction): void { $this->waveMoneytransaction = $transaction; $this->transaction = $transaction->transaction()->first(); } - public function addConflict(?string $message): void - { + public function addConflict(?string $message): void { $conflict = $this->transactionConflicts->newQuery()->make([ 'state' => $message, ]); @@ -107,23 +97,19 @@ public function addConflict(?string $message): void $conflict->save(); } - public function getTransaction(): Transaction - { + public function getTransaction(): Transaction { return $this->transaction; } - public function setValidData($waveMoneyTransactionData) - { + public function setValidData($waveMoneyTransactionData) { $this->validData = $waveMoneyTransactionData; } - public function getValidData() - { + public function getValidData() { return $this->validData; } - public function getSubTransaction() - { + public function getSubTransaction() { return $this->waveMoneyTransactionService->getWaveMoneyTransaction(); } } diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/Services/WaveMoneyCredentialService.php b/src/backend/packages/inensus/wave-money-payment-provider/src/Services/WaveMoneyCredentialService.php index be608a888..f70a2ca67 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/Services/WaveMoneyCredentialService.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/Services/WaveMoneyCredentialService.php @@ -4,18 +4,15 @@ use Inensus\WaveMoneyPaymentProvider\Models\WaveMoneyCredential; -class WaveMoneyCredentialService -{ +class WaveMoneyCredentialService { public function __construct( private WaveMoneyCredential $credential, - ) { - } + ) {} /** * This function uses one time on installation of the package. */ - public function createCredentials() - { + public function createCredentials() { return $this->credential->newQuery()->firstOrCreate(['id' => 1], [ 'merchant_id' => null, 'secret_key' => null, @@ -26,13 +23,11 @@ public function createCredentials() ]); } - public function getCredentials() - { + public function getCredentials() { return $this->credential->newQuery()->first(); } - public function updateCredentials($data) - { + public function updateCredentials($data) { $credential = $this->credential->newQuery()->find($data['id']); $credential->update([ diff --git a/src/backend/packages/inensus/wave-money-payment-provider/src/routes/api.php b/src/backend/packages/inensus/wave-money-payment-provider/src/routes/api.php index 35d48c22f..68f6e4973 100644 --- a/src/backend/packages/inensus/wave-money-payment-provider/src/routes/api.php +++ b/src/backend/packages/inensus/wave-money-payment-provider/src/routes/api.php @@ -10,8 +10,10 @@ Route::put('/', 'WaveMoneyCredentialController@update'); }); Route::group(['prefix' => 'wave-money-transaction'], function () { - Route::post('/start/{slug}', - ['middleware' => WaveMoneyTransactionMiddleware::class, 'uses' => 'WaveMoneyController@startTransaction']); + Route::post( + '/start/{slug}', + ['middleware' => WaveMoneyTransactionMiddleware::class, 'uses' => 'WaveMoneyController@startTransaction'] + ); Route::post('/callback/{slug}', [ 'middleware' => WaveMoneyTransactionCallbackMiddleware::class, 'uses' => 'WaveMoneyController@transactionCallBack', diff --git a/src/backend/packages/inensus/wavecom-payment-provider/src/Console/Commands/InstallPackage.php b/src/backend/packages/inensus/wavecom-payment-provider/src/Console/Commands/InstallPackage.php index fb1cba887..d97f200e4 100644 --- a/src/backend/packages/inensus/wavecom-payment-provider/src/Console/Commands/InstallPackage.php +++ b/src/backend/packages/inensus/wavecom-payment-provider/src/Console/Commands/InstallPackage.php @@ -4,13 +4,12 @@ use Illuminate\Console\Command; -class InstallPackage extends Command -{ +class InstallPackage extends Command { protected $signature = 'wavecom-payment-provider:install'; + protected $description = 'Install wavecom-money-payment-provider Package'; - public function handle(): void - { + public function handle(): void { $this->info('Installing WavecomPaymentProvider Integration Package\n'); $this->info('Package installed successfully..'); } diff --git a/src/backend/packages/inensus/wavecom-payment-provider/src/Http/Controllers/WaveComTransactionController.php b/src/backend/packages/inensus/wavecom-payment-provider/src/Http/Controllers/WaveComTransactionController.php index 72eb7e2a5..44a945444 100644 --- a/src/backend/packages/inensus/wavecom-payment-provider/src/Http/Controllers/WaveComTransactionController.php +++ b/src/backend/packages/inensus/wavecom-payment-provider/src/Http/Controllers/WaveComTransactionController.php @@ -9,14 +9,10 @@ use Inensus\WavecomPaymentProvider\Http\Requests\UploadTransactionRequest; use Inensus\WavecomPaymentProvider\Services\TransactionService; -class WaveComTransactionController extends Controller -{ - public function __construct(private TransactionService $transactionService) - { - } +class WaveComTransactionController extends Controller { + public function __construct(private TransactionService $transactionService) {} - public function uploadTransaction(UploadTransactionRequest $request): ApiResource - { + public function uploadTransaction(UploadTransactionRequest $request): ApiResource { $file = $request->getFile(); $result = $this->transactionService->createTransactionsFromFile($file); diff --git a/src/backend/packages/inensus/wavecom-payment-provider/src/Http/Requests/UploadTransactionRequest.php b/src/backend/packages/inensus/wavecom-payment-provider/src/Http/Requests/UploadTransactionRequest.php index 0cd00faea..624a13772 100644 --- a/src/backend/packages/inensus/wavecom-payment-provider/src/Http/Requests/UploadTransactionRequest.php +++ b/src/backend/packages/inensus/wavecom-payment-provider/src/Http/Requests/UploadTransactionRequest.php @@ -6,17 +6,14 @@ use Illuminate\Foundation\Http\FormRequest; -class UploadTransactionRequest extends FormRequest -{ +class UploadTransactionRequest extends FormRequest { public const TRANSACTION_FILE = 'transaction_file'; - public function getFile(): \Illuminate\Http\UploadedFile - { + public function getFile(): \Illuminate\Http\UploadedFile { return $this->file(self::TRANSACTION_FILE); } - public function rules() - { + public function rules() { return [self::TRANSACTION_FILE => 'required|mimes:csv,txt']; } } diff --git a/src/backend/packages/inensus/wavecom-payment-provider/src/Models/WaveComTransaction.php b/src/backend/packages/inensus/wavecom-payment-provider/src/Models/WaveComTransaction.php index 685735003..90de110a0 100644 --- a/src/backend/packages/inensus/wavecom-payment-provider/src/Models/WaveComTransaction.php +++ b/src/backend/packages/inensus/wavecom-payment-provider/src/Models/WaveComTransaction.php @@ -20,91 +20,77 @@ * @property string $message * @property int $amount */ -class WaveComTransaction extends BaseModel implements IRawTransaction, FullySupportedTransactionInterface -{ +class WaveComTransaction extends BaseModel implements FullySupportedTransactionInterface, IRawTransaction { protected $table = 'wavecom_transactions'; + public const RELATION_NAME = 'wavecom_transaction'; + public const STATUS_SUCCESS = 1; + public const STATUS_CANCELLED = -1; - public function getTransactionId(): string - { + public function getTransactionId(): string { return $this->transaction_id; } - public function getSender(): string - { + public function getSender(): string { return $this->sender; } - public function getMessage(): string - { + public function getMessage(): string { return $this->message; } - public function getAmount(): int - { + public function getAmount(): int { return $this->amount; } - public function setTransactionId(string $transactionId): void - { + public function setTransactionId(string $transactionId): void { $this->transaction_id = $transactionId; } - public function setSender(string $sender): void - { + public function setSender(string $sender): void { $this->sender = $sender; } - public function setMessage(string $message): void - { + public function setMessage(string $message): void { $this->message = $message; } - public function setAmount(int $amount): void - { + public function setAmount(int $amount): void { $this->amount = $amount; } - public function transaction(): MorphOne - { + public function transaction(): MorphOne { return $this->morphOne(Transaction::class, 'original_transaction'); } - public function manufacturerTransaction(): MorphTo - { + public function manufacturerTransaction(): MorphTo { return $this->morphTo(); } - public function conflicts(): MorphMany - { + public function conflicts(): MorphMany { return $this->morphMany(TransactionConflicts::class, 'transaction'); } - public function getManufacturerTransferType(): ?string - { + public function getManufacturerTransferType(): ?string { // TODO add type API/IMPORT return 'WaveCom'; } - public function getDescription(): ?string - { + public function getDescription(): ?string { return $this->getMessage(); } - public function setStatus(int $status) - { + public function setStatus(int $status) { $this->status = $status; } - public static function getTransactionName(): string - { + public static function getTransactionName(): string { return self::RELATION_NAME; } - public function getId(): int - { + public function getId(): int { return $this->id; } } diff --git a/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/EventServiceProvider.php b/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/EventServiceProvider.php index ecef44930..71b662f3c 100644 --- a/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/EventServiceProvider.php +++ b/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/EventServiceProvider.php @@ -4,8 +4,7 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class EventServiceProvider extends ServiceProvider -{ +class EventServiceProvider extends ServiceProvider { protected $subscribe = [ ]; @@ -14,8 +13,7 @@ class EventServiceProvider extends ServiceProvider * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/ObserverServiceProvider.php b/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/ObserverServiceProvider.php index 884016722..846c3686b 100644 --- a/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/ObserverServiceProvider.php +++ b/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/ObserverServiceProvider.php @@ -4,15 +4,13 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -class ObserverServiceProvider extends ServiceProvider -{ +class ObserverServiceProvider extends ServiceProvider { /** * Register any events for your application. * * @return void */ - public function boot() - { + public function boot() { parent::boot(); } } diff --git a/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/RouteServiceProvider.php b/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/RouteServiceProvider.php index fde7d974f..7476e97d5 100644 --- a/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/RouteServiceProvider.php +++ b/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/RouteServiceProvider.php @@ -5,22 +5,18 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; -class RouteServiceProvider extends ServiceProvider -{ +class RouteServiceProvider extends ServiceProvider { protected $namespace = 'Inensus\WavecomPaymentProvider\Http\Controllers'; - public function boot() - { + public function boot() { parent::boot(); } - public function map() - { + public function map() { $this->mapApiRoutes(); } - protected function mapApiRoutes() - { + protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) diff --git a/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/WaveComTransactionProvider.php b/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/WaveComTransactionProvider.php index d23449afa..61951f360 100644 --- a/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/WaveComTransactionProvider.php +++ b/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/WaveComTransactionProvider.php @@ -15,8 +15,7 @@ use Inensus\WavecomPaymentProvider\Services\TransactionService; use MPM\Transaction\Provider\ITransactionProvider; -class WaveComTransactionProvider implements ITransactionProvider -{ +class WaveComTransactionProvider implements ITransactionProvider { private Transaction $transaction; public function __construct( @@ -24,16 +23,13 @@ public function __construct( private SmsService $smsService, private TransactionConflicts $transactionConflicts, private WaveComTransaction $waveComTransaction, - ) { - } + ) {} - public function saveTransaction() - { + public function saveTransaction() { $this->transactionService->saveTransaction(); } - public function sendResult(bool $requestType, Transaction $transaction) - { + public function sendResult(bool $requestType, Transaction $transaction) { /** @var WaveComTransaction $waveComTransaction */ $waveComTransaction = $transaction->originalTransaction()->first(); $this->transactionService->setStatus($waveComTransaction, $requestType); @@ -46,44 +42,36 @@ public function sendResult(bool $requestType, Transaction $transaction) } } - public function validateRequest($request) - { + public function validateRequest($request) { // no need as the transaction initialized by uploading a separate file } - public function confirm(): void - { + public function confirm(): void { // TODO: Implement confirm() method. } - public function getMessage(): string - { + public function getMessage(): string { return $this->getTransaction()->getMessage(); } - public function getAmount(): int - { + public function getAmount(): int { return $this->getTransaction()->getAmount(); } - public function getSender(): string - { + public function getSender(): string { return $this->getTransaction()->getSender(); } - public function saveCommonData(): Model - { + public function saveCommonData(): Model { // TODO: Implement saveCommonData() method. } - public function init($transaction): void - { + public function init($transaction): void { $this->waveComTransaction = $transaction; $this->transaction = $transaction->transaction()->first(); } - public function addConflict(?string $message): void - { + public function addConflict(?string $message): void { $conflict = $this->transactionConflicts->newQuery()->make([ 'state' => $message, ]); @@ -91,8 +79,7 @@ public function addConflict(?string $message): void $conflict->save(); } - public function getTransaction(): Transaction - { + public function getTransaction(): Transaction { return $this->transaction; } } diff --git a/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/WavecomPaymentProviderServiceProvider.php b/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/WavecomPaymentProviderServiceProvider.php index 1f954e168..9dc1c1287 100644 --- a/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/WavecomPaymentProviderServiceProvider.php +++ b/src/backend/packages/inensus/wavecom-payment-provider/src/Providers/WavecomPaymentProviderServiceProvider.php @@ -9,10 +9,8 @@ use Inensus\WavecomPaymentProvider\Console\Commands\InstallPackage; use Inensus\WavecomPaymentProvider\Models\WaveComTransaction; -class WavecomPaymentProviderServiceProvider extends ServiceProvider -{ - public function boot(Filesystem $filesystem) - { +class WavecomPaymentProviderServiceProvider extends ServiceProvider { + public function boot(Filesystem $filesystem) { $this->app->register(RouteServiceProvider::class); if ($this->app->runningInConsole()) { $this->publishConfigFiles(); @@ -28,16 +26,14 @@ public function boot(Filesystem $filesystem) ); } - public function register() - { + public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/wavecom-payment-provider.php', 'wavecom-payment-provider'); $this->app->register(EventServiceProvider::class); $this->app->register(ObserverServiceProvider::class); $this->app->bind('WaveComPaymentProvider', WaveComTransactionProvider::class); } - public function publishConfigFiles() - { + public function publishConfigFiles() { $this->publishes( [ __DIR__.'/../../config/wavecom-payment-provider.php' => config_path( @@ -47,8 +43,7 @@ public function publishConfigFiles() ); } - public function publishVueFiles() - { + public function publishVueFiles() { $this->publishes( [ __DIR__.'/../resources/assets' => resource_path( @@ -59,15 +54,13 @@ public function publishVueFiles() ); } - public function publishMigrations($filesystem) - { + public function publishMigrations($filesystem) { $this->publishes([ __DIR__.'/../../database/migrations/create_wavecom_tables.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } - protected function getMigrationFileName(Filesystem $filesystem): string - { + protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) diff --git a/src/backend/packages/inensus/wavecom-payment-provider/src/Services/TransactionService.php b/src/backend/packages/inensus/wavecom-payment-provider/src/Services/TransactionService.php index 794a6501c..dcc7a9844 100644 --- a/src/backend/packages/inensus/wavecom-payment-provider/src/Services/TransactionService.php +++ b/src/backend/packages/inensus/wavecom-payment-provider/src/Services/TransactionService.php @@ -15,14 +15,10 @@ use Inensus\WavecomPaymentProvider\Models\WaveComTransaction; use ParseCsv\Csv; -class TransactionService extends AbstractPaymentAggregatorTransactionService -{ - public function __construct(private Csv $csv) - { - } +class TransactionService extends AbstractPaymentAggregatorTransactionService { + public function __construct(private Csv $csv) {} - public function createTransactionsFromFile(UploadedFile $file): array - { + public function createTransactionsFromFile(UploadedFile $file): array { $this->csv->auto($file); $skippedTransactions = []; @@ -46,6 +42,7 @@ public function createTransactionsFromFile(UploadedFile $file): array } else { $skippedTransactions[] = $transactionData['transaction_id'].' unkown reason'; } + continue; } @@ -60,22 +57,20 @@ public function createTransactionsFromFile(UploadedFile $file): array TransactionDataContainer::initialize($baseTransaction); ProcessPayment::dispatch($transaction->getId()) - ->allOnConnection('redis') - ->onQueue(config('services.queues.payment')); + ->allOnConnection('redis') + ->onQueue(config('services.queues.payment')); } return $skippedTransactions; } - public function setStatus(WaveComTransaction $transaction, bool $status): void - { + public function setStatus(WaveComTransaction $transaction, bool $status): void { $mappedStatus = $status ? WaveComTransaction::STATUS_SUCCESS : WaveComTransaction::STATUS_CANCELLED; $transaction->setStatus($mappedStatus); $transaction->save(); } - private function validateTransaction(array $transaction) - { + private function validateTransaction(array $transaction) { $rules = [ 'transaction_id' => 'required', 'sender' => 'required', diff --git a/src/backend/routes/api.php b/src/backend/routes/api.php index 46735e2c8..9fcbeaf2b 100644 --- a/src/backend/routes/api.php +++ b/src/backend/routes/api.php @@ -138,8 +138,10 @@ Route::get('/{person}/period', 'PaymentHistoryController@getPaymentPeriod')->where('personId', '[0-9]+'); Route::get('/debt/{personId}', 'PaymentHistoryController@debts')->where('personId', '[0-9]+'); Route::post('/overview', 'PaymentHistoryController@getPaymentRange'); - Route::get('/{personId}/payments/{period}/{limit?}/{order?}', 'PaymentHistoryController@show')->where('personId', - '[0-9]+'); + Route::get('/{personId}/payments/{period}/{limit?}/{order?}', 'PaymentHistoryController@show')->where( + 'personId', + '[0-9]+' + ); }); // People Route::group(['prefix' => 'people', 'middleware' => 'jwt.verify'], static function () { @@ -259,13 +261,17 @@ Route::put('/{meterSerial}/change-meter-tariff/{tariffId}', 'MeterTariffMeterParameterController@updateForMeter'); }); // Transactions -Route::group(['prefix' => 'transactions', 'middleware' => ['transaction.auth', 'transaction.request']], +Route::group( + ['prefix' => 'transactions', 'middleware' => ['transaction.auth', 'transaction.request']], static function () { Route::post('/airtel', 'TransactionController@store'); Route::post('/vodacom', ['as' => 'vodacomTransaction', 'uses' => 'TransactionController@store']); - Route::post('/agent', - ['as' => 'agent-transaction', 'uses' => 'TransactionController@store', 'middleware' => 'agent.balance']); - }); + Route::post( + '/agent', + ['as' => 'agent-transaction', 'uses' => 'TransactionController@store', 'middleware' => 'agent.balance'] + ); + } +); Route::group(['prefix' => 'time-of-usages', 'middleware' => 'jwt.verify'], static function () { Route::delete('/{timeOfUsageId}', 'TimeOfUsageController@destroy'); diff --git a/src/backend/routes/resources/AgentApp.php b/src/backend/routes/resources/AgentApp.php index 9aefd4fee..2ff9d901f 100644 --- a/src/backend/routes/resources/AgentApp.php +++ b/src/backend/routes/resources/AgentApp.php @@ -16,10 +16,14 @@ Route::group(['prefix' => 'customers'], function () { Route::get('/', 'AgentCustomerController@index'); Route::get('/search', 'AgentCustomerController@search'); - Route::get('/{customerId}/graph/{period}/{limit?}/{order?}', - 'AgentCustomersPaymentHistoryController@show')->where('customerId', '[0-9]+'); - Route::get('/graph/{period}/{limit?}/{order?}', - 'AgentCustomersPaymentHistoryController@index'); + Route::get( + '/{customerId}/graph/{period}/{limit?}/{order?}', + 'AgentCustomersPaymentHistoryController@show' + )->where('customerId', '[0-9]+'); + Route::get( + '/graph/{period}/{limit?}/{order?}', + 'AgentCustomersPaymentHistoryController@index' + ); }); Route::group(['prefix' => 'transactions'], function () { Route::get('/', 'AgentTransactionsController@index'); diff --git a/src/backend/routes/web.php b/src/backend/routes/web.php index dc718d7ff..26e6b9cf0 100644 --- a/src/backend/routes/web.php +++ b/src/backend/routes/web.php @@ -21,16 +21,19 @@ Route::get('/', 'HomeController@index')->name('home'); -Route::group(['prefix' => '/jobs', 'middleware' => 'auth'], +Route::group( + ['prefix' => '/jobs', 'middleware' => 'auth'], static function () { Route::get('/token/{id}/{recreate?}', static function () { $id = request('id'); $recreate = (bool) request('recreate'); TokenProcessor::dispatch( TransactionDataContainer::initialize(Transaction::find($id)), - $recreate, 1)->allOnConnection('redis')->onQueue( - config('services.queues.token') - ); + $recreate, + 1 + )->allOnConnection('redis')->onQueue( + config('services.queues.token') + ); })->where('id', '[0-9]+')->name('jobs.token'); Route::get('energy/{id}', function () { @@ -38,7 +41,8 @@ static function () { $transaction = Transaction::find($id); EnergyTransactionProcessor::dispatch($transaction)->allOnConnection('redis')->onQueue('energy_payment'); }); - }); + } +); /* * the group in which events can be fired manually again. diff --git a/src/backend/tests/CreatesApplication.php b/src/backend/tests/CreatesApplication.php index 18f982511..e7f4c9006 100644 --- a/src/backend/tests/CreatesApplication.php +++ b/src/backend/tests/CreatesApplication.php @@ -5,15 +5,13 @@ use Illuminate\Contracts\Console\Kernel; use Illuminate\Foundation\Application; -trait CreatesApplication -{ +trait CreatesApplication { /** * Creates the application. * * @return Application */ - public function createApplication() - { + public function createApplication() { $app = require __DIR__.'/../bootstrap/app.php'; $app->make(Kernel::class)->bootstrap(); diff --git a/src/backend/tests/Feature/AddressTest.php b/src/backend/tests/Feature/AddressTest.php index f7a8a6d3d..9cb80dadd 100644 --- a/src/backend/tests/Feature/AddressTest.php +++ b/src/backend/tests/Feature/AddressTest.php @@ -13,13 +13,11 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class AddressTest extends TestCase -{ +class AddressTest extends TestCase { use RefreshMultipleDatabases; use WithFaker; - public function testUserDefinesAnAddressToCustomerForOwnCompany() - { + public function testUserDefinesAnAddressToCustomerForOwnCompany() { $user = UserFactory::new()->create(); $person = PersonFactory::new()->create(); $city = CityFactory::new()->create(); @@ -42,8 +40,7 @@ public function testUserDefinesAnAddressToCustomerForOwnCompany() $this->assertEquals(1, $person->addresses()->first()->is_primary); } - public function testUserUpdatesAndAddressOfCustomerForOwnCompany() - { + public function testUserUpdatesAndAddressOfCustomerForOwnCompany() { $user = UserFactory::new()->create(); $person = PersonFactory::new()->create(); $city = CityFactory::new()->create(); @@ -69,8 +66,7 @@ public function testUserUpdatesAndAddressOfCustomerForOwnCompany() $this->assertEquals(0, $person->addresses()->first()->is_primary); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/AgentAppTest.php b/src/backend/tests/Feature/AgentAppTest.php index 7611e9012..0742d1c39 100644 --- a/src/backend/tests/Feature/AgentAppTest.php +++ b/src/backend/tests/Feature/AgentAppTest.php @@ -7,12 +7,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class AgentAppTest extends TestCase -{ +class AgentAppTest extends TestCase { use CreateEnvironments; - public function testAgentLogsIn() - { + public function testAgentLogsIn() { $this->createTestData(); $this->createAgent(); $agent = $this->agent; @@ -27,8 +25,7 @@ public function testAgentLogsIn() $this->assertNotNull($response->json('access_token')); } - public function testAgentGetsOwnData() - { + public function testAgentGetsOwnData() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -40,8 +37,7 @@ public function testAgentGetsOwnData() $this->assertEquals($agent->name, $response['name']); } - public function testAgentLogsOut() - { + public function testAgentLogsOut() { $this->createTestData(); $this->createAgent(); $agent = $this->agent; @@ -50,8 +46,7 @@ public function testAgentLogsOut() $this->assertEquals($response->json('message'), 'Successfully logged out'); } - public function testAgentRefreshesAuthToken() - { + public function testAgentRefreshesAuthToken() { $this->createTestData(); $this->createAgent(); $agent = $this->agent; @@ -59,8 +54,7 @@ public function testAgentRefreshesAuthToken() $response->assertStatus(200); } - public function testAgentSetsFirebaseToken() - { + public function testAgentSetsFirebaseToken() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -73,8 +67,7 @@ public function testAgentSetsFirebaseToken() $this->assertEquals($response['data']['fire_base_token'], $postData['fire_base_token']); } - public function testAgentGetsBalance() - { + public function testAgentGetsBalance() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -84,8 +77,7 @@ public function testAgentGetsBalance() $this->assertEquals($agent->balance, $response->getContent()); } - public function testAgentGetsCustomers() - { + public function testAgentGetsCustomers() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -102,8 +94,7 @@ public function testAgentGetsCustomers() $this->assertEquals(count($response['data']), $personCount); } - public function testAgentSearchesInCustomers() - { + public function testAgentSearchesInCustomers() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -122,8 +113,7 @@ public function testAgentSearchesInCustomers() $this->assertEquals($response['data'][0]['name'], $person->name); } - public function testAgentGetsCustomersPaymentFlow() - { + public function testAgentGetsCustomersPaymentFlow() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -146,8 +136,7 @@ public function testAgentGetsCustomersPaymentFlow() $this->assertNotNull($response->getContent()); } - public function testAgentGetsCustomerPaymentFlowByCustomerId() - { + public function testAgentGetsCustomerPaymentFlowByCustomerId() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -172,8 +161,7 @@ public function testAgentGetsCustomerPaymentFlowByCustomerId() $this->assertNotNull($response->getContent()); } - public function testAgentGetsCustomersTransactions() - { + public function testAgentGetsCustomersTransactions() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -196,8 +184,7 @@ public function testAgentGetsCustomersTransactions() $this->assertEquals(count($response['data']), $agentTransactionCount); } - public function testAgentGetsCustomerTransactionsByCustomerId() - { + public function testAgentGetsCustomerTransactionsByCustomerId() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -220,8 +207,7 @@ public function testAgentGetsCustomerTransactionsByCustomerId() $this->assertEquals(count($response['data']), $agentTransactionCount); } - public function testAgentGetsSoldAppliances() - { + public function testAgentGetsSoldAppliances() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -233,8 +219,7 @@ public function testAgentGetsSoldAppliances() $this->assertEquals(count($response['data']), 1); } - public function testAgentGetsCustomerSoldAppliancesByCustomerId() - { + public function testAgentGetsCustomerSoldAppliancesByCustomerId() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -246,8 +231,7 @@ public function testAgentGetsCustomerSoldAppliancesByCustomerId() $this->assertEquals(count($response['data']), 1); } - public function testAgentSalesAppliances() - { + public function testAgentSalesAppliances() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -265,8 +249,7 @@ public function testAgentSalesAppliances() $response->assertStatus(201); } - public function testAgentGetsAssignedAppliances() - { + public function testAgentGetsAssignedAppliances() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -278,8 +261,7 @@ public function testAgentGetsAssignedAppliances() $this->assertEquals(count($response['data']), $assignedApplianceCount); } - public function testAgentGetsApplicationDashboardBoxes() - { + public function testAgentGetsApplicationDashboardBoxes() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -306,8 +288,7 @@ public function testAgentGetsApplicationDashboardBoxes() $this->assertEquals(array_key_exists('since', $response['data']), true); } - public function testAgentGetsApplicationDashboardGraphValues() - { + public function testAgentGetsApplicationDashboardGraphValues() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -329,8 +310,7 @@ public function testAgentGetsApplicationDashboardGraphValues() $response->assertStatus(200); } - public function testAgentGetsApplicationDashboardWeeklyRevenues() - { + public function testAgentGetsApplicationDashboardWeeklyRevenues() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -352,8 +332,7 @@ public function testAgentGetsApplicationDashboardWeeklyRevenues() $response->assertStatus(200); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/AgentAppTicketsTest.php b/src/backend/tests/Feature/AgentAppTicketsTest.php index 0e817f6a6..84fb5522f 100644 --- a/src/backend/tests/Feature/AgentAppTicketsTest.php +++ b/src/backend/tests/Feature/AgentAppTicketsTest.php @@ -5,12 +5,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class AgentAppTicketsTest extends TestCase -{ +class AgentAppTicketsTest extends TestCase { use CreateEnvironments; - public function testAgentGetsTicketList() - { + public function testAgentGetsTicketList() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -25,8 +23,7 @@ public function testAgentGetsTicketList() $this->assertEquals($ticketCount, count($response['data']['data'])); } - public function testAgentGetsTicketById() - { + public function testAgentGetsTicketById() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -43,8 +40,7 @@ public function testAgentGetsTicketById() $this->assertEquals($this->agent->id, $response['data']['creator_id']); } - public function testAgentGetsTicketCustomerId() - { + public function testAgentGetsTicketCustomerId() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -54,15 +50,16 @@ public function testAgentGetsTicketCustomerId() $this->createTicketCard(); $ticketCount = 1; $this->createTicket($ticketCount, 1, $this->person->id, $this->agent->id); - $response = $this->actingAs($this->agent)->get(sprintf('/api/app/agents/ticket/customer/%s', - $this->person->id)); + $response = $this->actingAs($this->agent)->get(sprintf( + '/api/app/agents/ticket/customer/%s', + $this->person->id + )); $response->assertStatus(200); $this->assertEquals($this->ticket->id, $response['data']['data'][0]['id']); $this->assertEquals($this->agent->id, $response['data']['data'][0]['creator_id']); } - public function testAgentCreatesATicket() - { + public function testAgentCreatesATicket() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -87,8 +84,7 @@ public function testAgentCreatesATicket() $this->assertEquals('agent', $response['data'][0]['creator_type']); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/AgentAssignedApplianceWebTest.php b/src/backend/tests/Feature/AgentAssignedApplianceWebTest.php index 9a9992ec3..7cf185c2f 100644 --- a/src/backend/tests/Feature/AgentAssignedApplianceWebTest.php +++ b/src/backend/tests/Feature/AgentAssignedApplianceWebTest.php @@ -5,12 +5,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class AgentAssignedApplianceWebTest extends TestCase -{ +class AgentAssignedApplianceWebTest extends TestCase { use CreateEnvironments; - public function testUserGetsAgentsAssignedApplianceList() - { + public function testUserGetsAgentsAssignedApplianceList() { $this->createTestData(); $agentCount = 1; $this->createAgent($agentCount); @@ -21,8 +19,7 @@ public function testUserGetsAgentsAssignedApplianceList() $this->assertEquals(count($response['data']), $applianceCount); } - public function testUserAssignsAnAssignedApplianceToAgent() - { + public function testUserAssignsAnAssignedApplianceToAgent() { $this->createTestData(); $agentCount = 1; $this->createAgent($agentCount); @@ -42,8 +39,7 @@ public function testUserAssignsAnAssignedApplianceToAgent() $this->assertEquals($response['data']['cost'], $postData['cost']); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/AgentBalanceHistoryWebTest.php b/src/backend/tests/Feature/AgentBalanceHistoryWebTest.php index a28cd1a87..acfef26f3 100644 --- a/src/backend/tests/Feature/AgentBalanceHistoryWebTest.php +++ b/src/backend/tests/Feature/AgentBalanceHistoryWebTest.php @@ -5,12 +5,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class AgentBalanceHistoryWebTest extends TestCase -{ +class AgentBalanceHistoryWebTest extends TestCase { use CreateEnvironments; - public function testUserGetsAgentsBalanceHistories() - { + public function testUserGetsAgentsBalanceHistories() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -22,8 +20,7 @@ public function testUserGetsAgentsBalanceHistories() $this->assertEquals(count($response['data']), $agentBalanceHistoryCount); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/AgentChargeTest.php b/src/backend/tests/Feature/AgentChargeTest.php index 215946de4..7b0bef05e 100644 --- a/src/backend/tests/Feature/AgentChargeTest.php +++ b/src/backend/tests/Feature/AgentChargeTest.php @@ -6,12 +6,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class AgentChargeTest extends TestCase -{ +class AgentChargeTest extends TestCase { use CreateEnvironments; - public function testUserCreatesNewBalanceForAgent() - { + public function testUserCreatesNewBalanceForAgent() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -26,8 +24,7 @@ public function testUserCreatesNewBalanceForAgent() $this->assertEquals($agent->balance, $agentBalance + $postData['amount']); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/AgentCommissionTest.php b/src/backend/tests/Feature/AgentCommissionTest.php index 305d29917..46e884cb1 100644 --- a/src/backend/tests/Feature/AgentCommissionTest.php +++ b/src/backend/tests/Feature/AgentCommissionTest.php @@ -6,12 +6,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class AgentCommissionTest extends TestCase -{ +class AgentCommissionTest extends TestCase { use CreateEnvironments; - public function testUserGetsAgentCommissionList() - { + public function testUserGetsAgentCommissionList() { $this->createTestData(); $agentCommissionCount = 5; $this->createAgentCommission($agentCommissionCount); @@ -20,8 +18,7 @@ public function testUserGetsAgentCommissionList() $this->assertEquals(count($response['data']), $agentCommissionCount); } - public function testUserCreatesAgentCommission() - { + public function testUserCreatesAgentCommission() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -39,8 +36,7 @@ public function testUserCreatesAgentCommission() $this->assertEquals($lastCreatedAgentCommission->name, $response['data']['name']); } - public function testUserCanUpdateAnAgentCommission() - { + public function testUserCanUpdateAnAgentCommission() { $this->createTestData(); $this->createAgentCommission(); $putData = [ @@ -50,8 +46,10 @@ public function testUserCanUpdateAnAgentCommission() 'risk_balance' => -20000, ]; - $response = $this->actingAs($this->user)->put(sprintf('/api/agents/commissions/%s', - $this->agentCommissions[0]->id), $putData); + $response = $this->actingAs($this->user)->put(sprintf( + '/api/agents/commissions/%s', + $this->agentCommissions[0]->id + ), $putData); $response->assertStatus(200); $this->assertEquals($putData['name'], $response['data']['name']); $this->assertEquals($putData['energy_commission'], $response['data']['energy_commission']); @@ -59,8 +57,7 @@ public function testUserCanUpdateAnAgentCommission() $this->assertEquals($putData['risk_balance'], $response['data']['risk_balance']); } - public function testUserCanDeleteAnAgent() - { + public function testUserCanDeleteAnAgent() { $this->createTestData(); $this->createAgentCommission(); $response = $this->actingAs($this->user)->delete(sprintf('/api/agents/commissions/%s', $this->agentCommissions[0]->id)); @@ -68,8 +65,7 @@ public function testUserCanDeleteAnAgent() $this->assertEquals(0, $agentsCount); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/AgentReceiptTest.php b/src/backend/tests/Feature/AgentReceiptTest.php index 20fe57b04..7ec6af32d 100644 --- a/src/backend/tests/Feature/AgentReceiptTest.php +++ b/src/backend/tests/Feature/AgentReceiptTest.php @@ -6,12 +6,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class AgentReceiptTest extends TestCase -{ +class AgentReceiptTest extends TestCase { use CreateEnvironments; - public function testUserGetsAgentsReceipts() - { + public function testUserGetsAgentsReceipts() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -26,8 +24,7 @@ public function testUserGetsAgentsReceipts() $this->assertEquals($response['data'][0]['agent']['balance'], $agentBalance); } - public function testUserGetsAllReceipts() - { + public function testUserGetsAllReceipts() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -38,8 +35,7 @@ public function testUserGetsAllReceipts() $this->assertEquals(count($response['data']), 1); } - public function testUserCreatesNewReceipt() - { + public function testUserCreatesNewReceipt() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -54,8 +50,7 @@ public function testUserCreatesNewReceipt() $this->assertEquals($response['data']['amount'], $postData['amount']); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/AgentSoldApplianceWebTest.php b/src/backend/tests/Feature/AgentSoldApplianceWebTest.php index 4a3a6ba0d..01ffa9e76 100644 --- a/src/backend/tests/Feature/AgentSoldApplianceWebTest.php +++ b/src/backend/tests/Feature/AgentSoldApplianceWebTest.php @@ -5,12 +5,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class AgentSoldApplianceWebTest extends TestCase -{ +class AgentSoldApplianceWebTest extends TestCase { use CreateEnvironments; - public function testUserGetsAgentsSoldApplianceList() - { + public function testUserGetsAgentsSoldApplianceList() { $this->createTestData(); $this->createAgent(); $this->createAssignedAppliances(); @@ -21,8 +19,7 @@ public function testUserGetsAgentsSoldApplianceList() $this->assertEquals(count($response['data']), 1); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/AgentTest.php b/src/backend/tests/Feature/AgentTest.php index 9ceebe514..98f556782 100644 --- a/src/backend/tests/Feature/AgentTest.php +++ b/src/backend/tests/Feature/AgentTest.php @@ -7,12 +7,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class AgentTest extends TestCase -{ +class AgentTest extends TestCase { use CreateEnvironments; - public function testUserGetsAgentList() - { + public function testUserGetsAgentList() { $this->createTestData(); $agentCount = 4; $this->createAgent(4); @@ -21,8 +19,7 @@ public function testUserGetsAgentList() $this->assertEquals(count($response['data']), $agentCount); } - public function testUserGetsAgentById() - { + public function testUserGetsAgentById() { $this->createTestData(); $agentCount = 4; $this->createAgent(4); @@ -31,8 +28,7 @@ public function testUserGetsAgentById() $this->assertEquals($response['data']['id'], $this->agents[0]->id); } - public function testUserCreatesNewAgent() - { + public function testUserCreatesNewAgent() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -59,8 +55,7 @@ public function testUserCreatesNewAgent() $this->assertEquals($personAddress->phone, $postData['phone']); } - public function testUserCanUpdateAnAgent() - { + public function testUserCanUpdateAnAgent() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -85,8 +80,7 @@ public function testUserCanUpdateAnAgent() $this->assertEquals($putData['gender'], $response['data']['person']['sex']); } - public function testUserCanResetsAgentsPassword() - { + public function testUserCanResetsAgentsPassword() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -102,8 +96,7 @@ public function testUserCanResetsAgentsPassword() $response->assertStatus(200); } - public function testUserCanSearchAnAgentByName() - { + public function testUserCanSearchAnAgentByName() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -116,8 +109,7 @@ public function testUserCanSearchAnAgentByName() $this->assertEquals($responseData['name'], $this->agents[0]->name); } - public function testUserCanDeleteAnAgent() - { + public function testUserCanDeleteAnAgent() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -129,8 +121,7 @@ public function testUserCanDeleteAnAgent() $this->assertEquals(0, $agentsCount); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/AgentTransactionWebTest.php b/src/backend/tests/Feature/AgentTransactionWebTest.php index 5fe24ea9a..29c1d883c 100644 --- a/src/backend/tests/Feature/AgentTransactionWebTest.php +++ b/src/backend/tests/Feature/AgentTransactionWebTest.php @@ -5,12 +5,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class AgentTransactionWebTest extends TestCase -{ +class AgentTransactionWebTest extends TestCase { use CreateEnvironments; - public function testUserGetsAgentsTransactions() - { + public function testUserGetsAgentsTransactions() { $this->createTestData(); $this->createAgentCommission(); $this->createAgent(); @@ -24,8 +22,7 @@ public function testUserGetsAgentsTransactions() $this->assertEquals($response['data'][0]['amount'], $amount); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/CalinApiTest.php b/src/backend/tests/Feature/CalinApiTest.php index 7340ae89d..658459c12 100644 --- a/src/backend/tests/Feature/CalinApiTest.php +++ b/src/backend/tests/Feature/CalinApiTest.php @@ -15,8 +15,7 @@ use Illuminate\Support\Facades\Bus; use Tests\TestCase; -class CalinApiTest extends TestCase -{ +class CalinApiTest extends TestCase { use RefreshDatabase; use WithFaker; @@ -25,8 +24,7 @@ class CalinApiTest extends TestCase * for security reasons we can not provide a meter to perfom the test * This test passed on 28.06.2020 with a valid meter. */ - public function testGenerateTokenForAValidMeter(): void - { + public function testGenerateTokenForAValidMeter(): void { Bus::fake(); $this->withoutExceptionHandling(); diff --git a/src/backend/tests/Feature/CityTest.php b/src/backend/tests/Feature/CityTest.php index 8e696c3ef..bc378dfa4 100644 --- a/src/backend/tests/Feature/CityTest.php +++ b/src/backend/tests/Feature/CityTest.php @@ -15,21 +15,25 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class CityTest extends TestCase -{ +class CityTest extends TestCase { use RefreshMultipleDatabases; use WithFaker; private $user; + private $company; + private $companyDatabase; + private $person; + private $clusterIds = []; + private $miniGridIds = []; + private $cityIds = []; - public function testUserGetsCities() - { + public function testUserGetsCities() { $clusterCount = 1; $miniGridCount = 1; $cityCount = 5; @@ -39,8 +43,7 @@ public function testUserGetsCities() $this->assertEquals(count($response['data']), count($this->cityIds)); } - public function testUserGetsCityById() - { + public function testUserGetsCityById() { $clusterCount = 1; $miniGridCount = 1; $cityCount = 1; @@ -50,8 +53,7 @@ public function testUserGetsCityById() $this->assertEquals($response['data']['id'], $this->cityIds[0]); } - public function testUserCreatesNewCity() - { + public function testUserCreatesNewCity() { $clusterCount = 1; $miniGridCount = 1; $cityCount = 1; @@ -66,8 +68,7 @@ public function testUserCreatesNewCity() $this->assertEquals($response['data']['name'], $cityData['name']); } - public function testUserUpdatesACity() - { + public function testUserUpdatesACity() { $clusterCount = 2; $miniGridCount = 2; $cityCount = 1; @@ -83,8 +84,7 @@ public function testUserUpdatesACity() $this->assertEquals($response['data']['name'], $cityData['name']); } - protected function createTestData($clusterCount = 1, $miniGridCount = 1, $cityCount = 1) - { + protected function createTestData($clusterCount = 1, $miniGridCount = 1, $cityCount = 1) { $this->user = UserFactory::new()->create(); $this->company = CompanyFactory::new()->create(); $this->companyDatabase = CompanyDatabaseFactory::new()->create(); @@ -125,8 +125,7 @@ protected function createTestData($clusterCount = 1, $miniGridCount = 1, $cityCo } } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); @@ -134,8 +133,7 @@ public function actingAs($user, $driver = null) return $this; } - protected function generateUniqueNumber(): int - { + protected function generateUniqueNumber(): int { return $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber(); } diff --git a/src/backend/tests/Feature/ClusterDashboardCacheTest.php b/src/backend/tests/Feature/ClusterDashboardCacheTest.php index b0b3988dd..3698a6cee 100644 --- a/src/backend/tests/Feature/ClusterDashboardCacheTest.php +++ b/src/backend/tests/Feature/ClusterDashboardCacheTest.php @@ -28,27 +28,37 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class ClusterDashboardCacheTest extends TestCase -{ +class ClusterDashboardCacheTest extends TestCase { use RefreshMultipleDatabases; use WithFaker; private $user; + private $company; + private $city; + private $connectionType; + private $manufacturer; + private $meterType; + private $meter; + private $meterParameter; + private $meterTariff; + private $person; + private $token; + private $transaction; + private $clusterIds = []; - public function testUserUpdatesClusterDataInCache() - { + public function testUserUpdatesClusterDataInCache() { $clusterCount = 1; $meterCount = 2; $transactionCount = 3; @@ -58,8 +68,7 @@ public function testUserUpdatesClusterDataInCache() $this->assertEquals(count(Cache::get('ClustersList')), count($this->clusterIds)); } - public function testUserGetsClusterDataFromCacheById() - { + public function testUserGetsClusterDataFromCacheById() { $clusterCount = 2; $meterCount = 2; $transactionCount = 3; @@ -69,8 +78,7 @@ public function testUserGetsClusterDataFromCacheById() $this->assertEquals($response['data']['id'], $this->clusterIds[0]); } - protected function createTestData($clusterCount = 1, $meterCount = 1, $transactionCount = 1) - { + protected function createTestData($clusterCount = 1, $meterCount = 1, $transactionCount = 1) { $this->user = UserFactory::new()->create(); $this->city = CityFactory::new()->create(); $this->company = CompanyFactory::new()->create(); @@ -188,8 +196,7 @@ protected function createTestData($clusterCount = 1, $meterCount = 1, $transacti } } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); @@ -197,8 +204,7 @@ public function actingAs($user, $driver = null) return $this; } - protected function generateUniqueNumber(): int - { + protected function generateUniqueNumber(): int { return $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber(); } diff --git a/src/backend/tests/Feature/ClusterRevenueTest.php b/src/backend/tests/Feature/ClusterRevenueTest.php index 746b6d3d3..2bc023729 100644 --- a/src/backend/tests/Feature/ClusterRevenueTest.php +++ b/src/backend/tests/Feature/ClusterRevenueTest.php @@ -28,27 +28,37 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class ClusterRevenueTest extends TestCase -{ +class ClusterRevenueTest extends TestCase { use RefreshMultipleDatabases; use WithFaker; private $user; + private $company; + private $city; + private $connectionType; + private $manufacturer; + private $meterType; + private $meter; + private $meterParameter; + private $meterTariff; + private $person; + private $token; + private $transaction; + private $clusterIds = []; - public function testUserGetsClustersRevenueMonthly() - { + public function testUserGetsClustersRevenueMonthly() { $clusterCount = 2; $meterCount = 3; $transactionCount = 4; @@ -61,8 +71,7 @@ public function testUserGetsClustersRevenueMonthly() $this->assertEquals($totalRevenue, $this->getTotalTransactionAmount()); } - public function testUserGetsClustersRevenueWeekly() - { + public function testUserGetsClustersRevenueWeekly() { $clusterCount = 1; $meterCount = 5; $transactionCount = 2; @@ -75,25 +84,27 @@ public function testUserGetsClustersRevenueWeekly() $this->assertEquals($totalRevenue, $this->getTotalTransactionAmount()); } - public function testUserGetsRevenueInConnectionTypesAnalysisForCluster() - { + public function testUserGetsRevenueInConnectionTypesAnalysisForCluster() { $clusterCount = 1; $meterCount = 2; $transactionCount = 1; $this->createTestData($clusterCount, $meterCount, $transactionCount); - $response = $this->actingAs($this->user)->get(sprintf('/api/clusters/%s/revenue/analysis', - $this->clusterIds[0])); + $response = $this->actingAs($this->user)->get(sprintf( + '/api/clusters/%s/revenue/analysis', + $this->clusterIds[0] + )); $response->assertStatus(200); } - public function testUserGetsMiniGridRevenueMonthlyForCluster() - { + public function testUserGetsMiniGridRevenueMonthlyForCluster() { $clusterCount = 1; $meterCount = 1; $transactionCount = 1; $this->createTestData($clusterCount, $meterCount, $transactionCount); - $response = $this->actingAs($this->user)->get(sprintf('/api/clusters/%s/cities-revenue', - $this->clusterIds[0])); + $response = $this->actingAs($this->user)->get(sprintf( + '/api/clusters/%s/cities-revenue', + $this->clusterIds[0] + )); $response->assertStatus(200); $totalRevenue = array_reduce($response['data'], function ($acc, $curr) { return $acc + $curr['totalRevenue']; @@ -101,14 +112,15 @@ public function testUserGetsMiniGridRevenueMonthlyForCluster() $this->assertEquals($totalRevenue, $this->getTotalTransactionAmount()); } - public function testUserGetsMiniGridRevenueWeeklyForCluster() - { + public function testUserGetsMiniGridRevenueWeeklyForCluster() { $clusterCount = 1; $meterCount = 1; $transactionCount = 1; $this->createTestData($clusterCount, $meterCount, $transactionCount); - $response = $this->actingAs($this->user)->get(sprintf('/api/clusters/%s/cities-revenue?period=weekly', - $this->clusterIds[0])); + $response = $this->actingAs($this->user)->get(sprintf( + '/api/clusters/%s/cities-revenue?period=weekly', + $this->clusterIds[0] + )); $response->assertStatus(200); $totalRevenue = array_reduce($response['data'], function ($acc, $curr) { return $acc + $curr['totalRevenue']; @@ -116,8 +128,7 @@ public function testUserGetsMiniGridRevenueWeeklyForCluster() $this->assertEquals($totalRevenue, $this->getTotalTransactionAmount()); } - protected function getTotalTransactionAmount() - { + protected function getTotalTransactionAmount() { $clusterIds = $this->clusterIds; return Transaction::query() @@ -150,8 +161,7 @@ static function ($q) { )->get()->pluck('amount')->sum(); } - protected function createTestData($clusterCount = 1, $meterCount = 1, $transactionCount = 1) - { + protected function createTestData($clusterCount = 1, $meterCount = 1, $transactionCount = 1) { $this->user = UserFactory::new()->create(); $this->city = CityFactory::new()->create(); $this->company = CompanyFactory::new()->create(); @@ -274,8 +284,7 @@ protected function createTestData($clusterCount = 1, $meterCount = 1, $transacti } } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); @@ -283,8 +292,7 @@ public function actingAs($user, $driver = null) return $this; } - protected function generateUniqueNumber(): int - { + protected function generateUniqueNumber(): int { return $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber(); } diff --git a/src/backend/tests/Feature/ClusterTest.php b/src/backend/tests/Feature/ClusterTest.php index 1e94c9606..aa4944231 100644 --- a/src/backend/tests/Feature/ClusterTest.php +++ b/src/backend/tests/Feature/ClusterTest.php @@ -28,27 +28,37 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class ClusterTest extends TestCase -{ +class ClusterTest extends TestCase { use RefreshMultipleDatabases; use WithFaker; private $user; + private $company; + private $city; + private $connectionType; + private $manufacturer; + private $meterType; + private $meter; + private $meterParameter; + private $meterTariff; + private $person; + private $token; + private $transaction; + private $clusterIds = []; - public function testUserGetsClusterListForDashboard() - { + public function testUserGetsClusterListForDashboard() { $clusterCount = 1; $meterCount = 2; $transactionCount = 3; @@ -60,8 +70,7 @@ public function testUserGetsClusterListForDashboard() $this->assertEquals($response['data'][0]['clusterData']['meterCount'], $meterCount); } - public function testUserGetsClusterByIdForDashboard() - { + public function testUserGetsClusterByIdForDashboard() { $this->createTestData(); $response = $this->actingAs($this->user)->get(sprintf('/api/clusters/%s', $this->clusterIds[0])); $response->assertStatus(200); @@ -69,15 +78,13 @@ public function testUserGetsClusterByIdForDashboard() $this->assertEquals($response['data']['meterCount'], 1); } - public function testUserGetsClusterGeoDataById() - { + public function testUserGetsClusterGeoDataById() { $this->createTestData(); $response = $this->actingAs($this->user)->get(sprintf('/api/clusters/%s/geo', $this->clusterIds[0])); $response->assertStatus(200); } - public function testUserAddsNewCluster() - { + public function testUserAddsNewCluster() { $this->createTestData(); $clusterData = [ 'name' => 'test cluster', @@ -90,8 +97,7 @@ public function testUserAddsNewCluster() $this->assertEquals(Cluster::query()->count(), count($this->clusterIds) + 1); } - protected function createTestData($clusterCount = 1, $meterCount = 1, $transactionCount = 1) - { + protected function createTestData($clusterCount = 1, $meterCount = 1, $transactionCount = 1) { $this->user = UserFactory::new()->create(); $this->city = CityFactory::new()->create(); $this->company = CompanyFactory::new()->create(); @@ -211,8 +217,7 @@ protected function createTestData($clusterCount = 1, $meterCount = 1, $transacti } } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); @@ -220,8 +225,7 @@ public function actingAs($user, $driver = null) return $this; } - protected function generateUniqueNumber(): int - { + protected function generateUniqueNumber(): int { return $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber(); } diff --git a/src/backend/tests/Feature/ConnectionGroupTest.php b/src/backend/tests/Feature/ConnectionGroupTest.php index fc0c17d68..5d1c58fb9 100644 --- a/src/backend/tests/Feature/ConnectionGroupTest.php +++ b/src/backend/tests/Feature/ConnectionGroupTest.php @@ -11,19 +11,21 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class ConnectionGroupTest extends TestCase -{ +class ConnectionGroupTest extends TestCase { use RefreshMultipleDatabases; use WithFaker; private $user; + private $company; + private $companyDatabase; + private $person; + private $connectonGroupIds = []; - public function testUserGetsConnectionGroupList() - { + public function testUserGetsConnectionGroupList() { $connectionGroupCount = 5; $this->createTestData($connectionGroupCount); $response = $this->actingAs($this->user)->get('/api/connection-groups'); @@ -31,8 +33,7 @@ public function testUserGetsConnectionGroupList() $this->assertEquals(count($response['data']), count($this->connectonGroupIds)); } - public function testUserGetsConnectionGroupById() - { + public function testUserGetsConnectionGroupById() { $connectionGroupCount = 5; $this->createTestData($connectionGroupCount); $response = $this->actingAs($this->user)->get(sprintf('/api/connection-groups/%s', $this->connectonGroupIds[0])); @@ -40,8 +41,7 @@ public function testUserGetsConnectionGroupById() $this->assertEquals($response['data']['id'], $this->connectonGroupIds[0]); } - public function testUserCreatesNewConnectionGroup() - { + public function testUserCreatesNewConnectionGroup() { $connectionGroupCount = 0; $this->createTestData($connectionGroupCount); $connectionGroupData = ['name' => 'Test Connection Group']; @@ -50,19 +50,19 @@ public function testUserCreatesNewConnectionGroup() $this->assertEquals($response['data']['name'], $connectionGroupData['name']); } - public function testUserUpdatesAConnectionGroup() - { + public function testUserUpdatesAConnectionGroup() { $connectionGroupCount = 1; $this->createTestData($connectionGroupCount); $connectionGroupData = ['name' => 'Updated Connection Group']; - $response = $this->actingAs($this->user)->put(sprintf('/api/connection-groups/%s', - $this->connectonGroupIds[0]), $connectionGroupData); + $response = $this->actingAs($this->user)->put(sprintf( + '/api/connection-groups/%s', + $this->connectonGroupIds[0] + ), $connectionGroupData); $response->assertStatus(200); $this->assertEquals($response['data']['name'], $connectionGroupData['name']); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); @@ -70,8 +70,7 @@ public function actingAs($user, $driver = null) return $this; } - protected function createTestData($connectionGroupCount = 1) - { + protected function createTestData($connectionGroupCount = 1) { $this->user = UserFactory::new()->create(); $this->company = CompanyFactory::new()->create(); $this->companyDatabase = CompanyDatabaseFactory::new()->create(); diff --git a/src/backend/tests/Feature/ConnectionTypeTest.php b/src/backend/tests/Feature/ConnectionTypeTest.php index 5a2d0c64b..647843e66 100644 --- a/src/backend/tests/Feature/ConnectionTypeTest.php +++ b/src/backend/tests/Feature/ConnectionTypeTest.php @@ -11,19 +11,21 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class ConnectionTypeTest extends TestCase -{ +class ConnectionTypeTest extends TestCase { use RefreshMultipleDatabases; use WithFaker; private $user; + private $company; + private $companyDatabase; + private $person; + private $connectonTypeIds = []; - public function testUserGetsConnectionTypeList() - { + public function testUserGetsConnectionTypeList() { $connectionTypeCount = 5; $this->createTestData($connectionTypeCount); $response = $this->actingAs($this->user)->get('/api/connection-types'); @@ -31,8 +33,7 @@ public function testUserGetsConnectionTypeList() $this->assertEquals(count($response['data']), count($this->connectonTypeIds)); } - public function testUserGetsConnectionTypeById() - { + public function testUserGetsConnectionTypeById() { $connectionTypeCount = 5; $this->createTestData($connectionTypeCount); $response = $this->actingAs($this->user)->get(sprintf('/api/connection-types/%s', $this->connectonTypeIds[0])); @@ -40,8 +41,7 @@ public function testUserGetsConnectionTypeById() $this->assertEquals($response['data']['id'], $this->connectonTypeIds[0]); } - public function testUserCreatesNewConnectionType() - { + public function testUserCreatesNewConnectionType() { $connectionTypeCount = 0; $this->createTestData($connectionTypeCount); $connectionTypeData = ['name' => 'Test Connection Type']; @@ -50,19 +50,19 @@ public function testUserCreatesNewConnectionType() $this->assertEquals($response['data']['name'], $connectionTypeData['name']); } - public function testUserUpdatesAConnectionType() - { + public function testUserUpdatesAConnectionType() { $connectionTypeCount = 1; $this->createTestData($connectionTypeCount); $connectionTypeData = ['name' => 'Updated Connection Type']; - $response = $this->actingAs($this->user)->put(sprintf('/api/connection-types/%s', - $this->connectonTypeIds[0]), $connectionTypeData); + $response = $this->actingAs($this->user)->put(sprintf( + '/api/connection-types/%s', + $this->connectonTypeIds[0] + ), $connectionTypeData); $response->assertStatus(200); $this->assertEquals($response['data']['name'], $connectionTypeData['name']); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); @@ -70,8 +70,7 @@ public function actingAs($user, $driver = null) return $this; } - protected function createTestData($connectionTypeCount = 1) - { + protected function createTestData($connectionTypeCount = 1) { $this->user = UserFactory::new()->create(); $this->company = CompanyFactory::new()->create(); $this->companyDatabase = CompanyDatabaseFactory::new()->create(); diff --git a/src/backend/tests/Feature/CreateEnvironments.php b/src/backend/tests/Feature/CreateEnvironments.php index b94d88cd0..33f380694 100644 --- a/src/backend/tests/Feature/CreateEnvironments.php +++ b/src/backend/tests/Feature/CreateEnvironments.php @@ -44,86 +44,145 @@ use Inensus\Ticket\Services\TicketUserService; use Tests\RefreshMultipleDatabases; -trait CreateEnvironments -{ +trait CreateEnvironments { use RefreshMultipleDatabases; use WithFaker; private $user; + private $company; + private $city; + private $cluster; + private $miniGrid; + private $connectionType; + private $manufacturer; + private $meterType; + private $meter; + private $meterParameter; + private $meterTariff; + private $person; + private $token; + private $transaction; + private $connectionGroup; + private $connectonType; + private $subConnectionType; + private $target; + private $subTarget; + private $agent; + private $agentCommission; + private $address; + private $timeOfUsage; + private $companyDatabase; + private $meterToken; + private $paymentHistory; + private $assetType; + private $assignedAppliance; + private $soldAppliance; + private $agentReceipt; + private $agentTransaction; + private $agentBalanceHistory; + private $ticketCategory; + private $ticketUser; + private $ticketBoard; + private $ticketCard; + private $ticket; private $clusters = []; + private $miniGrids = []; + private $connectionGroups = []; + private $connectonTypes = []; + private $subConnectionTypes = []; + private $meterTypes = []; + private $manufacturers = []; + private $cities = []; + private $meterTariffs = []; + private $targets = []; + private $subTargets = []; + private $people = []; + private $assignedAppliances = []; + private $addresses = []; + private $agents = []; + private $agentCommissions = []; + private $transactions = []; + private $paymentHistories = []; + private $meters = []; + private $assetTypes = []; + private $soldAppliances = []; + private $agentReceipts = []; + private $agentTransactions = []; + private $agentBalanceHistories = []; + private $ticketCategories = []; + private $ticketUsers = []; + private $tickets = []; - protected function createTestData() - { + protected function createTestData() { $this->user = UserFactory::new()->create(); $this->company = CompanyFactory::new()->create(); $this->companyDatabase = CompanyDatabaseFactory::new()->create(); } - protected function createCluster($clusterCount = 1) - { + protected function createCluster($clusterCount = 1) { while ($clusterCount > 0) { $cluster = ClusterFactory::new()->create([ 'name' => $this->faker->unique()->companySuffix, @@ -138,8 +197,7 @@ protected function createCluster($clusterCount = 1) } } - protected function createMiniGrid($miniGridCount = 1) - { + protected function createMiniGrid($miniGridCount = 1) { while ($miniGridCount > 0) { $miniGrid = MiniGridFactory::new()->create([ 'cluster_id' => $this->getRandomIdFromList($this->clusters), @@ -154,8 +212,7 @@ protected function createMiniGrid($miniGridCount = 1) } } - protected function createCity($cityCount = 1) - { + protected function createCity($cityCount = 1) { while ($cityCount > 0) { $city = CityFactory::new()->create([ 'name' => $this->faker->unique()->citySuffix, @@ -172,8 +229,7 @@ protected function createCity($cityCount = 1) } } - protected function getMeter(): mixed - { + protected function getMeter(): mixed { $this->createTestData(); $meter = MeterFactory::new()->create([ 'meter_type_id' => $this->meterType->id, @@ -194,8 +250,7 @@ protected function getMeter(): mixed return $meter; } - protected function createMeterWithGeo(): void - { + protected function createMeterWithGeo(): void { $this->createTestData(); $meterCunt = 2; while ($meterCunt > 0) { @@ -234,8 +289,7 @@ protected function createMeterWithGeo(): void } } - protected function createMeterWithTransaction() - { + protected function createMeterWithTransaction() { $meter = $this->getMeter(); $this->transaction = TransactionFactory::new()->create([ 'id' => 1, @@ -264,8 +318,7 @@ protected function createMeterWithTransaction() return $meter; } - protected function createMetersWithDifferentMeterTypes($meterCountPerMeterType = 1): void - { + protected function createMetersWithDifferentMeterTypes($meterCountPerMeterType = 1): void { $meterTypeCount = count($this->meterTypes); while ($meterTypeCount > 0) { @@ -291,8 +344,7 @@ protected function createMetersWithDifferentMeterTypes($meterCountPerMeterType = } } - protected function createMeterManufacturer($manufacturerCount = 1): void - { + protected function createMeterManufacturer($manufacturerCount = 1): void { while ($manufacturerCount > 0) { $manufacturer = ManufacturerFactory::new()->create(); $address = Address::query()->make([ @@ -313,8 +365,7 @@ protected function createMeterManufacturer($manufacturerCount = 1): void } } - protected function createMeterTariff($meterTariffCount = 1, $withTimeOfUsage = false): void - { + protected function createMeterTariff($meterTariffCount = 1, $withTimeOfUsage = false): void { while ($meterTariffCount > 0) { $meterTariff = MeterTariffFactory::new()->create(); $this->meterTariffs[] = $meterTariff; @@ -335,8 +386,7 @@ protected function createMeterTariff($meterTariffCount = 1, $withTimeOfUsage = f } } - protected function createConnectionType($connectionTypeCount = 1, $subConnectionTypeCount = 1): void - { + protected function createConnectionType($connectionTypeCount = 1, $subConnectionTypeCount = 1): void { while ($connectionTypeCount > 0) { $connectionType = ConnectionTypeFactory::new()->create(); $this->connectonTypes[] = $connectionType; @@ -361,8 +411,7 @@ protected function createConnectionType($connectionTypeCount = 1, $subConnection } } - protected function createConnectionGroup($connectionGroupCount = 1): void - { + protected function createConnectionGroup($connectionGroupCount = 1): void { while ($connectionGroupCount > 0) { $connectionGroup = ConnectionGroupFactory::new()->create(); $this->connectionGroups[] = $connectionGroup; @@ -373,8 +422,7 @@ protected function createConnectionGroup($connectionGroupCount = 1): void } } - protected function createMeterType($meterTypeCount = 1): void - { + protected function createMeterType($meterTypeCount = 1): void { while ($meterTypeCount > 0) { $meterType = MeterTypeFactory::new()->create(); $this->meterTypes[] = $meterType; @@ -387,8 +435,7 @@ protected function createMeterType($meterTypeCount = 1): void } } - protected function createMeter($meterCount = 1): void - { + protected function createMeter($meterCount = 1): void { while ($meterCount > 0) { $meter = MeterFactory::new()->create([ 'meter_type_id' => $this->meterType->id, @@ -425,8 +472,7 @@ protected function createMeter($meterCount = 1): void } } - protected function createTarget($targetCount = 1): void - { + protected function createTarget($targetCount = 1): void { while ($targetCount > 0) { $target = TargetFactory::new()->create(); $this->targets[] = $target; @@ -437,8 +483,7 @@ protected function createTarget($targetCount = 1): void } } - protected function createSubTarget($subTargetCount = 1): void - { + protected function createSubTarget($subTargetCount = 1): void { while ($subTargetCount > 0) { $subTarget = SubTargetFactory::new()->create([ 'target_id' => $this->getRandomIdFromList($this->targets), @@ -452,8 +497,7 @@ protected function createSubTarget($subTargetCount = 1): void } } - protected function createPerson($personCount = 1, $isCustomer = 1) - { + protected function createPerson($personCount = 1, $isCustomer = 1) { while ($personCount > 0) { $person = PersonFactory::new()->create(['is_customer' => $isCustomer]); $this->people[] = $person; @@ -475,8 +519,7 @@ protected function createPerson($personCount = 1, $isCustomer = 1) } } - protected function createAgent($agentCount = 1) - { + protected function createAgent($agentCount = 1) { $this->createPerson($agentCount, 0); foreach ($this->people as $person) { @@ -494,8 +537,7 @@ protected function createAgent($agentCount = 1) } } - protected function createAgentCommission($agentCommissionCount = 1) - { + protected function createAgentCommission($agentCommissionCount = 1) { while ($agentCommissionCount > 0) { $agentCommission = AgentCommissionFactory::new()->create(); $this->agentCommissions[] = $agentCommission; @@ -507,8 +549,7 @@ protected function createAgentCommission($agentCommissionCount = 1) } } - protected function createAssetType($assetTypeCount = 1) - { + protected function createAssetType($assetTypeCount = 1) { while ($assetTypeCount > 0) { $assetType = AssetTypeFactory::new()->create(); $this->assetTypes[] = $assetType; @@ -520,8 +561,7 @@ protected function createAssetType($assetTypeCount = 1) } } - protected function createAssignedAppliances($applianceCount = 1) - { + protected function createAssignedAppliances($applianceCount = 1) { $this->createAssetType($applianceCount); while ($applianceCount > 0) { $assignedAppliance = AgentAssignedApplianceFactory::new()->create([ @@ -539,8 +579,7 @@ protected function createAssignedAppliances($applianceCount = 1) } } - protected function createAgentSoldAppliance($soldApplianceCount = 1) - { + protected function createAgentSoldAppliance($soldApplianceCount = 1) { while ($soldApplianceCount > 0) { $assignedApplianceId = $this->getRandomIdFromList($this->assignedAppliances); $assignedAppliance = collect($this->assignedAppliances)->where('id', $assignedApplianceId)->first(); @@ -569,8 +608,7 @@ protected function createAgentSoldAppliance($soldApplianceCount = 1) } } - protected function createAgentReceipt($agentReceiptCount = 1, $amount = 50) - { + protected function createAgentReceipt($agentReceiptCount = 1, $amount = 50) { while ($agentReceiptCount > 0) { $agentReceipt = AgentReceiptFactory::new()->create([ 'user_id' => 1, @@ -587,8 +625,7 @@ protected function createAgentReceipt($agentReceiptCount = 1, $amount = 50) } } - protected function createAgentBalanceHistory($agentBalanceHistoryCount = 1) - { + protected function createAgentBalanceHistory($agentBalanceHistoryCount = 1) { while ($agentBalanceHistoryCount > 0) { $agentBalanceHistory = AgentBalanceHistoryFactory::new()->create([ 'agent_id' => $this->getRandomIdFromList($this->agents), @@ -608,8 +645,7 @@ protected function createAgentBalanceHistory($agentBalanceHistoryCount = 1) } } - protected function createAgentTransaction($agentTransactionCount = 1, $amount = 100, $agentId = null) - { + protected function createAgentTransaction($agentTransactionCount = 1, $amount = 100, $agentId = null) { while ($agentTransactionCount > 0) { $meter = $this->getMeter(); @@ -688,8 +724,7 @@ protected function createAgentTransaction($agentTransactionCount = 1, $amount = } } - protected function createPaymentHistory($paymentHistoryCount = 1, $amount = 100, $agentId = null) - { + protected function createPaymentHistory($paymentHistoryCount = 1, $amount = 100, $agentId = null) { while ($paymentHistoryCount > 0) { $paymentHistory = PaymentHistoryFactory::new()->make([ 'id' => 1, @@ -730,8 +765,7 @@ protected function createPaymentHistory($paymentHistoryCount = 1, $amount = 100, } } - protected function createTicketCategory($ticketCategoryCount = 1) - { + protected function createTicketCategory($ticketCategoryCount = 1) { while ($ticketCategoryCount > 0) { $ticketCategory = TicketCategoryFactory::new()->create(); $this->ticketCategories[] = $ticketCategory; @@ -743,8 +777,7 @@ protected function createTicketCategory($ticketCategoryCount = 1) } } - protected function createTicket($ticketCount = 1, $status = 0, $customerId = null, $agentId = null) - { + protected function createTicket($ticketCount = 1, $status = 0, $customerId = null, $agentId = null) { while ($ticketCount > 0) { $trelloParams = [ 'idList' => $this->ticketCard->card_id, @@ -776,24 +809,20 @@ protected function createTicket($ticketCount = 1, $status = 0, $customerId = nul } } - protected function createTicketBoard() - { + protected function createTicketBoard() { $this->ticketBoard = TicketBoardFactory::new()->create(); } - protected function createTicketCard() - { + protected function createTicketCard() { $this->ticketCard = TicketCardFactory::new()->create(); } - protected function createTicketOutsourceReport($ticketOutSourceReportCount = 1) - { + protected function createTicketOutsourceReport($ticketOutSourceReportCount = 1) { while ($ticketOutSourceReportCount > 0) { } } - protected function createTicketUser($ticketUserCount = 1, $tag = 'inensusinensus') - { + protected function createTicketUser($ticketUserCount = 1, $tag = 'inensusinensus') { $ticketUserService = app()->make(TicketUserService::class); $externalUser = $ticketUserService->getByTag($tag); @@ -813,8 +842,7 @@ protected function createTicketUser($ticketUserCount = 1, $tag = 'inensusinensus } } - private function getRandomIdFromList(array $list, $startIndex = 1, $endIndex = null): int - { + private function getRandomIdFromList(array $list, $startIndex = 1, $endIndex = null): int { $ids = collect($list)->pluck('id')->toArray(); if ($endIndex === null) { diff --git a/src/backend/tests/Feature/EnergyTransactionProcessorTest.php b/src/backend/tests/Feature/EnergyTransactionProcessorTest.php index 3ca435eec..8622de553 100644 --- a/src/backend/tests/Feature/EnergyTransactionProcessorTest.php +++ b/src/backend/tests/Feature/EnergyTransactionProcessorTest.php @@ -21,13 +21,11 @@ use Illuminate\Support\Facades\Queue; use Tests\TestCase; -class EnergyTransactionProcessorTest extends TestCase -{ +class EnergyTransactionProcessorTest extends TestCase { use RefreshDatabase; use WithFaker; - public function testWithValidData() - { + public function testWithValidData() { Queue::fake(); PersonFactory::new()->create(); MeterTariffFactory::new()->create(); diff --git a/src/backend/tests/Feature/ManufacturerTest.php b/src/backend/tests/Feature/ManufacturerTest.php index 602ffdbe6..7f4c826b8 100644 --- a/src/backend/tests/Feature/ManufacturerTest.php +++ b/src/backend/tests/Feature/ManufacturerTest.php @@ -5,12 +5,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class ManufacturerTest extends TestCase -{ +class ManufacturerTest extends TestCase { use CreateEnvironments; - public function testUserGetsManufacturerList() - { + public function testUserGetsManufacturerList() { $this->createTestData(); $manufacturerCount = 4; $this->createMeterManufacturer($manufacturerCount); @@ -19,8 +17,7 @@ public function testUserGetsManufacturerList() $this->assertEquals(count($response['data']), count($this->manufacturers)); } - public function testUserGetsManufacturerById() - { + public function testUserGetsManufacturerById() { $this->createTestData(); $this->createMeterManufacturer(); $response = $this->actingAs($this->user)->get(sprintf('/api/manufacturers/%s', $this->manufacturers[0]->id)); @@ -28,8 +25,7 @@ public function testUserGetsManufacturerById() $this->assertEquals($response['data']['id'], $this->manufacturers[0]->id); } - public function testUserCreatesNewManufacturer() - { + public function testUserCreatesNewManufacturer() { $this->createTestData(); $this->createCity(); $manufacturerData = [ @@ -45,8 +41,7 @@ public function testUserCreatesNewManufacturer() $this->assertEquals($response['data']['name'], $manufacturerData['name']); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/MeterParameterTest.php b/src/backend/tests/Feature/MeterParameterTest.php index a31b9530e..8f79eaa84 100644 --- a/src/backend/tests/Feature/MeterParameterTest.php +++ b/src/backend/tests/Feature/MeterParameterTest.php @@ -20,13 +20,11 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class MeterParameterTest extends TestCase -{ +class MeterParameterTest extends TestCase { use RefreshMultipleDatabases; use WithFaker; - public function testUserAssignsAMeterParameterToAMeter() - { + public function testUserAssignsAMeterParameterToAMeter() { $this->withExceptionHandling(); $user = UserFactory::new()->create(); $city = CityFactory::new()->create(); @@ -62,8 +60,7 @@ public function testUserAssignsAMeterParameterToAMeter() $this->assertEquals($geographicalInformation->points, $meterParameterData['geo_points']); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/MeterTariffTest.php b/src/backend/tests/Feature/MeterTariffTest.php index 43913f13d..4f73fc280 100644 --- a/src/backend/tests/Feature/MeterTariffTest.php +++ b/src/backend/tests/Feature/MeterTariffTest.php @@ -11,12 +11,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class MeterTariffTest extends TestCase -{ +class MeterTariffTest extends TestCase { use CreateEnvironments; - public function testUserGetsMeterTariffList() - { + public function testUserGetsMeterTariffList() { $this->createTestData(); $meterTariffCount = 5; $this->createMeterTariff($meterTariffCount); @@ -25,8 +23,7 @@ public function testUserGetsMeterTariffList() $this->assertEquals(count($response['data']), count($this->meterTariffs)); } - public function testUserGetsMeterTariffById() - { + public function testUserGetsMeterTariffById() { $this->createTestData(); $this->createMeterTariff(); $response = $this->actingAs($this->user)->get(sprintf('/api/tariffs/%s', $this->meterTariffs[0]->id)); @@ -34,8 +31,7 @@ public function testUserGetsMeterTariffById() $this->assertEquals($response['data']['id'], $this->meterTariffs[0]->id); } - public function testUserUpdatesAMeterTariff() - { + public function testUserUpdatesAMeterTariff() { Queue::fake(); $this->createTestData(); $this->createMeterTariff(); @@ -69,8 +65,10 @@ public function testUserUpdatesAMeterTariff() 'access_rate_amount' => 100, ], ]; - $response = $this->actingAs($this->user)->put(sprintf('/api/tariffs/%s', - $this->meterTariffs[0]->id), $tariffData); + $response = $this->actingAs($this->user)->put(sprintf( + '/api/tariffs/%s', + $this->meterTariffs[0]->id + ), $tariffData); $response->assertStatus(200); $this->assertEquals($response['data']['name'], $tariffData['name']); $this->assertEquals($this->meterTariffs[0]->id, SocialTariff::query()->first()->tariff_id); @@ -78,8 +76,7 @@ public function testUserUpdatesAMeterTariff() $this->assertEquals($this->meterTariffs[0]->id, AccessRate::query()->first()->tariff_id); } - public function testUserCreatesBasicTariff(): void - { + public function testUserCreatesBasicTariff(): void { $this->createTestData(); $tariffData = [ 'name' => 'Tariff', @@ -93,8 +90,7 @@ public function testUserCreatesBasicTariff(): void $this->assertEquals(10000, MeterTariff::first()->total_price); } - public function testUserCreatesTariffWithPriceComponents(): void - { + public function testUserCreatesTariffWithPriceComponents(): void { Queue::fake(); $this->createTestData(); $tariffData = [ @@ -114,8 +110,7 @@ public function testUserCreatesTariffWithPriceComponents(): void $this->assertCount(1, MeterTariff::all()); } - public function testUserCreatesTariffWithSocialInputs(): void - { + public function testUserCreatesTariffWithSocialInputs(): void { $this->createTestData(); $tariffData = [ 'name' => 'Tariff', @@ -135,8 +130,7 @@ public function testUserCreatesTariffWithSocialInputs(): void $this->assertEquals(MeterTariff::query()->first()->id, SocialTariff::query()->first()->tariff_id); } - public function testUserCreatesTariffWithTimeOfUsages(): void - { + public function testUserCreatesTariffWithTimeOfUsages(): void { $this->createTestData(); $tariffData = [ 'name' => 'Test Tariff', @@ -164,8 +158,7 @@ public function testUserCreatesTariffWithTimeOfUsages(): void $this->assertEquals(MeterTariff::query()->first()->id, TimeOfUsage::query()->first()->tariff_id); } - public function testUserCreatesTariffWithAccessRate(): void - { + public function testUserCreatesTariffWithAccessRate(): void { $this->createTestData(); $tariffData = [ 'name' => 'Test Tariff', @@ -183,8 +176,7 @@ public function testUserCreatesTariffWithAccessRate(): void $this->assertEquals(MeterTariff::query()->first()->id, AccessRate::query()->first()->tariff_id); } - public function testUserGetsMeterListForATariff(): void - { + public function testUserGetsMeterListForATariff(): void { $this->createTestData(); $this->createMeterManufacturer(); $this->createMeterType(); @@ -193,16 +185,17 @@ public function testUserGetsMeterListForATariff(): void $this->createConnectionType(); $meterCount = 5; $this->createMeter($meterCount); - $response = $this->actingAs($this->user)->get(sprintf('/api/tariffs/%s/usage-count', - $this->meterTariffs[0]->id)); + $response = $this->actingAs($this->user)->get(sprintf( + '/api/tariffs/%s/usage-count', + $this->meterTariffs[0]->id + )); $response->assertStatus(200); $this->assertEquals($response['data']['count'], $meterCount); } - public function testComponentPriceChangesTotalPrice(): void - { + public function testComponentPriceChangesTotalPrice(): void { $this->createTestData(); $this->createMeterTariff(); $tariff = $this->meterTariff; @@ -220,8 +213,7 @@ public function testComponentPriceChangesTotalPrice(): void $this->assertEquals($tariffPrice + 200000, $updatedTariff->total_price); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/MeterTest.php b/src/backend/tests/Feature/MeterTest.php index 8bd4ab7e9..556141ef2 100644 --- a/src/backend/tests/Feature/MeterTest.php +++ b/src/backend/tests/Feature/MeterTest.php @@ -26,26 +26,35 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class MeterTest extends TestCase -{ +class MeterTest extends TestCase { use RefreshMultipleDatabases; use WithFaker; private $user; + private $company; + private $city; + private $connectionType; + private $manufacturer; + private $meterType; + private $meter; + private $meterParameter; + private $meterTariff; + private $person; + private $token; + private $transaction; - public function testUserGetsMeterList() - { + public function testUserGetsMeterList() { $this->createTestData(); $meterCunt = 5; while ($meterCunt > 0) { @@ -71,8 +80,7 @@ public function testUserGetsMeterList() $this->assertEquals(5, count($response['data'])); } - public function testUserCreatesAMeter() - { + public function testUserCreatesAMeter() { $this->createTestData(); $meterData = [ 'serial_number' => '123456789', @@ -86,33 +94,31 @@ public function testUserCreatesAMeter() $this->assertEquals($meter->serial_number, $meterData['serial_number']); } - public function testUserGetsMeterBySerialNumber() - { + public function testUserGetsMeterBySerialNumber() { $meter = $this->getMeter(); $response = $this->actingAs($this->user)->get(sprintf('/api/meters/%s', $meter->serial_number)); $response->assertStatus(200); $this->assertEquals($meter->serial_number, $response['data']['serial_number']); } - public function testUserSearchesMetersBySerialNumber() - { + public function testUserSearchesMetersBySerialNumber() { $meter = $this->getMeter(); $response = $this->actingAs($this->user)->get(sprintf('/api/meters/search?term=%s', $meter->serial_number)); $response->assertStatus(200); $this->assertEquals($response['data'][0]['id'], $meter->id); } - public function testUserSearchesMeterByTariffName() - { + public function testUserSearchesMeterByTariffName() { $meter = $this->getMeter(); - $response = $this->actingAs($this->user)->get(sprintf('/api/meters/search?term=%s', - $this->meterTariff->name)); + $response = $this->actingAs($this->user)->get(sprintf( + '/api/meters/search?term=%s', + $this->meterTariff->name + )); $response->assertStatus(200); $this->assertEquals($response['data'][0]['id'], $meter->id); } - public function testUserUpdatesMetersGeolocation() - { + public function testUserUpdatesMetersGeolocation() { $this->createMeterWithGeo(); $meterData = [ ['lat' => '444', 'lng' => '555', 'id' => 1], @@ -122,63 +128,68 @@ public function testUserUpdatesMetersGeolocation() $response->assertStatus(200); } - public function testUserGetsPersonMeters() - { + public function testUserGetsPersonMeters() { $meter = $this->getMeter(); - $response = $this->actingAs($this->user)->get(sprintf('/api/people/%s/meters', - $this->person->id)); + $response = $this->actingAs($this->user)->get(sprintf( + '/api/people/%s/meters', + $this->person->id + )); $response->assertStatus(200); $metersCount = Meter::query()->get()->count(); $this->assertEquals(count($response['data']['meters']), $metersCount); } - public function testUserGetsPersonMetersGeographicalInformation() - { + public function testUserGetsPersonMetersGeographicalInformation() { $this->createMeterWithGeo(); - $response = $this->actingAs($this->user)->get(sprintf('/api/people/%s/meters/geo', - $this->person->id)); + $response = $this->actingAs($this->user)->get(sprintf( + '/api/people/%s/meters/geo', + $this->person->id + )); $response->assertStatus(200); } - public function testUserGetsMetersTransactions() - { + public function testUserGetsMetersTransactions() { $meter = $this->createMeterWithTransaction(); - $response = $this->actingAs($this->user)->get(sprintf('/api/meters/%s/transactions', - $meter->serial_number)); + $response = $this->actingAs($this->user)->get(sprintf( + '/api/meters/%s/transactions', + $meter->serial_number + )); $response->assertStatus(200); $this->assertEquals($response['data'][0]['amount'], $this->transaction->amount); $this->assertEquals($response['data'][0]['id'], $this->transaction->id); } - public function testUserGetsMeterRevenueBySerialNumber() - { + public function testUserGetsMeterRevenueBySerialNumber() { $meter = $this->createMeterWithTransaction(); - $response = $this->actingAs($this->user)->get(sprintf('/api/meters/%s/revenue', - $meter->serial_number)); + $response = $this->actingAs($this->user)->get(sprintf( + '/api/meters/%s/revenue', + $meter->serial_number + )); $response->assertStatus(200); $this->assertEquals($response['data']['revenue'], $this->transaction->amount); } - public function testUserGetsMeterConsumptions() - { + public function testUserGetsMeterConsumptions() { $meter = $this->createMeterWithTransaction(); $consumption = MeterConsumptionFactory::new()->create(); - $response = $this->actingAs($this->user)->get(sprintf('/api/meters/%s/consumptions/%s/%s', - $meter->serial_number, Carbon::now()->subDays(3)->format('Y-m-d'), Carbon::now()->format('Y-m-d'))); + $response = $this->actingAs($this->user)->get(sprintf( + '/api/meters/%s/consumptions/%s/%s', + $meter->serial_number, + Carbon::now()->subDays(3)->format('Y-m-d'), + Carbon::now()->format('Y-m-d') + )); $response->assertStatus(200); $this->assertEquals($response['data'][0]['consumption'], $consumption->consumption); $this->assertEquals($response['data'][0]['meter_id'], $meter->id); } - public function testUserDeletesAMeter() - { + public function testUserDeletesAMeter() { $meter = $this->getMeter(); $response = $this->actingAs($this->user)->delete(sprintf('/api/meters/%s', $meter->id)); $response->assertStatus(204); } - protected function createTestData() - { + protected function createTestData() { $this->user = UserFactory::new()->create(); $this->city = CityFactory::new()->create(); $this->company = CompanyFactory::new()->create(); @@ -191,8 +202,7 @@ protected function createTestData() $this->person = PersonFactory::new()->create(); } - protected function getMeter(): mixed - { + protected function getMeter(): mixed { $this->createTestData(); $meter = MeterFactory::new()->create([ 'meter_type_id' => $this->meterType->id, @@ -213,8 +223,7 @@ protected function getMeter(): mixed return $meter; } - protected function createMeterWithGeo(): void - { + protected function createMeterWithGeo(): void { $this->createTestData(); $meterCunt = 2; while ($meterCunt > 0) { @@ -253,8 +262,7 @@ protected function createMeterWithGeo(): void } } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); @@ -262,8 +270,7 @@ public function actingAs($user, $driver = null) return $this; } - protected function createMeterWithTransaction() - { + protected function createMeterWithTransaction() { $meter = $this->getMeter(); $this->transaction = TransactionFactory::new()->create([ 'id' => 1, diff --git a/src/backend/tests/Feature/MeterTypeTest.php b/src/backend/tests/Feature/MeterTypeTest.php index a0dab9c82..7667c9836 100644 --- a/src/backend/tests/Feature/MeterTypeTest.php +++ b/src/backend/tests/Feature/MeterTypeTest.php @@ -5,12 +5,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class MeterTypeTest extends TestCase -{ +class MeterTypeTest extends TestCase { use CreateEnvironments; - public function testUserGetsMeterTypeList() - { + public function testUserGetsMeterTypeList() { $connectionTypeCount = 1; $subConnectionTypeCount = 1; $meterTypeCount = 5; @@ -24,8 +22,7 @@ public function testUserGetsMeterTypeList() $this->assertEquals(count($response['data']), count($this->meterTypes)); } - public function testUserGetsMeterTypeById() - { + public function testUserGetsMeterTypeById() { $connectionTypeCount = 1; $subConnectionTypeCount = 1; $meterTypeCount = 5; @@ -40,8 +37,7 @@ public function testUserGetsMeterTypeById() $this->assertEquals($response['data']['phase'], $this->meterTypes[0]->phase); } - public function testUserCreatesNewMeterType() - { + public function testUserCreatesNewMeterType() { $connectionTypeCount = 0; $subConnectionTypeCount = 0; $meterTypeCount = 0; @@ -61,8 +57,7 @@ public function testUserCreatesNewMeterType() $this->assertEquals($response['data']['phase'], $meterTypeData['phase']); } - public function testUserUpdatesAMeterType() - { + public function testUserUpdatesAMeterType() { $meterTypeCount = 1; $meterTariffCount = 1; $this->createTestData(); @@ -72,15 +67,16 @@ public function testUserUpdatesAMeterType() 'phase' => 3, 'max_current' => 15, ]; - $response = $this->actingAs($this->user)->put(sprintf('/api/meter-types/%s', - $this->meterTypes[0]->id), $meterTypeData); + $response = $this->actingAs($this->user)->put(sprintf( + '/api/meter-types/%s', + $this->meterTypes[0]->id + ), $meterTypeData); $response->assertStatus(200); $this->assertEquals($response['data']['max_current'], $meterTypeData['max_current']); $this->assertEquals($response['data']['phase'], $meterTypeData['phase']); } - public function testUserGetsMeterTypesWithMeterRelationByMeterTypeId() - { + public function testUserGetsMeterTypesWithMeterRelationByMeterTypeId() { $connectionTypeCount = 2; $this->createTestData(); $this->createMeterTariff(); @@ -90,14 +86,15 @@ public function testUserGetsMeterTypesWithMeterRelationByMeterTypeId() $this->createMeterManufacturer(); $this->createPerson(); $this->createMetersWithDifferentMeterTypes(); - $response = $this->actingAs($this->user)->get(sprintf('/api/meter-types/%s/list', - $this->meterTypes[0]->id)); + $response = $this->actingAs($this->user)->get(sprintf( + '/api/meter-types/%s/list', + $this->meterTypes[0]->id + )); $response->assertStatus(200); $this->assertEquals(count($response['data']['meters']), 1); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/MiniGridRevenueTest.php b/src/backend/tests/Feature/MiniGridRevenueTest.php index d21e3b296..047332e72 100644 --- a/src/backend/tests/Feature/MiniGridRevenueTest.php +++ b/src/backend/tests/Feature/MiniGridRevenueTest.php @@ -29,29 +29,41 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class MiniGridRevenueTest extends TestCase -{ +class MiniGridRevenueTest extends TestCase { use RefreshMultipleDatabases; use WithFaker; private $user; + private $company; + private $city; + private $connectionType; + private $manufacturer; + private $meterType; + private $meter; + private $meterParameter; + private $meterTariff; + private $person; + private $token; + private $transaction; + private $clusterIds = []; + private $miniGridIds = []; + private $soldEnergy; - public function testUserGetsSoldEnergyOfAMiniGridWithDefaultPeriod() - { + public function testUserGetsSoldEnergyOfAMiniGridWithDefaultPeriod() { $clusterCount = 1; $meterCount = 2; $transactionCount = 1; @@ -63,8 +75,7 @@ public function testUserGetsSoldEnergyOfAMiniGridWithDefaultPeriod() $this->assertEquals($soldEnergy, round($this->soldEnergy, 3)); } - public function testUserGetsSoldEnergyOfAMiniGridWithPeriod() - { + public function testUserGetsSoldEnergyOfAMiniGridWithPeriod() { $clusterCount = 1; $meterCount = 2; $transactionCount = 1; @@ -80,8 +91,7 @@ public function testUserGetsSoldEnergyOfAMiniGridWithPeriod() $this->assertEquals($soldEnergy, round($this->soldEnergy, 3)); } - public function testUserGetsTransactionRevenuesOfAMiniGridWithDefaultPeriod() - { + public function testUserGetsTransactionRevenuesOfAMiniGridWithDefaultPeriod() { $this->withExceptionHandling(); $clusterCount = 1; $meterCount = 2; @@ -94,8 +104,7 @@ public function testUserGetsTransactionRevenuesOfAMiniGridWithDefaultPeriod() $this->assertEquals($revenue, $this->getTotalTransactionAmount()); } - public function testUserGetsTransactionRevenuesOfAMiniGridWithPeriod() - { + public function testUserGetsTransactionRevenuesOfAMiniGridWithPeriod() { $clusterCount = 1; $meterCount = 2; $transactionCount = 1; @@ -112,8 +121,7 @@ public function testUserGetsTransactionRevenuesOfAMiniGridWithPeriod() $this->assertEquals($revenue, $this->getTotalTransactionAmount()); } - protected function getTotalTransactionAmount() - { + protected function getTotalTransactionAmount() { $clusterIds = $this->clusterIds; return Transaction::query() @@ -146,8 +154,7 @@ static function ($q) { )->get()->pluck('amount')->sum(); } - protected function createTestData($clusterCount = 1, $meterCount = 1, $transactionCount = 1) - { + protected function createTestData($clusterCount = 1, $meterCount = 1, $transactionCount = 1) { $this->user = UserFactory::new()->create(); $this->city = CityFactory::new()->create(); $this->company = CompanyFactory::new()->create(); @@ -271,8 +278,7 @@ protected function createTestData($clusterCount = 1, $meterCount = 1, $transacti } } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); @@ -280,8 +286,7 @@ public function actingAs($user, $driver = null) return $this; } - protected function generateUniqueNumber(): int - { + protected function generateUniqueNumber(): int { return $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber(); diff --git a/src/backend/tests/Feature/MiniGridTest.php b/src/backend/tests/Feature/MiniGridTest.php index 425d5489d..096e0b126 100644 --- a/src/backend/tests/Feature/MiniGridTest.php +++ b/src/backend/tests/Feature/MiniGridTest.php @@ -15,20 +15,23 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class MiniGridTest extends TestCase -{ +class MiniGridTest extends TestCase { use RefreshMultipleDatabases; use WithFaker; private $user; + private $company; + private $companyDatabase; + private $person; + private $clusterIds = []; + private $miniGridIds = []; - public function testUserGetsMiniGridList() - { + public function testUserGetsMiniGridList() { $clusterCount = 1; $miniGridCount = 2; $this->createTestData($clusterCount, $miniGridCount); @@ -37,8 +40,7 @@ public function testUserGetsMiniGridList() $this->assertEquals(count($response['data']), count($this->miniGridIds)); } - public function testUserGetsMiniGridById() - { + public function testUserGetsMiniGridById() { $clusterCount = 1; $miniGridCount = 2; $this->createTestData($clusterCount, $miniGridCount); @@ -47,8 +49,7 @@ public function testUserGetsMiniGridById() $this->assertEquals($response['data']['id'], $this->miniGridIds[0]); } - public function testUserGetsMiniGridByIdWithGeographicalInformation() - { + public function testUserGetsMiniGridByIdWithGeographicalInformation() { $clusterCount = 1; $miniGridCount = 2; $this->createTestData($clusterCount, $miniGridCount); @@ -57,8 +58,7 @@ public function testUserGetsMiniGridByIdWithGeographicalInformation() $this->assertEquals(array_key_exists('location', $response['data']), true); } - public function testUserCreatesNewMiniGrid() - { + public function testUserCreatesNewMiniGrid() { $clusterCount = 1; $miniGridCount = 0; $this->createTestData($clusterCount, $miniGridCount); @@ -76,8 +76,7 @@ public function testUserCreatesNewMiniGrid() $this->assertEquals(count(MiniGrid::query()->get()), 1); } - public function testUserUpdatesAMiniGrid() - { + public function testUserUpdatesAMiniGrid() { $clusterCount = 1; $miniGridCount = 1; $this->createTestData($clusterCount, $miniGridCount); @@ -90,8 +89,7 @@ public function testUserUpdatesAMiniGrid() $this->assertEquals($response['data']['name'], $miGridData['name']); } - protected function createTestData($clusterCount = 1, $miniGridCount = 1) - { + protected function createTestData($clusterCount = 1, $miniGridCount = 1) { $this->user = UserFactory::new()->create(); $this->company = CompanyFactory::new()->create(); $this->companyDatabase = CompanyDatabaseFactory::new()->create(); @@ -125,8 +123,7 @@ protected function createTestData($clusterCount = 1, $miniGridCount = 1) } } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); @@ -134,8 +131,7 @@ public function actingAs($user, $driver = null) return $this; } - protected function generateUniqueNumber(): int - { + protected function generateUniqueNumber(): int { return $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber() + $this->faker->unique()->randomNumber(); } diff --git a/src/backend/tests/Feature/PersonTest.php b/src/backend/tests/Feature/PersonTest.php index 27cf4f480..46e4a3dcb 100644 --- a/src/backend/tests/Feature/PersonTest.php +++ b/src/backend/tests/Feature/PersonTest.php @@ -18,13 +18,11 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class PersonTest extends TestCase -{ +class PersonTest extends TestCase { use RefreshMultipleDatabases; use WithFaker; - public function testUserGetsCustomerList() - { + public function testUserGetsCustomerList() { $user = UserFactory::new()->create(); $city = CityFactory::new()->create(); $company = CompanyFactory::new()->create(); @@ -44,8 +42,7 @@ public function testUserGetsCustomerList() $this->assertEquals(2, count($response['data'])); } - public function testUserGetsAllRegisteredPersonList() - { + public function testUserGetsAllRegisteredPersonList() { $user = UserFactory::new()->create(); $city = CityFactory::new()->create(); $company = CompanyFactory::new()->create(); @@ -57,8 +54,7 @@ public function testUserGetsAllRegisteredPersonList() $this->assertEquals(2, count($response['data'])); } - public function testUserGetPersonById() - { + public function testUserGetPersonById() { $user = UserFactory::new()->create(); $city = CityFactory::new()->create(); $company = CompanyFactory::new()->create(); @@ -69,8 +65,7 @@ public function testUserGetPersonById() $this->assertEquals($response['data']['name'], $person->name); } - public function testUserCanCreateNewPersonAsACustomer() - { + public function testUserCanCreateNewPersonAsACustomer() { $this->withExceptionHandling(); $user = UserFactory::new()->create(); $city = CityFactory::new()->create(); @@ -99,8 +94,7 @@ public function testUserCanCreateNewPersonAsACustomer() $this->assertEquals($personAddress->street, $postData['street']); } - public function testUserCanCreateNewPersonAsAMaintenanceUser() - { + public function testUserCanCreateNewPersonAsAMaintenanceUser() { $this->withExceptionHandling(); $user = UserFactory::new()->create(); $city = CityFactory::new()->create(); @@ -132,8 +126,7 @@ public function testUserCanCreateNewPersonAsAMaintenanceUser() $this->assertEquals($maintenanceUser->person->name, $postData['name']); } - public function testUserCanUpdateAPerson() - { + public function testUserCanUpdateAPerson() { $user = UserFactory::new()->create(); $city = CityFactory::new()->create(); $company = CompanyFactory::new()->create(); @@ -154,8 +147,7 @@ public function testUserCanUpdateAPerson() $this->assertEquals($updatedPerson->surname, 'updated surname'); } - public function testUserCanSearchAPersonByName() - { + public function testUserCanSearchAPersonByName() { $user = UserFactory::new()->create(); $city = CityFactory::new()->create(); $company = CompanyFactory::new()->create(); @@ -165,8 +157,7 @@ public function testUserCanSearchAPersonByName() $this->assertEquals($response['data'][0]['id'], $person->id); } - public function testUserCanSearchAPersonByPhoneNumber() - { + public function testUserCanSearchAPersonByPhoneNumber() { $user = UserFactory::new()->create(); $city = CityFactory::new()->create(); $company = CompanyFactory::new()->create(); @@ -180,8 +171,7 @@ public function testUserCanSearchAPersonByPhoneNumber() $this->assertEquals($responseData['addresses'][0]['phone'], $address->phone); } - public function testUserCanGetPersonsTransactions() - { + public function testUserCanGetPersonsTransactions() { $user = UserFactory::new()->create(); $city = CityFactory::new()->create(); $company = CompanyFactory::new()->create(); @@ -206,8 +196,7 @@ public function testUserCanGetPersonsTransactions() $this->assertEquals($transaction->amount, $response['data'][0]['amount']); } - public function testUserCanDeleteAPerson() - { + public function testUserCanDeleteAPerson() { $user = UserFactory::new()->create(); $city = CityFactory::new()->create(); $company = CompanyFactory::new()->create(); @@ -218,8 +207,7 @@ public function testUserCanDeleteAPerson() $this->assertEquals(0, $personListCount); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/SendSmsTest.php b/src/backend/tests/Feature/SendSmsTest.php index d22ee01a7..439a12c67 100644 --- a/src/backend/tests/Feature/SendSmsTest.php +++ b/src/backend/tests/Feature/SendSmsTest.php @@ -23,12 +23,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class SendSmsTest extends TestCase -{ +class SendSmsTest extends TestCase { use RefreshDatabase; - public function testStoreAndSend() - { + public function testStoreAndSend() { Queue::fake(); $this->withoutExceptionHandling(); $person = $this->initializeData(); @@ -40,8 +38,7 @@ public function testStoreAndSend() $this->assertEquals(1, $smsCount); } - private function initializeData() - { + private function initializeData() { $bodies = [ [ 'reference' => 'SmsTransactionHeader', @@ -202,8 +199,7 @@ private function initializeData() return $p; } - private function getData($person, $user): array - { + private function getData($person, $user): array { $data = [ 'person_id' => $person->id, 'message' => 'Its a dummy message', @@ -213,8 +209,7 @@ private function getData($person, $user): array return $data; } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); @@ -222,8 +217,7 @@ public function actingAs($user, $driver = null) return $this; } - public function testStoreSms() - { + public function testStoreSms() { Queue::fake(); $this->withoutExceptionHandling(); $person = $this->initializeData(); diff --git a/src/backend/tests/Feature/SocialTariffPiggyBankTest.php b/src/backend/tests/Feature/SocialTariffPiggyBankTest.php index 92d1d5767..5d5df2c73 100644 --- a/src/backend/tests/Feature/SocialTariffPiggyBankTest.php +++ b/src/backend/tests/Feature/SocialTariffPiggyBankTest.php @@ -17,14 +17,12 @@ use Illuminate\Support\Facades\Queue; use Tests\TestCase; -class SocialTariffPiggyBankTest extends TestCase -{ +class SocialTariffPiggyBankTest extends TestCase { use RefreshDatabase; use WithFaker; /** @test */ - public function testAddPiggyBankBalance() - { + public function testAddPiggyBankBalance() { MeterTariffFactory::new()->create(); MeterTariff::first()->socialTariff()->create([ 'tariff_id' => 1, @@ -59,8 +57,7 @@ public function testAddPiggyBankBalance() } /** @test */ - public function changeTariffAndResetSavings() - { + public function changeTariffAndResetSavings() { Queue::fake(); // create tariff MeterTariffFactory::new()->times(2)->create(); diff --git a/src/backend/tests/Feature/SubConnectionTypeTest.php b/src/backend/tests/Feature/SubConnectionTypeTest.php index b6011130c..feab24ad5 100644 --- a/src/backend/tests/Feature/SubConnectionTypeTest.php +++ b/src/backend/tests/Feature/SubConnectionTypeTest.php @@ -5,12 +5,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class SubConnectionTypeTest extends TestCase -{ +class SubConnectionTypeTest extends TestCase { use CreateEnvironments; - public function testUserGetsSubConnectionTypeList() - { + public function testUserGetsSubConnectionTypeList() { $connectionTypeCount = 1; $subConnectionTypeCount = 1; $meterTariffCount = 1; @@ -22,22 +20,22 @@ public function testUserGetsSubConnectionTypeList() $this->assertEquals(count($response['data']), count($this->subConnectionTypes)); } - public function testUserGetsSubConnectionTypesByConnectionTypeId() - { + public function testUserGetsSubConnectionTypesByConnectionTypeId() { $connectionTypeCount = 2; $subConnectionTypeCount = 1; $meterTariffCount = 1; $this->createTestData(); $this->createMeterTariff($meterTariffCount); $this->createConnectionType($connectionTypeCount, $subConnectionTypeCount); - $response = $this->actingAs($this->user)->get(sprintf('/api/sub-connection-types/%s', - $this->connectonTypes[0]->id)); + $response = $this->actingAs($this->user)->get(sprintf( + '/api/sub-connection-types/%s', + $this->connectonTypes[0]->id + )); $response->assertStatus(200); $this->assertEquals($response['data'][0]['connection_type_id'], $this->connectonTypes[0]->id); } - public function testUserCreatesNewSubConnectionType() - { + public function testUserCreatesNewSubConnectionType() { $connectionTypeCount = 1; $subConnectionTypeCount = 0; $meterTariffCount = 1; @@ -54,8 +52,7 @@ public function testUserCreatesNewSubConnectionType() $this->assertEquals($response['data']['name'], $subConnectionTypeData['name']); } - public function testUserUpdatesASubConnectionType() - { + public function testUserUpdatesASubConnectionType() { $connectionTypeCount = 1; $subConnectionTypeCount = 1; $meterTariffCount = 1; @@ -63,14 +60,15 @@ public function testUserUpdatesASubConnectionType() $this->createMeterTariff($meterTariffCount); $this->createConnectionType($connectionTypeCount, $subConnectionTypeCount); $subConnectionTypeData = ['name' => 'Updated SubConnection Type']; - $response = $this->actingAs($this->user)->put(sprintf('/api/sub-connection-types/%s', - $this->subConnectionTypes[0]->id), $subConnectionTypeData); + $response = $this->actingAs($this->user)->put(sprintf( + '/api/sub-connection-types/%s', + $this->subConnectionTypes[0]->id + ), $subConnectionTypeData); $response->assertStatus(200); $this->assertEquals($response['data']['name'], $subConnectionTypeData['name']); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/TargetTest.php b/src/backend/tests/Feature/TargetTest.php index 9168c0b5f..6860ec424 100644 --- a/src/backend/tests/Feature/TargetTest.php +++ b/src/backend/tests/Feature/TargetTest.php @@ -5,12 +5,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class TargetTest extends TestCase -{ +class TargetTest extends TestCase { use CreateEnvironments; - public function testUserGetsTargetList() - { + public function testUserGetsTargetList() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -23,8 +21,7 @@ public function testUserGetsTargetList() $this->assertEquals(count($response['data']), $targetCount); } - public function testUserGetsTargetById() - { + public function testUserGetsTargetById() { $this->createTestData(); $this->createCluster(); $this->createMiniGrid(); @@ -37,8 +34,7 @@ public function testUserGetsTargetById() $this->assertEquals($response['data']['id'], $this->targets[0]->id); } - public function testUserCreatesNewTarget() - { + public function testUserCreatesNewTarget() { $this->withExceptionHandling(); $this->createTestData(); $this->createCluster(); @@ -69,8 +65,7 @@ public function testUserCreatesNewTarget() $this->assertEquals($response['data']['target_date'], $targetData['period']); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/TicketTest.php b/src/backend/tests/Feature/TicketTest.php index cb29e9386..7f7ed2c32 100644 --- a/src/backend/tests/Feature/TicketTest.php +++ b/src/backend/tests/Feature/TicketTest.php @@ -7,12 +7,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class TicketTest extends TestCase -{ +class TicketTest extends TestCase { use CreateEnvironments; - public function testUserGetsTicketUserList() - { + public function testUserGetsTicketUserList() { $this->createTestData(); $this->createTicketUser(); $response = $this->actingAs($this->user)->get('/tickets/api/users'); @@ -20,8 +18,7 @@ public function testUserGetsTicketUserList() $this->assertEquals(1, count($response['data'])); } - public function testUserCreatesATicketUser() - { + public function testUserCreatesATicketUser() { $this->createTestData(); $postData = [ 'username' => 'test', @@ -34,8 +31,7 @@ public function testUserCreatesATicketUser() $this->assertEquals($ticketUser->user_name, $postData['username']); } - public function testUserCreatesATicket() - { + public function testUserCreatesATicket() { $this->createTestData(); $this->createPerson(); $this->createTicketCategory(); @@ -56,8 +52,7 @@ public function testUserCreatesATicket() $response->assertStatus(200); } - public function testUserGetsTicketList() - { + public function testUserGetsTicketList() { $this->createTestData(); $this->createPerson(); $this->createTicketCategory(); @@ -70,8 +65,7 @@ public function testUserGetsTicketList() $this->assertEquals(1, count($response['data']['data'])); } - public function testUserGetsTicketByTrelloId() - { + public function testUserGetsTicketByTrelloId() { $this->createTestData(); $this->createPerson(); $this->createTicketCategory(); @@ -86,8 +80,7 @@ public function testUserGetsTicketByTrelloId() $this->assertEquals($this->person->id, $response['data']['owner_id']); } - public function testUserClosesATicket() - { + public function testUserClosesATicket() { $this->createTestData(); $this->createPerson(); $this->createTicketCategory(); @@ -102,8 +95,7 @@ public function testUserClosesATicket() $this->assertEquals($trelloId, $response['data']['id']); } - public function testUserGetsAgentsTicketList() - { + public function testUserGetsAgentsTicketList() { $this->createTestData(); $this->createPerson(); $this->createAgentCommission(); @@ -118,8 +110,7 @@ public function testUserGetsAgentsTicketList() $this->assertEquals(1, count($response['data']['data'])); } - public function testUserCreatesATicketCategory() - { + public function testUserCreatesATicketCategory() { $this->createTestData(); $postData = [ 'labelName' => 'test category', @@ -133,8 +124,7 @@ public function testUserCreatesATicketCategory() $this->assertEquals($ticketCategory->label_name, $postData['labelName']); } - public function testUserGetsTicketCategoryList() - { + public function testUserGetsTicketCategoryList() { $this->createTestData(); $ticketCategoryCount = 5; $this->createTicketCategory($ticketCategoryCount); @@ -144,8 +134,7 @@ public function testUserGetsTicketCategoryList() $this->assertEquals($ticketCategoryCount, TicketCategory::query()->count()); } - public function testUserGetsTicketListForACustomer() - { + public function testUserGetsTicketListForACustomer() { $this->createTestData(); $this->createPerson(); $this->createAgentCommission(); @@ -160,8 +149,7 @@ public function testUserGetsTicketListForACustomer() $this->assertEquals(1, count($response['data']['data'])); } - public function testUserAddsCommentToTicketByTrelloId() - { + public function testUserAddsCommentToTicketByTrelloId() { $this->createTestData(); $this->createPerson(); $this->createTicketCategory(); @@ -180,8 +168,7 @@ public function testUserAddsCommentToTicketByTrelloId() $response->assertStatus(200); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/TimeOfUsageTest.php b/src/backend/tests/Feature/TimeOfUsageTest.php index d4479a7ed..9850b704d 100644 --- a/src/backend/tests/Feature/TimeOfUsageTest.php +++ b/src/backend/tests/Feature/TimeOfUsageTest.php @@ -6,12 +6,10 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class TimeOfUsageTest extends TestCase -{ +class TimeOfUsageTest extends TestCase { use CreateEnvironments; - public function testUserDeletesTimeOfUsageOfTariff() - { + public function testUserDeletesTimeOfUsageOfTariff() { $this->createTestData(); $meterTariffCount = 5; $withTimeOfUsage = true; @@ -21,8 +19,7 @@ public function testUserDeletesTimeOfUsageOfTariff() $response->assertStatus(200); } - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); diff --git a/src/backend/tests/Feature/TokenProcessorTest.php b/src/backend/tests/Feature/TokenProcessorTest.php index f873b9e83..2ee1e08cb 100644 --- a/src/backend/tests/Feature/TokenProcessorTest.php +++ b/src/backend/tests/Feature/TokenProcessorTest.php @@ -25,13 +25,11 @@ use Illuminate\Support\Facades\Queue; use Tests\TestCase; -class TokenProcessorTest extends TestCase -{ +class TokenProcessorTest extends TestCase { use RefreshDatabase; use WithFaker; - public function testWithValidTransaction() - { + public function testWithValidTransaction() { Queue::fake(); PersonFactory::new()->create(); MeterTariffFactory::new()->create(); diff --git a/src/backend/tests/Feature/UserResourceTest.php b/src/backend/tests/Feature/UserResourceTest.php index f7aefeb5d..f74ca3889 100644 --- a/src/backend/tests/Feature/UserResourceTest.php +++ b/src/backend/tests/Feature/UserResourceTest.php @@ -10,13 +10,11 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class UserResource extends TestCase -{ +class UserResource extends TestCase { use RefreshDatabase; use WithFaker; - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); @@ -25,8 +23,7 @@ public function actingAs($user, $driver = null) } /** @test */ - public function listRegisteredUsers(): void - { + public function listRegisteredUsers(): void { $user = UserFactory::new()->create(); // create random users UserFactory::times(30)->create(); @@ -37,8 +34,7 @@ public function listRegisteredUsers(): void } /** @test */ - public function createUser(): void - { + public function createUser(): void { $this->withoutExceptionHandling(); $user = UserFactory::new()->create(); $response = $this->actingAs($user)->post('/api/users', [ @@ -53,8 +49,7 @@ public function createUser(): void } /** @test */ - public function updateUserPassword(): void - { + public function updateUserPassword(): void { $user = UserFactory::new()->create(); // create user $this->actingAs($user)->post('/api/users', [ @@ -65,20 +60,21 @@ public function updateUserPassword(): void $user = User::query()->get()[1]; - $response = $this->actingAs($user)->put('/api/users/password/'.$user->id, + $response = $this->actingAs($user)->put( + '/api/users/password/'.$user->id, [ 'id' => $user->id, 'password' => '12345', 'confirm_password' => '12345', - ]); + ] + ); $response->assertStatus(200); $user = User::query()->get()[1]; $this->assertTrue(Hash::check('12345', $user->password)); } /** @test */ - public function resetUserPassword(): void - { + public function resetUserPassword(): void { $user = UserFactory::new()->create(); // create user $this->actingAs($user)->post('/api/users', [ @@ -95,8 +91,7 @@ public function resetUserPassword(): void } /** @test */ - public function resetPasswordWithNonExistingEmail(): void - { + public function resetPasswordWithNonExistingEmail(): void { $request = $this->post('/api/users/password', ['email' => 'ako@inensus.com']); $request->assertStatus(422); diff --git a/src/backend/tests/RefreshMultipleDatabases.php b/src/backend/tests/RefreshMultipleDatabases.php index b290e76f8..76b4fb6bd 100644 --- a/src/backend/tests/RefreshMultipleDatabases.php +++ b/src/backend/tests/RefreshMultipleDatabases.php @@ -7,28 +7,33 @@ use Illuminate\Foundation\Testing\RefreshDatabaseState; use Illuminate\Support\Facades\Artisan; -trait RefreshMultipleDatabases -{ +trait RefreshMultipleDatabases { use RefreshDatabase; - protected function refreshInMemoryDatabase() - { - Artisan::call('migrate:fresh', - ['--database' => 'micro_power_manager', '--path' => '/database/migrations/base']); - Artisan::call('migrate:fresh', - ['--database' => 'test_company_db', '--path' => '/database/migrations/test_company_db']); + protected function refreshInMemoryDatabase() { + Artisan::call( + 'migrate:fresh', + ['--database' => 'micro_power_manager', '--path' => '/database/migrations/base'] + ); + Artisan::call( + 'migrate:fresh', + ['--database' => 'test_company_db', '--path' => '/database/migrations/test_company_db'] + ); app(Kernel::class)->setArtisan(null); $this->app[Kernel::class]->setArtisan(null); } - protected function refreshTestDatabase() - { + protected function refreshTestDatabase() { if (!RefreshDatabaseState::$migrated) { - Artisan::call('migrate:fresh', - ['--database' => 'micro_power_manager', '--path' => '/database/migrations/base']); - - Artisan::call('migrate:fresh', - ['--database' => 'test_company_db', '--path' => '/database/migrations/test_company_db']); + Artisan::call( + 'migrate:fresh', + ['--database' => 'micro_power_manager', '--path' => '/database/migrations/base'] + ); + + Artisan::call( + 'migrate:fresh', + ['--database' => 'test_company_db', '--path' => '/database/migrations/test_company_db'] + ); app(Kernel::class)->setArtisan(null); diff --git a/src/backend/tests/TestCase.php b/src/backend/tests/TestCase.php index 61dd33b7b..aaf78024d 100644 --- a/src/backend/tests/TestCase.php +++ b/src/backend/tests/TestCase.php @@ -6,16 +6,14 @@ use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Tymon\JWTAuth\Facades\JWTAuth; -abstract class TestCase extends BaseTestCase -{ +abstract class TestCase extends BaseTestCase { use CreatesApplication; /** * generates an jwt for the given user * if user is not present it tries to generate a token for the first user. */ - protected function headers(?User $user = null) - { + protected function headers(?User $user = null) { if (!$user) { $user = User::create([ 'name' => 'John Doe', diff --git a/src/backend/tests/Unit/AgentSellApplianceTest.php b/src/backend/tests/Unit/AgentSellApplianceTest.php index 3aeeaa499..d44973b8b 100644 --- a/src/backend/tests/Unit/AgentSellApplianceTest.php +++ b/src/backend/tests/Unit/AgentSellApplianceTest.php @@ -17,13 +17,11 @@ use Tests\TestCase; use Tymon\JWTAuth\Facades\JWTAuth; -class AgentSellApplianceTest extends TestCase -{ +class AgentSellApplianceTest extends TestCase { use RefreshDatabase; use WithFaker; - public function actingAs($user, $driver = null) - { + public function actingAs($user, $driver = null) { $token = JWTAuth::fromUser($user); $this->withHeader('Authorization', "Bearer {$token}"); parent::actingAs($user); @@ -36,8 +34,7 @@ public function actingAs($user, $driver = null) * * @return void */ - public function testAgentSellAppliance() - { + public function testAgentSellAppliance() { $this->initData(); $data = [ 'agent_assigned_appliance_id' => 2, @@ -61,8 +58,7 @@ public function testAgentSellAppliance() $this->assertEquals($data['down_payment'], $paymentHistory->amount); } - public function initData() - { + public function initData() { $user = UserFactory::new()->create(); $this->actingAs($user); PersonFactory::new()->create(); diff --git a/src/backend/tests/Unit/Exports/DailyTransactions.php b/src/backend/tests/Unit/Exports/DailyTransactions.php index 7e6d6aefe..3125db1fe 100644 --- a/src/backend/tests/Unit/Exports/DailyTransactions.php +++ b/src/backend/tests/Unit/Exports/DailyTransactions.php @@ -2,12 +2,9 @@ use Tests\TestCase; -class DailyTransactions extends TestCase -{ +class DailyTransactions extends TestCase { /** * Get all transactions from the database (Seeder) and gets only the confirmed ones. */ - public function testGetDailyTransactions() - { - } + public function testGetDailyTransactions() {} } diff --git a/src/backend/tests/Unit/SmsProcessorTest.php b/src/backend/tests/Unit/SmsProcessorTest.php index 4fa02b129..f4adbf0d5 100644 --- a/src/backend/tests/Unit/SmsProcessorTest.php +++ b/src/backend/tests/Unit/SmsProcessorTest.php @@ -25,13 +25,11 @@ use Illuminate\Support\Facades\Queue; use Tests\TestCase; -class SmsProcessorTest extends TestCase -{ +class SmsProcessorTest extends TestCase { /* ./vendor/bin/phpunit --filter sms_sending_with_transaction */ use RefreshDatabase; - public function testTokenCreationWithValidTransaction() - { + public function testTokenCreationWithValidTransaction() { Queue::fake(); $transaction = $this->initializeData(); $transactionContainer = TransactionDataContainer::initialize($transaction); @@ -43,8 +41,7 @@ public function testTokenCreationWithValidTransaction() Queue::assertPushed(TokenProcessor::class); } - public function testSmsSendingWithTransaction() - { + public function testSmsSendingWithTransaction() { Queue::fake(); $transaction = $this->initializeData(); $transaction->sender = '905494322161'; @@ -56,8 +53,7 @@ public function testSmsSendingWithTransaction() Queue::assertPushed(SmsProcessor::class); } - public function testSmsSendingWithResendInformationWithNoTransaction() - { + public function testSmsSendingWithResendInformationWithNoTransaction() { Queue::fake(); $transaction = $this->initializeData(); $transaction->sender = '905494322161'; @@ -74,8 +70,7 @@ public function testSmsSendingWithResendInformationWithNoTransaction() Queue::assertPushed(SmsProcessor::class); } - private function addSmsBodies() - { + private function addSmsBodies() { $bodies = [ [ 'reference' => 'SmsTransactionHeader', @@ -175,8 +170,7 @@ private function addSmsBodies() return SmsBody::query()->get(); } - private function initializeData() - { + private function initializeData() { // create person MainSettingsFactory::new()->create(); diff --git a/src/backend/tests/Unit/Transaction/AccessRateTest.php b/src/backend/tests/Unit/Transaction/AccessRateTest.php index 794a46dd5..caef849bf 100644 --- a/src/backend/tests/Unit/Transaction/AccessRateTest.php +++ b/src/backend/tests/Unit/Transaction/AccessRateTest.php @@ -21,13 +21,11 @@ use Illuminate\Support\Facades\Bus; use Tests\TestCase; -class AccessRateTest extends TestCase -{ +class AccessRateTest extends TestCase { use RefreshDatabase; use WithFaker; - private function initApplication(): void - { + private function initApplication(): void { Bus::fake(); $manufacturer = ManufacturerFactory::new()->create(); $meterType = MeterTypeFactory::new()->create(); @@ -61,8 +59,7 @@ private function initApplication(): void /** * @throws \Exception */ - public function testWithNoAccessRate(): void - { + public function testWithNoAccessRate(): void { $this->initApplication(); $transaction = $this->createFakeTransaction(500); $transactionContainer = TransactionDataContainer::initialize($transaction); @@ -70,8 +67,7 @@ public function testWithNoAccessRate(): void $this->assertEquals(0, $transactionData->accessRateDebt); } - public function testWithCoverAccessRate(): void - { + public function testWithCoverAccessRate(): void { $this->initApplication(); $transaction = $this->createFakeTransaction(500); $transactionContainer = TransactionDataContainer::initialize($transaction); @@ -85,8 +81,7 @@ public function testWithCoverAccessRate(): void $this->assertEquals(0, $accessRatePayment->debt); } - public function testWithNonCoverAccessRate(): void - { + public function testWithNonCoverAccessRate(): void { $this->initApplication(); $transaction = $this->createFakeTransaction(500); $transactionContainer = TransactionDataContainer::initialize($transaction); @@ -100,8 +95,7 @@ public function testWithNonCoverAccessRate(): void $this->assertEquals(500, $accessRatePayment->debt); } - public function testWithExactlyAccessRateDebt() - { + public function testWithExactlyAccessRateDebt() { $this->initApplication(); $transaction = $this->createFakeTransaction(1000); @@ -120,8 +114,7 @@ public function testWithExactlyAccessRateDebt() $this->assertEquals(0, $accessRatePayment->debt); } - private function createFakeTransaction(int $amount) - { + private function createFakeTransaction(int $amount) { $vodacomTransaction = VodacomTransactionFactory::new()->create(); $transaction = TransactionFactory::new()->make(); $transaction->amount = $amount; diff --git a/src/backend/tests/Unit/Transaction/VodacomTransactionTest.php b/src/backend/tests/Unit/Transaction/VodacomTransactionTest.php index 8989e8338..411b735be 100644 --- a/src/backend/tests/Unit/Transaction/VodacomTransactionTest.php +++ b/src/backend/tests/Unit/Transaction/VodacomTransactionTest.php @@ -11,30 +11,38 @@ use MPM\Transaction\Provider\VodacomTransactionProvider; use Tests\TestCase; -class VodacomTransactionTest extends TestCase -{ +class VodacomTransactionTest extends TestCase { use RefreshDatabase; use WithFaker; /** * @var Response */ - public function testTransactionSentFromUnknownIpAddress(): void - { - $request = Request::create(URL::route('vodacomTransaction'), 'POST', [], [], [], - ['REMOTE_ADDR' => '127.0.0.2']); + public function testTransactionSentFromUnknownIpAddress(): void { + $request = Request::create( + URL::route('vodacomTransaction'), + 'POST', + [], + [], + [], + ['REMOTE_ADDR' => '127.0.0.2'] + ); $middleWare = new Transaction(); - $response = $middleWare->handle($request, function () { - }); + $response = $middleWare->handle($request, function () {}); self::assertEquals(401, $response->status()); } - public function testTransactionSentFromWhiteListedIpAddress(): void - { - $request = Request::create(URL::route('vodacomTransaction'), 'POST', [], [], [], - ['REMOTE_ADDR' => config('services.vodacom.ips')[0]]); + public function testTransactionSentFromWhiteListedIpAddress(): void { + $request = Request::create( + URL::route('vodacomTransaction'), + 'POST', + [], + [], + [], + ['REMOTE_ADDR' => config('services.vodacom.ips')[0]] + ); $middleWare = new Transaction();