From 3aa43f9e68cd1e8e3c08bfac15ffe245d7a9322a Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Thu, 27 Feb 2025 00:22:05 +0000 Subject: [PATCH] fix: update method signatures to include return types and refactor error messages to use Location model Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- phpstan-baseline.neon | 61 +------------------ .../Conditions/ReviewCount.php | 4 +- src/CartConditions/Delivery.php | 6 +- src/Classes/Location.php | 2 +- src/FormWidgets/MapArea.php | 2 +- src/FormWidgets/MapView.php | 2 +- src/FormWidgets/ScheduleEditor.php | 2 +- src/FormWidgets/SettingsEditor.php | 2 +- src/FormWidgets/StarRating.php | 2 +- src/MainMenuWidgets/LocationPicker.php | 2 +- src/Models/Review.php | 2 +- tests/Classes/CoveredAreaTest.php | 5 +- tests/Classes/LocationTest.php | 7 +-- 13 files changed, 22 insertions(+), 77 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4453486..170d1f6 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -11,57 +11,12 @@ parameters: path: src/Classes/Location.php - - message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:availableOrderTypes\\(\\)\\.$#" + message: "#^Call to an undefined method Igniter\\\\Local\\\\Models\\\\Location\\:\\:availableOrderTypes\\(\\)\\.$#" count: 1 path: src/Classes/Location.php - - message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:findDeliveryArea\\(\\)\\.$#" - count: 1 - path: src/Classes/Location.php - - - - message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:getDistanceUnit\\(\\)\\.$#" - count: 1 - path: src/Classes/Location.php - - - - message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:getKey\\(\\)\\.$#" - count: 3 - path: src/Classes/Location.php - - - - message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:getSettings\\(\\)\\.$#" - count: 1 - path: src/Classes/Location.php - - - - message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:getSlugKeyName\\(\\)\\.$#" - count: 1 - path: src/Classes/Location.php - - - - message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:listDeliveryAreas\\(\\)\\.$#" - count: 1 - path: src/Classes/Location.php - - - - message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:newQuery\\(\\)\\.$#" - count: 1 - path: src/Classes/Location.php - - - - message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:newWorkingSchedule\\(\\)\\.$#" - count: 1 - path: src/Classes/Location.php - - - - message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:searchOrDefaultDeliveryArea\\(\\)\\.$#" - count: 1 - path: src/Classes/Location.php - - - - message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:shouldAddLeadTime\\(\\)\\.$#" + message: "#^Call to an undefined method Igniter\\\\Local\\\\Models\\\\Location\\:\\:shouldAddLeadTime\\(\\)\\.$#" count: 1 path: src/Classes/Location.php @@ -131,25 +86,15 @@ parameters: path: src/Http/Controllers/Locations.php - - message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:getOrderTimeInterval\\(\\)\\.$#" + message: "#^Call to an undefined method Igniter\\\\Local\\\\Models\\\\Location\\:\\:getOrderTimeInterval\\(\\)\\.$#" count: 1 path: src/Listeners/MaxOrderPerTimeslotReached.php - - - message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:getSettings\\(\\)\\.$#" - count: 2 - path: src/Listeners/MaxOrderPerTimeslotReached.php - - message: "#^Access to an undefined property Igniter\\\\Admin\\\\Classes\\\\BaseWidget\\:\\:\\$previewMode\\.$#" count: 1 path: src/MainMenuWidgets/LocationPicker.php - - - message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:getKey\\(\\)\\.$#" - count: 1 - path: src/MainMenuWidgets/LocationPicker.php - - message: "#^Access to an undefined property Igniter\\\\Local\\\\Models\\\\Location\\:\\:\\$country\\.$#" count: 1 diff --git a/src/AutomationRules/Conditions/ReviewCount.php b/src/AutomationRules/Conditions/ReviewCount.php index e9f44fa..606419e 100644 --- a/src/AutomationRules/Conditions/ReviewCount.php +++ b/src/AutomationRules/Conditions/ReviewCount.php @@ -16,7 +16,7 @@ class ReviewCount extends BaseModelAttributesCondition protected $modelAttributes; - public function conditionDetails() + public function conditionDetails(): array { return [ 'name' => 'Review Count', @@ -24,7 +24,7 @@ public function conditionDetails() ]; } - public function defineModelAttributes() + public function defineModelAttributes(): array { return [ 'review_count' => [ diff --git a/src/CartConditions/Delivery.php b/src/CartConditions/Delivery.php index 3156ad2..eb0b7ff 100644 --- a/src/CartConditions/Delivery.php +++ b/src/CartConditions/Delivery.php @@ -15,7 +15,7 @@ class Delivery extends CartCondition protected $deliveryCharge = 0; - public function beforeApply() + public function beforeApply(): ?bool { // Do not apply condition when orderType is not delivery if (Location::orderType() != LocationModel::DELIVERY) { @@ -28,14 +28,14 @@ public function beforeApply() return null; } - public function getRules() + public function getRules(): array { return [ $this->deliveryCharge.' >= 0', ]; } - public function getActions() + public function getActions(): array { return [ ['value' => '+'.$this->deliveryCharge], diff --git a/src/Classes/Location.php b/src/Classes/Location.php index 0aaec3d..84e4a62 100644 --- a/src/Classes/Location.php +++ b/src/Classes/Location.php @@ -574,7 +574,7 @@ public function coveredArea(): CoveredArea return $coveredArea; } - public function userPosition(): ?\Igniter\Flame\Geolite\Model\Location + public function userPosition(): ?UserLocation { return $this->getSession('position', UserLocation::createFromArray([])); } diff --git a/src/FormWidgets/MapArea.php b/src/FormWidgets/MapArea.php index c0e3b1e..cca75a3 100644 --- a/src/FormWidgets/MapArea.php +++ b/src/FormWidgets/MapArea.php @@ -111,7 +111,7 @@ public function loadAssets(): void $this->addJs('mapview.shape.js', 'mapview-shape-js'); } - public function render() + public function render(): string { $this->prepareVars(); diff --git a/src/FormWidgets/MapView.php b/src/FormWidgets/MapView.php index 32e1530..64c1f7a 100644 --- a/src/FormWidgets/MapView.php +++ b/src/FormWidgets/MapView.php @@ -49,7 +49,7 @@ public function loadAssets(): void $this->addJs('mapview.shape.js', 'mapview-shape-js'); } - public function render() + public function render(): string { $this->prepareVars(); diff --git a/src/FormWidgets/ScheduleEditor.php b/src/FormWidgets/ScheduleEditor.php index e0394ae..d985749 100644 --- a/src/FormWidgets/ScheduleEditor.php +++ b/src/FormWidgets/ScheduleEditor.php @@ -46,7 +46,7 @@ public function initialize(): void ]); } - public function render() + public function render(): string { $this->prepareVars(); diff --git a/src/FormWidgets/SettingsEditor.php b/src/FormWidgets/SettingsEditor.php index 8306745..226035a 100644 --- a/src/FormWidgets/SettingsEditor.php +++ b/src/FormWidgets/SettingsEditor.php @@ -33,7 +33,7 @@ public function initialize(): void ]); } - public function render() + public function render(): string { $this->prepareVars(); diff --git a/src/FormWidgets/StarRating.php b/src/FormWidgets/StarRating.php index a2a16b6..61618d9 100644 --- a/src/FormWidgets/StarRating.php +++ b/src/FormWidgets/StarRating.php @@ -31,7 +31,7 @@ public function initialize(): void } } - public function render() + public function render(): string { $this->prepareVars(); diff --git a/src/MainMenuWidgets/LocationPicker.php b/src/MainMenuWidgets/LocationPicker.php index c51c18d..f431eef 100644 --- a/src/MainMenuWidgets/LocationPicker.php +++ b/src/MainMenuWidgets/LocationPicker.php @@ -37,7 +37,7 @@ public function initialize(): void ]); } - public function render() + public function render(): string { $this->prepareVars(); diff --git a/src/Models/Review.php b/src/Models/Review.php index 9c51b96..679e340 100644 --- a/src/Models/Review.php +++ b/src/Models/Review.php @@ -35,7 +35,7 @@ * @property bool $review_status * @property Carbon $updated_at * @property-read null|Customer $customer - * @method static Builder|Review whereReviewable() + * @method static Builder|Review whereReviewable(Model $object) * @mixin Model */ class Review extends Model diff --git a/tests/Classes/CoveredAreaTest.php b/tests/Classes/CoveredAreaTest.php index 50f68b0..6e19d90 100644 --- a/tests/Classes/CoveredAreaTest.php +++ b/tests/Classes/CoveredAreaTest.php @@ -8,6 +8,7 @@ use Igniter\Local\Classes\CoveredAreaCondition; use Igniter\Local\Facades\Location; use Igniter\Local\Models\LocationArea; +use Igniter\Flame\Geolite\Model\Location as GeoliteLocation; use Mockery; it('calculates delivery amount correctly', function(): void { @@ -42,8 +43,8 @@ ['distance' => 12, 'type' => 'equals_or_less', 'charge' => 15], ], ]); - Location::shouldReceive('userPosition')->andReturnSelf(); - Location::shouldReceive('isValid')->andReturnTrue(); + Location::shouldReceive('userPosition')->andReturn($userPosition = mock(GeoliteLocation::class)); + $userPosition->shouldReceive('isValid')->andReturnTrue(); Location::shouldReceive('checkDistance')->andReturn(20, 5, 15, 12); $coveredArea = new CoveredArea($model); diff --git a/tests/Classes/LocationTest.php b/tests/Classes/LocationTest.php index 37d72db..0e80661 100644 --- a/tests/Classes/LocationTest.php +++ b/tests/Classes/LocationTest.php @@ -13,7 +13,6 @@ use Igniter\Local\Classes\CoveredArea; use Igniter\Local\Classes\Location; use Igniter\Local\Classes\WorkingSchedule; -use Igniter\Local\Contracts\LocationInterface; use Igniter\Local\Facades\Location as LocationFacade; use Igniter\Local\Models\Location as LocationModel; use Igniter\Local\Models\LocationArea; @@ -39,7 +38,7 @@ }); it('returns current location when model is already set', function(): void { - $model = mock(LocationInterface::class); + $model = mock(LocationModel::class); $this->location->setModel($model); $result = $this->location->current(); @@ -83,7 +82,7 @@ }); it('returns current location in currentOrDefault', function(): void { - $model = mock(LocationInterface::class)->makePartial(); + $model = mock(LocationModel::class)->makePartial(); $this->location->setModel($model); $result = $this->location->currentOrDefault(); @@ -113,7 +112,7 @@ }); it('returns current location id in currentOrAssigned', function(): void { - $location = mock(LocationInterface::class)->makePartial(); + $location = mock(LocationModel::class)->makePartial(); $location->shouldReceive('getKey')->andReturn(1); $this->location->setCurrent($location);