Skip to content

Commit

Permalink
minor #1491 More consistent code style (shuraknows)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the main branch.

Discussion
----------

More consistent code style

Multiple-line code blocks is being separated with new line from single-line code blocks.

Also php-cs-fixer suggested fix: functions with default null arguments should accept null value.

Commits
-------

cb82e93 More consistent code style
  • Loading branch information
javiereguiluz committed Feb 5, 2024
2 parents dc20a11 + cb82e93 commit 4d9888d
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Command/AddUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi

// Ask for the email if it's not defined
$email = $input->getArgument('email');

if (null !== $email) {
$this->io->text(' > <info>Email</info>: '.$email);
} else {
Expand All @@ -147,6 +148,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi

// Ask for the full name if it's not defined
$fullName = $input->getArgument('full-name');

if (null !== $fullName) {
$this->io->text(' > <info>Full Name</info>: '.$fullName);
} else {
Expand Down Expand Up @@ -198,6 +200,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->io->success(sprintf('%s was successfully created: %s (%s)', $isAdmin ? 'Administrator user' : 'User', $user->getUsername(), $user->getEmail()));

$event = $stopwatch->stop('add-user-command');

if ($output->isVerbose()) {
$this->io->comment(sprintf('New user database id: %d / Elapsed time: %.2f ms / Consumed memory: %.2f MB', $user->getId(), $event->getDuration(), $event->getMemory() / (1024 ** 2)));
}
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ final class BlogController extends AbstractController
public function index(Request $request, int $page, string $_format, PostRepository $posts, TagRepository $tags): Response
{
$tag = null;

if ($request->query->has('tag')) {
$tag = $tags->findOneBy(['name' => $request->query->get('tag')]);
}

$latestPosts = $posts->findLatest($page, $tag);

// Every template name also has two extensions that specify the format and
Expand Down
1 change: 1 addition & 0 deletions src/DataFixtures/AppFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ private function getTagData(): array
private function getPostData(): array
{
$posts = [];

foreach ($this->getPhrases() as $i => $title) {
// $postData = [$title, $slug, $summary, $content, $publishedAt, $author, $tags, $comments];

Expand Down
1 change: 1 addition & 0 deletions src/Entity/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public function getComments(): Collection
public function addComment(Comment $comment): void
{
$comment->setPost($this);

if (!$this->comments->contains($comment)) {
$this->comments->add($comment);
}
Expand Down
1 change: 1 addition & 0 deletions src/EventSubscriber/CommentNotificationSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function onCommentCreated(CommentCreatedEvent $event): void
], UrlGeneratorInterface::ABSOLUTE_URL);

$subject = $this->translator->trans('notification.comment_created');

$body = $this->translator->trans('notification.comment_created.description', [
'title' => $post->getTitle(),
'link' => $linkToPost,
Expand Down
4 changes: 3 additions & 1 deletion src/EventSubscriber/RedirectToPreferredLocaleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ final class RedirectToPreferredLocaleSubscriber implements EventSubscriberInterf
public function __construct(
private readonly UrlGeneratorInterface $urlGenerator,
string $locales,
string $defaultLocale = null
?string $defaultLocale = null
) {
$this->locales = explode('|', trim($locales));

if (empty($this->locales)) {
throw new \UnexpectedValueException('The list of supported locales must not be empty.');
}
Expand Down Expand Up @@ -75,6 +76,7 @@ public function onKernelRequest(RequestEvent $event): void
// Ignore requests from referrers with the same HTTP host in order to prevent
// changing language for users who possibly already selected it for this application.
$referrer = $request->headers->get('referer');

if (null !== $referrer && u($referrer)->ignoreCase()->startsWith($request->getSchemeAndHttpHost())) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Form/DataTransformer/TagArrayToStringTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public function reverseTransform($string): array
$tags = $this->tags->findBy([
'name' => $names,
]);

$newNames = array_diff($names, $tags);

foreach ($newNames as $name) {
$tags[] = new Tag($name);

Expand Down
2 changes: 1 addition & 1 deletion src/Repository/PostRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(ManagerRegistry $registry)
parent::__construct($registry, Post::class);
}

public function findLatest(int $page = 1, Tag $tag = null): Paginator
public function findLatest(int $page = 1, ?Tag $tag = null): Paginator
{
$qb = $this->createQueryBuilder('p')
->addSelect('a', 't')
Expand Down
1 change: 1 addition & 0 deletions src/Twig/AppExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function getLocales(): array
}

$this->locales = [];

foreach ($this->localeCodes as $localeCode) {
$this->locales[] = ['code' => $localeCode, 'name' => Locales::getName($localeCode, $localeCode)];
}
Expand Down
2 changes: 2 additions & 0 deletions src/Twig/SourceCodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function getFunctions(): array
public function linkSourceFile(Environment $twig, string $file, int $line): string
{
$text = str_replace('\\', '/', $file);

if (str_starts_with($text, $this->projectDir)) {
$text = mb_substr($text, mb_strlen($this->projectDir));
}
Expand Down Expand Up @@ -180,6 +181,7 @@ private function unindentCode(string $code): string
});

$codeIsIndented = \count($indentedOrBlankLines) === \count($codeLines);

if ($codeIsIndented) {
$unindentedLines = array_map(static function ($lineOfCode) {
return u($lineOfCode)->after(' ');
Expand Down

0 comments on commit 4d9888d

Please sign in to comment.