Skip to content

Commit

Permalink
Merge pull request #102 from Coderberg/2.x
Browse files Browse the repository at this point in the history
2.x
  • Loading branch information
Coderberg committed Feb 14, 2023
2 parents 02ba69a + 38ac1b9 commit 01c81bd
Show file tree
Hide file tree
Showing 24 changed files with 195 additions and 180 deletions.
248 changes: 124 additions & 124 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ parameters:
locale: 'en'
app_locales: 'en|ru|nl|bg'
images_directory: '%kernel.project_dir%/public/uploads/images'
app_version: '2.4.4'
app_version: '2.4.5'

services:
# default configuration for services in *this* file
Expand Down
7 changes: 5 additions & 2 deletions public/robots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
# www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156449

User-agent: *
Disallow: /login
Disallow: /admin
Disallow: /*/login
Disallow: /*/admin
Disallow: /*/password
Disallow: /index.php
Disallow: /index.php/*
23 changes: 10 additions & 13 deletions src/Command/ListUsersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
)]
final class ListUsersCommand extends Command
{
private UserRepository $users;

public function __construct(UserRepository $users)
public function __construct(private readonly UserRepository $users)
{
parent::__construct();
$this->users = $users;
}

protected function configure(): void
Expand All @@ -46,15 +43,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$allUsers = $this->users->findBy([], ['id' => 'DESC'], $limit);

$usersAsPlainArrays = array_map(function (User $user) {
return [
$user->getId(),
$user->getProfile()->getFullName(),
$user->getUsername(),
$user->getEmail(),
implode(', ', $user->getRoles()),
];
}, $allUsers);
$usersAsPlainArrays = array_map(fn (User $user) => [
$user->getId(),
$user->getProfile()->getFullName(),
$user->getUsername(),
$user->getEmail(),
implode(', ', $user->getRoles()),
],
$allUsers
);

$bufferedOutput = new BufferedOutput();
$io = new SymfonyStyle($input, $bufferedOutput);
Expand Down
1 change: 1 addition & 0 deletions src/Controller/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function login(Request $request, Security $security, AuthenticationUtils
$form = $this->createForm(LoginFormType::class);

return $this->render('auth/login.html.twig', [
'robots' => 'noindex',
'site' => $this->site($request),
'error' => $helper->getLastAuthenticationError(),
'form' => $form,
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function passwordReset(ResettingService $service, Request $request): Resp
}

return $this->render('auth/passwords/password_reset.html.twig', [
'robots' => 'noindex',
'site' => $this->site($request),
'form' => $form->createView(),
]);
Expand Down Expand Up @@ -60,6 +61,7 @@ public function passwordResetConfirm(ResettingRepository $repository, Request $r
}

return $this->render('auth/passwords/password_change.html.twig', [
'robots' => 'noindex',
'site' => $this->site($request),
'form' => $form->createView(),
]);
Expand Down
2 changes: 1 addition & 1 deletion src/DataFixtures/UserFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

final class UserFixtures extends Fixture
{
public function __construct(private UserTransformer $transformer)
public function __construct(private readonly UserTransformer $transformer)
{
}

Expand Down
10 changes: 5 additions & 5 deletions src/Dto/FeedbackDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ final class FeedbackDto
{
#[Assert\NotBlank]
#[Assert\Length(min: 2, max: 100)]
private ?string $from_name;
private ?string $from_name = null;

#[Assert\NotBlank]
#[Assert\Email]
#[Assert\Length(min: 6)]
private ?string $from_email;
private ?string $from_email = null;

#[Assert\NotBlank]
#[Assert\Email]
#[Assert\Length(min: 6)]
private ?string $to_email;
private ?string $to_email = null;

private ?string $subject;
private ?string $subject = null;

#[Assert\NotBlank]
#[Assert\Length(min: 14)]
private ?string $message;
private ?string $message = null;

public function getFromName(): ?string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Mailer/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class Mailer
{
public function __construct(private MailerInterface $mailer)
public function __construct(private readonly MailerInterface $mailer)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Message/DeletePhotos.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class DeletePhotos
{
public function __construct(private Property $property)
public function __construct(private readonly Property $property)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Message/SendEmailConfirmationLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class SendEmailConfirmationLink
{
public function __construct(private User $user)
public function __construct(private readonly User $user)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Message/SendFeedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class SendFeedback
{
public function __construct(private FeedbackDto $feedback)
public function __construct(private readonly FeedbackDto $feedback)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Message/SendResetPasswordLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class SendResetPasswordLink
{
public function __construct(private User $user)
public function __construct(private readonly User $user)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Middleware/ThrottleRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class ThrottleRequests
{
public function __construct(private RateLimiterFactory $authLimiter)
public function __construct(private readonly RateLimiterFactory $authLimiter)
{
}

Expand All @@ -20,7 +20,7 @@ public function handle(Request $request): void
$request->getClientIp().$request->getPathInfo().$request->getMethod()
);

if (false === $limiter->consume(1)->isAccepted()) {
if (!$limiter->consume(1)->isAccepted()) {
throw new TooManyRequestsHttpException();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

final class VerifyCsrfToken
{
public function __construct(private CsrfTokenManagerInterface $tokenManager)
public function __construct(private readonly CsrfTokenManagerInterface $tokenManager)
{
}

Expand Down
6 changes: 6 additions & 0 deletions src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
* @method User|null find($id, $lockMode = null, $lockVersion = null)
* @method User|null findOneBy(array $criteria, array $orderBy = null)
* @method User[] findAll()
* @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class UserRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
Expand Down
2 changes: 1 addition & 1 deletion src/Security/RegistrationFormAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

final class RegistrationFormAuthenticator extends AbstractAuthenticator
{
public function __construct(private UrlGeneratorInterface $urlGenerator)
public function __construct(private readonly UrlGeneratorInterface $urlGenerator)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Security/Voter/PropertyVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

final class PropertyVoter extends Voter
{
public function __construct(private Security $security)
public function __construct(private readonly Security $security)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Security/Voter/UserVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class UserVoter extends Voter
{
public const USE_HTML = 'USE_HTML';

public function __construct(private SettingsRepository $repository)
public function __construct(private readonly SettingsRepository $repository)
{
}

Expand Down
23 changes: 11 additions & 12 deletions src/Transformer/RequestToArrayTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ final class RequestToArrayTransformer
{
public function transform(Request $request): array
{
$params = [];
$params['city'] = $request->query->getInt('city', 0);
$params['deal_type'] = $request->query->getInt('deal_type', 0);
$params['category'] = $request->query->getInt('category', 0);
$params['bedrooms'] = $request->query->getInt('bedrooms', 0);
$params['guests'] = $request->query->getInt('guests', 0);
$params['feature'] = $request->query->getInt('feature', 0);
$params['sort_by'] = $request->query->get('sort_by', 'priority_number');
$params['state'] = $request->query->get('state', 'published');
$params['page'] = $request->query->getInt('page', 1);

return $params;
return [
'city' => $request->query->getInt('city', 0),
'deal_type' => $request->query->getInt('deal_type', 0),
'category' => $request->query->getInt('category', 0),
'bedrooms' => $request->query->getInt('bedrooms', 0),
'guests' => $request->query->getInt('guests', 0),
'feature' => $request->query->getInt('feature', 0),
'sort_by' => $request->query->get('sort_by', 'priority_number'),
'state' => $request->query->get('state', 'published'),
'page' => $request->query->getInt('page', 1),
];
}
}
2 changes: 1 addition & 1 deletion src/Transformer/UserTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final class UserTransformer
{
public function __construct(private UserPasswordHasherInterface $passwordHasher)
public function __construct(private readonly UserPasswordHasherInterface $passwordHasher)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Twig/AppExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

final class AppExtension extends AbstractExtension
{
public function __construct(private TranslatorInterface $translator)
public function __construct(private readonly TranslatorInterface $translator)
{
}

public function getFilters(): array
{
return [
new TwigFilter('page', [$this, 'showPageNumber']),
new TwigFilter('page', $this->showPageNumber(...)),
];
}

Expand Down
4 changes: 4 additions & 0 deletions templates/layout/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<!-- Color the status bar on mobile devices -->
<meta name="theme-color" content="#ffffff">

{% if robots is defined and robots == 'noindex' %}
<meta name="robots" content="noindex, follow"/>
{% endif %}

<!-- Styles -->
{{ encore_entry_link_tags('css/app') }}
{% block stylesheets %}{% endblock %}
Expand Down
19 changes: 11 additions & 8 deletions tests/Helper/WebTestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@ trait WebTestHelper
{
public function authAsAdmin(WebTestCase $testCase): KernelBrowser
{
return $testCase::createClient([], [
'PHP_AUTH_USER' => 'admin',
'PHP_AUTH_PW' => 'admin',
]);
return $this->authAs($testCase, 'admin');
}

public function authAsUser(WebTestCase $testCase): KernelBrowser
{
return $testCase::createClient([], [
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'user',
]);
return $this->authAs($testCase, 'user');
}

private function authAs(WebTestCase $testCase, string $username): KernelBrowser
{
$client = $testCase::createClient();
$user = $this->getUser($client, $username);

// simulate $user being logged in
return $client->loginUser($user);
}

public function getRepository(KernelBrowser $client, string $entity): ObjectRepository
Expand Down

0 comments on commit 01c81bd

Please sign in to comment.