Skip to content

Commit

Permalink
[TASK] Use more native types in the blog extension
Browse files Browse the repository at this point in the history
Also add a missing property that already had a getter
and setter.

Also drop redundant type annotations and comments.

Used command:
> ./Build/Scripts/runTests.sh -s phpstanGenerateBaseline

Resolves: #98133
Related: #98132
Releases: main
Change-Id: I912d78df2d4f2b94b622c51a632690752dbb165b
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75432
Tested-by: Nikita Hovratov <nikita.h@live.de>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Nikita Hovratov <nikita.h@live.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
  • Loading branch information
oliverklee authored and maddy2101 committed Aug 12, 2022
1 parent 573e9b2 commit 13dc5aa
Show file tree
Hide file tree
Showing 16 changed files with 183 additions and 976 deletions.
30 changes: 0 additions & 30 deletions Build/phpstan/phpstan-baseline.neon
Expand Up @@ -2035,41 +2035,11 @@ parameters:
count: 1
path: ../../typo3/sysext/extbase/Classes/Validation/Validator/CollectionValidator.php

-
message: "#^Parameter \\#1 \\$iterator of method ExtbaseTeam\\\\BlogExample\\\\Controller\\\\BlogController\\:\\:getStructure\\(\\) expects iterable\\<TYPO3\\\\CMS\\\\Extbase\\\\DomainObject\\\\AbstractEntity\\>&Iterator, array\\|TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\QueryResultInterface given\\.$#"
count: 1
path: ../../typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Controller/BlogController.php

-
message: "#^Call to an undefined method TYPO3Fluid\\\\Fluid\\\\View\\\\ViewInterface\\:\\:setConfiguration\\(\\)\\.$#"
count: 1
path: ../../typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Controller/ContentController.php

-
message: "#^PHPDoc tag @param references unknown parameter\\: \\$response$#"
count: 1
path: ../../typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Controller/ContentController.php

-
message: "#^PHPDoc tag @return with type array is incompatible with native type Psr\\\\Http\\\\Message\\\\ResponseInterface\\.$#"
count: 1
path: ../../typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Controller/ContentController.php

-
message: "#^Parameter \\#1 \\$iterator of method ExtbaseTeam\\\\BlogExample\\\\Controller\\\\ContentController\\:\\:getStructure\\(\\) expects iterable\\<TYPO3\\\\CMS\\\\Extbase\\\\DomainObject\\\\AbstractEntity\\>&Iterator, array\\|TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\QueryResultInterface given\\.$#"
count: 1
path: ../../typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Controller/ContentController.php

-
message: "#^Property ExtbaseTeam\\\\BlogExample\\\\Domain\\\\Model\\\\Administrator\\:\\:\\$image \\(TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\ObjectStorage\\<TYPO3\\\\CMS\\\\Extbase\\\\Domain\\\\Model\\\\FileReference\\>\\) on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Domain/Model/Administrator.php

-
message: "#^Property ExtbaseTeam\\\\BlogExample\\\\Domain\\\\Model\\\\Administrator\\:\\:\\$usergroup \\(TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\ObjectStorage\\<ExtbaseTeam\\\\BlogExample\\\\Domain\\\\Model\\\\FrontendUserGroup\\>\\) on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Domain/Model/Administrator.php

-
message: "#^Instanceof between ExtbaseTeam\\\\BlogExample\\\\Domain\\\\Model\\\\Category\\|null and TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\Generic\\\\LazyLoadingProxy will always evaluate to false\\.$#"
count: 1
Expand Down
Expand Up @@ -18,39 +18,31 @@
namespace ExtbaseTeam\BlogExample\Controller;

use ExtbaseTeam\BlogExample\Domain\Model\Blog;
use ExtbaseTeam\BlogExample\Domain\Model\Post;
use ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Extbase\Annotation\IgnoreValidation;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
use TYPO3\CMS\Extbase\Mvc\View\JsonView;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory;
use TYPO3\CMS\Extbase\Property\Exception;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;

/**
* BlogController
*/
class BlogController extends ActionController
{
/**
* @var \ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository
*/
private $blogRepository;
private BlogRepository $blogRepository;

/**
* @var string
*/
protected $defaultViewObjectName = JsonView::class;

/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory
*/
private $dataMapFactory;
private DataMapFactory $dataMapFactory;

public function __construct(
\ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository $blogRepository,
\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory $dataMapFactory
) {
public function __construct(BlogRepository $blogRepository, DataMapFactory $dataMapFactory)
{
$this->blogRepository = $blogRepository;
$this->dataMapFactory = $dataMapFactory;
}
Expand All @@ -66,7 +58,7 @@ public function listAction(): ResponseInterface
return $this->htmlResponse();
}

public function detailsAction(Blog $blog=null): ResponseInterface
public function detailsAction(Blog $blog = null): ResponseInterface
{
return $this->htmlResponse($blog ? $blog->getTitle() : '');
}
Expand All @@ -81,24 +73,24 @@ public function testFormAction(): ResponseInterface
* // needs to be imported entirely, else the annotationChecker test script complains
* @IgnoreValidation("blogPost")
*/
public function testForwardAction($blogPost): ForwardResponse
public function testForwardAction(Post $blogPost): ForwardResponse
{
return (new ForwardResponse('testForwardTarget'))->withArguments(['blogPost' => $blogPost]);
}

/**
* @param \ExtbaseTeam\BlogExample\Domain\Model\Post $blogPost
*/
public function testForwardTargetAction($blogPost): ResponseInterface
public function testForwardTargetAction(Post $blogPost): ResponseInterface
{
return $this->htmlResponse('testForwardTargetAction');
}

/**
* @param \ExtbaseTeam\BlogExample\Domain\Model\Blog $blog
* @param \ExtbaseTeam\BlogExample\Domain\Model\Post $blogPost
* @param \ExtbaseTeam\BlogExample\Domain\Model\Post|null $blogPost
*/
public function testRelatedObjectAction($blog, $blogPost = null): ResponseInterface
public function testRelatedObjectAction(Blog $blog, ?Post $blogPost = null): ResponseInterface
{
return $this->htmlResponse('testRelatedObject');
}
Expand All @@ -121,8 +113,6 @@ public function processRequest(RequestInterface $request): ResponseInterface
/**
* Disable the default error flash message, otherwise we get an error because the flash message
* session handling is not available during functional tests.
*
* @return bool
*/
protected function getErrorFlashMessage(): bool
{
Expand All @@ -131,9 +121,8 @@ protected function getErrorFlashMessage(): bool

/**
* @param \Iterator|\TYPO3\CMS\Extbase\DomainObject\AbstractEntity[] $iterator
* @return array
*/
protected function getStructure($iterator): array
protected function getStructure(\Iterator|array $iterator): array
{
$structure = [];

Expand Down Expand Up @@ -165,9 +154,6 @@ protected function getStructure($iterator): array
return $structure;
}

/**
* @return string
*/
protected function getRuntimeIdentifier(): string
{
$arguments = [];
Expand Down
Expand Up @@ -17,72 +17,60 @@

namespace ExtbaseTeam\BlogExample\Controller;

use ExtbaseTeam\BlogExample\Domain\Repository\TtContentRepository;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
use TYPO3\CMS\Extbase\Mvc\View\JsonView;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory;
use TYPO3\CMS\Extbase\Property\Exception;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;

/**
* ContentController
*/
class ContentController extends ActionController
{
/**
* @var \ExtbaseTeam\BlogExample\Domain\Repository\TtContentRepository
*/
private $contentRepository;
private TtContentRepository $contentRepository;

/**
* @var string
*/
protected $defaultViewObjectName = JsonView::class;

/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory
*/
private $dataMapFactory;
private DataMapFactory $dataMapFactory;

public function __construct(
\ExtbaseTeam\BlogExample\Domain\Repository\TtContentRepository $contentRepository,
\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory $dataMapFactory
) {
public function __construct(TtContentRepository $contentRepository, DataMapFactory $dataMapFactory)
{
$this->contentRepository = $contentRepository;
$this->dataMapFactory = $dataMapFactory;
}

/**
* @return array
*/
public function listAction(): ResponseInterface
{
$content = $this->contentRepository->findAll();
$value = [];
$value[$this->getRuntimeIdentifier()] = $this->getStructure($content);
// this is required so we don't try to json_encode content of the image
$this->view->setConfiguration(['value' => [
'_descendAll' => [
$this->view->setConfiguration([
'value' => [
'_descendAll' => [
'_descendAll' => [
'_descendAll' => [
'_descendAll' => [
'_exclude' => ['contents'],
'_descendAll' => [
'_exclude' => ['contents'],
],
],
],
],
],
],
]]);
]);
$this->view->assign('value', $value);

return $this->jsonResponse();
}

/**
* @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @throws \RuntimeException
*/
public function processRequest(RequestInterface $request): ResponseInterface
Expand All @@ -99,9 +87,8 @@ public function processRequest(RequestInterface $request): ResponseInterface

/**
* @param \Iterator|\TYPO3\CMS\Extbase\DomainObject\AbstractEntity[] $iterator
* @return array
*/
protected function getStructure($iterator): array
protected function getStructure(\Iterator|array $iterator): array
{
$structure = [];

Expand Down Expand Up @@ -140,9 +127,6 @@ protected function getStructure($iterator): array
return $structure;
}

/**
* @return string
*/
protected function getRuntimeIdentifier(): string
{
$arguments = [];
Expand Down

0 comments on commit 13dc5aa

Please sign in to comment.