diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 00000000..f62ce2d7 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,29 @@ +name: "PHPStan analysis" + +on: + pull_request: + push: + branches: + - "master" + +jobs: + phpstan: + name: "PHPStan analysis" + runs-on: "ubuntu-latest" + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "pcov" + php-version: "${{ matrix.php-version }}" + ini-values: memory_limit=-1 + tools: composer:v2 + + - name: "Install dependencies" + run: "composer update --no-interaction --no-progress" + + - name: "Run PHPStan" + run: "vendor/bin/phpstan" diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index a306550b..b2245f48 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -17,16 +17,11 @@ jobs: dependencies: - "highest" php-version: - - "7.2" - - "7.3" - - "7.4" - - "8.0" - - "8.1" - "8.2" - "8.3" include: - - php-version: '7.2' + - php-version: '8.2' dependencies: "lowest" steps: diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..24fda018 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +help: ## Show this help. + @printf "\033[33mUsage:\033[0m\n make [target] [arg=\"val\"...]\n\n\033[33mTargets:\033[0m\n" + @grep -E '^[-a-zA-Z0-9_\.\/]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-30s\033[0m %s\n", $$1, $$2}' + +static-analysis: + @vendor/bin/phpstan analyse \ No newline at end of file diff --git a/README.md b/README.md index 130d776b..c741a97e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ +> [!CAUTION] +> This is an experimental fork to propose a possible new major version. +> +> It will not be compatible with any existing gateway. Do not try to create a gateway for this version, please +> share your [ideas](https://github.com/devnix-labs/omnipay-common/discussions/categories/ideas) so we can elaborate +> a clear roadmap to define the shape of a new Omnipay version. + # Omnipay Common **Core components for the Omnipay PHP payment processing library** diff --git a/composer.json b/composer.json index be27a33e..c2f24d02 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,10 @@ { "name": "Del" }, + { + "name": "Pablo Largo Mohedano", + "email": "devnix.code@gmail.com" + }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-common/contributors" @@ -42,7 +46,7 @@ "classmap": ["tests/OmnipayTest.php"] }, "require": { - "php": "^7.2|^8", + "php": "^8.2", "php-http/client-implementation": "^1", "php-http/message": "^1.5", "php-http/message-factory": "^1.1", @@ -55,7 +59,10 @@ "php-http/mock-client": "^1.6", "php-http/guzzle7-adapter": "^1", "squizlabs/php_codesniffer": "^3.8.1", - "http-interop/http-factory-guzzle": "^1.1" + "http-interop/http-factory-guzzle": "^1.1", + "phpstan/phpstan": "^1.12", + "phpstan/phpstan-phpunit": "^1.4", + "phpunit/phpunit": "^9.6" }, "extra": { "branch-alias": { diff --git a/phpstan.dist.neon b/phpstan.dist.neon new file mode 100644 index 00000000..e2bb8722 --- /dev/null +++ b/phpstan.dist.neon @@ -0,0 +1,8 @@ +includes: + - vendor/phpstan/phpstan/conf/bleedingEdge.neon + - vendor/phpstan/phpstan-phpunit/extension.neon + +parameters: + level: 0 + paths: + - src diff --git a/src/Common/CreditCard.php b/src/Common/CreditCard.php index c92285ba..07754685 100644 --- a/src/Common/CreditCard.php +++ b/src/Common/CreditCard.php @@ -407,16 +407,16 @@ public function getNumberMasked($mask = 'X') * Credit Card Brand * * Iterates through known/supported card brands to determine the brand of this card - * - * @return string */ - public function getBrand() + public function getBrand(): string|null { foreach ($this->getSupportedBrands() as $brand => $val) { if (preg_match($val, $this->getNumber())) { return $brand; } } + + return null; } /** diff --git a/src/Common/Message/AbstractRequest.php b/src/Common/Message/AbstractRequest.php index 004a7757..95ab7fca 100644 --- a/src/Common/Message/AbstractRequest.php +++ b/src/Common/Message/AbstractRequest.php @@ -308,9 +308,9 @@ private function getMoney($amount = null) * Validates and returns the formatted amount. * * @throws InvalidRequestException on any validation failure. - * @return string The amount formatted to the correct number of decimal places for the selected currency. + * @return string|null The amount formatted to the correct number of decimal places for the selected currency. */ - public function getAmount() + public function getAmount(): string|null { $money = $this->getMoney(); @@ -319,6 +319,8 @@ public function getAmount() return $moneyFormatter->format($money); } + + return null; } /** @@ -335,15 +337,17 @@ public function setAmount($value) /** * Get the payment amount as an integer. * - * @return integer + * @return int|null */ - public function getAmountInteger() + public function getAmountInteger(): int|null { $money = $this->getMoney(); if ($money !== null) { return (int) $money->getAmount(); } + + return null; } /** diff --git a/tests/Common/AbstractGatewayTest/MockAbstractGateway.php b/tests/Common/AbstractGatewayTest/MockAbstractGateway.php new file mode 100644 index 00000000..f5b72147 --- /dev/null +++ b/tests/Common/AbstractGatewayTest/MockAbstractGateway.php @@ -0,0 +1,12 @@ +