Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel Pint as a linter #100 #364

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 15 additions & 1 deletion src/backend/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;
10 changes: 4 additions & 6 deletions src/backend/app/Console/Commands/AbstractSharedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
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;

/**
* Configure the command.
*/
protected function configure(): void
{
protected function configure(): void {
parent::configure();

$this->addOption(
Expand All @@ -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);

Expand Down
7 changes: 3 additions & 4 deletions src/backend/app/Console/Commands/AccessRateChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
10 changes: 4 additions & 6 deletions src/backend/app/Console/Commands/AddMeterAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 4 additions & 6 deletions src/backend/app/Console/Commands/AddPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
10 changes: 4 additions & 6 deletions src/backend/app/Console/Commands/AdminPasswordResetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 9 additions & 16 deletions src/backend/app/Console/Commands/AssetRateChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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([
Expand All @@ -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'])
Expand All @@ -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) {
Expand All @@ -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([
Expand Down Expand Up @@ -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();
}
}
7 changes: 3 additions & 4 deletions src/backend/app/Console/Commands/BackupFull.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down
7 changes: 3 additions & 4 deletions src/backend/app/Console/Commands/BackupTenantDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
9 changes: 3 additions & 6 deletions src/backend/app/Console/Commands/CalinMeterReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -15,8 +15,7 @@ public function __construct(
parent::__construct();
}

public function handle(): void
{
public function handle(): void {
$this->clustersDashboardCacheDataService->setData();
}
}
13 changes: 7 additions & 6 deletions src/backend/app/Console/Commands/CreateDummyCompanyWithData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -25,14 +25,17 @@ class CreateDummyCompanyWithData extends Command
'email' => '[email protected]',
'protected_page_password' => '123123',
];

public const DUMMY_COMPANY_USER = [
'password' => '123123',
'email' => '[email protected]',
'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(
Expand All @@ -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;
Expand All @@ -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);
Expand Down
Loading
Loading