Skip to content

Commit

Permalink
Merge pull request #585 from extcode/task/cleanup_type_hint_in_class_…
Browse files Browse the repository at this point in the history
…properties

[TASK] Cleanup type hint in class properties
  • Loading branch information
extcode authored Oct 16, 2024
2 parents 61ccf31 + f88f5dc commit 56fe34c
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 134 deletions.
4 changes: 2 additions & 2 deletions Classes/Controller/Backend/Order/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public function downloadAction(Item $orderItem, string $pdfType): ResponseInterf
{
$getter = 'get' . ucfirst($pdfType) . 'Pdfs';
$pdfs = $orderItem->$getter();
/** @var File $originalPdf */
$originalPdf = end($pdfs->toArray())->getOriginalResource();
$pdfs = $pdfs->toArray();
$originalPdf = end($pdfs)->getOriginalResource();

if ($originalPdf) {
return $this->responseFactory->createResponse()
Expand Down
5 changes: 4 additions & 1 deletion Classes/Controller/Cart/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@

class CartController extends ActionController
{
protected $defaultViewObjectName = CartTemplateView::class;
public function __construct()
{
$this->defaultViewObjectName = CartTemplateView::class;
}

protected function initializeView(ViewInterface $view): void
{
Expand Down
3 changes: 1 addition & 2 deletions Classes/Controller/Cart/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class OrderController extends ActionController
{
protected function getErrorFlashMessage()
protected function getErrorFlashMessage(): bool|string
{
return LocalizationUtility::translate(
'tx_cart.error.validation',
Expand Down Expand Up @@ -166,7 +166,6 @@ protected function setDynamicValidation(
array $validatorConf
): void {
// build custom validation chain
/** @var ValidatorResolver $validatorResolver */
$validatorResolver = GeneralUtility::makeInstance(
ValidatorResolver::class
);
Expand Down
8 changes: 0 additions & 8 deletions Classes/Controller/Cart/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ class ProductController extends ActionController
{
public const AJAX_CART_TYPE_NUM = '2278001';

/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;

/**
* @param EventDispatcherInterface|null $eventDispatcher
*/
public function __construct(
EventDispatcherInterface $eventDispatcher = null
) {
Expand Down
7 changes: 1 addition & 6 deletions Classes/Domain/Model/Cart/BeVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public function toArray(): array
$innerVariantArr = [];

foreach ($this->beVariants as $variant) {
/** @var BeVariant $variant */
$innerVariantArr[] = [$variant->getId() => $variant->toArray()];
}

Expand Down Expand Up @@ -535,7 +534,6 @@ protected function calcGross(): void
if ($this->beVariants) {
$sum = 0.0;
foreach ($this->beVariants as $beVariant) {
/** @var BeVariant $beVariant */
$sum += $beVariant->getGross();
}
$this->gross = $sum;
Expand Down Expand Up @@ -621,10 +619,7 @@ public function getAdditional(string $key)
return $this->additional[$key];
}

/**
* @param string $key
*/
public function setAdditional($key, mixed $value): void
public function setAdditional(string $key, mixed $value): void
{
$this->additional[$key] = $value;
}
Expand Down
6 changes: 3 additions & 3 deletions Classes/Domain/Model/Cart/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class Cart

protected string $shippingCountry = '';

/**
* @var TaxClass[] $taxClasses
*/
public function __construct(
/**
* @var TaxClass[]
*/
protected array $taxClasses,
protected bool $isNetCart = false,
protected string $currencyCode = 'EUR',
Expand Down
5 changes: 0 additions & 5 deletions Classes/Domain/Model/Cart/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public function addBeVariant(BeVariant $newVariant): void
public function changeVariantsQuantity(array $variantQuantity): void
{
foreach ($variantQuantity as $variantId => $quantity) {
/** @var BeVariant $variant */
$variant = $this->beVariants[$variantId];

if (ctype_digit((string)$quantity)) {
Expand Down Expand Up @@ -172,7 +171,6 @@ public function getBeVariantById(string $variantId): ?BeVariant
public function removeBeVariants(array $variantsArray): int
{
foreach ($variantsArray as $variantId => $value) {
/** @var BeVariant $variant */
$variant = $this->beVariants[$variantId];
if ($variant) {
if (is_array($value)) {
Expand Down Expand Up @@ -554,7 +552,6 @@ protected function calcGross(): void
if ($this->beVariants) {
$sum = 0.0;
foreach ($this->beVariants as $variant) {
/** @var BeVariant $variant */
$sum += $variant->getGross();
}
$this->gross = $sum;
Expand Down Expand Up @@ -583,7 +580,6 @@ protected function calcNet(): void
if ($this->beVariants) {
$sum = 0.0;
foreach ($this->beVariants as $variant) {
/** @var BeVariant $variant */
$sum += $variant->getNet();
}
$this->net = $sum;
Expand All @@ -602,7 +598,6 @@ protected function reCalc(): void
if ($this->beVariants) {
$quantity = 0;
foreach ($this->beVariants as $variant) {
/** @var BeVariant $variant */
$quantity += $variant->getQuantity();
}

Expand Down
1 change: 0 additions & 1 deletion Classes/Domain/Validator/OrderItemValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ protected function getPropertyValue(object $object, string $propertyName): mixed
*/
protected function checkProperty(mixed $value, \Traversable $validators, string $propertyName): void
{
/** @var Result $result */
$result = null;
foreach ($validators as $validator) {
if ($validator instanceof ObjectValidatorInterface) {
Expand Down
3 changes: 0 additions & 3 deletions Classes/Event/CheckProductAvailabilityEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ public function setMessages(array $messages): void
$this->messages = $messages;
}

/**
* @param FlashMessage $message
*/
public function addMessage(FlashMessage $message): void
{
$this->messages[] = $message;
Expand Down
15 changes: 3 additions & 12 deletions Classes/EventListener/Order/Create/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,11 @@

abstract class Number
{
/**
* @var PersistenceManager
*/
protected $persistenceManager;
protected PersistenceManager $persistenceManager;

/**
* @var OrderItemRepository
*/
protected $orderItemRepository;
protected OrderItemRepository $orderItemRepository;

/**
* @var array
*/
protected $options;
protected array $options;

abstract protected function getRegistryName(NumberGeneratorEventInterface $event): string;

Expand Down
8 changes: 5 additions & 3 deletions Classes/EventListener/Order/Create/PersistOrder/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Extcode\Cart\Domain\Repository\Order\ShippingAddressRepository;
use Extcode\Cart\Event\Order\PersistOrderEvent;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\UserAspect;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;

Expand All @@ -38,10 +39,11 @@ public function __invoke(PersistOrderEvent $event): void

$orderItem->setPid($storagePid);

/** @var $userAspect */
$userAspect = GeneralUtility::makeInstance(Context::class)->getAspect('frontend.user');

if ($userAspect->isLoggedIn()) {
if (
$userAspect instanceof UserAspect &&
$userAspect->isLoggedIn()
) {
$frontendUserRepository = GeneralUtility::makeInstance(
FrontendUserRepository::class
);
Expand Down
11 changes: 0 additions & 11 deletions Classes/EventListener/Order/Create/PersistOrder/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ protected function addProduct(Product $cartProduct): void
protected function addProductVariants(Product $product): void
{
foreach ($product->getBeVariants() as $variant) {
/**
* Cart Variant
* @var BeVariant $variant
*/
if ($variant->getBeVariants()) {
$this->addVariantsOfVariant($variant, 1);
} else {
Expand Down Expand Up @@ -116,9 +112,6 @@ protected function addProductAdditional(
\Extcode\Cart\Domain\Model\Order\Product $product,
array $feVariant
): void {
/**
* @var ProductAdditional $productAdditional
*/
$productAdditional = GeneralUtility::makeInstance(
ProductAdditional::class,
$productAdditionalType,
Expand All @@ -138,10 +131,6 @@ protected function addVariantsOfVariant(BeVariant $variant, int $level): void
$level += 1;

foreach ($variant->getBeVariants() as $variantInner) {
/**
* Cart Variant Inner
* @var BeVariant $variantInner
*/
if ($variantInner->getBeVariants()) {
$this->addVariantsOfVariant($variantInner, $level);
} else {
Expand Down
16 changes: 3 additions & 13 deletions Classes/Hooks/ItemsProcFunc.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

class ItemsProcFunc
{
/** @var TemplateLayout $templateLayoutsUtility */
protected $templateLayoutsUtility;
protected TemplateLayout $templateLayoutsUtility;

public function __construct()
{
Expand All @@ -34,8 +33,6 @@ public function __construct()

/**
* Itemsproc function to extend the selection of templateLayouts in the plugin
*
* @param array &$config configuration array
*/
public function user_templateLayout(array &$config): void
{
Expand Down Expand Up @@ -99,12 +96,8 @@ protected function getExtKey($listType)

/**
* Reduce the template layouts by the ones that are not allowed in given colPos
*
* @param array $templateLayouts
* @param int $currentColPos
* @return array
*/
protected function reduceTemplateLayouts($templateLayouts, $currentColPos)
protected function reduceTemplateLayouts(array $templateLayouts, int $currentColPos): array
{
$currentColPos = (int)$currentColPos;
$restrictions = [];
Expand Down Expand Up @@ -132,11 +125,8 @@ protected function reduceTemplateLayouts($templateLayouts, $currentColPos)

/**
* Get page id, if negative, then it is a "after record"
*
* @param int $pid
* @return int
*/
protected function getPageId($pid)
protected function getPageId(int $pid): int
{
$pid = (int)$pid;

Expand Down
10 changes: 0 additions & 10 deletions Classes/Utility/CartUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

use Extcode\Cart\Domain\Model\Cart\Cart;
use Extcode\Cart\Domain\Model\Cart\Service;
use Extcode\Cart\Event\Cart\UpdateCountryEvent;
use Extcode\Cart\Service\PaymentMethodsServiceInterface;
use Extcode\Cart\Service\SessionHandler;
Expand Down Expand Up @@ -98,7 +97,6 @@ public function getNewCart(array $configurations): Cart

$taxClasses = $this->taxClassService->getTaxClasses($defaultCountry);

/** @var Cart $cart */
$cart = GeneralUtility::makeInstance(
Cart::class,
$taxClasses,
Expand All @@ -125,10 +123,6 @@ protected function setShipping(Cart $cart): void
$shippings = $this->shippingMethodsService->getShippingMethods($cart);

foreach ($shippings as $shipping) {
/**
* Shipping
* @var Service $shipping
*/
if ($shipping->isPreset()) {
if (!$shipping->isAvailable()) {
$fallBackId = $shipping->getFallBackId();
Expand All @@ -145,10 +139,6 @@ protected function setPayment(Cart $cart): void
$payments = $this->paymentMethodsService->getPaymentMethods($cart);

foreach ($payments as $payment) {
/**
* Payment
* @var Service $payment
*/
if ($payment->isPreset()) {
if (!$payment->isAvailable()) {
$fallBackId = $payment->getFallBackId();
Expand Down
13 changes: 2 additions & 11 deletions Classes/Utility/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ class TemplateLayout implements SingletonInterface
{
/**
* Get available template layouts for a certain page
*
* @param int $pageUid
* @param string $extKey
* @param string $pluginName
* @return array
*/
public function getAvailableTemplateLayouts($pageUid, $extKey, $pluginName)
public function getAvailableTemplateLayouts(int $pageUid, string $extKey, string $pluginName): array
{
$templateLayouts = [];
$pluginName = GeneralUtility::camelCaseToLowerCaseUnderscored($pluginName);
Expand Down Expand Up @@ -57,12 +52,8 @@ public function getAvailableTemplateLayouts($pageUid, $extKey, $pluginName)

/**
* Get template layouts defined in TsConfig
*
* @param $pageUid
* @param string $pluginName
* @return array
*/
protected function getTemplateLayoutsFromTsConfig($pageUid, $extKey, $pluginName)
protected function getTemplateLayoutsFromTsConfig(int $pageUid, string $extKey, string $pluginName): array
{
$templateLayouts = [];
$pagesTsConfig = BackendUtility::getPagesTSconfig($pageUid);
Expand Down
7 changes: 1 addition & 6 deletions Classes/ViewHelpers/FieldNameViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ public function render()
return $fieldName;
}

/**
* @param BeVariant $variant
*
* @return string
*/
protected function getVariantFieldName($variant)
protected function getVariantFieldName(BeVariant $variant): string
{
$fieldName = '';

Expand Down
14 changes: 4 additions & 10 deletions Classes/ViewHelpers/Format/CurrencyViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@

class CurrencyViewHelper extends AbstractViewHelper
{
/**
* @var ConfigurationManager
*/
protected $configurationManager;

public function __construct(ConfigurationManager $configurationManager)
{
$this->configurationManager = $configurationManager;
}
public function __construct(
protected readonly ConfigurationManager $configurationManager
) {}

/**
* Output is escaped already. We must not escape children, to avoid double encoding.
Expand Down Expand Up @@ -82,7 +76,7 @@ public function initializeArguments(): void
/**
* @return string the formatted amount.
*/
public function render()
public function render(): string
{
if ($this->hasArgument('currencySign')) {
$currencySign = $this->arguments['currencySign'];
Expand Down
Loading

0 comments on commit 56fe34c

Please sign in to comment.