Skip to content

Simplify codebase #31

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

Merged
merged 1 commit into from
Jun 6, 2025
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
3 changes: 1 addition & 2 deletions config/packages/dev/monolog.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use Symfony\Config\MonologConfig;

return static function (MonologConfig $monolog): void
{
return static function (MonologConfig $monolog): void {
$monolog->handler('main', [
'type' => 'stream',
'path' => '%kernel.logs_dir%/%kernel.environment%.log',
Expand Down
9 changes: 4 additions & 5 deletions config/packages/prod/monolog.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@

use Symfony\Config\MonologConfig;

return static function (MonologConfig $monolog): void
{
return static function (MonologConfig $monolog): void {
$monolog->handler('main', [
'type' => 'fingers_crossed',
'action_level' => 'error',
'handler' => 'nested',
'buffer_size' => 50
'buffer_size' => 50,
])->excludedHttpCode()->code(404)->code(405);
$monolog->handler('nested', [
'type' => 'stream',
'path' => 'php://stderr',
'level' => 'debug',
'formatter' => 'monolog.formatter.json'
'formatter' => 'monolog.formatter.json',
]);
$monolog->handler('console', [
'type' => 'console',
'process_psr_3_messages' => false
'process_psr_3_messages' => false,
])->channels()->elements(['!event', '!doctrine']);
};
5 changes: 2 additions & 3 deletions config/packages/security.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Config\SecurityConfig;

return static function (SecurityConfig $security): void
{
return static function (SecurityConfig $security): void {
$security->enableAuthenticatorManager(true);
$security->passwordHasher(PasswordAuthenticatedUserInterface::class, 'auto');
$userProvider = $security->provider('app_user_provider');
Expand All @@ -32,6 +31,6 @@
$mainFirewall->entryPoint('form_login');

$security->accessControl([
'path' => '^/dashboard', 'roles' => 'ROLE_USER'
'path' => '^/dashboard', 'roles' => 'ROLE_USER',
]);
};
5 changes: 2 additions & 3 deletions config/packages/test/monolog.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use Symfony\Config\MonologConfig;

return static function (MonologConfig $monolog): void
{
return static function (MonologConfig $monolog): void {
$monolog->handler('main', [
'type' => 'fingers_crossed',
'action_level' => 'error',
Expand All @@ -14,6 +13,6 @@
$monolog->handler('nested', [
'type' => 'stream',
'path' => '%kernel.logs_dir%/%kernel.environment%.log',
'level' => 'debug'
'level' => 'debug',
]);
};
5 changes: 1 addition & 4 deletions src/Command/ExampleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@ protected function configure(): void
);
}

protected function initialize(InputInterface $input, OutputInterface $output): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->ioStream = new SymfonyStyle($input, $output);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$optionSomething = $input->getOption(self::OPTION_SOMETHING);
if ($optionSomething) {
$this->ioStream->text('Bye world!');
Expand Down
9 changes: 2 additions & 7 deletions src/Controller/HttpClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@

final class HttpClientController extends AbstractController
{
private HttpClientInterface $httpClient;

public function __construct(HttpClientInterface $httpClient)
public function __construct(private readonly HttpClientInterface $httpClient)
{
$this->httpClient = $httpClient;
}

public function routeUsingHttpClient(): Response
Expand Down Expand Up @@ -65,9 +62,7 @@ public function routeMakingMultipleRequests(): Response

public function internalEndpointPost(Request $request): Response
{
$data = json_decode($request->getContent(), true);

return $this->json(['received' => $data]);
return $this->json(['received' => $request->toArray()]);
}

public function routeShouldNotMakeSpecificRequest(): Response
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class RegistrationController extends AbstractController
public function __construct(
private readonly Mailer $mailer,
private readonly UserRepositoryInterface $userRepository,
private readonly EventDispatcherInterface $eventDispatcher
private readonly EventDispatcherInterface $eventDispatcher,
) {
}

Expand Down
1 change: 1 addition & 0 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static function create(string $email, string $password, array $roles = []
$user->email = $email;
$user->password = $password;
$user->roles = $roles;

return $user;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Repository/Model/UserRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ interface UserRepositoryInterface
public function save(User $user): void;

public function getByEmail(string $email): ?User;
}
}
1 change: 1 addition & 0 deletions src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function getByEmail(string $email): ?User
{
/** @var User|null $user */
$user = $this->findOneBy(['email' => $email]);

return $user;
}
}
2 changes: 1 addition & 1 deletion src/Utils/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;

final class Mailer
final readonly class Mailer
{
public function __construct(private MailerInterface $mailer)
{
Expand Down
11 changes: 5 additions & 6 deletions tests/Functional/DoctrineCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ public function grabNumRecords(FunctionalTester $I)

public function grabRepository(FunctionalTester $I)
{
//With classes
// With classes
$repository = $I->grabRepository(User::class);
$I->assertInstanceOf(UserRepository::class, $repository);

//With Repository classes
// With Repository classes
$repository = $I->grabRepository(UserRepository::class);
$I->assertInstanceOf(UserRepository::class, $repository);

//With Entities
// With Entities
$user = $I->grabEntityFromRepository(User::class, [
'email' => '[email protected]'
'email' => '[email protected]',
]);
$repository = $I->grabRepository($user);
$I->assertInstanceOf(UserRepository::class, $repository);

//With Repository interfaces
// With Repository interfaces
$repository = $I->grabRepository(UserRepositoryInterface::class);
$I->assertInstanceOf(UserRepository::class, $repository);
}
Expand All @@ -43,5 +43,4 @@ public function seeNumRecords(FunctionalTester $I)
{
$I->seeNumRecords(1, User::class);
}

}
1 change: 1 addition & 0 deletions tests/Functional/EventsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function seeEvent(FunctionalTester $I)
$I->seeEvent('non-existent-event');
} catch (ExpectationFailedException $ex) {
$I->assertTrue(true, 'seeEvent assertion fails with non-existent events.');

return;
}
$I->fail('seeEvent assertion did not fail as expected');
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/ParameterCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class ParameterCest
{
public function grabParameter(FunctionalTester $I)
{
$locale = (string) $I->grabParameter('app.business_name');
$I->assertSame('Codeception', $locale);
$businessName = (string) $I->grabParameter('app.business_name');
$I->assertSame('Codeception', $businessName);
}
}
1 change: 0 additions & 1 deletion tests/Functional/RouterCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ public function seeInCurrentRoute(FunctionalTester $I)
$I->amOnPage('/');
$I->seeInCurrentRoute('index');
}

}
12 changes: 6 additions & 6 deletions tests/Functional/SecurityCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public function dontSeeRememberedAuthentication(FunctionalTester $I)
$I->submitForm('form[name=login]', [
'email' => '[email protected]',
'password' => '123456',
'_remember_me' => false
'_remember_me' => false,
]);
$I->dontSeeRememberedAuthentication();
}

public function seeAuthentication(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => '[email protected]'
'email' => '[email protected]',
]);
$I->amLoggedInAs($user);
$I->amOnPage('/dashboard');
Expand All @@ -43,15 +43,15 @@ public function seeRememberedAuthentication(FunctionalTester $I)
$I->submitForm('form[name=login]', [
'email' => '[email protected]',
'password' => '123456',
'_remember_me' => true
'_remember_me' => true,
]);
$I->seeRememberedAuthentication();
}

public function seeUserHasRole(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => '[email protected]'
'email' => '[email protected]',
]);
$I->amLoggedInAs($user);
$I->amOnPage('/');
Expand All @@ -62,7 +62,7 @@ public function seeUserHasRole(FunctionalTester $I)
public function seeUserHasRoles(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => '[email protected]'
'email' => '[email protected]',
]);
$I->amLoggedInAs($user);
$I->amOnPage('/');
Expand All @@ -73,7 +73,7 @@ public function seeUserHasRoles(FunctionalTester $I)
public function seeUserPasswordDoesNotNeedRehash(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => '[email protected]'
'email' => '[email protected]',
]);
$I->amLoggedInAs($user);
$I->amOnPage('/dashboard');
Expand Down
1 change: 0 additions & 1 deletion tests/Functional/ServicesCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ public function grabService(FunctionalTester $I)
$security = $I->grabService('security.helper');
$I->assertInstanceOf(Security::class, $security);
}

}
12 changes: 6 additions & 6 deletions tests/Functional/SessionCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class SessionCest
public function amLoggedInAs(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => '[email protected]'
'email' => '[email protected]',
]);
$I->amLoggedInAs($user);
$I->amOnPage('/dashboard');
Expand All @@ -28,7 +28,7 @@ public function amLoggedInAs(FunctionalTester $I)
public function amLoggedInWithToken(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => '[email protected]'
'email' => '[email protected]',
]);
$token = new PostAuthenticationToken($user, 'main', $user->getRoles());
$I->amLoggedInWithToken($token);
Expand All @@ -49,7 +49,7 @@ public function dontSeeInSession(FunctionalTester $I)
public function goToLogoutPath(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => '[email protected]'
'email' => '[email protected]',
]);
$I->amLoggedInAs($user);
$I->amOnPage('/dashboard');
Expand All @@ -63,7 +63,7 @@ public function goToLogoutPath(FunctionalTester $I)
public function logoutProgrammatically(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => '[email protected]'
'email' => '[email protected]',
]);
$I->amLoggedInAs($user);
$I->amOnPage('/dashboard');
Expand All @@ -78,7 +78,7 @@ public function logoutProgrammatically(FunctionalTester $I)
public function seeInSession(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => '[email protected]'
'email' => '[email protected]',
]);
$I->amLoggedInAs($user);
$I->amOnPage('/');
Expand All @@ -89,7 +89,7 @@ public function seeInSession(FunctionalTester $I)
public function seeSessionHasValues(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => '[email protected]'
'email' => '[email protected]',
]);
$I->amLoggedInAs($user);
$I->amOnPage('/');
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/TimeCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ public function seeRequestElapsedTimeLessThan(FunctionalTester $I)
$I->seeInCurrentUrl('register');
$I->seeRequestTimeIsLessThan(400);
}
}
}
2 changes: 1 addition & 1 deletion tests/Functional/TwigCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public function seeRenderedTemplate(FunctionalTester $I)
$I->seeRenderedTemplate('layout.html.twig');
$I->seeRenderedTemplate('security/login.html.twig');
}
}
}
Loading