From accedc63e48df7d7c434d30d656c2394c4b5bf55 Mon Sep 17 00:00:00 2001 From: David Molineus Date: Tue, 29 Nov 2022 11:05:30 +0100 Subject: [PATCH] Update coding standard --- .composer-require-checker.json | 11 ++ .editorconfig | 17 +++ .gitattributes | 5 + .github/FUNDING.yml | 1 + .github/dependabot.yaml | 27 +++++ .github/workflows/diagnostics.yml | 75 ++++++++++++ .gitignore | 22 +--- .phpcq.lock | 1 + .phpcq.yaml.dist | 96 +++++++++++++++ .travis.yml | 34 ------ build.default.properties | 4 - build.xml | 5 - composer.json | 109 ++++++++++-------- phpcs.xml.dist | 102 ++++++++++++++++ src/ContaoManager/Plugin.php | 17 +-- .../LeafletGeocodeWidgetExtension.php | 17 +-- .../RadiusWizardCallbackListener.php | 25 ++-- src/GeocodeWidget.php | 17 +-- src/LeafletGeocodeWidgetBundle.php | 15 +-- src/Resources/contao/config/config.php | 17 +-- src/Widget/GeocodeWidget.php | 52 ++++----- src/Widget/RadiusWidget.php | 34 +++--- 22 files changed, 457 insertions(+), 246 deletions(-) create mode 100644 .composer-require-checker.json create mode 100644 .editorconfig create mode 100644 .github/FUNDING.yml create mode 100644 .github/dependabot.yaml create mode 100644 .github/workflows/diagnostics.yml create mode 100644 .phpcq.lock create mode 100644 .phpcq.yaml.dist delete mode 100644 .travis.yml delete mode 100644 build.default.properties delete mode 100644 build.xml create mode 100644 phpcs.xml.dist diff --git a/.composer-require-checker.json b/.composer-require-checker.json new file mode 100644 index 0000000..fb94d0e --- /dev/null +++ b/.composer-require-checker.json @@ -0,0 +1,11 @@ +{ + "symbol-whitelist": [ + "null", "true", "false", + "static", "self", "parent", + "array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", + "Contao\\ManagerPlugin\\Bundle\\BundlePluginInterface", + "Contao\\ManagerPlugin\\Bundle\\Config\\BundleConfig", + "Contao\\ManagerPlugin\\Bundle\\Parser\\ParserInterface", + "Contao\\ManagerPlugin\\Bundle\\Config\\BundleConfig" + ] +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..891e8ea --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.php] +indent_size = 4 + +[*.js] +indent_size = 4 + +[{*.vue,*.json,*.html5,*.xlf,*.twig}] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes index 06d085f..266425f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,3 +8,8 @@ build.xml export-ignore phpunit.xml.dist export-ignore /tests export-ignore /specs export-ignore +.phpcq.lock export-ignore +.phpcq.yaml.dis export-ignore +psalm.xml export-ignore +phpcs.xml.dis export-ignore +composer.lock export-ignore diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..a53b22a --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [dmolineus] diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 0000000..100a305 --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,27 @@ +# https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 + +updates: + - commit-message: + include: "scope" + prefix: "composer" + directory: "/" + labels: + - "dependency" + open-pull-requests-limit: 0 + package-ecosystem: "composer" + schedule: + interval: "weekly" + versioning-strategy: "increase" + + - commit-message: + include: "scope" + prefix: "github-actions" + directory: "/" + labels: + - "dependency" + open-pull-requests-limit: 10 + package-ecosystem: "github-actions" + schedule: + interval: "weekly" diff --git a/.github/workflows/diagnostics.yml b/.github/workflows/diagnostics.yml new file mode 100644 index 0000000..23471a3 --- /dev/null +++ b/.github/workflows/diagnostics.yml @@ -0,0 +1,75 @@ +name: Code Quality Diagnostics + +on: + pull_request: + push: + branches: + - master + - develop + +jobs: + build: + runs-on: ubuntu-latest + + name: PHP ${{ matrix.php }} + + strategy: + fail-fast: false + matrix: + include: + - php: '7.4' + phpcq_install: 'install' + phpcq_flags: '' + - php: '8.0' + phpcq_install: 'update' + phpcq_flags: '' + - php: '8.1' + phpcq_install: 'update' + phpcq_flags: '' + + steps: + - name: Pull source + uses: actions/checkout@v2 + + - name: Setup PHP with PECL extension + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: xdebug2 + + - name: Cache composer cache directory + uses: actions/cache@v1 + env: + cache-name: composer-cache-dir-${{ matrix.php }} + with: + path: ~/.cache/composer + key: ${{ runner.os }}-build-${{ env.cache-name }} + + - name: Install composer dependencies + run: composer install + + - name: Cache vendor directory of phpcq tool runner + uses: actions/cache@v1 + env: + cache-name: vendor-${{ matrix.php }} + with: + path: $GITHUB_WORKSPACE/vendor + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + + - name: Update phpcq + run: $GITHUB_WORKSPACE/vendor/bin/phpcq self-update --unsigned + + - name: Install phpcq toolchain + run: $GITHUB_WORKSPACE/vendor/bin/phpcq ${{ matrix.phpcq_install }} -v + + - name: Run tests + run: $GITHUB_WORKSPACE/vendor/bin/phpcq run -o github-action -o default ${{ matrix.phpcq_flags }} -v + + - name: Upload build directory to artifact + uses: actions/upload-artifact@v2 + if: ${{ success() }} || ${{ failure() }} + with: + name: phpcq-builds-php-${{ matrix.php }} + path: .phpcq/build/ diff --git a/.gitignore b/.gitignore index a4e22b1..afe76fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,10 @@ -# OS -.DS_Store -Thumbs.db -.directory - -# IDEs -.buildpath -.project -.settings/ -.build/ -.external*/ -.idea/ -nbproject/ - # composer related vendor/ composer.lock -# build -build/ -build.properties - # Translations .tx + +# phpcq +/.phpcq/ +.phpcs-cache diff --git a/.phpcq.lock b/.phpcq.lock new file mode 100644 index 0000000..b40933f --- /dev/null +++ b/.phpcq.lock @@ -0,0 +1 @@ +{"plugins":{"composer-require-checker":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/composer-require-checker-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0"},"tool":{"composer-require-checker":"^3.8 || ^4.0"}},"checksum":{"type":"sha-512","value":"d5415bddfe024c5749d894034583882aee4e5c3e1087815d9fdd81cb5e71630f631a0e35de0ff84b97fbbf738c16ece5f83bd8c00695913eb846aa6f04577dc2"},"tools":{"composer-require-checker":{"version":"3.8.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar","requirements":{"php":{"php":"^7.4 || ^8.0","ext-json":"*","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar.asc"}},"composerLock":null},"phpmd":{"api-version":"1.0.0","version":"1.0.2.0","type":"php-file","url":"https://phpcq.github.io/repository/phpmd-1.0.2.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpmd":"^2.6.1"}},"checksum":{"type":"sha-512","value":"f22280a6dec8dbdd2ec1d83b294f23237fe32c34f4a298e52038e0a7a0074d541635b2b488b1a6098a42d8418a6cd8eb804406ea82b91e362be2b5d11a0915b0"},"tools":{"phpmd":{"version":"2.13.0","url":"https://github.com/phpmd/phpmd/releases/download/2.13.0/phpmd.phar","requirements":{"php":{"php":">=5.3.9","ext-xml":"*"}},"checksum":null,"signature":"https://github.com/phpmd/phpmd/releases/download/2.13.0/phpmd.phar.asc"}},"composerLock":null},"phpcpd":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/phpcpd-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcpd":"^6.0"}},"checksum":{"type":"sha-512","value":"1189ce0bf3fade4cb4241f1d96f915ef8fc7651f4450dc79fdf464ee3d6be3009316f0d423ce2d4af9d76ad50807b7fdf4d77bfa6d9ee2c91d6eda32ea214433"},"tools":{"phpcpd":{"version":"6.0.3","url":"https://phar.phpunit.de/phpcpd-6.0.3.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*"}},"checksum":{"type":"sha-256","value":"2cbaea7cfda1bb4299d863eb075e977c3f49055dd16d88529fae5150d48a84cb"},"signature":"https://phar.phpunit.de/phpcpd-6.0.3.phar.asc"}},"composerLock":null},"phploc":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phploc-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*","ext-json":"*"},"tool":{"phploc":"^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"}},"checksum":{"type":"sha-512","value":"f67b02d494796adf553cb3dd13ec06c1cb8e53c799954061749424251379541637538199afb3afa3c7a01cabd1cb6f1c53eb621f015dff9644c6c7cbf10c56d1"},"tools":{"phploc":{"version":"7.0.2","url":"https://phar.phpunit.de/phploc-7.0.2.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*"}},"checksum":{"type":"sha-256","value":"3d59778ec86faf25fd00e3a329b2f9ad4a3c751ca91601ea7dab70f887b0bf46"},"signature":"https://phar.phpunit.de/phploc-7.0.2.phar.asc"}},"composerLock":null},"phpcs":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phpcs-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcs":"^3.0 || ^2.0","phpcbf":"^3.0 || ^2.0"}},"checksum":{"type":"sha-512","value":"2737022369da1318cc4e0ea194e8a81019f7b079080d869aab878b7486052fdbe68fee3f28131f35573226def1aabd4bd005e038ee7b767c137b1107c1492a83"},"tools":{"phpcs":{"version":"3.7.1","url":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.1/phpcs.phar","requirements":{"php":{"php":">=5.4.0","ext-tokenizer":"*","ext-xmlwriter":"*","ext-simplexml":"*"}},"checksum":null,"signature":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.1/phpcs.phar.asc"},"phpcbf":{"version":"3.7.1","url":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.1/phpcbf.phar","requirements":{"php":{"php":">=5.4.0","ext-tokenizer":"*","ext-xmlwriter":"*","ext-simplexml":"*"}},"checksum":null,"signature":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.1/phpcbf.phar.asc"}},"composerLock":null},"composer-normalize":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/composer-normalize-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-json":"*"},"tool":{"composer-normalize":"^2.1"}},"checksum":{"type":"sha-512","value":"d59d3557cb20630734878a9115df5dd32d5aff815e5b15be36f6fb5d6e9d83dd36efd84215ab6529edcc924f600946f739a0d9e67723deff95c88346ab502498"},"tools":{"composer-normalize":{"version":"2.28.3","url":"https://github.com/ergebnis/composer-normalize/releases/download/2.28.3/composer-normalize.phar","requirements":{"php":{"php":"^7.4 || ^8.0"}},"checksum":null,"signature":"https://github.com/ergebnis/composer-normalize/releases/download/2.28.3/composer-normalize.phar.asc"}},"composerLock":null}},"tools":[]} \ No newline at end of file diff --git a/.phpcq.yaml.dist b/.phpcq.yaml.dist new file mode 100644 index 0000000..8959536 --- /dev/null +++ b/.phpcq.yaml.dist @@ -0,0 +1,96 @@ +phpcq: + repositories: + - https://phpcq.github.io/repository/repository.json + directories: + - src + artifact: .phpcq/build + + plugins: + composer-require-checker: + version: ^1.0 + signed: false + phpmd: + version: ^1.0 + signed: false + requirements: + phpmd: + signed: false + phpcpd: + version: ^1.1 + signed: false + phploc: + version: ^1.0 + signed: false + phpcs: + version: ^1.0 + signed: false + composer-normalize: + version: ^1.0 + signed: false + trusted-keys: + # composer-require-checker + - 033E5F8D801A2F8D + # sb@sebastian-bergmann.de + - 4AA394086372C20A + # psalm + - 8A03EA3B385DBAA1 + - 12CE0F1D262429A5 + # magl@magll.net + - D2CCAC42F6295E7D + # PHP_CodeSniffer + - 31C7E470E2138192 + # Composer normalize + - C00543248C87FB13 + # phpmd + - 0F9684B8B16B7AB0 + - A4E55EA12C7C085C + +tasks: + fix: + - composer-normalize-fix + - phpcbf + + verify: + - composer-require-checker + - composer-normalize + + analyze: + - phploc + - phpcpd + - phpmd + - phpcs +# - psalm + + default: + - verify + - analyze + + composer-require-checker: + config: + config_file: '.composer-require-checker.json' + + phpcs: + plugin: phpcs + config: &phpcs-config + standard: ~ + standard_paths: + - ./vendor/slevomat/coding-standard + - ./vendor/doctrine/coding-standard/lib + excluded: + - src/Resources/contao/languages + + phpcbf: + plugin: phpcs + config: + <<: *phpcs-config + fix: true + + composer-normalize: + config: + ignore_output: + - '#Root package is not of type "project", we will not installing Contao extensions\.#' + + composer-normalize-fix: + plugin: composer-normalize + config: + dry_run: false diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 688d626..0000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -language: php - -php: - - "5.6" - - "7.0" - - "7.1" - - "7.2" - -env: - - CONTAO_VERSION=contao/core-bundle ~4.4.2 - - CONTAO_VERSION=contao/core-bundle ~4.5.0 - -matrix: - exclude: - - php: 5.6 - env: CONTAO_VERSION=contao/core-bundle ~4.5.0 - - php: 7.0 - env: CONTAO_VERSION=contao/core-bundle ~4.5.0 - -sudo: false - -install: - - travis_retry composer self-update && composer --version - - travis_retry composer require $CONTAO_VERSION --no-update - - travis_retry composer update --prefer-dist --no-interaction - -script: ant -keep-going - -git: - depth: 2147483647 - -cache: - directories: - - vendor diff --git a/build.default.properties b/build.default.properties deleted file mode 100644 index 0f40b56..0000000 --- a/build.default.properties +++ /dev/null @@ -1,4 +0,0 @@ -phpcs.standard=${basedir}/vendor/phpcq/coding-standard/phpcs/PhpCodeQuality/ruleset.xml -phpmd.ruleset=${basedir}/vendor/phpcq/coding-standard/phpmd/ruleset.xml -phpcs.excluded = src/Resources/contao/languages -phpcpd.excluded = contao diff --git a/build.xml b/build.xml deleted file mode 100644 index 6974ffa..0000000 --- a/build.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/composer.json b/composer.json index fe30155..e94064d 100644 --- a/composer.json +++ b/composer.json @@ -1,51 +1,64 @@ { - "name": "netzmacht/contao-leaflet-geocode-widget", - "description": "Geocode widget based on Leaflet", - "keywords": [ - "geocode", - "contao", - "widget", - "leaflet" - ], - "type": "contao-bundle", - "license": "LGPL-3.0-or-later", - "authors": [ - { - "name": "David Molineus", - "email": "mail@netzmacht.de", - "homepage": "https://netzmacht.de", - "role": "Developer" - } - ], - "support": { - "email": "mail@netzmacht.de", - "issues": "https://github.com/contao-bootstrap/core/issues", - "wiki": "http://contao-bootstrap.netzmacht.de", - "source": "https://github.com/contao-bootstrap/core" - }, - "require": { - "php": "^7.4 || ^8.0", - "contao/core-bundle": "^4.13 || ^5.0", - "netzmacht/contao-leaflet-libraries": "~1.3" - }, - "require-dev": { - "contao/manager-plugin": "^2.0", - "phpcq/all-tasks": "^1.2", - "php-http/guzzle6-adapter": "^1.1" - }, - "suggest": { - "netzmacht/contao-leaflet-maps": "Leaflet Maps for Contao" - }, - "autoload": { - "psr-4": { - "Netzmacht\\Contao\\Leaflet\\GeocodeWidget\\": "src/" - } - }, - "extra": { - "branch-alias": { - "dev-master": "1.3.x-dev", - "dev-develop": "1.4.x-dev" - }, - "contao-manager-plugin": "Netzmacht\\Contao\\Leaflet\\GeocodeWidget\\ContaoManager\\Plugin" + "name": "netzmacht/contao-leaflet-geocode-widget", + "description": "Geocode widget based on Leaflet", + "license": "LGPL-3.0-or-later", + "type": "contao-bundle", + "keywords": [ + "geocode", + "contao", + "widget", + "leaflet" + ], + "authors": [ + { + "name": "David Molineus", + "email": "mail@netzmacht.de", + "homepage": "https://netzmacht.de", + "role": "Developer" } + ], + "support": { + "email": "mail@netzmacht.de", + "issues": "https://github.com/contao-bootstrap/core/issues", + "wiki": "http://contao-bootstrap.netzmacht.de", + "source": "https://github.com/contao-bootstrap/core" + }, + "require": { + "php": "^7.4 || ^8.0", + "contao/core-bundle": "^4.13 || ^5.0", + "netzmacht/contao-leaflet-libraries": "~1.3", + "symfony/config": "^5.4 || ^6.0", + "symfony/dependency-injection": "^5.4 || ^6.0", + "symfony/http-kernel": "^5.4 || ^6.0" + }, + "require-dev": { + "contao/manager-plugin": "^2.0", + "doctrine/coding-standard": "^9.0", + "phpcq/runner-bootstrap": "1.x-dev", + "phpspec/phpspec": "^6.3.0 || ^7.0" + }, + "suggest": { + "netzmacht/contao-leaflet-maps": "Leaflet Maps for Contao" + }, + "autoload": { + "psr-4": { + "Netzmacht\\Contao\\Leaflet\\GeocodeWidget\\": "src/" + } + }, + "config": { + "allow-plugins": { + "contao-components/installer": true, + "contao/manager-plugin": true, + "dealerdirect/phpcodesniffer-composer-installer": true, + "contao-community-alliance/composer-plugin": true + }, + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-develop": "1.4.x-dev", + "dev-master": "1.3.x-dev" + }, + "contao-manager-plugin": "Netzmacht\\Contao\\Leaflet\\GeocodeWidget\\ContaoManager\\Plugin" + } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..2f91a93 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,102 @@ + + + + + + + + + + vendor/autoload.php + + + + + + src + + + + + + + + + + + + + + src/Resources/contao/languages/* + + + + + + + + + + + + + + + + + + + + + + + + + spec/.*\.php + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index 5d6628a..44a3b91 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -1,14 +1,6 @@ - * @copyright 2016-2017 netzmacht David Molineus. All rights reserved. - * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/master/LICENSE - * @filesource - */ +declare(strict_types=1); namespace Netzmacht\Contao\Leaflet\GeocodeWidget\ContaoManager; @@ -18,17 +10,12 @@ use Contao\ManagerPlugin\Bundle\Config\BundleConfig; use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; use Netzmacht\Contao\Leaflet\GeocodeWidget\LeafletGeocodeWidgetBundle; -/** - * Contao Manager plugin. - * - * @package Netzmacht\Contao\Leaflet\GeocodeWidget\ContaoManager - */ class Plugin implements BundlePluginInterface { /** * {@inheritdoc} */ - public function getBundles(ParserInterface $parser) + public function getBundles(ParserInterface $parser): array { return [ BundleConfig::create(LeafletGeocodeWidgetBundle::class) diff --git a/src/DependencyInjection/LeafletGeocodeWidgetExtension.php b/src/DependencyInjection/LeafletGeocodeWidgetExtension.php index df63e1b..de0cca3 100644 --- a/src/DependencyInjection/LeafletGeocodeWidgetExtension.php +++ b/src/DependencyInjection/LeafletGeocodeWidgetExtension.php @@ -1,14 +1,6 @@ - * @copyright 2016-2018 netzmacht David Molineus. All rights reserved. - * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/master/LICENSE - * @filesource - */ +declare(strict_types=1); namespace Netzmacht\Contao\Leaflet\GeocodeWidget\DependencyInjection; @@ -17,15 +9,14 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -/** - * Class LeafletGeocodeWidgetExtension - */ +use function dirname; + class LeafletGeocodeWidgetExtension extends Extension { /** * {@inheritdoc} */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $loader = new YamlFileLoader( $container, diff --git a/src/EventListener/RadiusWizardCallbackListener.php b/src/EventListener/RadiusWizardCallbackListener.php index cb8b87a..cfec280 100644 --- a/src/EventListener/RadiusWizardCallbackListener.php +++ b/src/EventListener/RadiusWizardCallbackListener.php @@ -1,24 +1,13 @@ - * @copyright 2016-2018 netzmacht David Molineus. All rights reserved. - * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/master/LICENSE - * @filesource - */ +declare(strict_types=1); namespace Netzmacht\Contao\Leaflet\GeocodeWidget\EventListener; use Contao\DataContainer; -/** - * Class RadiusWizardCallbackListener - * - * @package Netzmacht\Contao\Leaflet\GeocodeWidget\EventListener - */ +use function sprintf; + class RadiusWizardCallbackListener { /** @@ -26,13 +15,13 @@ class RadiusWizardCallbackListener * * @param DataContainer $dataContainer Data container driver. * - * @return string - * * @SuppressWarnings(PHPMD.Superglobals) */ - public function generateWizard($dataContainer) + public function generateWizard(DataContainer $dataContainer): string { - if (!isset($GLOBALS['TL_DCA'][$dataContainer->table]['fields'][$dataContainer->field]['eval']['coordinates'])) { + $fields = $GLOBALS['TL_DCA'][$dataContainer->table]['fields']; + + if (! isset($fields[$dataContainer->field]['eval']['coordinates'])) { return ''; } diff --git a/src/GeocodeWidget.php b/src/GeocodeWidget.php index fe47724..0f4a29f 100644 --- a/src/GeocodeWidget.php +++ b/src/GeocodeWidget.php @@ -1,30 +1,17 @@ - * @copyright 2016-2018 netzmacht David Molineus. All rights reserved. - * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/master/LICENSE - * @filesource - */ +declare(strict_types=1); namespace Netzmacht\Contao\Leaflet\GeocodeWidget; use Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\GeocodeWidget as BaseWidget; -/** - * Class GeocodeWidget - * - * @deprecated - */ class GeocodeWidget extends BaseWidget { /** * {@inheritdoc} */ - public function __construct(array $arrAttributes = null) + public function __construct(?array $arrAttributes = null) { parent::__construct($arrAttributes); diff --git a/src/LeafletGeocodeWidgetBundle.php b/src/LeafletGeocodeWidgetBundle.php index 9546d82..9666050 100644 --- a/src/LeafletGeocodeWidgetBundle.php +++ b/src/LeafletGeocodeWidgetBundle.php @@ -1,24 +1,11 @@ - * @copyright 2016-2017 netzmacht David Molineus. All rights reserved. - * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/master/LICENSE - * @filesource - */ +declare(strict_types=1); namespace Netzmacht\Contao\Leaflet\GeocodeWidget; use Symfony\Component\HttpKernel\Bundle\Bundle; -/** - * Class LeafletGeocodeWidgetBundle - * - * @package Netzmacht\Contao\Leaflet\GeocodeWidget - */ class LeafletGeocodeWidgetBundle extends Bundle { } diff --git a/src/Resources/contao/config/config.php b/src/Resources/contao/config/config.php index 00a27b4..3bbfa49 100644 --- a/src/Resources/contao/config/config.php +++ b/src/Resources/contao/config/config.php @@ -1,14 +1,9 @@ - * @copyright 2016-2018 netzmacht David Molineus. All rights reserved. - * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/master/LICENSE - * @filesource - */ +declare(strict_types=1); -$GLOBALS['BE_FFL']['leaflet_geocode'] = 'Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\GeocodeWidget'; -$GLOBALS['BE_FFL']['leaflet_radius'] = 'Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\RadiusWidget'; +use Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\GeocodeWidget; +use Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\RadiusWidget; + +$GLOBALS['BE_FFL']['leaflet_geocode'] = GeocodeWidget::class; +$GLOBALS['BE_FFL']['leaflet_radius'] = RadiusWidget::class; diff --git a/src/Widget/GeocodeWidget.php b/src/Widget/GeocodeWidget.php index 5a91d9d..b755318 100644 --- a/src/Widget/GeocodeWidget.php +++ b/src/Widget/GeocodeWidget.php @@ -1,14 +1,6 @@ - * @copyright 2016-2018 netzmacht David Molineus. All rights reserved. - * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/master/LICENSE - * @filesource - */ +declare(strict_types=1); namespace Netzmacht\Contao\Leaflet\GeocodeWidget\Widget; @@ -16,9 +8,11 @@ use Contao\BackendTemplate; use Contao\StringUtil; use Contao\Widget; +use function is_array; +use function preg_match; +use function sprintf; + /** - * Class GeocodeWidget - * * @property int size * @property bool multiple */ @@ -27,14 +21,14 @@ class GeocodeWidget extends Widget /** * Submit user input. * - * @var boolean + * @var bool */ protected $blnSubmitInput = true; /** * Add a for attribute. * - * @var boolean + * @var bool */ protected $blnForAttribute = true; @@ -65,7 +59,7 @@ class GeocodeWidget extends Widget { $value = parent::validator($value); - if (!$value) { + if (! $value) { return $value; } @@ -78,10 +72,10 @@ class GeocodeWidget extends Widget } // See: http://stackoverflow.com/a/18690202 - if (!preg_match( - '#^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)(,[-+]?\d+)?$#', - $value - )) { + $pattern = '#^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),[-+]?(180(\.0+)?|' + . '((1[0-7]\d)|([1-9]?\d))(\.\d+)?)(,[-+]?\d+)?$#'; + + if (! preg_match($pattern, $value)) { $this->addError( sprintf( $GLOBALS['TL_LANG']['ERR']['leafletInvalidCoordinate'], @@ -95,20 +89,18 @@ class GeocodeWidget extends Widget /** * Generate the widget. - * - * @return string */ - public function generate() + public function generate(): string { $wrapperClass = 'wizard'; - if (!$this->multiple || !$this->size) { + if (! $this->multiple || ! $this->size) { $this->size = 1; } else { $wrapperClass .= ' wizard_' . $this->size; } - if (!is_array($this->value)) { + if (! is_array($this->value)) { $this->value = [$this->value]; } @@ -122,12 +114,12 @@ class GeocodeWidget extends Widget 'widget' => $this, 'value' => StringUtil::specialchars($this->value[$index]), 'class' => $this->strClass ? ' ' . $this->strClass : '', - 'id' => $this->strId . (($this->size > 1) ? '_' . $index : ''), - 'name' => $this->strName . (($this->size > 1) ? '[]' : ''), + 'id' => $this->strId . ($this->size > 1 ? '_' . $index : ''), + 'name' => $this->strName . ($this->size > 1 ? '[]' : ''), 'attributes' => $this->getAttributes(), 'wizard' => $this->wizard, 'label' => $this->strLabel, - 'radius' => $this->buildRadiusOptions() + 'radius' => $this->buildRadiusOptions(), ] ); @@ -140,13 +132,13 @@ class GeocodeWidget extends Widget /** * Build the radius options. * - * @return array|null + * @return array|null * * @SuppressWarnings(PHPMD.Superglobals) */ - private function buildRadiusOptions() + private function buildRadiusOptions(): ?array { - if (!$this->radius || !isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->radius])) { + if (! $this->radius || ! isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->radius])) { return null; } @@ -154,7 +146,7 @@ class GeocodeWidget extends Widget 'element' => 'ctrl_' . $this->radius, 'min' => 0, 'max' => 0, - 'defaultValue' => 0 + 'defaultValue' => 0, ]; if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->radius]['eval'])) { diff --git a/src/Widget/RadiusWidget.php b/src/Widget/RadiusWidget.php index 58ed85f..8cd39e2 100644 --- a/src/Widget/RadiusWidget.php +++ b/src/Widget/RadiusWidget.php @@ -1,14 +1,6 @@ - * @copyright 2016-2018 netzmacht David Molineus. All rights reserved. - * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/master/LICENSE - * @filesource - */ +declare(strict_types=1); namespace Netzmacht\Contao\Leaflet\GeocodeWidget\Widget; @@ -16,9 +8,11 @@ use Contao\BackendTemplate; use Contao\StringUtil; use Contao\TextField; -/** - * Class RadiusWidget - */ +use function is_array; +use function is_numeric; +use function round; +use function trim; + class RadiusWidget extends TextField { /** @@ -42,20 +36,18 @@ class RadiusWidget extends TextField /** * Generate the widget. - * - * @return string */ - public function generate() + public function generate(): string { $wrapperClass = $this->coordinates ? 'wizard' : ''; - if (!$this->multiple || !$this->size) { + if (! $this->multiple || ! $this->size) { $this->size = 1; } else { $wrapperClass .= ' wizard_' . $this->size; } - if (!is_array($this->value)) { + if (! is_array($this->value)) { $this->value = [$this->value]; } @@ -69,12 +61,12 @@ class RadiusWidget extends TextField 'widget' => $this, 'value' => StringUtil::specialchars($this->value[$index]), 'class' => $this->strClass ? ' ' . $this->strClass : '', - 'id' => $this->strId . (($this->size > 1) ? '_' . $index : ''), - 'name' => $this->strName . (($this->size > 1) ? '[]' : ''), + 'id' => $this->strId . ($this->size > 1 ? '_' . $index : ''), + 'name' => $this->strName . ($this->size > 1 ? '[]' : ''), 'attributes' => $this->getAttributes(), 'wizard' => $this->wizard, 'label' => $this->strLabel, - 'coordinates' => $this->coordinates + 'coordinates' => $this->coordinates, ] ); @@ -92,7 +84,7 @@ class RadiusWidget extends TextField if (is_numeric($varInput) && $this->steps > 0) { $steps = (int) $this->steps; $varInput = (int) $varInput; - $varInput = ($steps * round($varInput / $steps)); + $varInput = $steps * round($varInput / $steps); } return parent::validator($varInput);