Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pes 2155 phpstan lvl 2 #84

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packetery/Checkout/Controller/Adminhtml/Order/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function execute(): AbstractResult
return $this->resultRedirectFactory->create()->setPath('*/*/index');
}

/** @var \Magento\Framework\View\Element\AbstractBlock $addressDetailBlock */
$addressDetailBlock = $resultPage->getLayout()->getBlock('packetery_order_address_detail');
$addressDetailBlock->setData('order', $order);
$addressDetailBlock->setData('magentoOrder', $magentoOrder);
Expand Down
8 changes: 8 additions & 0 deletions Packetery/Checkout/Model/Carrier/AbstractCarrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public function __construct(
$this->packeteryConfig = $brain->createConfig($this);
}

/**
* @return mixed
*/
public function getStore()
{
return parent::getStore();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function isAssignableToPricingRule(): bool

/**
* @param int|null $dynamicCarrierId
* @return \Packetery\Checkout\Model\Carrier|null
* @return \Packetery\Checkout\Model\Carrier\Imp\PacketeryPacketaDynamic\DynamicCarrier|null
*/
public function getDynamicCarrierById(?int $dynamicCarrierId): ?AbstractDynamicCarrier
{
Expand Down
8 changes: 8 additions & 0 deletions Packetery/Checkout/Model/ResourceModel/Order/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ protected function _construct()
$this->_init('Packetery\Checkout\Model\Order', 'Packetery\Checkout\Model\ResourceModel\Order');
}

/**
* @return \Packetery\Checkout\Model\Order[]
*/
public function getItems()
{
return parent::getItems();
}

/**
* @return string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@ public function savePricingRule(array $postData, array $weightRules): \Packetery
*/
public function setPricingRuleEnabled(int $id, bool $enabled): void
{
$rule = $this->pricingRuleCollectionFactory->create()->getItemById($id);
$rule->setData('enabled', $enabled);
$rule->save();
/** @var \Packetery\Checkout\Model\ResourceModel\Pricingrule\Collection $collection */
$collection = $this->pricingRuleCollectionFactory->create();
$collection->addFilter('id', $id);
$collection->setDataToAll('enabled', $enabled);
$collection->save();
}

/**
Expand Down
4 changes: 0 additions & 4 deletions Packetery/Checkout/Model/Weight/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@ public function getItemsWeight(array $allVisibleItems): float

foreach ($allVisibleItems as $item) {
if ($item->getProductType() === 'configurable') {
/** @var \Magento\Catalog\Model\Product $configurableProduct */
$configurableProduct = $item->getProduct();
if ($configurableProduct->isVirtual()) {
$configurableWeight = 0.0;
} else {
$configurableWeight = $configurableProduct->getWeight();
}

/** @var Item[] $children */
$children = ($item->getChildren() ?: []); // contains only ordered items
foreach ($children as $child) {
/** @var \Magento\Catalog\Model\Product $childProduct */
$childProduct = $child->getProduct();
if ($childProduct->isVirtual()) {
$productWeights[$childProduct->getId()] = 0.0;
Expand All @@ -62,7 +59,6 @@ public function getItemsWeight(array $allVisibleItems): float
}

foreach ($allVisibleItems as $item) {
/** @var \Magento\Catalog\Model\Product $product */
$product = $item->getProduct();
if ($item->getProductType() === 'simple' && !array_key_exists($product->getId(), $productWeights)) {
if ($product->isVirtual()) {
Expand Down
32 changes: 32 additions & 0 deletions Packetery/Checkout/Model/Weight/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,36 @@ public static function fromOrderItem(\Magento\Sales\Model\Order\Item $item): sel

return $instance;
}

/**
* @return string
*/
public function getProductType()
{
return parent::getProductType();
}

/**
* @return self[]
*/
public function getChildren()
{
return $this->getData('children');
}

/**
* @return int
*/
public function getQty()
{
return $this->getData('qty');
}

/**
* @return \Magento\Catalog\Model\Product
*/
public function getProduct()
{
return $this->getData('product');
}
}
1 change: 1 addition & 0 deletions Packetery/Checkout/Observer/Sales/AddressPlaceAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function execute(
\Magento\Framework\Event\Observer $observer
) {
$orderId = $observer->getData('order_id');
/** @var \Magento\Sales\Model\Order $order */
$order = $this->orderRepository->get($orderId);
$orderNumber = $order->getIncrementId();
$shippingAddress = $order->getShippingAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
$order = $transport['order'];
$collection = $this->orderCollectionFactory->create();
$collection->addFilter('order_number', $order->getData('increment_id'));
/** @var \Packetery\Checkout\Model\Order|null $packeteryOrder */
$items = ( $collection->getItems() ?: [] );
/** @var \Packetery\Checkout\Model\Order|null $packeteryOrder */
$packeteryOrder = array_shift($items);

$transport['packetery_is_pickup_point'] = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/** @var \Packetery\Checkout\Block\Adminhtml\Order\AddressDetail $block */
/** @var \Magento\Framework\View\Element\AbstractBlock $block */
/** @var \Packetery\Checkout\Model\Order $packeteryOrder */
$packeteryOrder = $block->getData('order');
$packeteryMagentoOrder = $block->getData('magentoOrder');
Expand Down
5 changes: 4 additions & 1 deletion phpstan-config.neon
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
parameters:
bootstrapFiles:
- phpstan-autoload.php
level: 1
level: 2
fileExtensions:
- php
- phtml
paths:
- ./Packetery/Checkout
ignoreErrors:
- '#Call to an undefined method Magento\\(.*)+\(\)\.#' # It is typical for Magento related code to use PHP magic.
- '#Call to an undefined static method Magento\\(.*)+\(\)\.#'