cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,68 +1,70 @@
<?php
/*
* Copyright (C) 2019 Champs Libres Cooperative <info@champs-libres.coop>
/**
* Chill is a software for social workers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Form\DataMapper;
use Symfony\Component\Form\DataMapperInterface;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\PostalCode;
use Symfony\Component\Form\FormInterface;
use Iterator;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\FormInterface;
/**
* Add a data mapper to Address.
*
*
* If the address is incomplete, the data mapper returns null
*/
class AddressDataMapper implements DataMapperInterface
{
/**
*
* @param Address $address
* @param \Iterator $forms
* @param Iterator $forms
*/
public function mapDataToForms($address, $forms)
{
if (NULL === $address) {
if (null === $address) {
return;
}
if (!$address instanceof Address) {
throw new UnexpectedTypeException($address, Address::class);
}
foreach ($forms as $key => $form) {
/** @var FormInterface $form */
switch ($key) {
case 'streetAddress1':
$form->setData($address->getStreetAddress1());
break;
case 'streetAddress2':
$form->setData($address->getStreetAddress2());
break;
case 'postCode':
$form->setData($address->getPostcode());
break;
case 'validFrom':
$form->setData($address->getValidFrom());
break;
case 'isNoAddress':
$form->setData($address->isNoAddress());
break;
default:
break;
}
@@ -70,8 +72,7 @@ class AddressDataMapper implements DataMapperInterface
}
/**
*
* @param \Iterator $forms
* @param Iterator $forms
* @param Address $address
*/
public function mapFormsToData($forms, &$address)
@@ -79,40 +80,53 @@ class AddressDataMapper implements DataMapperInterface
if (!$address instanceof Address) {
$address = new Address();
}
$isNoAddress = false;
foreach ($forms as $key => $form) {
if ($key === 'isNoAddress') {
if ('isNoAddress' === $key) {
$isNoAddress = $form->get('isNoAddress')->getData();
}
}
foreach ($forms as $key => $form) {
/** @var FormInterface $form */
switch($key) {
switch ($key) {
case 'postCode':
if (!$form->getData() instanceof PostalCode && !$isNoAddress) {
$address = null;
return;
}
$address->setPostcode($form->getData());
break;
case 'streetAddress1':
if (empty($form->getData()) && !$isNoAddress) {
$address = null;
return;
}
$address->setStreetAddress1($form->getData());
break;
case 'streetAddress2':
$address->setStreetAddress2($form->getData());
break;
case 'validFrom':
$address->setValidFrom($form->getData());
break;
case 'isNoAddress':
$address->setIsNoAddress($form->getData());
break;
default:
break;
}

View File

@@ -1,10 +1,16 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Form\DataMapper;
use Chill\MainBundle\Entity\Scope;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\FormInterface;
class ScopePickerDataMapper implements DataMapperInterface
{
@@ -13,7 +19,7 @@ class ScopePickerDataMapper implements DataMapperInterface
*/
private $scope;
public function __construct(Scope $scope = null)
public function __construct(?Scope $scope = null)
{
$this->scope = $scope;
}
@@ -24,6 +30,7 @@ class ScopePickerDataMapper implements DataMapperInterface
if ($this->scope instanceof Scope) {
$forms['scope']->setData($this->scope);
return;
}