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

@@ -1,14 +1,6 @@
<?php
/**
* 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
*/
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)

View File

@@ -1,14 +1,6 @@
<?php
/**
* 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
*/
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,

View File

@@ -1,24 +1,13 @@
<?php
/**
* 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
*/
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 '';
}

View File

@@ -1,30 +1,17 @@
<?php
/**
* 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
*/
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);

View File

@@ -1,24 +1,11 @@
<?php
/**
* 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
*/
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
{
}

View File

@@ -1,14 +1,9 @@
<?php
/**
* 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
*/
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;

View File

@@ -1,14 +1,6 @@
<?php
/**
* 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
*/
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<string,mixed>|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'])) {

View File

@@ -1,14 +1,6 @@
<?php
/**
* 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
*/
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);