mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 13:51:44 +00:00
feat: add PHPStan level 5 with zero errors
- Install phpstan/phpstan, add phpstan.neon at level 5 targeting PHP 8.3 - Add phpstan-bootstrap.php stubs for Laravel helper functions (app, config, config_path, app_path, session) unavailable in standalone packages - Fix CartCondition::setOrder() - removed incorrect @return int (method is void) - Fix CartCondition::getCalculatedValue() - removed incorrect @return mixed PHPDoc - Fix Cart::condition() - remove redundant instanceof check the type system already guarantees - Fix Cart::fireEvent() - remove array_values() on already-list literal array - Fix ItemCollection - add @property annotations for magic __get properties - Fix ItemCollection::getAssociatedModel() - correct @return bool to @return mixed - Fix ItemCollection::getConditions() - remove dead is_array && !instanceof check - Fix Validator - add @method stub so PHPStan resolves make() through __callStatic - Add ignoreErrors for trait.unused (HasCart designed for external Livewire use) - Add ignoreErrors for round() mode mismatch (PHPStan 2.x PHP 8.4 stubs bug) - Add phpstan step to CI (PHP 8.3 only, matches phpVersion config)
This commit is contained in:
+1
-5
@@ -342,10 +342,6 @@ public function condition(array|CartCondition $condition): self
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (! $condition instanceof CartCondition) {
|
||||
throw new InvalidConditionException('Argument 1 must be an instance of \'Wearepixel\Cart\CartCondition\'');
|
||||
}
|
||||
|
||||
$conditions = $this->getConditions();
|
||||
|
||||
if ($condition->getOrder() === 0) {
|
||||
@@ -735,6 +731,6 @@ protected function fireEvent(string $name, ?string $type = null, mixed $data = n
|
||||
$eventData[$type] = $data;
|
||||
}
|
||||
|
||||
return $this->events->dispatch('LaravelCart.' . $name, array_values([$eventData, $this]), true);
|
||||
return $this->events->dispatch('LaravelCart.' . $name, [$eventData, $this], true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,13 +105,11 @@ public function setValue($value): void
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the order to apply this condition. If no argument order is applied we return 0 as
|
||||
* indicator that no assignment has been made
|
||||
* Set the order to apply this condition.
|
||||
*
|
||||
* @param int $order
|
||||
* @return int
|
||||
*/
|
||||
public function setOrder($order = 1)
|
||||
public function setOrder($order = 1): void
|
||||
{
|
||||
$this->args['order'] = $order;
|
||||
}
|
||||
@@ -139,8 +137,6 @@ public function applyCondition($totalOrSubTotalOrPrice)
|
||||
|
||||
/**
|
||||
* get the calculated value of this condition supplied by the subtotal|price
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCalculatedValue($totalOrSubTotalOrPrice = null): int|float
|
||||
{
|
||||
|
||||
+11
-3
@@ -5,6 +5,14 @@
|
||||
use Illuminate\Support\Collection;
|
||||
use Wearepixel\Cart\Helpers\Helpers;
|
||||
|
||||
/**
|
||||
* @property mixed $id
|
||||
* @property string $name
|
||||
* @property float|int $price
|
||||
* @property int|float $quantity
|
||||
* @property array<string, mixed> $attributes
|
||||
* @property mixed $conditions
|
||||
*/
|
||||
class ItemCollection extends Collection
|
||||
{
|
||||
/**
|
||||
@@ -46,7 +54,7 @@ public function __get($name)
|
||||
/**
|
||||
* return the associated model of an item
|
||||
*
|
||||
* @return bool
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getAssociatedModel()
|
||||
{
|
||||
@@ -97,7 +105,7 @@ public function getConditions()
|
||||
|
||||
// check if we're already an array of CartConditions
|
||||
foreach ($conditions as $key => $condition) {
|
||||
if ($condition instanceof CartCondition) {
|
||||
if (is_object($condition) && $condition instanceof CartCondition) {
|
||||
return $conditions;
|
||||
}
|
||||
}
|
||||
@@ -105,7 +113,7 @@ public function getConditions()
|
||||
$hasSubArray = false;
|
||||
|
||||
foreach ($conditions as $key => $condition) {
|
||||
if (is_array($condition) && ! $condition instanceof CartCondition) {
|
||||
if (is_array($condition)) {
|
||||
$hasSubArray = true;
|
||||
$conditionsArray[] = new CartCondition($condition);
|
||||
} elseif ($condition instanceof CartCondition) {
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
use Illuminate\Translation\FileLoader;
|
||||
use Illuminate\Translation\Translator;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Validation\Validator make(array $data, array $rules, array $messages = [], array $attributes = [])
|
||||
*/
|
||||
abstract class Validator
|
||||
{
|
||||
protected static $factory;
|
||||
|
||||
Reference in New Issue
Block a user