Skip to content

Commit

Permalink
Minor fixes after minor fixes :) (trailing slashes, etc.)
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev committed Feb 12, 2024
1 parent e18d6b7 commit d989b95
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ commands or migrations. Hierarchy consists of permissions, roles, and rules:
- Permissions are granules of access such as "create a post" or "read a post."
- A role is what is assigned to the user. The Role is granted one or more permissions. Typical roles are "manager" or
"admin."
- Rule is a PHP class that has given some data answers a single question "given the data has the user the permission asked
for."
- Rule is a PHP class that has given some data answers a single question "given the data has the user the permission
asked for."

To create a permission, use the following code:

Expand Down
2 changes: 1 addition & 1 deletion src/Assignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class Assignment
public function __construct(
private readonly string $userId,
private string $itemName,
private readonly int $createdAt
private readonly int $createdAt,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/CompositeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class CompositeRule implements RuleInterface
*/
public function __construct(
private readonly string $operator,
private readonly array $ruleNames
private readonly array $ruleNames,
) {
if (!in_array($operator, [self::AND, self::OR], true)) {
throw new InvalidArgumentException(
Expand Down
2 changes: 1 addition & 1 deletion src/RuleContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class RuleContext
{
public function __construct(
private readonly RuleFactoryInterface $ruleFactory,
private readonly array $parameters
private readonly array $parameters,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/RuleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Yiisoft\Rbac;

/**
* The Rule represents a business constraint that may be associated with a role or a permission.
* The rule represents a business constraint that may be associated with a role or a permission.
*/
interface RuleInterface
{
Expand Down
11 changes: 8 additions & 3 deletions src/SimpleItemsStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function getAll(): array

public function getByNames(array $names): array
{
return array_filter($this->getAll(), static fn (Item $item): bool => in_array($item->getName(), $names, true));
return array_filter(
$this->getAll(),
static fn (Item $item): bool => in_array($item->getName(), $names, strict: true),
);
}

public function get(string $name): Permission|Role|null
Expand Down Expand Up @@ -74,7 +77,9 @@ public function getRolesByNames(array $names): array
{
return array_filter(
$this->getAll(),
static fn (Permission|Role $item): bool => $item instanceof Role && in_array($item->getName(), $names, true),
static function (Permission|Role $item) use ($names): bool {
return $item instanceof Role && in_array($item->getName(), $names, strict: true);
},
);
}

Expand All @@ -93,7 +98,7 @@ public function getPermissionsByNames(array $names): array
return array_filter(
$this->getAll(),
static function (Permission|Role $item) use ($names): bool {
return $item instanceof Permission && in_array($item->getName(), $names, true);
return $item instanceof Permission && in_array($item->getName(), $names, strict: true);
},
);
}
Expand Down

0 comments on commit d989b95

Please sign in to comment.