From 851df77b16552296937e13dd15d8baa640e413c1 Mon Sep 17 00:00:00 2001 From: Daniel Mohns Date: Wed, 11 Dec 2024 13:57:01 +0100 Subject: [PATCH] Fix `larastan` warning (#406) --- src/backend/app/Http/Controllers/Reports.php | 4 ++-- src/backend/app/Misc/LoanDataContainer.php | 4 ++-- src/backend/app/Services/AgentAssignedApplianceService.php | 2 +- src/backend/app/Services/AgentSoldApplianceService.php | 6 +++--- src/backend/app/Services/ClusterMeterService.php | 2 +- src/backend/app/Services/MeterService.php | 6 +++--- src/backend/app/Services/PersonMeterService.php | 6 ++---- .../app/Sms/BodyParsers/SmsResendInformationHeader.php | 2 +- src/backend/app/Traits/RestExceptionHandler.php | 2 +- 9 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/backend/app/Http/Controllers/Reports.php b/src/backend/app/Http/Controllers/Reports.php index 8cae8ee84..5c4a2af78 100644 --- a/src/backend/app/Http/Controllers/Reports.php +++ b/src/backend/app/Http/Controllers/Reports.php @@ -534,10 +534,10 @@ private function generateReportForCity( $sheet = $this->spreadsheet->getActiveSheet(); $sheet->setTitle('graphs'.$startDate.'-'.$endDate); - $transactions = $this->transaction::with(['meter.meterParameter.tariff', 'meter.meterParameter.connectionType']) + $transactions = $this->transaction::with(['device.device.tariff', 'device.device.connectionType']) ->selectRaw('id,message,SUM(amount) as amount,GROUP_CONCAT(DISTINCT id SEPARATOR \',\') AS transaction_ids') ->whereHas( - 'meter.meterParameter.address', + 'device.device.address', function ($q) use ($cityId) { $q->where('city_id', $cityId); } diff --git a/src/backend/app/Misc/LoanDataContainer.php b/src/backend/app/Misc/LoanDataContainer.php index 056bffe66..2cf853740 100644 --- a/src/backend/app/Misc/LoanDataContainer.php +++ b/src/backend/app/Misc/LoanDataContainer.php @@ -93,7 +93,7 @@ public function loanCost() { private function getCustomerDueRates($owner): Collection { $loans = AssetPerson::query()->where('person_id', $owner->id)->pluck('id'); - return AssetRate::with('assetPerson.assetType') + return AssetRate::with('assetPerson.device') ->whereIn('asset_person_id', $loans) ->where('remaining', '>', 0) ->whereDate('due_date', '<', date('Y-m-d')) @@ -111,7 +111,7 @@ private function getCustomerDueRates($owner): Collection { private function getMeterOwner(string $serialNumber): ?Person { try { /** @var Meter $meter */ - $meter = Meter::with('meterParameter.owner') + $meter = Meter::with('device.person') ->where('serial_number', $serialNumber) ->firstOrFail(); } catch (ModelNotFoundException $ex) { diff --git a/src/backend/app/Services/AgentAssignedApplianceService.php b/src/backend/app/Services/AgentAssignedApplianceService.php index 837502e67..530241954 100644 --- a/src/backend/app/Services/AgentAssignedApplianceService.php +++ b/src/backend/app/Services/AgentAssignedApplianceService.php @@ -25,7 +25,7 @@ public function create(array $applianceData): AgentAssignedAppliances { } public function getById(int $id): AgentAssignedAppliances { - return $this->agentAssignedAppliance->newQuery()->with('applianceType')->find($id); + return $this->agentAssignedAppliance->newQuery()->with('appliance')->find($id); } public function update($model, array $data): AgentAssignedAppliances { diff --git a/src/backend/app/Services/AgentSoldApplianceService.php b/src/backend/app/Services/AgentSoldApplianceService.php index 1662010bf..7c2ee1b28 100644 --- a/src/backend/app/Services/AgentSoldApplianceService.php +++ b/src/backend/app/Services/AgentSoldApplianceService.php @@ -23,7 +23,7 @@ public function create($applianceData): AgentSoldAppliance { } public function getById(int $agentId, ?int $customerId = null): AgentSoldAppliance { - return $this->assetPerson->newQuery()->with(['person', 'assetType', 'rates']) + return $this->assetPerson->newQuery()->with(['person', 'device', 'rates']) ->whereHasMorph( 'creator', [Agent::class], @@ -59,7 +59,7 @@ public function getAll( $query = $this->agentSoldAppliance->newQuery()->with([ 'assignedAppliance', - 'assignedAppliance.applianceType', + 'assignedAppliance.appliance.assetType', 'person', ]); @@ -87,7 +87,7 @@ function ($q) use ($agentId) { } public function list($agentId) { - return $this->assetPerson->newQuery()->with(['person', 'assetType', 'rates']) + return $this->assetPerson->newQuery()->with(['person', 'device', 'rates']) ->whereHasMorph( 'creator', [Agent::class], diff --git a/src/backend/app/Services/ClusterMeterService.php b/src/backend/app/Services/ClusterMeterService.php index 41a9f69d9..887d93b4e 100644 --- a/src/backend/app/Services/ClusterMeterService.php +++ b/src/backend/app/Services/ClusterMeterService.php @@ -10,7 +10,7 @@ public function __construct(private Cluster $cluster, private Meter $meter) {} public function getCountById($clusterId): int { return $this->meter->newQuery()->whereHas( - 'meterParameter', + 'device', function ($q) use ($clusterId) { $q->whereHas( 'address', diff --git a/src/backend/app/Services/MeterService.php b/src/backend/app/Services/MeterService.php index cac55efb3..840793858 100644 --- a/src/backend/app/Services/MeterService.php +++ b/src/backend/app/Services/MeterService.php @@ -40,17 +40,17 @@ public function search($term, $paginate): LengthAwarePaginator { public function getMeterWithAllRelations(int $meterId) { return $this->meter->newQuery()->with([ 'tariff', - 'device.geo', + 'device.device.geo', 'meterType', ])->find($meterId); } public function getUsedMetersGeoWithAccessRatePayments(): Collection|array { - return $this->meter->newQuery()->with(['device.geo', 'accessRatePayment'])->where('in_use', 1)->get(); + return $this->meter->newQuery()->with(['device.device.geo', 'accessRatePayment'])->where('in_use', 1)->get(); } public function getUsedMetersGeoWithAccessRatePaymentsInCities($cities): Collection|array { - return $this->meter->newQuery()->with(['device.geo', 'accessRatePayment']) + return $this->meter->newQuery()->with(['device.device.geo', 'accessRatePayment']) ->whereHas( 'device', fn ($q) => $q->whereHas( diff --git a/src/backend/app/Services/PersonMeterService.php b/src/backend/app/Services/PersonMeterService.php index e42334b74..29ff29128 100644 --- a/src/backend/app/Services/PersonMeterService.php +++ b/src/backend/app/Services/PersonMeterService.php @@ -2,20 +2,18 @@ namespace App\Services; -use App\Models\Meter\Meter; use App\Models\Person\Person; class PersonMeterService { public function __construct( private Person $person, - private Meter $meter, ) {} public function getPersonMeters(int $personId) { - return $this->person->newQuery()->with(['meters.tariff', 'meters.meter'])->find($personId); + return $this->person->newQuery()->with(['devices.device.tariff', 'meters.meter'])->find($personId); } public function getPersonMetersGeographicalInformation(int $personId) { - return $this->person->newQuery()->with(['meters.meter', 'meters.geo'])->find($personId); + return $this->person->newQuery()->with(['devices.device.meter', 'meters.geo'])->find($personId); } } diff --git a/src/backend/app/Sms/BodyParsers/SmsResendInformationHeader.php b/src/backend/app/Sms/BodyParsers/SmsResendInformationHeader.php index d79d4c724..68c0c5b13 100644 --- a/src/backend/app/Sms/BodyParsers/SmsResendInformationHeader.php +++ b/src/backend/app/Sms/BodyParsers/SmsResendInformationHeader.php @@ -17,7 +17,7 @@ protected function getVariableValue($variable) { $person = $this->data->meter->meterParameter->owner()->first(); } else { try { - $person = Person::query()->with(['meters.meter' => function ($q) { + $person = Person::query()->with(['devices.device' => function ($q) { return $q->where('serial_number', $this->data['meter'])->first(); }])->firstOrFail(); } catch (\Exception $e) { diff --git a/src/backend/app/Traits/RestExceptionHandler.php b/src/backend/app/Traits/RestExceptionHandler.php index 9b111153b..44fb0b9f8 100644 --- a/src/backend/app/Traits/RestExceptionHandler.php +++ b/src/backend/app/Traits/RestExceptionHandler.php @@ -125,7 +125,7 @@ protected function isValidationException($e): bool { * * @return JsonResponse */ - protected function jsonResponse(?array $payload = null, $status_code) { + protected function jsonResponse(?array $payload = null, $status_code = 400) { $payload = $payload ?: []; return response()->json(