Skip to content

Commit

Permalink
feature #198 Add support for PHP 8 (pamil)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.0-dev branch.

Discussion
----------

Related to Sylius/Sylius#12298.

Commits
-------

5748c0c Add support for PHP 8
  • Loading branch information
SirDomin authored Apr 27, 2021
2 parents 2278677 + 5748c0c commit 1eebec9
Show file tree
Hide file tree
Showing 23 changed files with 555 additions and 36 deletions.
29 changes: 19 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,33 @@ jobs:
tests:
runs-on: ubuntu-latest

name: "PHP ${{ matrix.php }}, MySQL ${{ matrix.mysql }}, Sylius ${{ matrix.sylius }}"
name: "PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, Sylius ${{ matrix.sylius }}, MySQL ${{ matrix.mysql }}"

strategy:
fail-fast: false
matrix:
php: [7.4, 7.3]
node: [10.x]
mysql: [5.7, 8.0]
symfony: [^4.4, ^5.2]
sylius: [~1.8.0, ~1.9.0]
php: ["8.0", "7.4", "7.3"]
node: ["10.x"]
mysql: ["5.7", "8.0"]
symfony: ["^4.4", "^5.2"]
sylius: ["~1.8.0", "~1.9.0", "~1.10@dev"]

exclude:
-
php: 7.3
mysql: 8.0
php: "7.3"
mysql: "8.0"
-
sylius: ~1.8.0
symfony: ^5.2
sylius: "~1.8.0"
symfony: "^5.2"
-
php: "7.3"
sylius: "~1.10@dev"
-
php: "8.0"
sylius: "~1.8.0"
-
php: "8.0"
sylius: "~1.9.0"
env:
APP_ENV: test
DATABASE_URL: "mysql://root:[email protected]/sylius?serverVersion=${{ matrix.mysql }}"
Expand Down
2 changes: 1 addition & 1 deletion behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ default:
extensions:
DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~

Lakion\Behat\MinkDebugExtension:
FriendsOfBehat\MinkDebugExtension:
directory: etc/build
clean_start: false
screenshot: true
Expand Down
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
"description": "PayPal plugin for Sylius.",
"license": "MIT",
"require": {
"php": "^7.3",
"php": "^7.3 || ^8.0",

"sylius/sylius": "^1.8",
"nyholm/append-query-string": "^0.1.1",
"phpseclib/phpseclib": "^2.0",
"sylius-labs/doctrine-migrations-extra-bundle": "^0.1.3",
"doctrine/doctrine-migrations-bundle": "^3.0"
Expand All @@ -23,17 +22,17 @@
"friends-of-behat/mink-extension": "^2.4",
"friends-of-behat/page-object-extension": "^0.3",
"friends-of-behat/suite-settings-extension": "^1.0",
"friends-of-behat/mink-debug-extension": "^2.0",
"friends-of-behat/symfony-extension": "^2.1",
"friends-of-behat/variadic-extension": "^1.3",
"friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev",
"lakion/mink-debug-extension": "^1.2.3",
"phpspec/phpspec": "^6.1",
"phpstan/phpstan": "0.12.25",
"phpstan/phpstan-doctrine": "0.12.13",
"phpstan/phpstan-webmozart-assert": "0.12.4",
"phpstan/phpstan": "0.12.84",
"phpstan/phpstan-doctrine": "0.12.33",
"phpstan/phpstan-webmozart-assert": "0.12.12",
"phpunit/phpunit": "^8.5",
"sensiolabs/security-checker": "^6.0",
"sylius-labs/coding-standard": "^3.1",
"sylius-labs/coding-standard": "^4.0",
"symfony/browser-kit": "^4.4 || ^5.2",
"symfony/debug-bundle": "^4.4 || ^5.2",
"symfony/dotenv": "^4.4 || ^5.2",
Expand Down
6 changes: 0 additions & 6 deletions easy-coding-standard.yml

This file was deleted.

15 changes: 15 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
use SlevomatCodingStandard\Sniffs\Commenting\InlineDocCommentDeclarationSniff;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import('vendor/sylius-labs/coding-standard/ecs.php');

$containerConfigurator->parameters()->set(Option::SKIP, [
VisibilityRequiredFixer::class => ['*Spec.php'],
InlineDocCommentDeclarationSniff::class . '.MissingVariable',
]);
};
3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ parameters:
# Test dependencies
- 'tests/Application/app/**.php'
- 'tests/Application/src/**.php'

ignoreErrors:
- '/Parameter #1 $configuration of method Symfony\Component\DependencyInjection\Extension\Extension::processConfiguration() expects Symfony\Component\Config\Definition\ConfigurationInterface, Symfony\Component\Config\Definition\ConfigurationInterface|null given./'
3 changes: 2 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
<file name="src/DependencyInjection/Configuration.php"/>
<file name="src/DependencyInjection/Configuration.php" />
<file name="src/UrlUtils.php" />
</ignoreFiles>
</projectFiles>

Expand Down
5 changes: 3 additions & 2 deletions src/Onboarding/Initiator/OnboardingInitiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Sylius\Component\Core\Model\AdminUserInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\PayPalPlugin\UrlUtils;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security;

Expand Down Expand Up @@ -36,15 +37,15 @@ public function initiate(PaymentMethodInterface $paymentMethod): string
/** @var AdminUserInterface $user */
$user = $this->security->getUser();

return append_query_string(
return UrlUtils::appendQueryString(
$this->createPartnerReferralsUrl,
http_build_query([
'email' => $user->getEmail(),
'return_url' => $this->urlGenerator->generate('sylius_admin_payment_method_create', [
'factory' => 'sylius.pay_pal',
], UrlGeneratorInterface::ABSOLUTE_URL),
]),
APPEND_QUERY_STRING_REPLACE_DUPLICATE
UrlUtils::APPEND_QUERY_STRING_REPLACE_DUPLICATE
);
}

Expand Down
3 changes: 0 additions & 3 deletions src/Onboarding/Processor/BasicOnboardingProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Sylius\PayPalPlugin\Onboarding\Processor;

use GuzzleHttp\ClientInterface;
use Sylius\Bundle\PayumBundle\Model\GatewayConfig;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\PayPalPlugin\Exception\PayPalPluginException;
use Sylius\PayPalPlugin\Exception\PayPalWebhookAlreadyRegisteredException;
Expand Down Expand Up @@ -44,8 +43,6 @@ public function process(
}

$gatewayConfig = $paymentMethod->getGatewayConfig();

/** @var GatewayConfig $gatewayConfig */
Assert::notNull($gatewayConfig);

$onboardingId = (string) $request->query->get('onboarding_id');
Expand Down
84 changes: 84 additions & 0 deletions src/UrlUtils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

declare(strict_types=1);

namespace Sylius\PayPalPlugin;

/**
* Code copied from https://github.com/Nyholm/append_query_string.
*/
final class UrlUtils
{
public const APPEND_QUERY_STRING_IGNORE_DUPLICATE = 0;

public const APPEND_QUERY_STRING_REPLACE_DUPLICATE = 1;

public const APPEND_QUERY_STRING_SKIP_DUPLICATE = 2;

private function __construct()
{
}

/**
* Add a query string to an existing URL.
*
* @param string $url The base URL. Example "https://nyholm.tech?biz=1"
* @param string $queryString A string like "foo=bar&baz=2"
* @param int $mode How to handle duplicate keys. See predefined constants above.
*
* @return string the resulting string
*/
public static function appendQueryString(string $url, string $queryString, int $mode = APPEND_QUERY_STRING_IGNORE_DUPLICATE): string
{
if ('' === $queryString) {
return $url;
}

$existing = parse_url($url, \PHP_URL_QUERY);
$fragment = parse_url($url, \PHP_URL_FRAGMENT);
$fragment = $fragment ? '#' . $fragment : '';

// Remove fragment
if (false !== strrpos($url, '#')) {
$url = substr($url, 0, strrpos($url, '#'));
}

// If no existing query string
if (empty($existing)) {
// Check for "?" at the last character in $url
$questionMark = '?';
if ('?' === $url[strlen($url) - 1]) {
$questionMark = '';
}

return $url . $questionMark . $queryString . $fragment;
}

// Remove query string from URL
$result = substr($url, 0, strrpos($url, $existing) ?: 0);

if (self::APPEND_QUERY_STRING_IGNORE_DUPLICATE === $mode) {
$result .= $existing . '&' . $queryString;
} else {
preg_match_all('#([^&=]+)(=[^&]+)?#si', $existing, $existingArray);
preg_match_all('#([^&=]+)(=[^&]+)?#si', $queryString, $queryStringArray);
if (self::APPEND_QUERY_STRING_REPLACE_DUPLICATE === $mode) {
$intersect = array_intersect($existingArray[1], $queryStringArray[1]);
$keyMap = array_flip($queryStringArray[1]);
foreach ($intersect as $key => $paramName) {
$existing = str_replace($existingArray[0][$key], $queryStringArray[0][$keyMap[$paramName]], $existing);
$queryString = str_replace($queryStringArray[0][$keyMap[$paramName]], '', $queryString);
}
} elseif (self::APPEND_QUERY_STRING_SKIP_DUPLICATE === $mode) {
$intersect = array_intersect($queryStringArray[1], $existingArray[1]);
foreach ($intersect as $key => $paramName) {
$queryString = str_replace($queryStringArray[0][$key], '', $queryString);
}
}
$result .= trim((string) preg_replace('#&&+#i', '&', $existing . '&' . $queryString), '&');
}

// add fragment
return $result . $fragment;
}
}
2 changes: 0 additions & 2 deletions tests/Application/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
Sylius\Bundle\ThemeBundle\SyliusThemeBundle::class => ['all' => true],
Sylius\Bundle\AdminBundle\SyliusAdminBundle::class => ['all' => true],
Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true],
FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true],
Sylius\Bundle\AdminApiBundle\SyliusAdminApiBundle::class => ['all' => true],
Sylius\PayPalPlugin\SyliusPayPalPlugin::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
Expand Down
1 change: 0 additions & 1 deletion tests/Application/config/packages/_sylius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ imports:
- { resource: "@SyliusCoreBundle/Resources/config/app/config.yml" }

- { resource: "@SyliusAdminBundle/Resources/config/app/config.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/app/config.yml" }

- { resource: "@SyliusShopBundle/Resources/config/app/config.yml" }

Expand Down
6 changes: 6 additions & 0 deletions tests/Application/config/sylius/1.10/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true],
];
Loading

0 comments on commit 1eebec9

Please sign in to comment.