Accéder à l'en-tête Accéder au contenu principal Accéder au pied de page
Retour aux actualités
Non classé
07/10/2019 Cyrille Martraire

_plugin pour insérer code ->Enlighter – Customizable Syntax Highlighter

Nouveau plugin pour insérer du code .

Insérez votre code, choisissez votre langage (C++, Java, ..) .

A bientôt,

Tanguy

 

<?php

namespace MyCompanyAppPost;

use MyCompanyAppRepositoryCommentRepository;
use MyCompanyAppRepositoryPostRepository;

final class GetPostsList
{
    /** @var PostRepository */
    private $postRepository;

    /** @var CommentRepository */
    private $commentRepository;

    public function __construct(PostRepository $postRepository, CommentRepository $commentRepository)
    {
        $this->postRepository = $postRepository;
        $this->commentRepository = $commentRepository;
    }

    public function __invoke(): array
    {
        $postViews = [];

        foreach ($this->postRepository->getAll() as $post) {
            $isLessThanAWeekOld = (clone $post->publishedAt)->add(new DateInterval('P1W')) > new DateTime();

            $postViews[] = new PostView(
                $post->title,
                $this->commentRepository->countByPost($post),
                $isLessThanAWeekOld
            );
        }

        return $postViews;
    }
}