Skip to content

Commit

Permalink
fix: update method signatures to include return types and refactor er…
Browse files Browse the repository at this point in the history
…ror messages to use Location model

Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Feb 27, 2025
1 parent 220c2de commit 3aa43f9
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 77 deletions.
61 changes: 3 additions & 58 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/AutomationRules/Conditions/ReviewCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class ReviewCount extends BaseModelAttributesCondition

protected $modelAttributes;

public function conditionDetails()
public function conditionDetails(): array
{
return [
'name' => 'Review Count',
'description' => 'Number of reviews for this order or reservation',
];
}

public function defineModelAttributes()
public function defineModelAttributes(): array
{
return [
'review_count' => [
Expand Down
6 changes: 3 additions & 3 deletions src/CartConditions/Delivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion src/Classes/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([]));
}
Expand Down
2 changes: 1 addition & 1 deletion src/FormWidgets/MapArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/FormWidgets/MapView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/FormWidgets/ScheduleEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function initialize(): void
]);
}

public function render()
public function render(): string
{
$this->prepareVars();

Expand Down
2 changes: 1 addition & 1 deletion src/FormWidgets/SettingsEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function initialize(): void
]);
}

public function render()
public function render(): string
{
$this->prepareVars();

Expand Down
2 changes: 1 addition & 1 deletion src/FormWidgets/StarRating.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function initialize(): void
}
}

public function render()
public function render(): string
{
$this->prepareVars();

Expand Down
2 changes: 1 addition & 1 deletion src/MainMenuWidgets/LocationPicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function initialize(): void
]);
}

public function render()
public function render(): string
{
$this->prepareVars();

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/Classes/CoveredAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions tests/Classes/LocationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 3aa43f9

Please sign in to comment.