Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix phpstan and php-cs issues #382

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ jobs:
DATABASE_CHARSET: utf8mb4
DATABASE_COLLATE: utf8mb4_unicode_ci

- php-version: '8.2'
database: mysql
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak
DATABASE_URL: mysql://root:[email protected]/sulu_form_test?serverVersion=5.7
DATABASE_CHARSET: utf8mb4
DATABASE_COLLATE: utf8mb4_unicode_ci

- php-version: '8.3'
database: mysql
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak
DATABASE_URL: mysql://root:[email protected]/sulu_form_test?serverVersion=5.7
DATABASE_CHARSET: utf8mb4
DATABASE_COLLATE: utf8mb4_unicode_ci

services:
mysql:
image: mysql:5.7
Expand Down Expand Up @@ -86,6 +106,9 @@ jobs:
tools: ${{ matrix.tools }}
coverage: none

- name: Remove not required tooling for tests
run: composer remove php-cs-fixer/shim --dev

- name: Install composer dependencies
uses: ramsey/composer-install@v1
with:
Expand Down
5 changes: 4 additions & 1 deletion Admin/FormAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
use Sulu\Component\Security\Authorization\SecurityCheckerInterface;
use Sulu\Component\Webspace\Manager\WebspaceManagerInterface;

/**
* @final
*/
class FormAdmin extends Admin
{
public const SECURITY_CONTEXT = 'sulu.form.forms';
Expand Down Expand Up @@ -188,7 +191,7 @@ public function getSecurityContexts()
return [
'Sulu' => [
'Form' => [
static::SECURITY_CONTEXT => [
self::SECURITY_CONTEXT => [
PermissionTypes::VIEW,
PermissionTypes::ADD,
PermissionTypes::EDIT,
Expand Down
8 changes: 2 additions & 6 deletions Configuration/FormConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ public function getWebsiteMailConfiguration(): ?MailConfigurationInterface
/**
* Set admin mail configuration.
*
* @param MailConfigurationInterface $adminMailConfiguration
*
* @return $this
*/
public function setAdminMailConfiguration(MailConfigurationInterface $adminMailConfiguration = null)
public function setAdminMailConfiguration(?MailConfigurationInterface $adminMailConfiguration = null)
{
$this->adminMailConfiguration = $adminMailConfiguration;

Expand All @@ -83,11 +81,9 @@ public function setAdminMailConfiguration(MailConfigurationInterface $adminMailC
/**
* Set website mail configuration.
*
* @param MailConfigurationInterface $websiteMailConfiguration
*
* @return $this
*/
public function setWebsiteMailConfiguration(MailConfigurationInterface $websiteMailConfiguration = null)
public function setWebsiteMailConfiguration(?MailConfigurationInterface $websiteMailConfiguration = null)
{
$this->websiteMailConfiguration = $websiteMailConfiguration;

Expand Down
2 changes: 1 addition & 1 deletion Configuration/FormConfigurationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getSave(): bool;
/**
* Get file fields.
*
* @return mixed[]
* @return int[]
*/
public function getFileFields(): array;

Expand Down
40 changes: 20 additions & 20 deletions Controller/DynamicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Sulu\Bundle\FormBundle\Repository\FormRepository;
use Sulu\Bundle\MediaBundle\Media\Exception\MediaNotFoundException;
use Sulu\Bundle\MediaBundle\Media\Manager\MediaManagerInterface;
use Sulu\Component\Rest\ListBuilder\ListRepresentation;
use Sulu\Component\Rest\ListBuilder\PaginatedRepresentation;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
Expand Down Expand Up @@ -87,12 +87,15 @@ public function cgetAction(Request $request): Response
{
$locale = $this->getLocale($request);
$filters = $this->getFilters($request);
$page = $request->get('page', 1);
$limit = $request->get('limit');
$page = (int) $request->query->getInt('page', 1);
$limit = (int) $request->query->getInt('limit');
$offset = (int) (($page - 1) * $limit);
$view = $request->get('view', 'default');
$sortOrder = $request->get('sortOrder', 'asc');
$sortBy = $request->get('sortBy', 'created');
/** @var string $view */
$view = $request->query->get('view', 'default');
/** @var string $sortOrder */
$sortOrder = $request->query->get('sortOrder', 'asc');
/** @var string $sortBy */
$sortBy = $request->query->get('sortBy', 'created');

$entries = $this->dynamicRepository->findByFilters(
$filters,
Expand All @@ -111,12 +114,9 @@ public function cgetAction(Request $request): Response
$total = \count($entries) + $offset;
}

// create list representation
$representation = new ListRepresentation(
$representation = new PaginatedRepresentation(
$entries,
'dynamic_forms',
$request->get('_route'),
$request->query->all(),
$page,
$limit,
$total
Expand Down Expand Up @@ -158,14 +158,14 @@ public function deleteAction(Request $request, int $id): Response
protected function getFilters(Request $request): array
{
$filters = [
'type' => $request->get('type'),
'typeId' => $request->get('typeId'),
'webspaceKey' => $request->get('webspaceKey'),
'form' => $request->get('form'),
'fromDate' => $request->get('fromDate'),
'toDate' => $request->get('toDate'),
'search' => $request->get('search'),
'searchFields' => \array_filter(\explode(',', $request->get('fields', ''))),
'type' => $request->query->get('type'),
'typeId' => $request->query->get('typeId'),
'webspaceKey' => $request->query->get('webspaceKey'),
'form' => $request->query->get('form'),
'fromDate' => $request->query->get('fromDate'),
'toDate' => $request->query->get('toDate'),
'search' => $request->query->get('search'),
'searchFields' => \array_filter(\explode(',', $request->query->get('fields', ''))),
];

return \array_filter($filters);
Expand All @@ -182,8 +182,8 @@ protected function loadForm(Request $request): Form
return $this->formRepository->loadById($formId);
}

public function getLocale(Request $request): ?string
public function getLocale(Request $request): string
{
return $request->get('locale', $request->getLocale());
return $request->query->get('locale', $request->getLocale());
}
}
6 changes: 5 additions & 1 deletion Controller/FormWebsiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormRegistryInterface;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -224,7 +225,7 @@ protected function getErrors(): array
*
* @return mixed[]
*/
protected function getAttributes($attributes, StructureInterface $structure = null, $preview = false)
protected function getAttributes($attributes, ?StructureInterface $structure = null, $preview = false)
{
if (null === $this->attributes) { // for performance only called once
$this->attributes = parent::getAttributes($attributes, $structure, $preview);
Expand All @@ -237,6 +238,9 @@ protected function getAttributes($attributes, StructureInterface $structure = nu
return $this->attributes;
}

/**
* @return class-string<FormTypeInterface>
*/
private function getTypeClass(string $key): string
{
return $this->getParameter('sulu_form.static_forms')[$key]['class'];
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/SuluFormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('type_mailchimp.xml');
}

/** @var array<string, class-string> $bundles */
$bundles = $container->getParameter('kernel.bundles');

if (\array_key_exists('SuluArticleBundle', $bundles)) {
Expand Down
2 changes: 0 additions & 2 deletions Dynamic/FormFieldTypeConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public function getXmlPath(): string

/**
* Sets template.
*
* @return FormFieldTypeConfiguration
*/
public function setXmlPath(string $xmlPath): self
{
Expand Down
7 changes: 5 additions & 2 deletions Dynamic/Types/ChoiceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ protected function getChoices(FormFieldTranslation $translation): array
/**
* Returns options for multichoice form type like select, multiple select, radio or checkboxes.
*
* @param mixed[] $options
* @param array<string, mixed> $options
*
* @return mixed[]
*/
private function getChoiceOptions(
FormFieldTranslation $translation,
array $options
): array {
if (isset($options['attr']['placeholder'])) {
if (isset($options['attr'])
&& \is_array($options['attr'])
&& isset($options['attr']['placeholder'])
) {
$options['placeholder'] = $options['attr']['placeholder'];
unset($options['attr']['placeholder']);
}
Expand Down
5 changes: 4 additions & 1 deletion Dynamic/Types/CountryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public function getConfiguration(): FormFieldTypeConfiguration

public function build(FormBuilderInterface $builder, FormField $field, string $locale, array $options): void
{
if (isset($options['attr']['placeholder'])) {
if (isset($options['attr'])
&& \is_array($options['attr'])
&& isset($options['attr']['placeholder'])
) {
$options['placeholder'] = $options['attr']['placeholder'];
unset($options['attr']['placeholder']);
}
Expand Down
6 changes: 0 additions & 6 deletions Dynamic/Types/HiddenType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class HiddenType implements FormFieldTypeInterface
{
use SimpleTypeTrait;

/**
* {@inheritdoc}
*/
public function getConfiguration(): FormFieldTypeConfiguration
{
return new FormFieldTypeConfiguration(
Expand All @@ -35,9 +32,6 @@ public function getConfiguration(): FormFieldTypeConfiguration
);
}

/**
* {@inheritdoc}
*/
public function build(FormBuilderInterface $builder, FormField $field, string $locale, array $options): void
{
$type = TypeHiddenType::class;
Expand Down
4 changes: 3 additions & 1 deletion Dynamic/Types/SimpleTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ trait SimpleTypeTrait
*/
public function getDefaultValue(FormField $field, string $locale)
{
return $field->getTranslation($locale)->getDefaultValue();
$translation = $field->getTranslation($locale);

return $translation ? $translation->getDefaultValue() : null;
}
}
Loading
Loading