Skip to content

Commit

Permalink
Updated rector configuration. Added missing types in functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed May 10, 2024
1 parent 6bc876d commit 9faf962
Show file tree
Hide file tree
Showing 31 changed files with 322 additions and 226 deletions.
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

require_once \dirname(__DIR__) . '/vendor/autoload_runtime.php';

return fn (array $context) => new Kernel((string) $context['APP_ENV'], (bool) $context['APP_DEBUG']);
return fn (array $context): kernel => new Kernel((string) $context['APP_ENV'], (bool) $context['APP_DEBUG']);
12 changes: 8 additions & 4 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
use Rector\Symfony\Set\TwigSetList;

return RectorConfig::configure()
->withBootstrapFiles([
__DIR__ . '/vendor/autoload.php',
])->withPaths([
->withRootFiles()
->withPaths([
__DIR__ . '/config',
__DIR__ . '/src',
__DIR__ . '/tests',
Expand All @@ -40,9 +39,14 @@
// global
SetList::PHP_82,
SetList::CODE_QUALITY,
SetList::PRIVATIZATION,
SetList::INSTANCEOF,
SetList::STRICT_BOOLEANS,
SetList::TYPE_DECLARATION,
// Doctrine
DoctrineSetList::DOCTRINE_DBAL_30,
DoctrineSetList::DOCTRINE_DBAL_40,
DoctrineSetList::DOCTRINE_CODE_QUALITY,
DoctrineSetList::DOCTRINE_COLLECTION_22,
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
// PHP-Unit
PHPUnitSetList::PHPUNIT_100,
Expand Down
4 changes: 2 additions & 2 deletions resources/data/csp.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"form-action": "self",
"manifest-src": "self",
"frame-ancestors": "self",
"script-src": "%nonce%",
"script-src": "nonce",
"script-src-elem": [
"%nonce%",
"nonce",
"https://www.google.com",
"https://api.iconify.design"
],
Expand Down
6 changes: 3 additions & 3 deletions resources/data/csp.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"form-action": "self",
"manifest-src": "self",
"frame-ancestors": "self",
"script-src": "%nonce%",
"script-src": "nonce",
"script-src-elem": [
"%nonce%",
"nonce",
"https://www.google.com",
"https://api.iconify.design"
],
Expand Down Expand Up @@ -41,5 +41,5 @@
"https://robohash.org",
"https://openweathermap.org"
],
"report-uri": "%report%"
"report-uri": "report"
}
4 changes: 2 additions & 2 deletions src/Controller/CalculationArchiveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ private function createQueryForm(CalculationArchiveService $service, Calculation
->updateOptions([
'multiple' => true,
'expanded' => true,
'group_by' => fn () => null,
'group_by' => fn (): null => null,
'query_builder' => static fn (CalculationStateRepository $repository): QueryBuilder => $repository->getEditableQueryBuilder(),
])
->labelClass('checkbox-inline checkbox-switch')
->add(CalculationStateListType::class);

$helper->field('target')
->updateOptions([
'group_by' => fn () => null,
'group_by' => fn (): null => null,
'query_builder' => static fn (CalculationStateRepository $repository): QueryBuilder => $repository->getNotEditableQueryBuilder(),
])
->add(CalculationStateListType::class);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/CalculationUpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private function createQueryForm(CalculationUpdateQuery $query): FormInterface
->updateOptions([
'multiple' => true,
'expanded' => true,
'group_by' => fn () => null,
'group_by' => fn (): null => null,
'query_builder' => static fn (CalculationStateRepository $repository): QueryBuilder => $repository->getEditableQueryBuilder(),
])
->labelClass('checkbox-inline checkbox-switch')
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private function checkAjaxRequest(Request $request): void
/**
* @psalm-param class-string $className
*/
private function count($className): int
private function count(string $className): int
{
return $this->manager->getRepository($className)->count();
}
Expand Down
50 changes: 9 additions & 41 deletions src/Controller/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
use App\Service\AbstractHttpClientService;
use App\Service\CaptchaImageService;
use App\Service\MailerService;
use App\Service\RecaptchaResponseService;
use App\Service\RecaptchaService;
use App\Service\SearchService;
use App\Service\SwissPostService;
use App\Traits\CookieTrait;
use App\Traits\GroupByTrait;
use App\Traits\StrengthLevelTranslatorTrait;
use App\Translator\TranslatorFactory;
use App\Utils\FormatUtils;
use App\Utils\StringUtils;
use App\Validator\Captcha;
use App\Validator\Password;
Expand Down Expand Up @@ -359,8 +359,11 @@ public function password(Request $request, CaptchaImageService $service): Respon
* Display the reCaptcha.
*/
#[GetPost(path: '/recaptcha', name: 'test_recaptcha')]
public function recaptcha(Request $request, RecaptchaService $service): Response
{
public function recaptcha(
Request $request,
RecaptchaService $service,
RecaptchaResponseService $responseService
): Response {
$data = [
'subject' => 'My subject',
'message' => 'My message',
Expand All @@ -376,15 +379,10 @@ public function recaptcha(Request $request, RecaptchaService $service): Response
$form = $helper->createForm();
if ($this->handleRequestForm($request, $form)) {
$response = $service->getLastResponse();
if ($response instanceof ReCaptchaResponse) {
/** @psalm-var array<string, string[]|string|bool> $values */
$values = $response->toArray();
$message = $this->formatRecaptchaResult($values);

return $this->redirectToHomePage($message);
}
$message = $response instanceof ReCaptchaResponse ?
$responseService->format($response) : 'test.recaptcha_success';

return $this->redirectToHomePage('test.recaptcha_success');
return $this->redirectToHomePage($message);
}

return $this->render('test/recaptcha.html.twig', ['form' => $form]);
Expand Down Expand Up @@ -542,36 +540,6 @@ public function tree(Request $request, GroupRepository $repository, EntityManage
]);
}

/**
* @psalm-param array<string, string[]|string|bool> $values
*/
private function formatRecaptchaResult(array $values): string
{
$html = '';
$values = \array_filter($values);
foreach ($values as $key => $value) {
$html .= '<div class="row">';
if (\is_array($value)) {
$value = \implode('<br>', $value);
} elseif (\is_bool($value)) {
$value = \json_encode($value);
} elseif ('score' === $key) {
$value = FormatUtils::formatPercent($value);
} elseif ('challenge_ts' === $key) {
$time = \strtotime($value);
if (false !== $time) {
$value = FormatUtils::formatDateTime($time, timeType: \IntlDateFormatter::MEDIUM);
}
}
$html .= '<div class="col-4">' . $key . '</div>';
$html .= '<div class="col-1">:</div>';
$html .= '<div class="col-7">' . $value . '</div>';
$html .= '</div>';
}

return $html;
}

private function getCategories(EntityManagerInterface $manager): array
{
/** @psalm-var CategoryRepository $repository */
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Task/TaskListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function configureOptions(OptionsResolver $resolver): void
'data-category-id' => $task->getCategoryId(),
'data-unit' => $task->getUnit(),
],
'query_builder' => fn (Options $options) => $this->getSortedBuilder($options),
'query_builder' => fn (Options $options): QueryBuilder => $this->getSortedBuilder($options),
'query_all' => false,
]);
$resolver->setAllowedTypes('query_all', 'bool');
Expand Down
3 changes: 2 additions & 1 deletion src/Form/Type/CountryFlagType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Service\CountryFlagService;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\ChoiceList\ChoiceList;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
Expand All @@ -36,7 +37,7 @@ public function configureOptions(OptionsResolver $resolver): void
{
$defaultCode = CountryFlagService::getDefaultCode();
$resolver->setDefaults([
'choice_loader' => fn (Options $options) => ChoiceList::lazy($this, fn (): array => $this->loadChoices($options)),
'choice_loader' => fn (Options $options): ChoiceLoaderInterface => ChoiceList::lazy($this, fn (): array => $this->loadChoices($options)),
'attr' => ['class' => self::FLAG_CLASS],
'preferred_choices' => [$defaultCode],
'choice_translation_locale' => null,
Expand Down
Loading

0 comments on commit 9faf962

Please sign in to comment.