Applied rector suggestions

This commit is contained in:
Jan Böhmer 2024-06-22 00:31:43 +02:00
parent 4106bcef5f
commit 20f32c7f12
170 changed files with 808 additions and 761 deletions

View file

@ -142,7 +142,7 @@ class AttachmentFormType extends AbstractType
if (!$file instanceof UploadedFile) {
//When no file was uploaded, but a URL was entered, try to determine the attachment name from the URL
if (empty($attachment->getName()) && !empty($attachment->getURL())) {
if ((trim($attachment->getName()) === '') && ($attachment->getURL() !== null && $attachment->getURL() !== '')) {
$name = basename(parse_url($attachment->getURL(), PHP_URL_PATH));
$attachment->setName($name);
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -17,7 +20,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Form;
use Symfony\Component\Form\AbstractTypeExtension;
@ -51,4 +53,4 @@ class PasswordTypeExtension extends AbstractTypeExtension
$view->vars['password_estimator'] = $options['password_estimator'];
}
}
}

View file

@ -45,9 +45,7 @@ class PermissionsType extends AbstractType
$resolver->setDefaults([
'show_legend' => true,
'show_presets' => false,
'show_dependency_notice' => static function (Options $options) {
return !$options['disabled'];
},
'show_dependency_notice' => static fn(Options $options) => !$options['disabled'],
'constraints' => static function (Options $options) {
if (!$options['disabled']) {
return [new NoLockout()];

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -17,7 +20,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Form\ProjectSystem;
use App\Entity\ProjectSystem\Project;
@ -83,4 +85,4 @@ class ProjectAddPartsType extends AbstractType
$resolver->setAllowedTypes('project', ['null', Project::class]);
}
}
}

View file

@ -100,7 +100,7 @@ class StructuralEntityChoiceHelper
public function generateChoiceAttrCurrency(Currency $choice, Options|array $options): array
{
$tmp = $this->generateChoiceAttr($choice, $options);
$symbol = empty($choice->getIsoCode()) ? null : Currencies::getSymbol($choice->getIsoCode());
$symbol = $choice->getIsoCode() === '' ? null : Currencies::getSymbol($choice->getIsoCode());
$tmp['data-short'] = $options['short'] ? $symbol : $choice->getName();
//Show entities that are not added to DB yet separately from other entities

View file

@ -52,11 +52,7 @@ class StructuralEntityChoiceLoader extends AbstractChoiceLoader
protected function loadChoices(): iterable
{
//If the starting_element is set and not persisted yet, add it to the list
if ($this->starting_element !== null && $this->starting_element->getID() === null) {
$tmp = [$this->starting_element];
} else {
$tmp = [];
}
$tmp = $this->starting_element !== null && $this->starting_element->getID() === null ? [$this->starting_element] : [];
if ($this->additional_element) {
$tmp = $this->createNewEntitiesFromValue($this->additional_element);
@ -163,7 +159,7 @@ class StructuralEntityChoiceLoader extends AbstractChoiceLoader
// the same as the value that is generated for the same entity after it is persisted.
// Otherwise, errors occurs that the element could not be found.
foreach ($values as &$data) {
$data = trim($data);
$data = trim((string) $data);
$data = preg_replace('/\s*->\s*/', '->', $data);
}
unset ($data);

View file

@ -108,12 +108,8 @@ class StructuralEntityType extends AbstractType
$resolver->setDefault('dto_value', null);
$resolver->setAllowedTypes('dto_value', ['null', 'string']);
//If no help text is explicitly set, we use the dto value as help text and show it as html
$resolver->setDefault('help', function (Options $options) {
return $this->dtoText($options['dto_value']);
});
$resolver->setDefault('help_html', function (Options $options) {
return $options['dto_value'] !== null;
});
$resolver->setDefault('help', fn(Options $options) => $this->dtoText($options['dto_value']));
$resolver->setDefault('help_html', fn(Options $options) => $options['dto_value'] !== null);
$resolver->setDefault('attr', function (Options $options) {
$tmp = [