Skip to content

Commit

Permalink
Refactor CategoryBundle parts to Constructor Property Promotion (#7398)
Browse files Browse the repository at this point in the history
  • Loading branch information
mamazu committed May 6, 2024
1 parent 2616888 commit 02535d3
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 437 deletions.
17 changes: 6 additions & 11 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3676,7 +3676,7 @@ parameters:
path: src/Sulu/Bundle/CategoryBundle/Category/CategoryManager.php

-
message: "#^Thrown exceptions in a catch block must bundle the previous exception \\(see throw statement line 267\\)\\. More info\\: http\\://bit\\.ly/bundleexception$#"
message: "#^Thrown exceptions in a catch block must bundle the previous exception \\(see throw statement line 213\\)\\. More info\\: http\\://bit\\.ly/bundleexception$#"
count: 1
path: src/Sulu/Bundle/CategoryBundle/Category/CategoryManager.php

Expand Down Expand Up @@ -3765,6 +3765,11 @@ parameters:
count: 1
path: src/Sulu/Bundle/CategoryBundle/Content/Types/CategorySelection.php

-
message: "#^Call to an undefined method Sulu\\\\Component\\\\Rest\\\\ListBuilder\\\\ListBuilderInterface\\:\\:setParameter\\(\\)\\.$#"
count: 1
path: src/Sulu/Bundle/CategoryBundle/Controller/CategoryController.php

-
message: "#^Left side of && is always true\\.$#"
count: 1
Expand Down Expand Up @@ -3955,11 +3960,6 @@ parameters:
count: 1
path: src/Sulu/Bundle/CategoryBundle/Controller/CategoryController.php

-
message: "#^Property Sulu\\\\Bundle\\\\CategoryBundle\\\\Controller\\\\CategoryController\\:\\:\\$listBuilderFactory \\(Sulu\\\\Component\\\\Rest\\\\ListBuilder\\\\Doctrine\\\\DoctrineListBuilderFactory\\) does not accept Sulu\\\\Component\\\\Rest\\\\ListBuilder\\\\Doctrine\\\\DoctrineListBuilderFactoryInterface\\.$#"
count: 1
path: src/Sulu/Bundle/CategoryBundle/Controller/CategoryController.php

-
message: "#^Strict comparison using \\=\\=\\= between false and string will always evaluate to false\\.$#"
count: 1
Expand Down Expand Up @@ -4070,11 +4070,6 @@ parameters:
count: 1
path: src/Sulu/Bundle/CategoryBundle/Controller/KeywordController.php

-
message: "#^Property Sulu\\\\Bundle\\\\CategoryBundle\\\\Controller\\\\KeywordController\\:\\:\\$listBuilderFactory \\(Sulu\\\\Component\\\\Rest\\\\ListBuilder\\\\Doctrine\\\\DoctrineListBuilderFactory\\) does not accept Sulu\\\\Component\\\\Rest\\\\ListBuilder\\\\Doctrine\\\\DoctrineListBuilderFactoryInterface\\.$#"
count: 1
path: src/Sulu/Bundle/CategoryBundle/Controller/KeywordController.php

-
message: "#^Method Sulu\\\\Bundle\\\\CategoryBundle\\\\DependencyInjection\\\\SuluCategoryExtension\\:\\:load\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
24 changes: 3 additions & 21 deletions src/Sulu/Bundle/CategoryBundle/Admin/CategoryAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,11 @@ class CategoryAdmin extends Admin

public const EDIT_FORM_VIEW = 'sulu_category.edit_form';

/**
* @var ViewBuilderFactoryInterface
*/
private $viewBuilderFactory;

/**
* @var SecurityCheckerInterface
*/
private $securityChecker;

/**
* @var LocalizationManagerInterface
*/
private $localizationManager;

public function __construct(
ViewBuilderFactoryInterface $viewBuilderFactory,
SecurityCheckerInterface $securityChecker,
LocalizationManagerInterface $localizationManager
private ViewBuilderFactoryInterface $viewBuilderFactory,
private SecurityCheckerInterface $securityChecker,
private LocalizationManagerInterface $localizationManager
) {
$this->viewBuilderFactory = $viewBuilderFactory;
$this->securityChecker = $securityChecker;
$this->localizationManager = $localizationManager;
}

public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void
Expand Down
72 changes: 9 additions & 63 deletions src/Sulu/Bundle/CategoryBundle/Category/CategoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,71 +43,17 @@ class CategoryManager implements CategoryManagerInterface

public static $catTranslationEntityName = CategoryTranslationInterface::class;

/**
* @var EntityManagerInterface
*/
private $em;

/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;

/**
* @var UserRepositoryInterface
*/
private $userRepository;

/**
* @var CategoryRepositoryInterface
*/
private $categoryRepository;

/**
* @var CategoryMetaRepositoryInterface
*/
private $categoryMetaRepository;

/**
* @var CategoryTranslationRepositoryInterface
*/
private $categoryTranslationRepository;

/**
* @var KeywordManagerInterface
*/
private $keywordManager;

/**
* @var DomainEventCollectorInterface
*/
private $domainEventCollector;

/**
* @var TrashManagerInterface|null
*/
private $trashManager;

public function __construct(
CategoryRepositoryInterface $categoryRepository,
CategoryMetaRepositoryInterface $categoryMetaRepository,
CategoryTranslationRepositoryInterface $categoryTranslationRepository,
UserRepositoryInterface $userRepository,
KeywordManagerInterface $keywordManager,
EntityManagerInterface $em,
EventDispatcherInterface $eventDispatcher,
DomainEventCollectorInterface $domainEventCollector,
?TrashManagerInterface $trashManager = null
private CategoryRepositoryInterface $categoryRepository,
private CategoryMetaRepositoryInterface $categoryMetaRepository,
private CategoryTranslationRepositoryInterface $categoryTranslationRepository,
private UserRepositoryInterface $userRepository,
private KeywordManagerInterface $keywordManager,
private EntityManagerInterface $em,
private EventDispatcherInterface $eventDispatcher,
private DomainEventCollectorInterface $domainEventCollector,
private ?TrashManagerInterface $trashManager = null
) {
$this->em = $em;
$this->userRepository = $userRepository;
$this->categoryRepository = $categoryRepository;
$this->categoryMetaRepository = $categoryMetaRepository;
$this->categoryTranslationRepository = $categoryTranslationRepository;
$this->eventDispatcher = $eventDispatcher;
$this->keywordManager = $keywordManager;
$this->domainEventCollector = $domainEventCollector;
$this->trashManager = $trashManager;
}

public function findById($id)
Expand Down
32 changes: 4 additions & 28 deletions src/Sulu/Bundle/CategoryBundle/Category/KeywordManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,12 @@
*/
class KeywordManager implements KeywordManagerInterface
{
/**
* @var KeywordRepositoryInterface
*/
private $keywordRepository;

/**
* @var CategoryTranslationRepositoryInterface
*/
private $categoryTranslationRepository;

/**
* @var EntityManagerInterface
*/
private $entityManager;

/**
* @var DomainEventCollectorInterface
*/
private $domainEventCollector;

public function __construct(
KeywordRepositoryInterface $keywordRepository,
CategoryTranslationRepositoryInterface $categoryTranslationRepository,
EntityManagerInterface $entityManager,
DomainEventCollectorInterface $domainEventCollector
private KeywordRepositoryInterface $keywordRepository,
private CategoryTranslationRepositoryInterface $categoryTranslationRepository,
private EntityManagerInterface $entityManager,
private DomainEventCollectorInterface $domainEventCollector
) {
$this->keywordRepository = $keywordRepository;
$this->categoryTranslationRepository = $categoryTranslationRepository;
$this->entityManager = $entityManager;
$this->domainEventCollector = $domainEventCollector;
}

public function save(KeywordInterface $keyword, CategoryInterface $category, $force = null)
Expand Down
19 changes: 4 additions & 15 deletions src/Sulu/Bundle/CategoryBundle/Command/RecoverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,11 @@ class RecoverCommand extends Command
{
protected static $defaultName = 'sulu:categories:recover';

/**
* @var EntityManagerInterface
*/
private $entityManager;

/**
* @var CategoryRepositoryInterface
*/
private $categoryRepository;

public function __construct(EntityManagerInterface $entityManager, CategoryRepositoryInterface $categoryRepository)
{
public function __construct(
private EntityManagerInterface $entityManager,
private CategoryRepositoryInterface $categoryRepository,
) {
parent::__construct();

$this->entityManager = $entityManager;
$this->categoryRepository = $categoryRepository;
}

protected function configure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@

class CategorySelection extends ComplexContentType implements ContentTypeExportInterface
{
/**
* @var CategoryManagerInterface
*/
private $categoryManager;

public function __construct(CategoryManagerInterface $categoryManager)
{
$this->categoryManager = $categoryManager;
public function __construct(
private CategoryManagerInterface $categoryManager
) {
}

public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,9 @@

class SingleCategorySelection extends SimpleContentType implements ContentTypeExportInterface
{
/**
* @var CategoryManagerInterface
*/
private $categoryManager;

public function __construct(CategoryManagerInterface $categoryManager)
public function __construct(private CategoryManagerInterface $categoryManager)
{
parent::__construct('single_category_selection');

$this->categoryManager = $categoryManager;
}

public function getContentData(PropertyInterface $property)
Expand Down
57 changes: 7 additions & 50 deletions src/Sulu/Bundle/CategoryBundle/Controller/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Sulu\Component\Rest\AbstractRestController;
use Sulu\Component\Rest\Exception\RestException;
use Sulu\Component\Rest\ListBuilder\CollectionRepresentation;
use Sulu\Component\Rest\ListBuilder\Doctrine\DoctrineListBuilderFactory;
use Sulu\Component\Rest\ListBuilder\Doctrine\DoctrineListBuilderFactoryInterface;
use Sulu\Component\Rest\ListBuilder\FieldDescriptorInterface;
use Sulu\Component\Rest\ListBuilder\ListBuilderInterface;
Expand All @@ -41,41 +40,6 @@ class CategoryController extends AbstractRestController implements ClassResource
{
use RequestParametersTrait;

/**
* @var CategoryRepositoryInterface
*/
private $categoryRepository;

/**
* @var TranslatorInterface
*/
private $translator;

/**
* @var RestHelperInterface
*/
private $restHelper;

/**
* @var DoctrineListBuilderFactory
*/
private $listBuilderFactory;

/**
* @var FieldDescriptorFactoryInterface
*/
private $fieldDescriptorFactory;

/**
* @var CategoryManagerInterface
*/
private $categoryManager;

/**
* @var class-string
*/
private $categoryClass;

/**
* @deprecated Use the CategoryInterface::RESOURCE_KEY constant instead
*/
Expand All @@ -86,22 +50,15 @@ class CategoryController extends AbstractRestController implements ClassResource
*/
public function __construct(
ViewHandlerInterface $viewHandler,
CategoryRepositoryInterface $categoryRepository,
TranslatorInterface $translator,
RestHelperInterface $restHelper,
DoctrineListBuilderFactoryInterface $listBuilderFactory,
FieldDescriptorFactoryInterface $fieldDescriptorFactory,
CategoryManagerInterface $categoryManager,
string $categoryClass
private CategoryRepositoryInterface $categoryRepository,
private TranslatorInterface $translator,
private RestHelperInterface $restHelper,
private DoctrineListBuilderFactoryInterface $listBuilderFactory,
private FieldDescriptorFactoryInterface $fieldDescriptorFactory,
private CategoryManagerInterface $categoryManager,
private string $categoryClass
) {
parent::__construct($viewHandler);
$this->categoryRepository = $categoryRepository;
$this->translator = $translator;
$this->restHelper = $restHelper;
$this->listBuilderFactory = $listBuilderFactory;
$this->fieldDescriptorFactory = $fieldDescriptorFactory;
$this->categoryManager = $categoryManager;
$this->categoryClass = $categoryClass;
}

public function getAction($id, Request $request)
Expand Down

0 comments on commit 02535d3

Please sign in to comment.