Skip to content

Commit

Permalink
Use snake case for item attribute names (ease migration from Yii 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev committed Jan 11, 2024
1 parent cba39d8 commit 03073d9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions src/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ final public function getAttributes(): array
return [

Check failure on line 150 in src/Item.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

InvalidReturnStatement

src/Item.php:150:16: InvalidReturnStatement: The inferred type 'array{created_at: int|null, description: string, name: string, rule_name: null|string, type: string, updated_at: int|null}' does not match the declared return type 'array{createdAt: int|null, description: string, name: string, ruleName: null|string, type: string, updatedAt: int|null}' for Yiisoft\Rbac\Item::getAttributes due to additional array shape fields (rule_name, updated_at, created_at) (see https://psalm.dev/128)

Check failure on line 150 in src/Item.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

InvalidReturnStatement

src/Item.php:150:16: InvalidReturnStatement: The inferred type 'array{created_at: int|null, description: string, name: string, rule_name: null|string, type: string, updated_at: int|null}' does not match the declared return type 'array{createdAt: int|null, description: string, name: string, ruleName: null|string, type: string, updatedAt: int|null}' for Yiisoft\Rbac\Item::getAttributes due to additional array shape fields (rule_name, updated_at, created_at) (see https://psalm.dev/128)

Check failure on line 150 in src/Item.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

InvalidReturnStatement

src/Item.php:150:16: InvalidReturnStatement: The inferred type 'array{created_at: int|null, description: string, name: string, rule_name: null|string, type: string, updated_at: int|null}' does not match the declared return type 'array{createdAt: int|null, description: string, name: string, ruleName: null|string, type: string, updatedAt: int|null}' for Yiisoft\Rbac\Item::getAttributes due to additional array shape fields (rule_name, updated_at, created_at) (see https://psalm.dev/128)
'name' => $this->getName(),
'description' => $this->getDescription(),
'ruleName' => $this->getRuleName(),
'rule_name' => $this->getRuleName(),
'type' => $this->getType(),
'updatedAt' => $this->getUpdatedAt(),
'createdAt' => $this->getCreatedAt(),
'updated_at' => $this->getUpdatedAt(),
'created_at' => $this->getCreatedAt(),
];
}
}
28 changes: 14 additions & 14 deletions tests/Common/AssignmentsStorageTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,25 +270,25 @@ protected function getFixtures(): array
];
$items = array_map(
static function (array $item) use ($time): array {
$item['createdAt'] = $time;
$item['updatedAt'] = $time;
$item['created_at'] = $time;
$item['updated_at'] = $time;

return $item;
},
$items,
);
$assignments = [
['itemName' => 'Researcher', 'userId' => 'john'],
['itemName' => 'Accountant', 'userId' => 'john'],
['itemName' => 'Quality control specialist', 'userId' => 'john'],
['itemName' => 'Operator', 'userId' => 'jack'],
['itemName' => 'Manager', 'userId' => 'jack'],
['itemName' => 'Support specialist', 'userId' => 'jack'],
['itemName' => 'Operator', 'userId' => 'jeff'],
['item_name' => 'Researcher', 'user_id' => 'john'],
['item_name' => 'Accountant', 'user_id' => 'john'],
['item_name' => 'Quality control specialist', 'user_id' => 'john'],
['item_name' => 'Operator', 'user_id' => 'jack'],
['item_name' => 'Manager', 'user_id' => 'jack'],
['item_name' => 'Support specialist', 'user_id' => 'jack'],
['item_name' => 'Operator', 'user_id' => 'jeff'],
];
$assignments = array_map(
static function (array $item) use ($time): array {
$item['createdAt'] = $time;
$item['created_at'] = $time;

return $item;
},
Expand All @@ -304,8 +304,8 @@ protected function populateItemsStorage(): void
$name = $itemData['name'];
$item = $itemData['type'] === Item::TYPE_PERMISSION ? new Permission($name) : new Role($name);
$item = $item
->withCreatedAt($itemData['createdAt'])
->withUpdatedAt($itemData['updatedAt']);
->withCreatedAt($itemData['created_at'])
->withUpdatedAt($itemData['updated_at']);
$this->getItemsStorage()->add($item);
}
}
Expand All @@ -315,8 +315,8 @@ protected function populateAssignmentsStorage(): void
foreach ($this->getFixtures()['assignments'] as $assignmentData) {
$this->getAssignmentsStorage()->add(
new Assignment(
userId: $assignmentData['userId'],
itemName: $assignmentData['itemName'],
userId: $assignmentData['user_id'],
itemName: $assignmentData['item_name'],
createdAt: time(),
),
);
Expand Down
8 changes: 4 additions & 4 deletions tests/Common/ItemsStorageTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,8 @@ protected function getFixtures(): array
$items[] = [
'name' => $name,
'type' => $type,
'createdAt' => $time,
'updatedAt' => $time,
'created_at' => $time,
'updated_at' => $time,
];
$type === Item::TYPE_ROLE ? $this->initialRolesCount++ : $this->initialPermissionsCount++;
}
Expand Down Expand Up @@ -652,8 +652,8 @@ protected function populateItemsStorage(): void
$name = $itemData['name'];
$item = $itemData['type'] === Item::TYPE_PERMISSION ? new Permission($name) : new Role($name);
$item = $item
->withCreatedAt($itemData['createdAt'])
->withUpdatedAt($itemData['updatedAt']);
->withCreatedAt($itemData['created_at'])
->withUpdatedAt($itemData['updated_at']);
$storage->add($item);
}

Expand Down
12 changes: 6 additions & 6 deletions tests/Common/ManagerLogicTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,10 @@ public function testAddRole(): void
[
'name' => 'new role',
'description' => 'new role description',
'ruleName' => EasyRule::class,
'rule_name' => EasyRule::class,
'type' => 'role',
'updatedAt' => 1_642_026_148,
'createdAt' => 1_642_026_147,
'updated_at' => 1_642_026_148,
'created_at' => 1_642_026_147,
],
$storedRole->getAttributes()
);
Expand Down Expand Up @@ -696,10 +696,10 @@ public function testAddPermission(): void
[
'name' => 'edit post',
'description' => 'edit a post',
'ruleName' => null,
'rule_name' => null,
'type' => 'permission',
'updatedAt' => 1_642_026_148,
'createdAt' => 1_642_026_147,
'updated_at' => 1_642_026_148,
'created_at' => 1_642_026_147,
],
$storedPermission->getAttributes()
);
Expand Down
6 changes: 3 additions & 3 deletions tests/PermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function testDefaultAttributes(): void
$this->assertSame([
'name' => 'test',
'description' => '',
'ruleName' => null,
'rule_name' => null,
'type' => Item::TYPE_PERMISSION,
'updatedAt' => null,
'createdAt' => null,
'updated_at' => null,
'created_at' => null,
], $permission->getAttributes());
}
}
6 changes: 3 additions & 3 deletions tests/RoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public function testDefaultAttributes(): void
$this->assertSame([
'name' => 'test',
'description' => '',
'ruleName' => null,
'rule_name' => null,
'type' => Item::TYPE_ROLE,
'updatedAt' => null,
'createdAt' => null,
'updated_at' => null,
'created_at' => null,
], $permission->getAttributes());
}
}

0 comments on commit 03073d9

Please sign in to comment.