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

[ECP-9489] Implement PHPStan and fix relevant issues #2843

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ccc53ca
[ECP-9489] Fix dynamic property declaration issues
Jan 3, 2025
7789747
[ECP-9489] Fix dynamic property declaration issues
Jan 6, 2025
2cd445a
[ECP-9489] Implement PHPStan analyses on the main workflow
Jan 6, 2025
f201e8d
[ECP-9489] Add missing class import
Jan 6, 2025
501675f
[ECP-9489] Add missing argument for sprintf
Jan 6, 2025
77a1c9b
[ECP-9489] Add missing return values
Jan 6, 2025
5cf2cf2
[ECP-9489] Use constructor argument instead of method for setting up …
Jan 6, 2025
60a9c7e
[ECP-9489] Use repository instead of model class to save/load the ent…
Jan 6, 2025
d484e46
[ECP-9489] Use object manager to load Invoice entity class
Jan 14, 2025
b1169fa
[ECP-9489] Remove unused constructor argument
Jan 14, 2025
c350101
[ECP-9489] Implement repository for Adyen Invoice model
Jan 14, 2025
c39e109
[ECP-9489] Remove unused constructor arguments
Jan 14, 2025
b085fb6
[ECP-9489] Fix unit tests
Jan 14, 2025
100d6aa
[ECP-9489] Use MaskedQuoteIdToQuoteIdInterface for resolving masked c…
Jan 14, 2025
f13e7df
[ECP-9489] Fix unit tests
Jan 15, 2025
47d5ea4
[ECP-9489] Fix PHPStan workflow
Jan 15, 2025
3514bd8
[ECP-9489] Add PHPStan config file to exclude vendor dir
Jan 15, 2025
fd4818c
[ECP-9489] Fix formatting
Jan 15, 2025
0cc71ea
[ECP-9489] Adjust PHPStan configuration
Jan 15, 2025
3856f44
[ECP-9489] Adjust PHPStan configuration
Jan 15, 2025
064d6b8
[ECP-9489] Adjust PHPStan configuration
Jan 15, 2025
596afdc
[ECP-9489] Adjust PHPStan configuration
Jan 15, 2025
f3fbfc5
[ECP-9489] Adjust PHPStan workflow
Jan 15, 2025
46b299a
[ECP-9489] Update PHPDocs for the interface
Jan 15, 2025
4203483
[ECP-9489] Implement AdyenCreditmemoRepository and deprecated old met…
Jan 15, 2025
a500de6
[ECP-9489] Update PHPDocs
Jan 15, 2025
1e0fe84
[ECP-9489] Skip class.notFound errors for pseudo test classes
Jan 16, 2025
894b9e3
[ECP-9489] Fix DB initialization parameters
Jan 16, 2025
9215392
[ECP-9489] Implement AdyenOrderPaymentRepository
Jan 17, 2025
3856ca6
Merge remote-tracking branch 'origin/main' into ECP-9489
Jan 20, 2025
ab2c6ff
[ECP-9489] Update unit tests
Jan 21, 2025
85b5b9a
[ECP-9489] Update unit tests
Jan 21, 2025
13aed2d
[ECP-9489] Update unit tests
Jan 21, 2025
ad675ad
[ECP-9489] Update unit tests
Jan 21, 2025
dbfe659
[ECP-9489] Update unit tests
Jan 21, 2025
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
46 changes: 46 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: PHPStan analysis

on:
pull_request:
pull_request_target:
workflow_dispatch:

jobs:
build:
if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) || (github.event_name == 'workflow_dispatch')
environment: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) && 'external' || 'internal' }}
runs-on: ubuntu-latest

strategy:
matrix:
php-version: [8.2,8.3]

steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
fetch-depth: 0

- name: Use PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer:v2

- name: Test plugin installation
run: |
echo "{\"http-basic\":{\"repo.magento.com\":{\"username\":\"${MAGENTO_USERNAME}\",\"password\":\"${MAGENTO_PASSWORD}\"}}}" > auth.json
composer install --prefer-dist
env:
CI: true
MAGENTO_USERNAME: ${{ secrets.MAGENTO_USERNAME }}
MAGENTO_PASSWORD: ${{ secrets.MAGENTO_PASSWORD }}

- name: Install Magento PHPStan dependecies
run: |
composer require --dev bitexpert/phpstan-magento
composer config allow-plugins.phpstan/extension-installer true
composer require --dev phpstan/extension-installer

- name: PHPStan
run: vendor/bin/phpstan analyse -c phpstan.neon
66 changes: 66 additions & 0 deletions Api/Repository/AdyenCreditmemoRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
*
* Adyen Payment Module
*
* Copyright (c) 2025 Adyen N.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Api\Repository;

use Adyen\Payment\Api\Data\CreditmemoInterface;
use Adyen\Payment\Api\Data\NotificationInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Api\SearchResultsInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;

interface AdyenCreditmemoRepositoryInterface
{
/**
* Retrieve adyen_creditmemo entity by the ID.
*
* @param int $entityId
* @return CreditmemoInterface Adyen creditmemo entity
* @throws NoSuchEntityException
*/
public function get(int $entityId): CreditmemoInterface;

/**
* Retrieve adyen_creditmemo entities by `adyen_order_payment_id`.
*
* @param int $adyenOrderPaymentId
* @return CreditmemoInterface[]|null
*/
public function getByAdyenOrderPaymentId(int $adyenOrderPaymentId): ?array;

/**
* Retrieve adyen_creditmemo entity by the given notification using the `pspreference` column.
*
* @param NotificationInterface $notification
* @return CreditmemoInterface|null
*/
public function getByRefundWebhook(NotificationInterface $notification): ?CreditmemoInterface;

/**
* Retrieve adyen_creditmemo entities which match a specified criteria.
*
* @param SearchCriteriaInterface $searchCriteria
* @return SearchResultsInterface
*
* @throws LocalizedException
*/
public function getList(SearchCriteriaInterface $searchCriteria): SearchResultsInterface;

/**
* Performs persist operations for a specified adyen_creditmemo.
*
* @param CreditmemoInterface $entity adyen_creditmemo entity.
* @return CreditmemoInterface
*/
public function save(CreditmemoInterface $entity): CreditmemoInterface;
}
56 changes: 56 additions & 0 deletions Api/Repository/AdyenInvoiceRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
*
* Adyen Payment Module
*
* Copyright (c) 2025 Adyen N.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Api\Repository;

use Adyen\Payment\Api\Data\InvoiceInterface;
use Adyen\Payment\Api\Data\NotificationInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Api\SearchResultsInterface;
use Magento\Framework\Exception\LocalizedException;

interface AdyenInvoiceRepositoryInterface
{
/**
* Retrieve adyen_invoice entities which match a specified criteria.
*
* @param SearchCriteriaInterface $searchCriteria
* @return SearchResultsInterface
*
* @throws LocalizedException
*/
public function getList(SearchCriteriaInterface $searchCriteria): SearchResultsInterface;

/**
* Retrieve adyen_invoice entity by the given notification using the `pspreference` column.
*
* @param NotificationInterface $notification
* @return InvoiceInterface|null
*/
public function getByCaptureWebhook(NotificationInterface $notification): ?InvoiceInterface;

/**
* Retrieve adyen_invoice entities by `adyen_order_payment_id`.
*
* @param int $adyenOrderPaymentId
* @return InvoiceInterface[]|null
*/
public function getByAdyenOrderPaymentId(int $adyenOrderPaymentId): ?array;

/**
* Performs persist operations for a specified adyen_invoice.
*
* @param InvoiceInterface $entity adyen_invoice entity
* @return InvoiceInterface
*/
public function save(InvoiceInterface $entity): InvoiceInterface;
}
57 changes: 57 additions & 0 deletions Api/Repository/AdyenOrderPaymentRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
*
* Adyen Payment Module
*
* Copyright (c) 2025 Adyen N.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Api\Repository;

use Adyen\Payment\Api\Data\OrderPaymentInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Api\SearchResultsInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;

interface AdyenOrderPaymentRepositoryInterface
{
const AVAILABLE_CAPTURE_STATUSES = [
OrderPaymentInterface::CAPTURE_STATUS_AUTO_CAPTURE,
OrderPaymentInterface::CAPTURE_STATUS_MANUAL_CAPTURE,
OrderPaymentInterface::CAPTURE_STATUS_PARTIAL_CAPTURE,
OrderPaymentInterface::CAPTURE_STATUS_NO_CAPTURE
];

/**
* Retrieve adyen_order_payment entity by the ID.
*
* @param int $entityId
* @return OrderPaymentInterface Adyen order payment entity
* @throws NoSuchEntityException
*/
public function get(int $entityId): OrderPaymentInterface;

/**
* Retrieve adyen_order_payment entities by `payment_id`.
*
* @param int $paymentId
* @param array $captureStatuses
* @return OrderPaymentInterface[]|null
*/
public function getByPaymentId(int $paymentId, array $captureStatuses = []): ?array;

/**
* Retrieve adyen_order_payment entities which match a specified criteria.
*
* @param SearchCriteriaInterface $searchCriteria
* @return SearchResultsInterface
*
* @throws LocalizedException
*/
public function getList(SearchCriteriaInterface $searchCriteria): SearchResultsInterface;
}
59 changes: 11 additions & 48 deletions Block/Checkout/Multishipping/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Adyen\Payment\Helper\Config;
use Adyen\Payment\Helper\PaymentMethods;
use Adyen\Payment\Helper\PaymentResponseHandler;
use Adyen\Payment\Model\PaymentResponse;
use Adyen\Payment\Model\ResourceModel\PaymentResponse\Collection;
use Adyen\Payment\Model\Ui\AdyenCheckoutSuccessConfigProvider;
use Magento\Framework\Api\SearchCriteriaBuilder;
Expand All @@ -28,53 +27,17 @@

class Success extends \Magento\Multishipping\Block\Checkout\Success
{
/**
* @var bool
*/
private $isAdyenPayment;

/**
* @var PaymentResponse[]
*/
private $paymentResponseEntities;

/**
* @var Data
*/
private $adyenHelper;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @var SerializerInterface
*/
private $serializerInterface;

/**
* @var AdyenCheckoutSuccessConfigProvider
*/
private $configProvider;

/**
* @var OrderRepositoryInterface
*/
private $orderRepository;

/**
* @var SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;


private $configHelper;

/**
* @var []
*/
private $ordersInfo;
private bool $isAdyenPayment;
private ?array $paymentResponseEntities;
private ?array $ordersInfo;
private Data $adyenHelper;
private StoreManagerInterface $storeManager;
private SerializerInterface $serializerInterface;
private AdyenCheckoutSuccessConfigProvider $configProvider;
private OrderRepositoryInterface $orderRepository;
private SearchCriteriaBuilder $searchCriteriaBuilder;
private Config $configHelper;
private PaymentMethods $paymentMethodsHelper;

public function __construct(
Collection $paymentResponseCollection,
Expand Down
14 changes: 10 additions & 4 deletions Block/Checkout/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,42 @@
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\OrderFactory;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Sales\Model\OrderFactory;

class Success extends Template
{
protected $order;
protected CheckoutSession $checkoutSession;
protected CustomerSession $customerSession;
protected OrderFactory $orderFactory;
protected Data $adyenHelper;
protected StoreManagerInterface $storeManager;
private Config $configHelper;
private SerializerInterface $serializerInterface;
private AdyenCheckoutSuccessConfigProvider $configProvider;
private QuoteIdToMaskedQuoteId $quoteIdToMaskedQuoteId;
private OrderRepositoryInterface $orderRepository;
/** @deprecated This property has been deprecated and will be removed on V10. */
protected OrderFactory $orderFactory;

Check failure on line 43 in Block/Checkout/Success.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Property Adyen\Payment\Block\Checkout\Success::$orderFactory has unknown class Magento\Sales\Model\OrderFactory as its type.

Check failure on line 43 in Block/Checkout/Success.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Property Adyen\Payment\Block\Checkout\Success::$orderFactory has unknown class Magento\Sales\Model\OrderFactory as its type.

public function __construct(
Context $context,
CheckoutSession $checkoutSession,
CustomerSession $customerSession,
QuoteIdToMaskedQuoteId $quoteIdToMaskedQuoteId,
OrderFactory $orderFactory,

Check failure on line 50 in Block/Checkout/Success.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Parameter $orderFactory of method Adyen\Payment\Block\Checkout\Success::__construct() has invalid type Magento\Sales\Model\OrderFactory.

Check failure on line 50 in Block/Checkout/Success.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Parameter $orderFactory of method Adyen\Payment\Block\Checkout\Success::__construct() has invalid type Magento\Sales\Model\OrderFactory.
Data $adyenHelper,
Config $configHelper,
AdyenCheckoutSuccessConfigProvider $configProvider,
StoreManagerInterface $storeManager,
SerializerInterface $serializerInterface,
OrderRepositoryInterface $orderRepository,
array $data = []
) {
parent::__construct($context, $data);

$this->checkoutSession = $checkoutSession;
$this->customerSession = $customerSession;
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
Expand All @@ -61,7 +67,7 @@
$this->configProvider = $configProvider;
$this->storeManager = $storeManager;
$this->serializerInterface = $serializerInterface;
parent::__construct($context, $data);
$this->orderRepository = $orderRepository;
}

/**
Expand Down Expand Up @@ -164,7 +170,7 @@
public function getOrder()
{
if ($this->order == null) {
$this->order = $this->orderFactory->create()->load($this->checkoutSession->getLastOrderId());
$this->order = $this->orderRepository->get($this->checkoutSession->getLastOrderId());
}
return $this->order;
}
Expand Down
Loading
Loading