Update coding standard

This commit is contained in:
David Molineus
2022-11-29 11:05:30 +01:00
parent 37f94737c5
commit accedc63e4
22 changed files with 457 additions and 246 deletions

View File

@@ -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"
]
}

17
.editorconfig Normal file
View File

@@ -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

5
.gitattributes vendored
View File

@@ -8,3 +8,8 @@ build.xml export-ignore
phpunit.xml.dist export-ignore phpunit.xml.dist export-ignore
/tests export-ignore /tests export-ignore
/specs 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

1
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
github: [dmolineus]

27
.github/dependabot.yaml vendored Normal file
View File

@@ -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"

75
.github/workflows/diagnostics.yml vendored Normal file
View File

@@ -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/

22
.gitignore vendored
View File

@@ -1,24 +1,10 @@
# OS
.DS_Store
Thumbs.db
.directory
# IDEs
.buildpath
.project
.settings/
.build/
.external*/
.idea/
nbproject/
# composer related # composer related
vendor/ vendor/
composer.lock composer.lock
# build
build/
build.properties
# Translations # Translations
.tx .tx
# phpcq
/.phpcq/
.phpcs-cache

1
.phpcq.lock Normal file

File diff suppressed because one or more lines are too long

96
.phpcq.yaml.dist Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="netzmacht/contao-leaflet-geocode-widget" default="build">
<!-- import the main build system -->
<import file="vendor/phpcq/phpcq/phpcq.main.xml" />
</project>

View File

@@ -1,51 +1,64 @@
{ {
"name": "netzmacht/contao-leaflet-geocode-widget", "name": "netzmacht/contao-leaflet-geocode-widget",
"description": "Geocode widget based on Leaflet", "description": "Geocode widget based on Leaflet",
"keywords": [ "license": "LGPL-3.0-or-later",
"geocode", "type": "contao-bundle",
"contao", "keywords": [
"widget", "geocode",
"leaflet" "contao",
], "widget",
"type": "contao-bundle", "leaflet"
"license": "LGPL-3.0-or-later", ],
"authors": [ "authors": [
{ {
"name": "David Molineus", "name": "David Molineus",
"email": "mail@netzmacht.de", "email": "mail@netzmacht.de",
"homepage": "https://netzmacht.de", "homepage": "https://netzmacht.de",
"role": "Developer" "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"
} }
],
"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"
}
} }

102
phpcs.xml.dist Normal file
View File

@@ -0,0 +1,102 @@
<?xml version="1.0"?>
<ruleset>
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<!-- Required for the SlevomatCodingStandard which utilizes composer dependencies -->
<autoload>vendor/autoload.php</autoload>
<!-- Ignore warnings, show progress of the run and show sniff names -->
<arg value="nps"/>
<!-- Directories to be checked -->
<file>src</file>
<!-- Include full Doctrine Coding Standard -->
<rule ref="Doctrine">
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
</rule>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="120"/>
</properties>
<exclude-pattern>src/Resources/contao/languages/*</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
<properties>
<property name="enableObjectTypeHint" value="false" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<properties>
<property name="enableMixedTypeHint" value="false" />
<property name="enableUnionTypeHint" value="false" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
<properties>
<property name="enableStaticTypeHint" value="false" />
<property name="enableMixedTypeHint" value="false" />
<property name="enableUnionTypeHint" value="false" />
</properties>
</rule>
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>spec/.*\.php</exclude-pattern>
</rule>
<!-- Require specific order of phpDoc annotations with empty newline between specific groups -->
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
<properties>
<property name="linesCountBeforeFirstContent" value="0"/>
<property name="linesCountAfterLastContent" value="0"/>
<property name="linesCountBetweenDescriptionAndAnnotations" value="1"/>
<property name="linesCountBetweenAnnotationsGroups" value="1"/>
<property name="annotationsGroups" type="array">
<element value="
@internal,
@deprecated,
"/>
<element value="
@template,
@psalm-template,
@template-implements,
@template-extends,
@implements,
@extends
"/>
<element value="
@link,
@see,
@uses,
"/>
<element value="
@ORM\,
@ODM\,
@PHPCR\,
"/>
<element value="
@param,
@psalm-param,
@phpstan-param,
"/>
<element value="
@return,
@psalm-return,
@phpstan-return,
"/>
<element value="@throws"/>
</property>
</properties>
</rule>
</ruleset>

View File

@@ -1,14 +1,6 @@
<?php <?php
/** declare(strict_types=1);
* Geocode backend widget based on Leaflet.
*
* @package netzmacht
* @author David Molineus <david.molineus@netzmacht.de>
* @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
*/
namespace Netzmacht\Contao\Leaflet\GeocodeWidget\ContaoManager; namespace Netzmacht\Contao\Leaflet\GeocodeWidget\ContaoManager;
@@ -18,17 +10,12 @@ use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Netzmacht\Contao\Leaflet\GeocodeWidget\LeafletGeocodeWidgetBundle; use Netzmacht\Contao\Leaflet\GeocodeWidget\LeafletGeocodeWidgetBundle;
/**
* Contao Manager plugin.
*
* @package Netzmacht\Contao\Leaflet\GeocodeWidget\ContaoManager
*/
class Plugin implements BundlePluginInterface class Plugin implements BundlePluginInterface
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getBundles(ParserInterface $parser) public function getBundles(ParserInterface $parser): array
{ {
return [ return [
BundleConfig::create(LeafletGeocodeWidgetBundle::class) BundleConfig::create(LeafletGeocodeWidgetBundle::class)

View File

@@ -1,14 +1,6 @@
<?php <?php
/** declare(strict_types=1);
* Geocode backend widget based on Leaflet.
*
* @package netzmacht
* @author David Molineus <david.molineus@netzmacht.de>
* @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
*/
namespace Netzmacht\Contao\Leaflet\GeocodeWidget\DependencyInjection; 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\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
/** use function dirname;
* Class LeafletGeocodeWidgetExtension
*/
class LeafletGeocodeWidgetExtension extends Extension class LeafletGeocodeWidgetExtension extends Extension
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function load(array $configs, ContainerBuilder $container) public function load(array $configs, ContainerBuilder $container): void
{ {
$loader = new YamlFileLoader( $loader = new YamlFileLoader(
$container, $container,

View File

@@ -1,24 +1,13 @@
<?php <?php
/** declare(strict_types=1);
* Geocode backend widget based on Leaflet.
*
* @package netzmacht
* @author David Molineus <david.molineus@netzmacht.de>
* @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
*/
namespace Netzmacht\Contao\Leaflet\GeocodeWidget\EventListener; namespace Netzmacht\Contao\Leaflet\GeocodeWidget\EventListener;
use Contao\DataContainer; use Contao\DataContainer;
/** use function sprintf;
* Class RadiusWizardCallbackListener
*
* @package Netzmacht\Contao\Leaflet\GeocodeWidget\EventListener
*/
class RadiusWizardCallbackListener class RadiusWizardCallbackListener
{ {
/** /**
@@ -26,13 +15,13 @@ class RadiusWizardCallbackListener
* *
* @param DataContainer $dataContainer Data container driver. * @param DataContainer $dataContainer Data container driver.
* *
* @return string
*
* @SuppressWarnings(PHPMD.Superglobals) * @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 ''; return '';
} }

View File

@@ -1,30 +1,17 @@
<?php <?php
/** declare(strict_types=1);
* Geocode backend widget based on Leaflet.
*
* @package netzmacht
* @author David Molineus <david.molineus@netzmacht.de>
* @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
*/
namespace Netzmacht\Contao\Leaflet\GeocodeWidget; namespace Netzmacht\Contao\Leaflet\GeocodeWidget;
use Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\GeocodeWidget as BaseWidget; use Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\GeocodeWidget as BaseWidget;
/**
* Class GeocodeWidget
*
* @deprecated
*/
class GeocodeWidget extends BaseWidget class GeocodeWidget extends BaseWidget
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function __construct(array $arrAttributes = null) public function __construct(?array $arrAttributes = null)
{ {
parent::__construct($arrAttributes); parent::__construct($arrAttributes);

View File

@@ -1,24 +1,11 @@
<?php <?php
/** declare(strict_types=1);
* Geocode backend widget based on Leaflet.
*
* @package netzmacht
* @author David Molineus <david.molineus@netzmacht.de>
* @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
*/
namespace Netzmacht\Contao\Leaflet\GeocodeWidget; namespace Netzmacht\Contao\Leaflet\GeocodeWidget;
use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* Class LeafletGeocodeWidgetBundle
*
* @package Netzmacht\Contao\Leaflet\GeocodeWidget
*/
class LeafletGeocodeWidgetBundle extends Bundle class LeafletGeocodeWidgetBundle extends Bundle
{ {
} }

View File

@@ -1,14 +1,9 @@
<?php <?php
/** declare(strict_types=1);
* Geocode backend widget based on Leaflet.
*
* @package netzmacht
* @author David Molineus <david.molineus@netzmacht.de>
* @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
*/
$GLOBALS['BE_FFL']['leaflet_geocode'] = 'Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\GeocodeWidget'; use Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\GeocodeWidget;
$GLOBALS['BE_FFL']['leaflet_radius'] = 'Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\RadiusWidget'; use Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\RadiusWidget;
$GLOBALS['BE_FFL']['leaflet_geocode'] = GeocodeWidget::class;
$GLOBALS['BE_FFL']['leaflet_radius'] = RadiusWidget::class;

View File

@@ -1,14 +1,6 @@
<?php <?php
/** declare(strict_types=1);
* Geocode backend widget based on Leaflet.
*
* @package netzmacht
* @author David Molineus <david.molineus@netzmacht.de>
* @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
*/
namespace Netzmacht\Contao\Leaflet\GeocodeWidget\Widget; namespace Netzmacht\Contao\Leaflet\GeocodeWidget\Widget;
@@ -16,9 +8,11 @@ use Contao\BackendTemplate;
use Contao\StringUtil; use Contao\StringUtil;
use Contao\Widget; use Contao\Widget;
use function is_array;
use function preg_match;
use function sprintf;
/** /**
* Class GeocodeWidget
*
* @property int size * @property int size
* @property bool multiple * @property bool multiple
*/ */
@@ -27,14 +21,14 @@ class GeocodeWidget extends Widget
/** /**
* Submit user input. * Submit user input.
* *
* @var boolean * @var bool
*/ */
protected $blnSubmitInput = true; protected $blnSubmitInput = true;
/** /**
* Add a for attribute. * Add a for attribute.
* *
* @var boolean * @var bool
*/ */
protected $blnForAttribute = true; protected $blnForAttribute = true;
@@ -65,7 +59,7 @@ class GeocodeWidget extends Widget
{ {
$value = parent::validator($value); $value = parent::validator($value);
if (!$value) { if (! $value) {
return $value; return $value;
} }
@@ -78,10 +72,10 @@ class GeocodeWidget extends Widget
} }
// See: http://stackoverflow.com/a/18690202 // See: http://stackoverflow.com/a/18690202
if (!preg_match( $pattern = '#^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),[-+]?(180(\.0+)?|'
'#^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)(,[-+]?\d+)?$#', . '((1[0-7]\d)|([1-9]?\d))(\.\d+)?)(,[-+]?\d+)?$#';
$value
)) { if (! preg_match($pattern, $value)) {
$this->addError( $this->addError(
sprintf( sprintf(
$GLOBALS['TL_LANG']['ERR']['leafletInvalidCoordinate'], $GLOBALS['TL_LANG']['ERR']['leafletInvalidCoordinate'],
@@ -95,20 +89,18 @@ class GeocodeWidget extends Widget
/** /**
* Generate the widget. * Generate the widget.
*
* @return string
*/ */
public function generate() public function generate(): string
{ {
$wrapperClass = 'wizard'; $wrapperClass = 'wizard';
if (!$this->multiple || !$this->size) { if (! $this->multiple || ! $this->size) {
$this->size = 1; $this->size = 1;
} else { } else {
$wrapperClass .= ' wizard_' . $this->size; $wrapperClass .= ' wizard_' . $this->size;
} }
if (!is_array($this->value)) { if (! is_array($this->value)) {
$this->value = [$this->value]; $this->value = [$this->value];
} }
@@ -122,12 +114,12 @@ class GeocodeWidget extends Widget
'widget' => $this, 'widget' => $this,
'value' => StringUtil::specialchars($this->value[$index]), 'value' => StringUtil::specialchars($this->value[$index]),
'class' => $this->strClass ? ' ' . $this->strClass : '', 'class' => $this->strClass ? ' ' . $this->strClass : '',
'id' => $this->strId . (($this->size > 1) ? '_' . $index : ''), 'id' => $this->strId . ($this->size > 1 ? '_' . $index : ''),
'name' => $this->strName . (($this->size > 1) ? '[]' : ''), 'name' => $this->strName . ($this->size > 1 ? '[]' : ''),
'attributes' => $this->getAttributes(), 'attributes' => $this->getAttributes(),
'wizard' => $this->wizard, 'wizard' => $this->wizard,
'label' => $this->strLabel, 'label' => $this->strLabel,
'radius' => $this->buildRadiusOptions() 'radius' => $this->buildRadiusOptions(),
] ]
); );
@@ -140,13 +132,13 @@ class GeocodeWidget extends Widget
/** /**
* Build the radius options. * Build the radius options.
* *
* @return array|null * @return array<string,mixed>|null
* *
* @SuppressWarnings(PHPMD.Superglobals) * @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; return null;
} }
@@ -154,7 +146,7 @@ class GeocodeWidget extends Widget
'element' => 'ctrl_' . $this->radius, 'element' => 'ctrl_' . $this->radius,
'min' => 0, 'min' => 0,
'max' => 0, 'max' => 0,
'defaultValue' => 0 'defaultValue' => 0,
]; ];
if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->radius]['eval'])) { if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->radius]['eval'])) {

View File

@@ -1,14 +1,6 @@
<?php <?php
/** declare(strict_types=1);
* Geocode backend widget based on Leaflet.
*
* @package netzmacht
* @author David Molineus <david.molineus@netzmacht.de>
* @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
*/
namespace Netzmacht\Contao\Leaflet\GeocodeWidget\Widget; namespace Netzmacht\Contao\Leaflet\GeocodeWidget\Widget;
@@ -16,9 +8,11 @@ use Contao\BackendTemplate;
use Contao\StringUtil; use Contao\StringUtil;
use Contao\TextField; use Contao\TextField;
/** use function is_array;
* Class RadiusWidget use function is_numeric;
*/ use function round;
use function trim;
class RadiusWidget extends TextField class RadiusWidget extends TextField
{ {
/** /**
@@ -42,20 +36,18 @@ class RadiusWidget extends TextField
/** /**
* Generate the widget. * Generate the widget.
*
* @return string
*/ */
public function generate() public function generate(): string
{ {
$wrapperClass = $this->coordinates ? 'wizard' : ''; $wrapperClass = $this->coordinates ? 'wizard' : '';
if (!$this->multiple || !$this->size) { if (! $this->multiple || ! $this->size) {
$this->size = 1; $this->size = 1;
} else { } else {
$wrapperClass .= ' wizard_' . $this->size; $wrapperClass .= ' wizard_' . $this->size;
} }
if (!is_array($this->value)) { if (! is_array($this->value)) {
$this->value = [$this->value]; $this->value = [$this->value];
} }
@@ -69,12 +61,12 @@ class RadiusWidget extends TextField
'widget' => $this, 'widget' => $this,
'value' => StringUtil::specialchars($this->value[$index]), 'value' => StringUtil::specialchars($this->value[$index]),
'class' => $this->strClass ? ' ' . $this->strClass : '', 'class' => $this->strClass ? ' ' . $this->strClass : '',
'id' => $this->strId . (($this->size > 1) ? '_' . $index : ''), 'id' => $this->strId . ($this->size > 1 ? '_' . $index : ''),
'name' => $this->strName . (($this->size > 1) ? '[]' : ''), 'name' => $this->strName . ($this->size > 1 ? '[]' : ''),
'attributes' => $this->getAttributes(), 'attributes' => $this->getAttributes(),
'wizard' => $this->wizard, 'wizard' => $this->wizard,
'label' => $this->strLabel, 'label' => $this->strLabel,
'coordinates' => $this->coordinates 'coordinates' => $this->coordinates,
] ]
); );
@@ -92,7 +84,7 @@ class RadiusWidget extends TextField
if (is_numeric($varInput) && $this->steps > 0) { if (is_numeric($varInput) && $this->steps > 0) {
$steps = (int) $this->steps; $steps = (int) $this->steps;
$varInput = (int) $varInput; $varInput = (int) $varInput;
$varInput = ($steps * round($varInput / $steps)); $varInput = $steps * round($varInput / $steps);
} }
return parent::validator($varInput); return parent::validator($varInput);