Skip to content

Commit

Permalink
Code review suggestions applied
Browse files Browse the repository at this point in the history
  • Loading branch information
kisztof committed Nov 6, 2023
1 parent 1eb3d8f commit 913960c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 48 deletions.
29 changes: 9 additions & 20 deletions src/lib/Tab/LocationView/AuthorsTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

namespace Ibexa\AdminUi\Tab\LocationView;

use ArrayObject;
use Ibexa\AdminUi\Specification\UserExists;
use Ibexa\AdminUi\UI\Dataset\DatasetFactory;
use Ibexa\Contracts\AdminUi\Tab\AbstractEventDispatchingTab;
use Ibexa\Contracts\AdminUi\Tab\OrderedTabInterface;
use Ibexa\Contracts\Core\Repository\SectionService;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo;
Expand All @@ -25,25 +24,17 @@ class AuthorsTab extends AbstractEventDispatchingTab implements OrderedTabInterf
{
public const URI_FRAGMENT = 'ibexa-tab-location-view-authors';

protected UserService $userService;

protected SectionService $sectionService;

protected DatasetFactory $datasetFactory;
private UserService $userService;

public function __construct(
Environment $twig,
TranslatorInterface $translator,
SectionService $sectionService,
UserService $userService,
DatasetFactory $datasetFactory,
EventDispatcherInterface $eventDispatcher
) {
parent::__construct($twig, $translator, $eventDispatcher);

$this->sectionService = $sectionService;
$this->userService = $userService;
$this->datasetFactory = $datasetFactory;
}

public function getIdentifier(): string
Expand Down Expand Up @@ -81,22 +72,21 @@ public function getTemplateParameters(array $contextParameters = []): array
$versionInfo = $content->getVersionInfo();
$contentInfo = $versionInfo->getContentInfo();

$viewParameters = [
$viewParameters = new ArrayObject([
'content_info' => $contentInfo,
'version_info' => $versionInfo,
];
]);

$this->supplyCreator($viewParameters, $contentInfo);
$this->supplyLastContributor($viewParameters, $versionInfo);

return array_replace($contextParameters, $viewParameters);
return array_replace($contextParameters, $viewParameters->getArrayCopy());
}

/**
* @param array<string, mixed> $parameters
* @param \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo
* @param \ArrayObject<string, mixed|null> $parameters
*/
private function supplyLastContributor(array &$parameters, VersionInfo $versionInfo): void
private function supplyLastContributor(ArrayObject $parameters, VersionInfo $versionInfo): void
{
$parameters['last_contributor'] = null;
if ((new UserExists($this->userService))->isSatisfiedBy($versionInfo->creatorId)) {
Expand All @@ -105,10 +95,9 @@ private function supplyLastContributor(array &$parameters, VersionInfo $versionI
}

/**
* @param array<string,mixed|null> $parameters
* @param \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo
* @param \ArrayObject<string, mixed|null> $parameters
*/
private function supplyCreator(array &$parameters, ContentInfo $contentInfo): void
private function supplyCreator(ArrayObject $parameters, ContentInfo $contentInfo): void
{
$parameters['creator'] = null;
if ((new UserExists($this->userService))->isSatisfiedBy($contentInfo->ownerId)) {
Expand Down
31 changes: 3 additions & 28 deletions src/lib/Tab/LocationView/DetailsTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Ibexa\Contracts\AdminUi\Tab\OrderedTabInterface;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\SectionService;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo;
Expand All @@ -34,11 +33,9 @@ class DetailsTab extends AbstractEventDispatchingTab implements OrderedTabInterf
{
public const URI_FRAGMENT = 'ibexa-tab-location-view-details';

protected UserService $userService;
private SectionService $sectionService;

protected SectionService $sectionService;

protected DatasetFactory $datasetFactory;
private DatasetFactory $datasetFactory;

private FormFactoryInterface $formFactory;

Expand All @@ -48,7 +45,6 @@ public function __construct(
Environment $twig,
TranslatorInterface $translator,
SectionService $sectionService,
UserService $userService,
DatasetFactory $datasetFactory,
FormFactoryInterface $formFactory,
PermissionResolver $permissionResolver,
Expand All @@ -57,7 +53,6 @@ public function __construct(
parent::__construct($twig, $translator, $eventDispatcher);

$this->sectionService = $sectionService;
$this->userService = $userService;
$this->datasetFactory = $datasetFactory;
$this->formFactory = $formFactory;
$this->permissionResolver = $permissionResolver;
Expand Down Expand Up @@ -114,9 +109,6 @@ public function getTemplateParameters(array $contextParameters = []): array
return array_replace($contextParameters, $viewParameters->getArrayCopy());
}

/**
* @param \ArrayObject $parameters
*/
private function supplySortFieldClauseMap(ArrayObject $parameters): void
{
$parameters['sort_field_clause_map'] = [
Expand All @@ -132,11 +124,7 @@ private function supplySortFieldClauseMap(ArrayObject $parameters): void
];
}

/**
* @param \ArrayObject $parameters
* @param \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo
*/
private function supplyObjectStateParameters(ArrayObject &$parameters, ContentInfo $contentInfo): void
private function supplyObjectStateParameters(ArrayObject $parameters, ContentInfo $contentInfo): void
{
$objectStatesDataset = $this->datasetFactory->objectStates();
$objectStatesDataset->load($contentInfo);
Expand Down Expand Up @@ -176,11 +164,6 @@ private function canUserAssignObjectState(): bool
return $this->permissionResolver->hasAccess('state', 'assign') !== false;
}

/**
* @param \ArrayObject $parameters
* @param \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Location $location
*/
private function supplySectionParameters(ArrayObject $parameters, ContentInfo $contentInfo, Location $location): void
{
$canSeeSection = $this->permissionResolver->canUser('section', 'view', $contentInfo);
Expand Down Expand Up @@ -208,10 +191,6 @@ private function supplySectionParameters(ArrayObject $parameters, ContentInfo $c
}
}

/**
* @param \ArrayObject $parameters
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Location $location
*/
private function supplyFormLocationUpdate(ArrayObject $parameters, Location $location): void
{
$parameters['form_location_update'] = $this->formFactory->create(
Expand All @@ -220,10 +199,6 @@ private function supplyFormLocationUpdate(ArrayObject $parameters, Location $loc
)->createView();
}

/**
* @param \ArrayObject $parameters
* @param \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo
*/
private function supplyTranslations(ArrayObject $parameters, VersionInfo $versionInfo): void
{
$translationsDataset = $this->datasetFactory->translations();
Expand Down

0 comments on commit 913960c

Please sign in to comment.