From 0f937674d926c5b21a075a08bd0e637af8566e77 Mon Sep 17 00:00:00 2001 From: Maxime Huran Date: Tue, 25 Jun 2024 12:22:24 +0200 Subject: [PATCH 1/3] Update files and recipes to add Sylius 1.13 compatibility --- .github/workflows/recipe.yaml | 46 +++++--------- .github/workflows/security.yaml | 13 ++-- .github/workflows/tests.yaml | 21 +++---- .php-cs-fixer.dist.php | 29 +++++---- .php-version.dist | 2 +- Makefile | 8 +-- README.md | 28 ++++++--- composer.json | 61 +++++-------------- dist/.env.local | 1 + docker-compose.yaml.dist | 1 - phpstan.neon | 12 ++-- recipes/1.0-dev | 1 - .../monsieurbiz_media_manager_plugin.yaml | 12 ---- .../monsieurbiz_media_manager_plugin.yaml | 2 - recipes/1.0/manifest.json | 15 ----- src/DependencyInjection/Configuration.php | 9 +-- 16 files changed, 93 insertions(+), 168 deletions(-) create mode 100644 dist/.env.local delete mode 120000 recipes/1.0-dev delete mode 100644 recipes/1.0/config/packages/monsieurbiz_media_manager_plugin.yaml delete mode 100644 recipes/1.0/config/routes/monsieurbiz_media_manager_plugin.yaml delete mode 100644 recipes/1.0/manifest.json diff --git a/.github/workflows/recipe.yaml b/.github/workflows/recipe.yaml index 9eaaa19..741bdbb 100644 --- a/.github/workflows/recipe.yaml +++ b/.github/workflows/recipe.yaml @@ -9,28 +9,20 @@ jobs: recipe: - name: Flex recipe (PHP ${{ matrix.php }}, Sylius ${{ matrix.sylius }}) - runs-on: ubuntu-latest strategy: fail-fast: false matrix: - php: ['7.4' ,'8.0', '8.1'] - sylius: [ "~1.9.0", "~1.10.0", "~1.11.0", "~1.12.0"] - include: - - php: '8.1' - sylius: '~1.12.0' - sylius_paypal: '~1.5.0' + php: ['8.0', '8.1', '8.2'] + sylius: ["~1.11.0", "~1.12.0", "~1.13.0"] exclude: - - php: 8.1 - sylius: "~1.9.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,6 +31,7 @@ jobs: php-version: ${{ matrix.php }} extensions: gd, intl, json ini-values: date.timezone=UTC + tools: symfony-cli - name: Set project php-version run: | @@ -77,23 +70,16 @@ jobs: run: | composer require --no-install --no-scripts --no-progress sylius/sylius="${{ matrix.sylius }}" - # Fix Paypal 1.5 on Sylius 1.12 and PHP 8.1 - - name: Make sure to install the required version of Sylius Paypal Plugin - if: ${{ matrix.sylius_paypal }} - working-directory: ./sylius - run: | - composer require --no-install --no-scripts --no-progress sylius/paypal-plugin="${{ matrix.sylius_paypal }}" # @see https://github.com/Sylius/PayPalPlugin/issues/295 - - 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 --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/"}' - name: Require plugin & install all dependencies working-directory: ./sylius diff --git a/.github/workflows/security.yaml b/.github/workflows/security.yaml index 4e12805..c100cfa 100644 --- a/.github/workflows/security.yaml +++ b/.github/workflows/security.yaml @@ -8,14 +8,12 @@ jobs: security: - name: Security check (PHP ${{ matrix.php }}) - runs-on: ubuntu-latest strategy: fail-fast: false matrix: - php: ['7.4', '8.0', '8.1'] + php: ['8.1', '8.2'] steps: - uses: actions/checkout@v3 @@ -23,12 +21,12 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php }} - ini-values: date.timezone=UTC + php-version: ${{ matrix.php }} + extensions: gd, intl, json - name: Set project php-version run: | - echo ${{ matrix.php }} > .php-version + echo "${{ matrix.php }}" > .php-version - name: Determine composer cache directory id: composer-cache-directory @@ -39,7 +37,7 @@ jobs: id: cache-composer with: path: ${{ steps.composer-cache-directory.outputs.directory }} - key: composer2-php:${{ matrix.php }}-${{ hashFiles('**/composer.json') }} + key: composer2-php:${{ matrix.php }}-${{ github.sha }} restore-keys: composer2-php:${{ matrix.php }}- - name: Ensure that composer cache directory exists @@ -52,3 +50,4 @@ jobs: run: composer update --prefer-dist - uses: symfonycorp/security-checker-action@v4 + diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index ad79561..877ce6a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -9,14 +9,12 @@ jobs: php: - name: Quality tests (PHP ${{ matrix.php }}) - runs-on: ubuntu-latest strategy: fail-fast: false matrix: - php: ['8.0', '8.1'] + php: ['8.1', '8.2'] env: SYMFONY_ARGS: --no-tls @@ -24,22 +22,21 @@ jobs: DOCKER_INTERACTIVE_ARGS: -t steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 with: node-version: '14' - - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php }} - ini-values: date.timezone=UTC - tools: symfony-cli + 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 - name: Determine composer cache directory id: composer-cache-directory @@ -50,7 +47,7 @@ jobs: id: cache-composer with: path: ${{ steps.composer-cache-directory.outputs.directory }} - key: composer2-php:${{ matrix.php }}-${{ hashFiles('**/composer.json') }} + key: composer2-php:${{ matrix.php }}-${{ github.sha }} restore-keys: composer2-php:${{ matrix.php }}- - name: Ensure that composer cache directory exists diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 5a79af0..97de4ae 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 affad11..78c4374 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,7 @@ .DEFAULT_GOAL := help SHELL=/bin/bash APP_DIR=tests/Application -SYLIUS_VERSION=1.12.0 -SYLIUS_PAYPAL_VERSION=1.5.0 +SYLIUS_VERSION=1.13.0 SYMFONY=cd ${APP_DIR} && symfony COMPOSER=symfony composer CONSOLE=${SYMFONY} console @@ -73,7 +72,6 @@ setup_application: (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 - (cd ${APP_DIR} && ${COMPOSER} require --no-install --no-scripts --no-progress sylius/paypal-plugin="~${SYLIUS_PAYPAL_VERSION}") # @see https://github.com/Sylius/PayPalPlugin/issues/295 $(MAKE) ${APP_DIR}/.php-version $(MAKE) ${APP_DIR}/php.ini (cd ${APP_DIR} && ${COMPOSER} install --no-interaction) @@ -85,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 @@ -136,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 + ${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 27c95a6..ae7fd34 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,30 @@ [![Banner of Sylius Media Manager plugin](docs/images/banner.jpg)](https://monsieurbiz.com/agence-web-experte-sylius) -

Media Manager for Sylius

+

Sylius Media Manager

[![Media Manager Plugin license](https://img.shields.io/github/license/monsieurbiz/SyliusMediaManagerPlugin?public)](https://github.com/monsieurbiz/SyliusMediaManagerPlugin/blob/master/LICENSE.txt) -[![Recipe](https://github.com/monsieurbiz/SyliusMediaManagerPlugin/actions/workflows/recipe.yaml/badge.svg?branch=master&event=push)](https://github.com/monsieurbiz/SyliusMediaManagerPlugin/actions/workflows/recipe.yaml) -[![Tests](https://github.com/monsieurbiz/SyliusMediaManagerPlugin/actions/workflows/tests.yaml/badge.svg?branch=master&event=push)](https://github.com/monsieurbiz/SyliusMediaManagerPlugin/actions/workflows/tests.yaml) -[![Security](https://github.com/monsieurbiz/SyliusMediaManagerPlugin/actions/workflows/security.yaml/badge.svg?branch=master&event=push)](https://github.com/monsieurbiz/SyliusMediaManagerPlugin/actions/workflows/security.yaml) +[![Tests Status](https://img.shields.io/github/actions/workflow/status/monsieurbiz/SyliusMediaManagerPlugin/tests.yaml?branch=master&logo=github)](https://github.com/monsieurbiz/SyliusMediaManagerPlugin/actions?query=workflow%3ATests) +[![Recipe Status](https://img.shields.io/github/actions/workflow/status/monsieurbiz/SyliusMediaManagerPlugin/recipe.yaml?branch=master&label=recipes&logo=github)](https://github.com/monsieurbiz/SyliusMediaManagerPlugin/actions?query=workflow%3ASecurity) +[![Security Status](https://img.shields.io/github/actions/workflow/status/monsieurbiz/SyliusMediaManagerPlugin/security.yaml?branch=master&label=security&logo=github)](https://github.com/monsieurbiz/SyliusMediaManagerPlugin/actions?query=workflow%3ASecurity) +This plugin adds a rich editor on the fields you want. Now you can manage your content very easily! ![Demo of the media manager](docs/images/demo.gif) +## 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"]' +``` Install the plugin via composer: @@ -33,11 +47,7 @@ return [ ]; ``` -Copy the plugin configuration files in your `config` folder: - -```bash -cp -Rv vendor/monsieurbiz/sylius-media-manager-plugin/recipes/1.0/config/ config -``` +Copy the plugin configuration files in your `config` folder: https://github.com/monsieurbiz/symfony-recipes/tree/master/monsieurbiz/sylius-media-manager-plugin/1.0/config Add these variables to your `.env` : diff --git a/composer.json b/composer.json index 6014dd1..14fd9b0 100644 --- a/composer.json +++ b/composer.json @@ -5,45 +5,17 @@ "description": "Add a media manager to your Sylius.", "license": "MIT", "require": { - "php": "~7.4|~8.0", - "ext-mbstring": "*", - "ext-json": "*", - "sylius/sylius": ">=1.9 <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": { @@ -63,23 +35,20 @@ "phpspec": "phpspec run" }, "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + }, "symfony": { "docker": false, - "endpoint": [ - "https://api.github.com/repos/monsieurbiz/symfony-recipes/contents/index.json?ref=flex/master", - "flex://defaults" - ] - }, - "branch-alias": { - "dev-master": "1.0-dev" + "endpoint": ["https://api.github.com/repos/monsieurbiz/symfony-recipes/contents/index.json?ref=flex/master", "flex://defaults"] } }, "config": { "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true, "symfony/thanks": true, - "ergebnis/composer-normalize": true, "symfony/flex": true, + "dealerdirect/phpcodesniffer-composer-installer": true, + "ergebnis/composer-normalize": true, "php-http/discovery": true } } diff --git a/dist/.env.local b/dist/.env.local new file mode 100644 index 0000000..6c1a99e --- /dev/null +++ b/dist/.env.local @@ -0,0 +1 @@ +SYLIUS_FIXTURES_HOSTNAME=${SYMFONY_DEFAULT_ROUTE_HOST:-localhost} diff --git a/docker-compose.yaml.dist b/docker-compose.yaml.dist index 955683c..24d6f0c 100644 --- a/docker-compose.yaml.dist +++ b/docker-compose.yaml.dist @@ -1,4 +1,3 @@ -version: '3.8' services: database: image: mysql:8.0 diff --git a/phpstan.neon b/phpstan.neon index 4864945..bb1c338 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,18 +1,14 @@ -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/MonsieurBizSyliusMediaManagerExtension.php' # Test dependencies - 'tests/Application/**/*' + + ignoreErrors: + - identifier: missingType.iterableValue diff --git a/recipes/1.0-dev b/recipes/1.0-dev deleted file mode 120000 index 9f8e9b6..0000000 --- a/recipes/1.0-dev +++ /dev/null @@ -1 +0,0 @@ -1.0 \ No newline at end of file diff --git a/recipes/1.0/config/packages/monsieurbiz_media_manager_plugin.yaml b/recipes/1.0/config/packages/monsieurbiz_media_manager_plugin.yaml deleted file mode 100644 index 13548b6..0000000 --- a/recipes/1.0/config/packages/monsieurbiz_media_manager_plugin.yaml +++ /dev/null @@ -1,12 +0,0 @@ -imports: - - { resource: "@MonsieurBizSyliusMediaManagerPlugin/Resources/config/config.yaml" } - -liip_imagine: - loaders: - default: - filesystem: - data_root: - - "%sylius_core.public_dir%/media/image" - - "%sylius_core.public_dir%/media" # Add media folder -twig: - form_themes: ['@MonsieurBizSyliusMediaManagerPlugin/Admin/MediaManager/Form/_theme.html.twig'] diff --git a/recipes/1.0/config/routes/monsieurbiz_media_manager_plugin.yaml b/recipes/1.0/config/routes/monsieurbiz_media_manager_plugin.yaml deleted file mode 100644 index 3acc020..0000000 --- a/recipes/1.0/config/routes/monsieurbiz_media_manager_plugin.yaml +++ /dev/null @@ -1,2 +0,0 @@ -monsieurbiz_sylius_media_manager_admin: - resource: "@MonsieurBizSyliusMediaManagerPlugin/Resources/config/routes.yaml" diff --git a/recipes/1.0/manifest.json b/recipes/1.0/manifest.json deleted file mode 100644 index 97651bc..0000000 --- a/recipes/1.0/manifest.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "bundles": { - "MonsieurBiz\\SyliusMediaManagerPlugin\\MonsieurBizSyliusMediaManagerPlugin": [ - "all" - ] - }, - "copy-from-recipe": { - "config/": "%CONFIG_DIR%/" - }, - "env": { - "MONSIEURBIZ_SYLIUS_MEDIA_MANAGER_PUBLIC_FOLDER": "%kernel.project_dir%/public", - "MONSIEURBIZ_SYLIUS_MEDIA_MANAGER_ROOT_FOLDER_FROM_PUBLIC": "media", - "MONSIEURBIZ_SYLIUS_MEDIA_MANAGER_MAX_FILE_SIZE": "5M" - } -} diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 9829e05..065b033 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -24,14 +24,7 @@ final class Configuration implements ConfigurationInterface public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('monsieurbiz_sylius_media_manager'); - if (method_exists($treeBuilder, 'getRootNode')) { - $treeBuilder->getRootNode(); - - return $treeBuilder; - } - - // BC layer for symfony/config 4.1 and older - $treeBuilder->root('monsieurbiz_sylius_media_manager'); + $treeBuilder->getRootNode(); return $treeBuilder; } From 144f56eedf8cfa2b0a07fc8395ad1efea14fd51e Mon Sep 17 00:00:00 2001 From: Maxime Huran Date: Tue, 25 Jun 2024 12:25:52 +0200 Subject: [PATCH 2/3] Fix PHP CS --- src/Exception/FileTooBigException.php | 14 ++++++++------ src/Helper/FileHelper.php | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Exception/FileTooBigException.php b/src/Exception/FileTooBigException.php index 6347bc4..e7679ca 100644 --- a/src/Exception/FileTooBigException.php +++ b/src/Exception/FileTooBigException.php @@ -32,12 +32,14 @@ public function __construct(string $filename, int $size, int $maxAllowedSizeByte $this->maxAllowedSizeBytes = $maxAllowedSizeBytes; $this->maxAllowedSize = $maxAllowedSize; parent::__construct( - sprintf('File `%s` couldn\'t be created. File size %s is bigger than %s bytes. (%s)', - $filename, - $size, - $maxAllowedSizeBytes, - $maxAllowedSize - )); + sprintf( + 'File `%s` couldn\'t be created. File size %s is bigger than %s bytes. (%s)', + $filename, + $size, + $maxAllowedSizeBytes, + $maxAllowedSize + ) + ); } public function getFilename(): string diff --git a/src/Helper/FileHelper.php b/src/Helper/FileHelper.php index 15382d5..8b27788 100644 --- a/src/Helper/FileHelper.php +++ b/src/Helper/FileHelper.php @@ -362,11 +362,11 @@ private static function parseFilesize(string $size): int switch (substr($size, -1)) { case 't': $max *= 1024; - // no break + // no break case 'g': $max *= 1024; - // no break + // no break case 'm': $max *= 1024; - // no break + // no break case 'k': $max *= 1024; } From f61e9366871f017a78d037f70c8bc93c91a43560 Mon Sep 17 00:00:00 2001 From: Maxime Huran Date: Tue, 25 Jun 2024 12:34:44 +0200 Subject: [PATCH 3/3] Fix PHP Stan and PHP MD --- src/Controller/BrowserController.php | 6 +++++- src/Twig/Extension/FilterExtensionDecorator.php | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Controller/BrowserController.php b/src/Controller/BrowserController.php index 4408ec8..ea69450 100644 --- a/src/Controller/BrowserController.php +++ b/src/Controller/BrowserController.php @@ -26,6 +26,7 @@ use MonsieurBiz\SyliusMediaManagerPlugin\Exception\InvalidTypeException; use MonsieurBiz\SyliusMediaManagerPlugin\Helper\FileHelperInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -90,6 +91,9 @@ public function chooseAction( return new JsonResponse(['path' => $fileHelper->cleanPath($path)]); } + /** + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + */ public function uploadAction( FileHelperInterface $fileHelper, Request $request, @@ -99,7 +103,7 @@ public function uploadAction( $folder = (string) $request->request->get('folder', ''); $file = $request->files->get('file'); - if (null === $file) { + if (null === $file || !($file instanceof UploadedFile)) { return new JsonResponse([ 'error' => $translator->trans('monsieurbiz_sylius_media_manager.error.cannot_upload_file'), ], Response::HTTP_BAD_REQUEST); diff --git a/src/Twig/Extension/FilterExtensionDecorator.php b/src/Twig/Extension/FilterExtensionDecorator.php index 56ec37d..6738a1c 100644 --- a/src/Twig/Extension/FilterExtensionDecorator.php +++ b/src/Twig/Extension/FilterExtensionDecorator.php @@ -36,10 +36,10 @@ public function __construct( /** * Allow us to have multiple data roots for svg images. * - * @param mixed $path - * @param mixed $filter - * @param mixed|null $resolver - * @param mixed $referenceType + * @param string $path + * @param string $filter + * @param string|null $resolver + * @param int $referenceType */ public function filter( $path,