diff --git a/Build/phpstan-baseline.neon b/Build/phpstan-baseline.neon new file mode 100644 index 00000000..2c4057f4 --- /dev/null +++ b/Build/phpstan-baseline.neon @@ -0,0 +1,26 @@ +parameters: + ignoreErrors: + - + message: "#^Call to an undefined method Extcode\\\\Cart\\\\Service\\\\PaymentMethodsServiceInterface\\:\\:getConfigurationsForType\\(\\)\\.$#" + count: 1 + path: ../Classes/Controller/Cart/OrderController.php + + - + message: "#^Call to an undefined method Extcode\\\\Cart\\\\Domain\\\\Model\\\\Cart\\\\CartCouponInterface\\:\\:getTaxClass\\(\\)\\.$#" + count: 2 + path: ../Classes/Domain/Model/Cart/Cart.php + + - + message: "#^Call to an undefined method Extcode\\\\Cart\\\\Domain\\\\Model\\\\Cart\\\\CartCouponInterface\\:\\:setCart\\(\\)\\.$#" + count: 1 + path: ../Classes/Domain/Model/Cart/Cart.php + + - + message: "#^Call to an undefined method Extcode\\\\Cart\\\\Service\\\\PaymentMethodsServiceInterface\\:\\:getConfigurationsForType\\(\\)\\.$#" + count: 1 + path: ../Classes/EventListener/Order/Finish/ClearCart.php + + - + message: "#^Call to an undefined method TYPO3Fluid\\\\Fluid\\\\Core\\\\Rendering\\\\RenderingContextInterface\\:\\:getRequest\\(\\)\\.$#" + count: 1 + path: ../Classes/View/CartTemplateView.php diff --git a/Build/phpstan.neon b/Build/phpstan.neon index 6799cd10..13c67700 100644 --- a/Build/phpstan.neon +++ b/Build/phpstan.neon @@ -1,8 +1,10 @@ +includes: + - phpstan-baseline.neon parameters: - level: 1 + level: 4 paths: - ../Classes - ../Configuration - ../Tests - ../ext_emconf.php - - ../ext_localconf.php \ No newline at end of file + - ../ext_localconf.php diff --git a/Classes/Controller/Backend/ActionController.php b/Classes/Controller/Backend/ActionController.php index c3f3f8e8..2a8fcbd5 100644 --- a/Classes/Controller/Backend/ActionController.php +++ b/Classes/Controller/Backend/ActionController.php @@ -26,7 +26,7 @@ protected function initializeAction(): void ConfigurationManager::CONFIGURATION_TYPE_FRAMEWORK ); - $pageId = (int)$this->request->getQueryParams()['id'] ?? 1; + $pageId = (int)($this->request->getQueryParams()['id'] ?? 1); BackendUtility::readPageAccess( $pageId, diff --git a/Classes/Controller/Cart/CartController.php b/Classes/Controller/Cart/CartController.php index e9949b01..7224e066 100755 --- a/Classes/Controller/Cart/CartController.php +++ b/Classes/Controller/Cart/CartController.php @@ -20,7 +20,6 @@ use Psr\Http\Message\ResponseInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters; -use TYPO3Fluid\Fluid\View\ViewInterface; class CartController extends ActionController { @@ -29,7 +28,7 @@ public function __construct() $this->defaultViewObjectName = CartTemplateView::class; } - protected function initializeView(ViewInterface $view): void + protected function initializeView(CartTemplateView $view): void { if ($this->request->getControllerActionName() !== 'show') { return; @@ -131,7 +130,6 @@ public function showAction( $currentStepHasError = false; if ($extbaseAttribute instanceof ExtbaseRequestParameters - && $extbaseAttribute->getOriginalRequestMappingResults() && $extbaseAttribute->getOriginalRequestMappingResults()->hasErrors() ) { $currentStepHasError = true; diff --git a/Classes/Domain/Model/Cart/BeVariant.php b/Classes/Domain/Model/Cart/BeVariant.php index ee1ffbdd..43fd6300 100644 --- a/Classes/Domain/Model/Cart/BeVariant.php +++ b/Classes/Domain/Model/Cart/BeVariant.php @@ -11,12 +11,8 @@ * LICENSE file that was distributed with this source code. */ -use Psr\EventDispatcher\EventDispatcherInterface; - class BeVariant { - private ?EventDispatcherInterface $eventDispatcher = null; - protected ?Product $product = null; protected ?BeVariant $parentBeVariant = null; diff --git a/Classes/Domain/Model/Cart/Cart.php b/Classes/Domain/Model/Cart/Cart.php index 1a465f5d..915929ab 100644 --- a/Classes/Domain/Model/Cart/Cart.php +++ b/Classes/Domain/Model/Cart/Cart.php @@ -66,9 +66,6 @@ class Cart protected string $shippingCountry = ''; - /** - * @var TaxClass[] $taxClasses - */ public function __construct( protected array $taxClasses, protected bool $isNetCart = false, @@ -576,7 +573,7 @@ public function addCoupon(CartCouponInterface $coupon): int public function removeCoupon(string $couponCode): int { - if (!$this->coupons[$couponCode]) { + if (!isset($this->coupons[$couponCode])) { return -1; } @@ -718,7 +715,7 @@ public function changeProductsQuantity(array $productQuantityArray): void foreach ($productQuantityArray as $productPuid => $quantity) { $product = $this->products[$productPuid]; - if ($product) { + if ($product instanceof Product) { if (is_array($quantity)) { $this->subCount($product->getQuantity()); $this->subGross($product->getGross()); @@ -763,11 +760,7 @@ public function removeProductByIds(array $products): bool } $product = $this->products[$productId]; - if ($product) { - $this->removeProduct($product, $products[$productId]); - } else { - return false; - } + $this->removeProduct($product, $products[$productId]); $this->updateServiceAttributes(); diff --git a/Classes/EventListener/Order/Create/PersistOrder/Item.php b/Classes/EventListener/Order/Create/PersistOrder/Item.php index 8dd4d45b..684ee469 100644 --- a/Classes/EventListener/Order/Create/PersistOrder/Item.php +++ b/Classes/EventListener/Order/Create/PersistOrder/Item.php @@ -40,6 +40,7 @@ public function __invoke(PersistOrderEvent $event): void $orderItem->setPid($storagePid); $userAspect = GeneralUtility::makeInstance(Context::class)->getAspect('frontend.user'); + if ( $userAspect instanceof UserAspect && $userAspect->isLoggedIn() diff --git a/Tests/Unit/Domain/Model/Cart/BeVariantTest.php b/Tests/Unit/Domain/Model/Cart/BeVariantTest.php index 70998490..dd255dde 100644 --- a/Tests/Unit/Domain/Model/Cart/BeVariantTest.php +++ b/Tests/Unit/Domain/Model/Cart/BeVariantTest.php @@ -526,10 +526,6 @@ protected function getAccessibleMock( bool $callOriginalClone = true, bool $callAutoload = true ) { - if ($originalClassName === '') { - throw new \InvalidArgumentException('$originalClassName must not be empty.', 1334701880); - } - $mockBuilder = $this->getMockBuilder($this->buildAccessibleProxy($originalClassName)) ->onlyMethods($methods) ->setConstructorArgs($arguments) diff --git a/Tests/Unit/Domain/Model/Order/AbstractAddressTest.php b/Tests/Unit/Domain/Model/Order/AbstractAddressTest.php index 2450f4c6..c0fd98e1 100644 --- a/Tests/Unit/Domain/Model/Order/AbstractAddressTest.php +++ b/Tests/Unit/Domain/Model/Order/AbstractAddressTest.php @@ -13,12 +13,17 @@ use Extcode\Cart\Domain\Model\Order\Item; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\MockObject\MockObject; +use TYPO3\TestingFramework\Core\AccessibleObjectInterface; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; #[CoversClass(AbstractAddress::class)] class AbstractAddressTest extends UnitTestCase { - protected AbstractAddress $address; + /** + * @var MockObject&AbstractAddress + */ + protected MockObject $address; public function setUp(): void { @@ -604,6 +609,7 @@ public function additionalIsInternallyJsonString(): void 'additional' => true, ]; + /** @var AccessibleObjectInterface&MockObject&AbstractAddress $address */ $address = $this->getAccessibleMock( AbstractAddress::class, [], @@ -641,7 +647,7 @@ public function additionalIsInternallyJsonString(): void * @param bool $callOriginalClone whether to call the __clone method * @param bool $callAutoload whether to call any autoload function * - * @return MockObject&AccessibleObjectInterface&T a mock of `$originalClassName` with access methods added + * @return MockObject&AccessibleObjectInterface * * @throws \InvalidArgumentException */ @@ -653,11 +659,7 @@ protected function getAccessibleMock( bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true - ) { - if ($originalClassName === '') { - throw new \InvalidArgumentException('$originalClassName must not be empty.', 1334701880); - } - + ): MockObject { $mockBuilder = $this->getMockBuilder($this->buildAccessibleProxy($originalClassName)) ->addMethods($methods) ->setConstructorArgs($arguments) diff --git a/Tests/Unit/Domain/Model/Product/AbstractProductTest.php b/Tests/Unit/Domain/Model/Product/AbstractProductTest.php index 4d7974bb..3e6d68ef 100644 --- a/Tests/Unit/Domain/Model/Product/AbstractProductTest.php +++ b/Tests/Unit/Domain/Model/Product/AbstractProductTest.php @@ -18,6 +18,9 @@ #[CoversClass(AbstractProduct::class)] class AbstractProductTest extends UnitTestCase { + /** + * @var MockObject&AbstractProduct + */ protected MockObject $product; public function setUp(): void diff --git a/Tests/Unit/Validation/Validator/EmptyValidatorTest.php b/Tests/Unit/Validation/Validator/EmptyValidatorTest.php index d9a202ba..f86974e2 100644 --- a/Tests/Unit/Validation/Validator/EmptyValidatorTest.php +++ b/Tests/Unit/Validation/Validator/EmptyValidatorTest.php @@ -11,6 +11,7 @@ use Extcode\Cart\Validation\Validator\EmptyValidator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\MockObject\MockObject; use TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; @@ -39,10 +40,13 @@ protected function validatorOptions(array $options): void public function setUp(): void { - $this->validator = $this->getMockBuilder($this->validatorClassName) + /** @var MockObject&EmptyValidator $validator */ + $validator = $this->getMockBuilder($this->validatorClassName) ->onlyMethods(['translateErrorMessage']) ->getMock(); + $this->validator = $validator; + parent::setUp(); }