diff --git a/.github/workflows/recipe.yaml b/.github/workflows/recipe.yaml
index bac4a22..f18740b 100644
--- a/.github/workflows/recipe.yaml
+++ b/.github/workflows/recipe.yaml
@@ -11,27 +11,18 @@ jobs:
runs-on: ubuntu-latest
- env:
- SYMFONY_ENDPOINT: http://127.0.0.1/
-
strategy:
fail-fast: false
matrix:
- php: ['7.4' ,'8.0', '8.1']
- sylius: ["~1.8.0", "~1.9.0", "~1.10.0", "~1.11.0", "~1.12.0"]
+ php: ['8.0', '8.1', '8.2']
+ sylius: ["~1.11.0", "~1.12.0", "~1.13.0"]
exclude:
- - php: 8.1
- sylius: "~1.8.0"
- - php: 8.1
- sylius: "~1.9.0"
- - php: 8.0
- sylius: "~1.8.0"
- - php: 8.0
- sylius: "~1.9.0"
- - php: 7.4
- sylius: "~1.11.0"
- - php: 7.4
- sylius: "~1.12.0"
+ - php: '8.2'
+ sylius: '~1.11.0'
+ - php: '8.0'
+ sylius: '~1.12.0'
+ - php: '8.0'
+ sylius: '~1.13.0'
steps:
- name: Setup PHP
@@ -39,33 +30,28 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: gd, intl, json
+ ini-values: date.timezone=UTC
+ tools: symfony-cli
- name: Set project php-version
run: |
- echo "${{ matrix.php }}" > .php-version
+ echo ${{ matrix.php }} > .php-version
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
with:
path: plugin
- # Run the server at the start so it can download the recipes!
- - name: Run standalone symfony flex server
- run: |
- echo ${{ github.token }} | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- docker run --rm --name flex -d -v $PWD/plugin/recipes:/var/www/flex/var/repo/private/monsieurbiz/sylius-menu-plugin -p 80:80 docker.pkg.github.com/monsieurbiz/docker/symfony-flex-server:latest contrib official
- docker ps
-
- name: Determine composer cache directory
id: composer-cache-directory
working-directory: plugin
run: echo "directory=$(composer config cache-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies installed with composer
- uses: actions/cache@v2
+ uses: actions/cache@v3
id: cache-composer
with:
path: ${{ steps.composer-cache-directory.outputs.directory }}
- key: composer2-php:${{ matrix.php }}-sylius:${{ matrix.sylius }}-${{ github.sha }}
+ key: composer2-php:${{ matrix.php }}-sylius:${{ matrix.sylius }}-${{ hashFiles('**/composer.json') }}
restore-keys: composer2-php:${{ matrix.php }}-sylius:${{ matrix.sylius }}-
- name: Ensure that composer cache directory exists
@@ -87,21 +73,15 @@ jobs:
- name: Setup some requirements
working-directory: ./sylius
run: |
+ composer config --no-plugins allow-plugins true
+ composer config --no-plugins extra.symfony.allow-contrib true
+ composer config --no-plugins secure-http false
+ composer config --no-plugins --unset platform.php
+ composer config --no-plugins extra.symfony.docker false
+ composer config --no-plugins --json extra.symfony.endpoint '["https://api.github.com/repos/monsieurbiz/symfony-recipes/contents/index.json?ref=flex/master","flex://defaults"]'
composer config repositories.plugin '{"type": "path", "url": "../plugin/"}'
- composer config extra.symfony.allow-contrib true
- composer config secure-http false
- composer config --unset platform.php
- - name: Require plugin without install
+ - name: Require plugin & install all dependencies
working-directory: ./sylius
run: |
- composer require --no-install --no-scripts monsieurbiz/sylius-menu-plugin="*@dev"
-
- - name: Composer install
- working-directory: ./sylius
- run: |
- composer config --no-plugins allow-plugins true
- composer install
-
- - name: Show flex server logs
- run: docker logs --tail 100 flex
+ composer require monsieurbiz/sylius-menu-plugin="*@dev"
diff --git a/.github/workflows/security.yaml b/.github/workflows/security.yaml
index 408c929..c100cfa 100644
--- a/.github/workflows/security.yaml
+++ b/.github/workflows/security.yaml
@@ -13,10 +13,10 @@ jobs:
strategy:
fail-fast: false
matrix:
- php: ['7.4', '8.0', '8.1']
+ php: ['8.1', '8.2']
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
@@ -33,7 +33,7 @@ jobs:
run: echo "directory=$(composer config cache-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies installed with composer
- uses: actions/cache@v2
+ uses: actions/cache@v3
id: cache-composer
with:
path: ${{ steps.composer-cache-directory.outputs.directory }}
@@ -46,10 +46,8 @@ jobs:
- name: Composer Github Auth
run: composer config -g github-oauth.github.com ${{ github.token }}
- - uses: actions/checkout@v2
-
- name: Install PHP dependencies
run: composer update --prefer-dist
- - uses: symfonycorp/security-checker-action@v3
+ - uses: symfonycorp/security-checker-action@v4
diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml
index be8ed81..877ce6a 100644
--- a/.github/workflows/tests.yaml
+++ b/.github/workflows/tests.yaml
@@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- php: ['8.0', '8.1']
+ php: ['8.1', '8.2']
env:
SYMFONY_ARGS: --no-tls
@@ -31,22 +31,19 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: gd, intl, json
+ ini-values: date.timezone=UTC
+ tools: symfony-cli
- name: Set project php-version
run: |
echo "${{ matrix.php }}" > .php-version
- - name: Install symfony CLI
- run: |
- curl https://get.symfony.com/cli/installer | bash
- echo "${HOME}/.symfony5/bin" >> $GITHUB_PATH
-
- name: Determine composer cache directory
id: composer-cache-directory
run: echo "directory=$(composer config cache-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies installed with composer
- uses: actions/cache@v2
+ uses: actions/cache@v3
id: cache-composer
with:
path: ${{ steps.composer-cache-directory.outputs.directory }}
diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php
index 63bd537..843cfb7 100644
--- a/.php-cs-fixer.dist.php
+++ b/.php-cs-fixer.dist.php
@@ -49,10 +49,8 @@
'binary_operator_spaces' => true,
'blank_line_after_opening_tag' => true,
'blank_line_after_namespace' => true,
+ 'blank_lines_before_namespace' => true,
'blank_line_before_statement' => true,
- 'braces' => [
- 'allow_single_line_closure' => true,
- ],
'cast_spaces' => true,
'class_attributes_separation' => true,
'class_definition' => [
@@ -62,7 +60,7 @@
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'comment_to_phpdoc' => true,
- 'compact_nullable_typehint' => true,
+ 'compact_nullable_type_declaration' => true,
'concat_space' => [
'spacing' => 'one',
],
@@ -88,8 +86,12 @@
'fully_qualified_strict_types' => true,
'function_declaration' => true,
'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',
@@ -110,6 +112,7 @@
'lowercase_static_reference' => true,
'magic_constant_casing' => true,
'method_argument_space' => true,
+ 'modernize_strpos' => false,
'modernize_types_casting' => true,
'multiline_comment_opening_closing' => true,
'multiline_whitespace_before_semicolons' => [
@@ -117,7 +120,7 @@
],
'native_constant_invocation' => true,
'native_function_casing' => true,
- 'new_with_braces' => true,
+ 'new_with_parentheses' => true,
'no_alias_functions' => true,
'no_alternative_syntax' => true,
'no_blank_lines_after_class_opening' => true,
@@ -156,27 +159,27 @@
'no_short_bool_cast' => true,
'no_spaces_after_function_name' => true,
'no_spaces_around_offset' => true,
- 'no_spaces_inside_parenthesis' => true,
+ 'spaces_inside_parentheses' => true,
'no_superfluous_elseif' => true,
'no_superfluous_phpdoc_tags' => [
'allow_mixed' => true,
],
'no_unset_cast' => true,
'no_unneeded_control_parentheses' => true,
- 'no_unneeded_curly_braces' => true,
+ 'no_unneeded_braces' => true,
'no_unneeded_final_method' => true,
'no_unset_on_property' => true,
'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,
'no_whitespace_in_blank_line' => true,
'non_printable_character' => true,
'normalize_index_brace' => true,
+ 'nullable_type_declaration_for_default_null_value' => false,
'object_operator_without_whitespace' => true,
'ordered_imports' => [
'imports_order' => [
@@ -211,7 +214,9 @@
'phpdoc_order' => true,
'phpdoc_return_self_reference' => true,
'phpdoc_scalar' => true,
- 'phpdoc_separation' => true,
+ 'phpdoc_separation' => ['groups' => [
+ ['ORM\\*'], ['Assert\\*'],
+ ]],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_tag_type' => true,
'phpdoc_to_comment' => false,
@@ -231,7 +236,6 @@
'self_accessor' => true,
'short_scalar_cast' => true,
'single_blank_line_at_eof' => true,
- 'single_blank_line_before_namespace' => true,
'single_class_element_per_statement' => true,
'single_import_per_statement' => true,
'single_line_after_imports' => true,
@@ -248,6 +252,7 @@
'elements' => ['arrays'],
],
'trim_array_spaces' => true,
+ 'type_declaration_spaces' => true,
'unary_operator_spaces' => true,
'visibility_required' => [
'elements' => [
diff --git a/.php-version.dist b/.php-version.dist
index b8eb026..2983cad 100644
--- a/.php-version.dist
+++ b/.php-version.dist
@@ -1 +1 @@
-8.1
+8.2
diff --git a/Makefile b/Makefile
index 10bfbdd..d10b6c7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
.DEFAULT_GOAL := help
SHELL=/bin/bash
APP_DIR=tests/Application
-SYLIUS_VERSION=1.12.0
+SYLIUS_VERSION=1.13.0
SYMFONY=cd ${APP_DIR} && symfony
COMPOSER=symfony composer
CONSOLE=${SYMFONY} console
@@ -69,6 +69,8 @@ setup_application:
(cd ${APP_DIR} && ${COMPOSER} config repositories.plugin '{"type": "path", "url": "../../"}')
(cd ${APP_DIR} && ${COMPOSER} config extra.symfony.allow-contrib true)
(cd ${APP_DIR} && ${COMPOSER} config minimum-stability dev)
+ (cd ${APP_DIR} && ${COMPOSER} config --no-plugins allow-plugins true)
+ (cd ${APP_DIR} && ${COMPOSER} config --no-plugins --json extra.symfony.endpoint '["https://api.github.com/repos/monsieurbiz/symfony-recipes/contents/index.json?ref=flex/master","flex://defaults"]')
(cd ${APP_DIR} && ${COMPOSER} require --no-install --no-scripts --no-progress sylius/sylius="~${SYLIUS_VERSION}") # Make sure to install the required version of sylius because the sylius-standard has a soft constraint
$(MAKE) ${APP_DIR}/.php-version
$(MAKE) ${APP_DIR}/php.ini
@@ -81,6 +83,8 @@ setup_application:
${APP_DIR}/docker-compose.yaml:
rm -f ${APP_DIR}/docker-compose.yml
rm -f ${APP_DIR}/docker-compose.yaml
+ rm -f ${APP_DIR}/compose.yml # Remove Sylius file about Docker
+ rm -f ${APP_DIR}/compose.override.dist.yml # Remove Sylius file about Docker
ln -s ../../docker-compose.yaml.dist ${APP_DIR}/docker-compose.yaml
.PHONY: ${APP_DIR}/docker-compose.yaml
@@ -132,7 +136,7 @@ test.container: ## Lint the symfony container
${CONSOLE} lint:container
test.yaml: ## Lint the symfony Yaml files
- ${CONSOLE} lint:yaml ../../recipes ../../src/Resources/config --parse-tags
+ ${CONSOLE} lint:yaml ../../src/Resources/config --parse-tags
test.schema: ## Validate MySQL Schema
${CONSOLE} doctrine:schema:validate
diff --git a/README.md b/README.md
index 0c9e337..6eced54 100644
--- a/README.md
+++ b/README.md
@@ -1,15 +1,30 @@
[![Banner of Sylius Menu plugin](docs/images/banner.jpg)](https://monsieurbiz.com/agence-web-experte-sylius)
-
Menu Plugin
+Sylius Menu Plugin
[![Menu Plugin license](https://img.shields.io/github/license/monsieurbiz/SyliusMenuPlugin?public)](https://github.com/monsieurbiz/SyliusMenuPlugin/blob/master/LICENSE.txt)
-[![Tests Status](https://img.shields.io/github/workflow/status/monsieurbiz/SyliusMenuPlugin/Tests?logo=github)](https://github.com/monsieurbiz/SyliusMenuPlugin/actions?query=workflow%3ATests)
-[![Security Status](https://img.shields.io/github/workflow/status/monsieurbiz/SyliusMenuPlugin/Security?label=security&logo=github)](https://github.com/monsieurbiz/SyliusMenuPlugin/actions?query=workflow%3ASecurity)
+[![Tests Status](https://img.shields.io/github/actions/workflow/status/monsieurbiz/SyliusMenuPlugin/tests.yaml?branch=master&logo=github)](https://github.com/monsieurbiz/SyliusMenuPlugin/actions?query=workflow%3ATests)
+[![Recipe Status](https://img.shields.io/github/actions/workflow/status/monsieurbiz/SyliusMenuPlugin/recipe.yaml?branch=master&label=recipes&logo=github)](https://github.com/monsieurbiz/SyliusMenuPlugin/actions?query=workflow%3ASecurity)
+[![Security Status](https://img.shields.io/github/actions/workflow/status/monsieurbiz/SyliusMenuPlugin/security.yaml?branch=master&label=security&logo=github)](https://github.com/monsieurbiz/SyliusMenuPlugin/actions?query=workflow%3ASecurity)
This plugins allows you to manage your menus.
+## Compatibility
+
+| Sylius Version | PHP Version |
+|---|---|
+| 1.11 | 8.0 - 8.1 |
+| 1.12 | 8.1 - 8.2 |
+| 1.13 | 8.1 - 8.2 |
+
## Installation
+If you want to use our recipes, you can configure your composer.json by running:
+
+```json
+composer config --no-plugins --json extra.symfony.endpoint '["https://api.github.com/repos/monsieurbiz/symfony-recipes/contents/index.json?ref=flex/master","flex://defaults"]'
+```
+
```bash
composer require monsieurbiz/sylius-menu-plugin
```
@@ -61,6 +76,8 @@ It provides URLs for :
You can add your own custom Provider by creating a class which implements the `MonsieurBiz\SyliusMenuPlugin\Provider\UrlProviderInterface` interface.
+https://github.com/monsieurbiz/SyliusMenuPlugin/assets/11380627/98edde9e-8a25-46be-bc1c-7a2b06d15ead
+
## Menu example
### Admin form index
diff --git a/composer.json b/composer.json
index 405faa9..33bbf88 100644
--- a/composer.json
+++ b/composer.json
@@ -5,43 +5,17 @@
"description": "This plugins allows you to manage menus.",
"license": "MIT",
"require": {
- "php": "~7.4|~8.0",
- "sylius/sylius": ">=1.8 <1.13"
+ "php": "^8.0",
+ "sylius/sylius": ">=1.11 <1.14"
},
"require-dev": {
- "behat/behat": "^3.6.1",
- "behat/mink-selenium2-driver": "^1.4",
- "dmore/behat-chrome-extension": "^1.3",
- "dmore/chrome-mink-driver": "^2.7",
- "doctrine/data-fixtures": "^1.4",
- "ergebnis/composer-normalize": "^2.5",
- "friends-of-behat/mink": "^1.8",
- "friends-of-behat/mink-browserkit-driver": "^1.4",
- "friends-of-behat/mink-extension": "^2.4",
- "friends-of-behat/page-object-extension": "^0.3",
- "friends-of-behat/symfony-extension": "^2.1",
- "friends-of-behat/variadic-extension": "^1.3",
- "hwi/oauth-bundle": "^1.1",
- "lchrusciel/api-test-case": "^5.0",
- "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 || ^7.2",
- "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"
+ "friendsofphp/php-cs-fixer": "^3.16",
+ "phpspec/phpspec": "^7.0",
+ "phpstan/phpstan": "^1.8.4",
+ "phpstan/phpstan-doctrine": "^1.3.2",
+ "phpstan/phpstan-webmozart-assert": "^1.1",
+ "phpunit/phpunit": "^10.5",
+ "phpmd/phpmd": "^2.15"
},
"prefer-stable": true,
"autoload": {
@@ -61,11 +35,12 @@
"phpspec": "phpspec run"
},
"extra": {
- "symfony": {
- "require": "^4.4"
- },
"branch-alias": {
"dev-master": "1.3-dev"
+ },
+ "symfony": {
+ "docker": false,
+ "endpoint": ["https://api.github.com/repos/monsieurbiz/symfony-recipes/contents/index.json?ref=flex/master", "flex://defaults"]
}
},
"config": {
diff --git a/phpstan.neon b/phpstan.neon
index b551d67..fbba240 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -1,18 +1,15 @@
-includes:
- - vendor/phpstan/phpstan-doctrine/extension.neon
- - vendor/phpstan/phpstan-webmozart-assert/extension.neon
-
parameters:
level: max
paths:
- %rootDir%/src/
- checkMissingIterableValueType: false
-
- excludes_analyse:
+ excludePaths:
# Makes PHPStan crash
- - 'src/DependencyInjection/Configuration.php'
- 'src/DependencyInjection/MonsieurBizSyliusMenuExtension.php'
# Test dependencies
- 'tests/Application/**/*'
+
+ ignoreErrors:
+ - identifier: missingType.generics
+ - identifier: missingType.iterableValue
diff --git a/recipes/1.0-dev/config/packages/monsieurbiz_sylius_menu_plugin.yaml b/recipes/1.0-dev/config/packages/monsieurbiz_sylius_menu_plugin.yaml
deleted file mode 100644
index 5b3d08b..0000000
--- a/recipes/1.0-dev/config/packages/monsieurbiz_sylius_menu_plugin.yaml
+++ /dev/null
@@ -1,2 +0,0 @@
-imports:
- - { resource: "@MonsieurBizSyliusMenuPlugin/Resources/config/config.yaml" }
diff --git a/recipes/1.0-dev/config/routes/monsieurbiz_sylius_menu_plugin.yaml b/recipes/1.0-dev/config/routes/monsieurbiz_sylius_menu_plugin.yaml
deleted file mode 100644
index 0c3393c..0000000
--- a/recipes/1.0-dev/config/routes/monsieurbiz_sylius_menu_plugin.yaml
+++ /dev/null
@@ -1,3 +0,0 @@
-monsieurbiz_menu_admin_menu:
- resource: "@MonsieurBizSyliusMenuPlugin/Resources/config/routes/admin.yaml"
- prefix: /%sylius_admin.path_name%
diff --git a/recipes/1.0-dev/manifest.json b/recipes/1.0-dev/manifest.json
deleted file mode 100644
index cf56ec8..0000000
--- a/recipes/1.0-dev/manifest.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "bundles": {
- "MonsieurBiz\\SyliusMenuPlugin\\MonsieurBizSyliusMenuPlugin": [
- "all"
- ]
- },
- "copy-from-recipe": {
- "config/": "%CONFIG_DIR%/"
- }
-}
diff --git a/recipes/1.3-dev/config/packages/monsieurbiz_sylius_menu_plugin.yaml b/recipes/1.3-dev/config/packages/monsieurbiz_sylius_menu_plugin.yaml
deleted file mode 100644
index 36dbbe7..0000000
--- a/recipes/1.3-dev/config/packages/monsieurbiz_sylius_menu_plugin.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-imports:
- - { resource: "@MonsieurBizSyliusMenuPlugin/Resources/config/config.yaml" }
-
-twig:
- form_themes: ['@MonsieurBizSyliusMenuPlugin/Admin/Browser/Form/_theme.html.twig']
diff --git a/recipes/1.3-dev/config/routes/monsieurbiz_sylius_menu_plugin.yaml b/recipes/1.3-dev/config/routes/monsieurbiz_sylius_menu_plugin.yaml
deleted file mode 100644
index 0c3393c..0000000
--- a/recipes/1.3-dev/config/routes/monsieurbiz_sylius_menu_plugin.yaml
+++ /dev/null
@@ -1,3 +0,0 @@
-monsieurbiz_menu_admin_menu:
- resource: "@MonsieurBizSyliusMenuPlugin/Resources/config/routes/admin.yaml"
- prefix: /%sylius_admin.path_name%
diff --git a/recipes/1.3-dev/manifest.json b/recipes/1.3-dev/manifest.json
deleted file mode 100644
index cf56ec8..0000000
--- a/recipes/1.3-dev/manifest.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "bundles": {
- "MonsieurBiz\\SyliusMenuPlugin\\MonsieurBizSyliusMenuPlugin": [
- "all"
- ]
- },
- "copy-from-recipe": {
- "config/": "%CONFIG_DIR%/"
- }
-}
diff --git a/src/Controller/MenuItemResourceController.php b/src/Controller/MenuItemResourceController.php
index 6bd9526..115b76d 100644
--- a/src/Controller/MenuItemResourceController.php
+++ b/src/Controller/MenuItemResourceController.php
@@ -79,6 +79,9 @@ private function getNewIndex(int $index, int $max, string $direction): int
return $indexToGo;
}
+ /**
+ * @return MenuItemInterface[]
+ */
private function getItems(MenuItemInterface $resource): array
{
$items = [];
diff --git a/src/DependencyInjection/MonsieurBizSyliusMenuExtension.php b/src/DependencyInjection/MonsieurBizSyliusMenuExtension.php
index 445e33c..40e03ea 100644
--- a/src/DependencyInjection/MonsieurBizSyliusMenuExtension.php
+++ b/src/DependencyInjection/MonsieurBizSyliusMenuExtension.php
@@ -14,6 +14,7 @@
namespace MonsieurBiz\SyliusMenuPlugin\DependencyInjection;
use MonsieurBiz\SyliusMenuPlugin\Provider\UrlProviderInterface;
+use Sylius\Bundle\CoreBundle\DependencyInjection\PrependDoctrineMigrationsTrait;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
@@ -22,8 +23,10 @@
final class MonsieurBizSyliusMenuExtension extends Extension implements PrependExtensionInterface
{
+ use PrependDoctrineMigrationsTrait;
+
/**
- * @inheritdoc
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function load(array $config, ContainerBuilder $container): void
{
@@ -32,24 +35,30 @@ public function load(array $config, ContainerBuilder $container): void
$container->registerForAutoconfiguration(UrlProviderInterface::class)->addTag('monsieurbiz_menu.url_provider');
}
- /**
- * @inheritdoc
- */
public function getAlias(): string
{
return str_replace('monsieur_biz', 'monsieurbiz', parent::getAlias());
}
- /**
- * @inheritdoc
- */
public function prepend(ContainerBuilder $container): void
{
- $doctrineConfig = $container->getExtensionConfig('doctrine_migrations');
- $container->prependExtensionConfig('doctrine_migrations', [
- 'migrations_paths' => array_merge(array_pop($doctrineConfig)['migrations_paths'] ?? [], [
- 'MonsieurBiz\SyliusMenuPlugin\Migrations' => '@MonsieurBizSyliusMenuPlugin/Migrations',
- ]),
- ]);
+ $this->prependDoctrineMigrations($container);
+ }
+
+ protected function getMigrationsNamespace(): string
+ {
+ return 'MonsieurBiz\SyliusMenuPlugin\Migrations';
+ }
+
+ protected function getMigrationsDirectory(): string
+ {
+ return '@MonsieurBizSyliusMenuPlugin/Migrations';
+ }
+
+ protected function getNamespacesOfMigrationsExecutedBefore(): array
+ {
+ return [
+ 'Sylius\Bundle\CoreBundle\Migrations',
+ ];
}
}
diff --git a/src/Entity/Menu.php b/src/Entity/Menu.php
index 4c93181..f3f7cf7 100644
--- a/src/Entity/Menu.php
+++ b/src/Entity/Menu.php
@@ -81,13 +81,10 @@ public function getFirstLevelItems(): array
if (null === $items) {
return [];
}
- $filteredItems = $items->filter(function ($item) {
- if (!$item->getParent()) {
- return $item;
- }
-
- return null;
+ $filteredItems = $items->filter(function (MenuItemInterface $item) {
+ return !$item->getParent();
})->toArray();
+
uasort($filteredItems, function ($itemA, $itemB) {
return $itemA->getPosition() <=> $itemB->getPosition();
});
diff --git a/src/Entity/MenuItem.php b/src/Entity/MenuItem.php
index 6b0cb8b..ea3ea83 100644
--- a/src/Entity/MenuItem.php
+++ b/src/Entity/MenuItem.php
@@ -24,7 +24,6 @@
class MenuItem implements MenuItemInterface
{
use TimestampableTrait;
-
use TranslatableTrait {
__construct as protected initializeTranslationsCollection;
}
diff --git a/src/Entity/MenuItemInterface.php b/src/Entity/MenuItemInterface.php
index 6a5cf6e..4a10e11 100644
--- a/src/Entity/MenuItemInterface.php
+++ b/src/Entity/MenuItemInterface.php
@@ -23,14 +23,8 @@ public function getMenu(): ?MenuInterface;
public function setMenu(?MenuInterface $menu): void;
- /**
- * @return MenuItemInterface|null
- */
public function getParent(): ?self;
- /**
- * @param MenuItemInterface|null $parent
- */
public function setParent(?self $parent): void;
public function getPosition(): ?int;
@@ -47,19 +41,10 @@ public function getItems(): ?Collection;
*/
public function setItems(?Collection $items): void;
- /**
- * @param MenuItemInterface $item
- */
public function hasItem(self $item): bool;
- /**
- * @param MenuItemInterface $item
- */
public function addItem(self $item): void;
- /**
- * @param MenuItemInterface $item
- */
public function removeItem(self $item): void;
public function isTargetBlank(): bool;
diff --git a/src/EventListener/Doctrine/MenuItemListener.php b/src/EventListener/Doctrine/MenuItemListener.php
index 2223b95..2779e33 100644
--- a/src/EventListener/Doctrine/MenuItemListener.php
+++ b/src/EventListener/Doctrine/MenuItemListener.php
@@ -20,9 +20,6 @@ final class MenuItemListener
{
private MenuItemRepositoryInterface $menuItemRepository;
- /**
- * MenuItemListener constructor.
- */
public function __construct(MenuItemRepositoryInterface $menuItemRepository)
{
$this->menuItemRepository = $menuItemRepository;
diff --git a/src/Fixture/Factory/MenuFixtureFactory.php b/src/Fixture/Factory/MenuFixtureFactory.php
index 3d4b744..d7308b2 100644
--- a/src/Fixture/Factory/MenuFixtureFactory.php
+++ b/src/Fixture/Factory/MenuFixtureFactory.php
@@ -17,7 +17,6 @@
use MonsieurBiz\SyliusMenuPlugin\Entity\MenuItemInterface;
use MonsieurBiz\SyliusMenuPlugin\Entity\MenuItemTranslationInterface;
use Sylius\Bundle\CoreBundle\Fixture\Factory\AbstractExampleFactory;
-use Sylius\Component\Product\Generator\SlugGeneratorInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -31,11 +30,6 @@ final class MenuFixtureFactory extends AbstractExampleFactory implements MenuFix
private OptionsResolver $optionsResolver;
- /**
- * @var SlugGeneratorInterface
- */
- private $slugGenerator;
-
/**
* MenuFixtureFactory constructor.
*/
@@ -43,11 +37,9 @@ public function __construct(
FactoryInterface $menuFactory,
FactoryInterface $menuItemFactory,
FactoryInterface $menuItemTranslationFactory,
- SlugGeneratorInterface $slugGenerator
) {
$this->menuFactory = $menuFactory;
$this->menuItemFactory = $menuItemFactory;
- $this->slugGenerator = $slugGenerator;
$this->menuItemTranslationFactory = $menuItemTranslationFactory;
$this->optionsResolver = new OptionsResolver();
$this->configureOptions($this->getOptionsResolver());
diff --git a/src/Fixture/MenuFixture.php b/src/Fixture/MenuFixture.php
index a5e970a..05d8473 100644
--- a/src/Fixture/MenuFixture.php
+++ b/src/Fixture/MenuFixture.php
@@ -54,7 +54,7 @@ public function configureResourceNode(ArrayNodeDefinition $resourceNode): void
->end()
->end()
->end()
- ;
+ ;
}
public function getName(): string
diff --git a/src/Form/Type/MenuItemType.php b/src/Form/Type/MenuItemType.php
index e564fff..075f1fb 100644
--- a/src/Form/Type/MenuItemType.php
+++ b/src/Form/Type/MenuItemType.php
@@ -14,6 +14,7 @@
namespace MonsieurBiz\SyliusMenuPlugin\Form\Type;
use Doctrine\ORM\EntityRepository;
+use MonsieurBiz\SyliusMenuPlugin\Entity\MenuItemInterface;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
@@ -21,6 +22,7 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
+use Webmozart\Assert\Assert;
final class MenuItemType extends AbstractResourceType
{
@@ -34,6 +36,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$builder
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void {
$item = $event->getData();
+ /** @var MenuItemInterface $item */
+ Assert::isInstanceOf($item, MenuItemInterface::class);
$event->getForm()
->add('parent', EntityType::class, [
'class' => $this->dataClass,
diff --git a/src/Provider/ProductUrlProvider.php b/src/Provider/ProductUrlProvider.php
index b56777c..9b0bbc1 100644
--- a/src/Provider/ProductUrlProvider.php
+++ b/src/Provider/ProductUrlProvider.php
@@ -51,6 +51,7 @@ protected function getResults(string $locale, string $search = ''): iterable
$queryBuilder->setMaxResults($this->getMaxResults());
+ /** @phpstan-ignore-next-line */
return $queryBuilder->getQuery()->getResult();
}
diff --git a/src/Provider/TaxonUrlProvider.php b/src/Provider/TaxonUrlProvider.php
index 4f91664..609bed0 100644
--- a/src/Provider/TaxonUrlProvider.php
+++ b/src/Provider/TaxonUrlProvider.php
@@ -54,6 +54,7 @@ protected function getResults(string $locale, string $search = ''): iterable
$queryBuilder->setMaxResults($this->getMaxResults());
+ /** @phpstan-ignore-next-line */
return $queryBuilder->getQuery()->getResult();
}
@@ -62,6 +63,12 @@ protected function addItemFromResult(object $result, string $locale): void
Assert::isInstanceOf($result, TaxonInterface::class);
/** @var TaxonInterface $result */
$result->setCurrentLocale($locale);
+
+ // Avoid incorrect locale while getting fullname in the root taxon
+ if (!$result->isRoot()) {
+ $result->getRoot()?->setCurrentLocale($locale);
+ }
+
$this->addItem(
(string) $result->getFullname(' > '),
$this->router->generate('sylius_shop_product_index', ['slug' => $result->getSlug(), '_locale' => $locale])
diff --git a/src/Repository/MenuItemRepository.php b/src/Repository/MenuItemRepository.php
index bdb9d82..096ada7 100644
--- a/src/Repository/MenuItemRepository.php
+++ b/src/Repository/MenuItemRepository.php
@@ -34,6 +34,7 @@ public function getLastPositionWithinMenu(MenuInterface $menu): int
->setParameter('menu', $menu)
;
+ /** @phpstan-ignore-next-line */
return (int) $queryBuilder->getQuery()->getSingleScalarResult();
}
@@ -50,6 +51,7 @@ public function getLastPositionWithinMenuItem(MenuItemInterface $menuItem): int
->setParameter('parent', $menuItem)
;
+ /** @phpstan-ignore-next-line */
return (int) $queryBuilder->getQuery()->getSingleScalarResult();
}
}
diff --git a/src/Repository/MenuRepository.php b/src/Repository/MenuRepository.php
index b9b7d31..1b7bcf3 100644
--- a/src/Repository/MenuRepository.php
+++ b/src/Repository/MenuRepository.php
@@ -32,6 +32,7 @@ public function findOneByLocaleAndCode(string $localeCode, string $code): ?MenuI
->setParameter('code', $code)
;
+ /** @phpstan-ignore-next-line */
return (new MenuTreeHydrator())($queryBuilder->getQuery()->getOneOrNullResult());
}
}