Skip to content

Commit

Permalink
Remaining occurences
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev committed Feb 13, 2024
1 parent 2a5d859 commit ddacc15
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/ItemsStorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* A storage for RBAC roles and permissions used in {@see Manager}.
*
* @psalm-type ItemsIndexedByName = array<string, Permission|Role>
* @psalm-type AccessTree = array<string, array{
* @psalm-type Hierarchy = array<string, array{
* item: Permission|Role,
* children: array<string, Permission|Role>
* }>
Expand Down Expand Up @@ -173,7 +173,7 @@ public function getParents(string $name): array;
*
* @return array A mapping between parent names and according items with all their children (references to other
* parents found).
* @psalm-return AccessTree
* @psalm-return Hierarchy
*/
public function getHierarchy(string $name): array;

Expand Down
14 changes: 7 additions & 7 deletions src/SimpleItemsStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* }
*
* @psalm-import-type ItemsIndexedByName from ItemsStorageInterface
* @psalm-import-type AccessTree from ItemsStorageInterface
* @psalm-import-type Hierarchy from ItemsStorageInterface
*/
abstract class SimpleItemsStorage implements ItemsStorageInterface
{
Expand Down Expand Up @@ -118,7 +118,7 @@ public function getHierarchy(string $name): array
}

$result = [$name => ['item' => $this->items[$name], 'children' => []]];
$this->fillAccessTreeRecursive($name, $result);
$this->fillHierarchyRecursive($name, $result);

return $result;
}
Expand Down Expand Up @@ -310,12 +310,12 @@ private function fillParentsRecursive(string $name, array &$result): void
}

/**
* @psalm-param AccessTree $result
* @psalm-param-out AccessTree $result
* @psalm-param Hierarchy $result
* @psalm-param-out Hierarchy $result
*
* @psalm-param ItemsIndexedByName $addedChildItems
*/
private function fillAccessTreeRecursive(string $name, array &$result, array $addedChildItems = []): void
private function fillHierarchyRecursive(string $name, array &$result, array $addedChildItems = []): void
{
foreach ($this->children as $parentName => $childItems) {
foreach ($childItems as $childItem) {
Expand All @@ -325,14 +325,14 @@ private function fillAccessTreeRecursive(string $name, array &$result, array $ad

$parent = $this->get($parentName);
if ($parent !== null) {
/** @psalm-var AccessTree $result Imported type in `psalm-param-out` is not resolved. */
/** @psalm-var Hierarchy $result Imported type in `psalm-param-out` is not resolved. */
$result[$parentName]['item'] = $this->items[$parentName];

$addedChildItems[$childItem->getName()] = $childItem;
$result[$parentName]['children'] = $addedChildItems;
}

$this->fillAccessTreeRecursive($parentName, $result, $addedChildItems);
$this->fillHierarchyRecursive($parentName, $result, $addedChildItems);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions tests/Common/ItemsStorageTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function setUp(): void
ClockMock::freeze(new DateTime('2023-05-10 08:24:39'));
}

if ($this->name() === 'testGetAccessTree') {
if ($this->name() === 'testGetHierarchy') {
ClockMock::freeze(new DateTime('2023-12-24 17:51:18'));
}

Expand All @@ -37,7 +37,7 @@ protected function setUp(): void

protected function tearDown(): void
{
if (in_array($this->name(), ['testAddWithCurrentTimestamps', 'testGetAccessTree'], strict: true)) {
if (in_array($this->name(), ['testAddWithCurrentTimestamps', 'testGetHierarchy'], strict: true)) {
ClockMock::reset();
}

Expand Down Expand Up @@ -408,7 +408,7 @@ public function testGetParents(string $childName, array $expectedParents): void
}
}

public static function dataGetAccessTree(): array
public static function dataGetHierarchy(): array
{
$createdAt = (new DateTime('2023-12-24 17:51:18'))->getTimestamp();
$postsViewPermission = (new Permission('posts.view'))->withCreatedAt($createdAt)->withUpdatedAt($createdAt);
Expand Down Expand Up @@ -489,11 +489,11 @@ public static function dataGetAccessTree(): array
}

/**
* @dataProvider dataGetAccessTree
* @dataProvider dataGetHierarchy
*/
public function testGetAccessTree(string $name, array $expectedAccessTree): void
public function testGetHierarchy(string $name, array $expectedHierarchy): void
{
$this->assertEquals($expectedAccessTree, $this->getItemsStorage()->getHierarchy($name));
$this->assertEquals($expectedHierarchy, $this->getItemsStorage()->getHierarchy($name));
}

public function testRemoveChildren(): void
Expand Down

0 comments on commit ddacc15

Please sign in to comment.