Skip to content

Commit

Permalink
Merge pull request #587 from extcode/task/raise_phpstan_level
Browse files Browse the repository at this point in the history
Task/raise phpstan level
  • Loading branch information
extcode authored Oct 16, 2024
2 parents f6853a4 + 2509493 commit cb2a245
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 32 deletions.
26 changes: 26 additions & 0 deletions Build/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions Build/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
includes:
- phpstan-baseline.neon
parameters:
level: 1
level: 4
paths:
- ../Classes
- ../Configuration
- ../Tests
- ../ext_emconf.php
- ../ext_localconf.php
- ../ext_localconf.php
2 changes: 1 addition & 1 deletion Classes/Controller/Backend/ActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions Classes/Controller/Cart/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand Down Expand Up @@ -131,7 +130,6 @@ public function showAction(

$currentStepHasError = false;
if ($extbaseAttribute instanceof ExtbaseRequestParameters
&& $extbaseAttribute->getOriginalRequestMappingResults()
&& $extbaseAttribute->getOriginalRequestMappingResults()->hasErrors()
) {
$currentStepHasError = true;
Expand Down
4 changes: 0 additions & 4 deletions Classes/Domain/Model/Cart/BeVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 3 additions & 10 deletions Classes/Domain/Model/Cart/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ class Cart

protected string $shippingCountry = '';

/**
* @var TaxClass[] $taxClasses
*/
public function __construct(
protected array $taxClasses,
protected bool $isNetCart = false,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions Classes/EventListener/Order/Create/PersistOrder/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 0 additions & 4 deletions Tests/Unit/Domain/Model/Cart/BeVariantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 9 additions & 7 deletions Tests/Unit/Domain/Model/Order/AbstractAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -604,6 +609,7 @@ public function additionalIsInternallyJsonString(): void
'additional' => true,
];

/** @var AccessibleObjectInterface&MockObject&AbstractAddress $address */
$address = $this->getAccessibleMock(
AbstractAddress::class,
[],
Expand Down Expand Up @@ -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
*/
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Domain/Model/Product/AbstractProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#[CoversClass(AbstractProduct::class)]
class AbstractProductTest extends UnitTestCase
{
/**
* @var MockObject&AbstractProduct
*/
protected MockObject $product;

public function setUp(): void
Expand Down
6 changes: 5 additions & 1 deletion Tests/Unit/Validation/Validator/EmptyValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit cb2a245

Please sign in to comment.