Skip to content

Commit

Permalink
[TASK] Streamline type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminkott committed May 22, 2023
1 parent 0eeacbb commit 8056c0f
Show file tree
Hide file tree
Showing 33 changed files with 74 additions and 430 deletions.
17 changes: 3 additions & 14 deletions Classes/AvatarProvider/GravatarProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,9 @@

class GravatarProvider implements AvatarProviderInterface, SingletonInterface
{
/**
* @var GravatarUriBuilderInterface
*/
private $gravatarUriBuilder;

/**
* @var AvatarResourceResolverInterface
*/
private $avatarResourceResolver;

/**
* @var bool
*/
private $proxyGravatarImage;
private GravatarUriBuilderInterface $gravatarUriBuilder;
private AvatarResourceResolverInterface $avatarResourceResolver;
private bool $proxyGravatarImage;

final public function __construct()
{
Expand Down
56 changes: 11 additions & 45 deletions Classes/Controller/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace T3G\AgencyPack\Blog\Controller;

use Psr\Http\Message\ResponseInterface;
use T3G\AgencyPack\Blog\Domain\Model\Comment;
use T3G\AgencyPack\Blog\Domain\Model\Post;
use T3G\AgencyPack\Blog\Domain\Repository\PostRepository;
use T3G\AgencyPack\Blog\Service\CacheService;
Expand All @@ -20,69 +19,36 @@

class CommentController extends ActionController
{
/**
* @var PostRepository
*/
protected $postRepository;

/**
* @var CommentService
*/
protected $commentService;

/**
* @var CacheService
*/
protected $blogCacheService;

/**
* @param PostRepository $postRepository
*/
public function injectPostRepository(PostRepository $postRepository): void
{
protected PostRepository $postRepository;
protected CommentService $commentService;
protected CacheService $cacheService;

public function __construct(
PostRepository $postRepository,
CommentService $commentService,
CacheService $cacheService
) {
$this->postRepository = $postRepository;
}

/**
* @param \T3G\AgencyPack\Blog\Service\CommentService $commentService
*/
public function injectCommentService(CommentService $commentService): void
{
$this->commentService = $commentService;
}

/**
* @param \T3G\AgencyPack\Blog\Service\CacheService $cacheService
*/
public function injectBlogCacheService(CacheService $cacheService): void
{
$this->blogCacheService = $cacheService;
$this->cacheService = $cacheService;
}

/**
* Show comment form.
*
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function formAction(): ResponseInterface
{
$this->view->assign('post', $this->postRepository->findCurrentPost());
return $this->htmlResponse();
}

/**
* @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function commentsAction(): ResponseInterface
{
$post = $this->postRepository->findCurrentPost();
if ($post instanceof Post) {
$comments = $this->commentService->getCommentsByPost($post);
foreach ($comments as $comment) {
$this->blogCacheService->addTagToPage('tx_blog_comment_' . $comment->getUid());
$this->cacheService->addTagToPage('tx_blog_comment_' . $comment->getUid());
}
$this->view->assign('comments', $comments);
$this->view->assign('post', $post);
Expand Down
93 changes: 18 additions & 75 deletions Classes/Controller/WidgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,69 +22,24 @@

class WidgetController extends ActionController
{
/**
* @var CategoryRepository
*/
protected $categoryRepository;

/**
* @var TagRepository
*/
protected $tagRepository;

/**
* @var PostRepository
*/
protected $postRepository;

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

/**
* @var CacheService
*/
protected $blogCacheService;

/**
* @param CategoryRepository $categoryRepository
*/
public function injectCategoryRepository(CategoryRepository $categoryRepository): void
{
protected CategoryRepository $categoryRepository;
protected TagRepository $tagRepository;
protected PostRepository $postRepository;
protected CommentRepository $commentRepository;
protected CacheService $cacheService;

public function __construct(
CategoryRepository $categoryRepository,
TagRepository $tagRepository,
PostRepository $postRepository,
CommentRepository $commentRepository,
CacheService $cacheService
) {
$this->categoryRepository = $categoryRepository;
}

/**
* @param TagRepository $tagRepository
*/
public function injectTagRepository(TagRepository $tagRepository): void
{
$this->tagRepository = $tagRepository;
}

/**
* @param PostRepository $postRepository
*/
public function injectPostRepository(PostRepository $postRepository): void
{
$this->postRepository = $postRepository;
}

/**
* @param CommentRepository $commentRepository
*/
public function injectCommentRepository(CommentRepository $commentRepository): void
{
$this->commentRepository = $commentRepository;
}

/**
* @param \T3G\AgencyPack\Blog\Service\CacheService $cacheService
*/
public function injectBlogCacheService(CacheService $cacheService): void
{
$this->blogCacheService = $cacheService;
$this->cacheService = $cacheService;
}

public function categoriesAction(): ResponseInterface
Expand All @@ -98,7 +53,7 @@ public function categoriesAction(): ResponseInterface
$this->view->assign('categories', $categories);
$this->view->assign('currentCategory', $currentCategory);
foreach ($categories as $category) {
$this->blogCacheService->addTagToPage('tx_blog_category_' . $category->getUid());
$this->cacheService->addTagToPage('tx_blog_category_' . $category->getUid());
}
return $this->htmlResponse();
}
Expand Down Expand Up @@ -136,18 +91,13 @@ public function tagsAction(): ResponseInterface
}
unset($tagReference);
foreach ($tags as $tag) {
$this->blogCacheService->addTagToPage('tx_blog_tag_' . (int)$tag['uid']);
$this->cacheService->addTagToPage('tx_blog_tag_' . (int)$tag['uid']);
}
$this->view->assign('tags', $tags);
$this->view->assign('currentTag', $currentTag);
return $this->htmlResponse();
}

/**
* @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function recentPostsAction(): ResponseInterface
{
$limit = (int)($this->settings['widgets']['recentposts']['limit'] ?? 0);
Expand All @@ -157,31 +107,24 @@ public function recentPostsAction(): ResponseInterface
: $this->postRepository->findAll();

foreach ($posts as $post) {
$this->blogCacheService->addTagsForPost($post);
$this->cacheService->addTagsForPost($post);
}
$this->view->assign('posts', $posts);
return $this->htmlResponse();
}

/**
* @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function commentsAction(): ResponseInterface
{
$limit = (int)($this->settings['widgets']['comments']['limit'] ?? 5);
$blogSetup = isset($this->settings['widgets']['comments']['blogSetup']) ? (int) $this->settings['widgets']['comments']['blogSetup'] : null;
$comments = $this->commentRepository->findActiveComments($limit, $blogSetup);
$this->view->assign('comments', $comments);
foreach ($comments as $comment) {
$this->blogCacheService->addTagToPage('tx_blog_comment_' . $comment->getUid());
$this->cacheService->addTagToPage('tx_blog_comment_' . $comment->getUid());
}
return $this->htmlResponse();
}

/**
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
*/
public function archiveAction(): ResponseInterface
{
$posts = $this->postRepository->findMonthsAndYearsWithPosts();
Expand Down
2 changes: 0 additions & 2 deletions Classes/DataTransferObject/AvatarResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
interface AvatarResource
{
public function getUri(): UriInterface;

public function getContentType(): string;

public function getContent(): string;
}
17 changes: 3 additions & 14 deletions Classes/DataTransferObject/Gravatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,9 @@

class Gravatar implements AvatarResource
{
/**
* @var UriInterface
*/
private $uri;

/**
* @var string
*/
private $contentType;

/**
* @var string
*/
private $content;
private UriInterface $uri;
private string $contentType;
private string $content;

public function __construct(UriInterface $uri, string $contentType, string $content)
{
Expand Down
31 changes: 7 additions & 24 deletions Classes/DataTransferObject/PostRepositoryDemand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,26 @@ class PostRepositoryDemand
/**
* @var int[]
*/
protected $posts = [];
protected array $posts = [];

/**
* @var Category[]
*/
protected $categories = [];

/**
* @var string
*/
protected $categoriesConjunction = Constants::REPOSITORY_CONJUNCTION_AND;
protected array $categories = [];
protected string $categoriesConjunction = Constants::REPOSITORY_CONJUNCTION_AND;

/**
* @var Tag[]
*/
protected $tags = [];

/**
* @var string
*/
protected $tagsConjunction = Constants::REPOSITORY_CONJUNCTION_AND;
protected array $tags = [];
protected string $tagsConjunction = Constants::REPOSITORY_CONJUNCTION_AND;

/**
* @var string[]
*/
protected $ordering = [];
protected array $ordering = [];

/**
* @var int
*/
protected $limit = 0;
protected int $limit = 0;

/**
* @return int[]
Expand Down Expand Up @@ -100,9 +89,6 @@ public function removeCategory(Category $category): self
return $this;
}

/**
* @return string
*/
public function getCategoriesConjunction(): string
{
return $this->categoriesConjunction;
Expand Down Expand Up @@ -140,9 +126,6 @@ public function removeTag(Tag $tag): self
return $this;
}

/**
* @return string
*/
public function getTagsConjunction(): string
{
return $this->tagsConjunction;
Expand Down
4 changes: 0 additions & 4 deletions Classes/Domain/Factory/CommentFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ class CommentFormFactory extends AbstractFormFactory
* Build a FormDefinition.
* This example build a FormDefinition manually,
* so $configuration and $prototypeName are unused.
*
* @param array $configuration
* @param string $prototypeName
* @return FormDefinition
*/
public function build(array $configuration, string $prototypeName = null): FormDefinition
{
Expand Down
5 changes: 0 additions & 5 deletions Classes/Domain/Repository/AuthorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
*/
class AuthorRepository extends Repository
{
/**
* Initializes the repository.
*
* @throws \InvalidArgumentException
*/
public function initializeObject(): void
{
$this->defaultOrderings = [
Expand Down
Loading

0 comments on commit 8056c0f

Please sign in to comment.