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

Open
wants to merge 65 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 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
c23ec18
[ECP-9489] Write unit tests
Jan 28, 2025
70b6c72
[ECP-9489] Fix wrong array comparison
Jan 28, 2025
f554d12
[ECP-9489] Write unit tests
Jan 28, 2025
597b351
[ECP-9489] Use inbuilt PHP function
Jan 28, 2025
a342bb3
Merge branch 'main' into ECP-9489
candemiralp Jan 28, 2025
75bf608
[ECP-9489] Use interface constant for query field name
Jan 28, 2025
9976d3e
[ECP-9489] Write unit tests
Jan 28, 2025
2ed7939
[ECP-9489] Use Magento Select class instead of Zend DB
Jan 28, 2025
ffc8553
Merge remote-tracking branch 'origin/main' into ECP-9489
Jan 28, 2025
a46110d
[EPC-9489] Write unit tests
Jan 29, 2025
4df3263
[EPC-9489] Write unit tests
Jan 29, 2025
101938a
[EPC-9489] Fix
Jan 29, 2025
896a61a
[EPC-9489] Remove unnecessary override
Jan 29, 2025
1418b44
[EPC-9489] Write unit tests
Jan 29, 2025
006bfde
[EPC-9489] Write unit tests
Jan 29, 2025
0ae8b44
[EPC-9489] Write unit tests
Jan 29, 2025
339753d
[EPC-9489] Write unit tests
Jan 29, 2025
8ab1fc2
[EPC-9489] Write unit tests
Jan 29, 2025
d6fe961
[EPC-9489] Write unit tests
Jan 29, 2025
472d8a5
[EPC-9489] Deprecate unused method
Jan 30, 2025
2ff0636
[EPC-9489] Write unit tests
Jan 30, 2025
3cbb7ca
[EPC-9489] Write unit tests
Jan 31, 2025
7740e8f
[EPC-9489] Write unit tests
Jan 31, 2025
8b9a8a4
[EPC-9489] Write unit tests
Jan 31, 2025
4b9c712
[EPC-9489] Check the method name before resetting orderId
Jan 31, 2025
648d2a5
[EPC-9489] Fix undefined property error
Jan 31, 2025
99e706a
[EPC-9489] Update workflow file
Jan 31, 2025
e11ede7
[EPC-9489] Update ignore notation
Jan 31, 2025
0c259c5
[EPC-9489] Update ignore notation
Jan 31, 2025
db2bcfa
Merge branch 'main' into ECP-9489
candemiralp Feb 5, 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
8 changes: 8 additions & 0 deletions .github/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,11 @@ setup-mftf:
# Magento Functional Testing Framework
mftf:
vendor/bin/mftf run:group --remove -- AdyenMagentoSuite || vendor/bin/mftf run:failed

phpstan-install:
composer require --dev bitexpert/phpstan-magento
composer config allow-plugins.phpstan/extension-installer true
composer require --dev phpstan/extension-installer

phpstan-run:
vendor/bin/phpstan analyse -c vendor/adyen/module-payment/phpstan.neon
62 changes: 62 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: PHPStan analysis workflow
run-name: PHPStan analysis workflow

on:
pull_request:
branches: [main]
pull_request_target:
branches: [main]

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' }}
strategy:
matrix:
php-version: ["8.3"]
magento-version: ["2.4.7-p2"]
runs-on:
group: larger-runners
labels: ubuntu-latest-8-cores
timeout-minutes: 25
env:
PHP_VERSION: ${{ matrix.php-version }}
MAGENTO_VERSION: ${{ matrix.magento-version }}
ADYEN_API_KEY: ${{secrets.ADYEN_API_KEY}}
ADYEN_CLIENT_KEY: ${{secrets.ADYEN_CLIENT_KEY}}
ADYEN_MERCHANT: ${{secrets.ADYEN_MERCHANT}}
ADMIN_USERNAME: ${{secrets.MAGENTO_ADMIN_USERNAME}}
ADMIN_PASSWORD: ${{secrets.MAGENTO_ADMIN_PASSWORD}}
DONATION_ACCOUNT: ${{secrets.DONATION_ACCOUNT}}
DEPLOY_SAMPLEDATA: 1
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}

- name: Install Magento
run: docker compose -f .github/docker-compose.yml run --rm web make magento

- name: Start web server in background
run: docker compose -f .github/docker-compose.yml up -d web

- name: Setup permissions
run: docker exec magento2-container make fs

- name: Check install
run: docker exec magento2-container make sys-check

- name: Install plugin
run: docker exec -u www-data magento2-container make plugin

- name: Install PHPStan dependencies
run: docker compose -f .github/docker-compose.yml run --rm web make phpstan-install

- name: Kill Cron Jobs
run: docker exec magento2-container /etc/init.d/cron stop

- name: Setup permissions
run: docker exec magento2-container make fs

- name: Run PHPStan
run: docker exec magento2-container make phpstan-run
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,22 +22,25 @@
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;

public function __construct(
Context $context,
Expand All @@ -50,8 +53,11 @@ public function __construct(
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 @@ public function __construct(
$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 getEnvironment()
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