Skip to content

Commit

Permalink
Merge pull request #55 from jacquesbh/bump-sylius-support
Browse files Browse the repository at this point in the history
feat: Sylius 1.12 compatibility
  • Loading branch information
jacquesbh authored Jan 3, 2023
2 parents df3bfe0 + 485ee53 commit 8668b3b
Show file tree
Hide file tree
Showing 25 changed files with 129 additions and 164 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.4' ,'8.0']
sylius: ['~1.8.0', '~1.9.0', '~1.10.0', '~1.11.0']
php: ['7.4', '8.0', '8.1']
sylius: ['~1.8.0', '~1.9.0', '~1.10.0', '~1.11.0', '~1.12.0']
exclude:
- php: 8.0
sylius: '~1.8.0'
- php: 8.0
sylius: '~1.9.0'
- php: 8.1
sylius: '~1.8.0'
- php: 8.1
sylius: '~1.9.0'
- php: 7.4
sylius: '~1.11.0'
- php: 7.4
sylius: '~1.12.0'

steps:
- name: Setup PHP
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0']
php: ['7.4', '8.0', '8.1']

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.0']
php: ['8.0', '8.1']

env:
SYMFONY_ARGS: --no-tls
Expand Down Expand Up @@ -67,8 +67,6 @@ jobs:

- run: make test.phpcs

- run: make test.phpunit

- run: make test.phpstan

- run: make test.phpmd
Expand Down
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,15 @@
/.php-version
/php.ini
/.phpunit.result.cache
/node_modules
/yarn.lock

###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###

###> symfony/webpack-encore-bundle ###
/node_modules/
npm-debug.log
yarn-error.log
###< symfony/webpack-encore-bundle ###
8 changes: 6 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
'function_to_constant' => true,
'function_typehint_space' => true,
'general_phpdoc_tag_rename' => true,
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => false,
'import_functions' => false,
],
'header_comment' => [
'header' => $header,
'location' => 'after_open',
Expand Down Expand Up @@ -169,8 +174,7 @@
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_comma_in_singleline' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_whitespace_before_comma_in_array' => true,
Expand Down
2 changes: 1 addition & 1 deletion .php-version.dist
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.0
8.1
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DEFAULT_GOAL := help
SHELL=/bin/bash
APP_DIR=tests/Application
SYLIUS_VERSION=1.11.0
SYLIUS_VERSION=1.12.0
SYMFONY=cd ${APP_DIR} && symfony
COMPOSER=symfony composer
CONSOLE=${SYMFONY} console
Expand Down Expand Up @@ -106,7 +106,7 @@ apply_dist:
### TESTS
### ¯¯¯¯¯

test.all: test.composer test.phpstan test.phpmd test.phpunit test.phpspec test.phpcs test.yaml test.schema test.twig test.container ## Run all tests in once
test.all: test.composer test.phpstan test.phpmd test.phpspec test.phpcs test.yaml test.schema test.twig test.container ## Run all tests in once

test.composer: ## Validate composer.json
${COMPOSER} validate --strict
Expand All @@ -117,9 +117,6 @@ test.phpstan: ## Run PHPStan
test.phpmd: ## Run PHPMD
${COMPOSER} phpmd

test.phpunit: ## Run PHPUnit
${COMPOSER} phpunit

test.phpspec: ## Run PHPSpec
${COMPOSER} phpspec

Expand Down
41 changes: 18 additions & 23 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"description": "Add a settings panel to your Sylius.",
"license": "MIT",
"require": {
"php": "~7.4|~8.0",
"php": "~7.4|^8.0",
"ext-mbstring": "*",
"ext-json": "*",
"sylius/sylius": ">=1.8 <1.12"
"sylius/sylius": ">=1.8 <1.13"
},
"require-dev": {
"behat/behat": "^3.6.1",
Expand All @@ -28,22 +28,21 @@
"matthiasnoback/symfony-config-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.4",
"pamil/prophecy-common": "^0.1",
"phpspec/phpspec": "^6.1",
"phpstan/phpstan": "^0.12.57",
"phpstan/phpstan-doctrine": "^0.12.19",
"phpstan/phpstan-webmozart-assert": "^0.12.7",
"phpunit/phpunit": "^8.5",
"psalm/plugin-mockery": "^0.3",
"psr/event-dispatcher": "^1.0",
"sylius-labs/coding-standard": "^3.1",
"symfony/browser-kit": "^4.4",
"symfony/debug-bundle": "^4.4",
"symfony/dotenv": "^4.4",
"symfony/flex": "^1.7",
"symfony/web-profiler-bundle": "^4.4",
"phpmd/phpmd": "@stable"
"mockery/mockery": "@stable",
"pamil/prophecy-common": "@stable",
"phpspec/phpspec": "@stable",
"phpstan/phpstan": "@stable",
"phpstan/phpstan-doctrine": "@stable",
"phpstan/phpstan-webmozart-assert": "@stable",
"psalm/plugin-mockery": "@stable",
"psr/event-dispatcher": "@stable",
"symfony/browser-kit": "@stable",
"symfony/debug-bundle": "@stable",
"symfony/dotenv": "@stable",
"symfony/flex": "@stable",
"symfony/web-profiler-bundle": "@stable",
"phpmd/phpmd": "@stable",
"friendsofphp/php-cs-fixer": "@stable"
},
"prefer-stable": true,
"autoload": {
Expand All @@ -56,16 +55,12 @@
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"phpcs": "php-cs-fixer fix --using-cache=false",
"phpcs": "php-cs-fixer fix --using-cache=no",
"phpstan": "phpstan analyse -c phpstan.neon src/",
"phpmd": "phpmd --exclude Migrations/* src/ ansi phpmd.xml",
"phpunit": "phpunit",
"phpspec": "phpspec run"
},
"extra": {
"symfony": {
"require": "^4.4"
},
"branch-alias": {
"dev-master": "1.0-dev"
}
Expand Down
4 changes: 3 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ parameters:

checkMissingIterableValueType: false

excludes_analyse:
checkGenericClassInNonGenericObjectType: false

excludePaths:
# Makes PHPStan crash
- 'src/DependencyInjection/Configuration.php'
- 'src/DependencyInjection/MonsieurBizSyliusSettingsExtension.php'
Expand Down
55 changes: 0 additions & 55 deletions phpunit.xml.dist

This file was deleted.

2 changes: 1 addition & 1 deletion src/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function formAction(Request $request, RegistryInterface $registry, string

$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$data = (array) $form->getData();
$this->settingsProcessor->processData($settings, $data);
$this->addFlash('success', 'monsieurbiz.settings.settings_successfully_saved');

Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/InstantiateSettingsPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function process(ContainerBuilder $container): void

private function validateSettingsResource(string $class): void
{
$classImplements = (array) class_implements($class) ?? [];
$classImplements = (array) (class_implements($class) ?: []);
if (!\in_array(SettingsInterface::class, $classImplements, true)) {
throw new InvalidArgumentException(sprintf('Class "%s" must implement "%s" to be registered as a Settings resource.', $class, SettingsInterface::class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function load(array $config, ContainerBuilder $container): void
$loader->load('services.yaml');
}

public function getAlias()
public function getAlias(): string
{
return str_replace('monsieur_biz', 'monsieurbiz', parent::getAlias());
}
Expand Down
2 changes: 2 additions & 0 deletions src/Entity/Setting/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ class Setting implements SettingInterface

/**
* @var DateTimeInterface|null
*
* @ORM\Column(name="created_at", type="datetime_immutable")
* @Gedmo\Timestampable(on="create")
*/
protected $createdAt;

/**
* @var DateTimeInterface|null
*
* @ORM\Column(name="updated_at", type="datetime")
* @Gedmo\Timestampable(on="update")
*/
Expand Down
1 change: 1 addition & 0 deletions src/Factory/SettingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function __construct(string $className)
*/
public function createNew()
{
/** @var SettingInterface */
return new $this->className();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/AbstractSettingsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function configureOptions(OptionsResolver $resolver): void

public function addWithDefaultCheckbox(FormBuilderInterface $builder, string $child, string $type = null, array $options = []): self
{
$data = $builder->getData();
$data = (array) $builder->getData();
$builder->add($child, $type, $options);
if (!$this->isDefaultForm($builder)) {
$builder->add($child . '___' . Settings::DEFAULT_KEY, DefaultCheckboxType::class, [
Expand Down
3 changes: 2 additions & 1 deletion src/Form/MainSettingsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ public function configureOptions(OptionsResolver $resolver): void
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
/** @var SettingsInterface $settings */
$settings = $options['settings'];
$data = $options['data'];
$data = (array) $options['data'];
$builder->add(
$key = Settings::DEFAULT_KEY . '-' . Settings::DEFAULT_KEY,
$settings->getFormClass(),
Expand Down
14 changes: 5 additions & 9 deletions src/Processor/SettingsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@
use Doctrine\ORM\EntityManagerInterface;
use LogicException;
use MonsieurBiz\SyliusSettingsPlugin\Factory\SettingFactoryInterface;
use MonsieurBiz\SyliusSettingsPlugin\Repository\SettingRepositoryInterface;
use MonsieurBiz\SyliusSettingsPlugin\Settings\Settings;
use MonsieurBiz\SyliusSettingsPlugin\Settings\SettingsInterface;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use TypeError;

final class SettingsProcessor implements SettingsProcessorInterface
{
private ChannelRepositoryInterface $channelRepository;

private RepositoryInterface $localeRepository;

private SettingRepositoryInterface $settingRepository;

private EntityManagerInterface $entityManager;

private SettingFactoryInterface $settingFactory;
Expand All @@ -42,13 +40,11 @@ final class SettingsProcessor implements SettingsProcessorInterface
public function __construct(
ChannelRepositoryInterface $channelRepository,
RepositoryInterface $localeRepository,
SettingRepositoryInterface $settingRepository,
EntityManagerInterface $entityManager,
SettingFactoryInterface $settingFactory
) {
$this->channelRepository = $channelRepository;
$this->localeRepository = $localeRepository;
$this->settingRepository = $settingRepository;
$this->entityManager = $entityManager;
$this->settingFactory = $settingFactory;
}
Expand All @@ -73,13 +69,13 @@ private function getChannelIdAndLocaleCodeFromSettingKey(string $settingKey): ar
// Default website + Default locale
case sprintf('%1$s-%1$s', Settings::DEFAULT_KEY) === $settingKey:
return [null, null];
// Default website + locale
// Default website + locale
case 1 === preg_match(sprintf('`^%1$s-(?!%1$s)(?P<localeCode>.+)$`', Settings::DEFAULT_KEY), $settingKey, $matches):
return [null, $matches['localeCode']];
// Website + default locale
// Website + default locale
case 1 === preg_match(sprintf('`^channel-(?P<channelId>[0-9]+)-%1$s$`', Settings::DEFAULT_KEY), $settingKey, $matches):
return [(int) $matches['channelId'], null];
// Website + locale
// Website + locale
case 1 === preg_match(sprintf('`^channel-(?P<channelId>[0-9]+)-(?!%1$s)(?P<localeCode>.+)$`', Settings::DEFAULT_KEY), $settingKey, $matches):
return [(int) $matches['channelId'], $matches['localeCode']];
default:
Expand Down Expand Up @@ -137,7 +133,7 @@ private function saveNewAndExistingSettings(array $data, array $actualSettings,
$this->entityManager->persist($setting);

continue;
} catch (\TypeError $e) {
} catch (TypeError $e) {
// The type doesn't match, it could be normal, let's find the type out of the value.
}
}
Expand Down
Loading

0 comments on commit 8668b3b

Please sign in to comment.