Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ phpunit.phar

# PHP CS Fixer
/.php-cs-fixer.cache
/.php-cs-fixer.php
13 changes: 13 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,29 @@
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

$finder = (new Finder())->in([
__DIR__ . '/config',
__DIR__ . '/src',
__DIR__ . '/tests',
]);

return (new Config())
->setRiskyAllowed(true)
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@PER-CS3.0' => true,
'no_unused_imports' => true,
'ordered_class_elements' => true,
'class_attributes_separation' => ['elements' => ['method' => 'one']],
'declare_strict_types' => true,
'native_function_invocation' => true,
'native_constant_invocation' => true,
'fully_qualified_strict_types' => [
'import_symbols' => true
],
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
],
])
->setFinder($finder);
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 2.1.3 under development

- no changes in this release.
- Enh #285: Explicitly import functions in "use" section (@mspirkov)

## 2.1.2 December 19, 2025

Expand Down
1 change: 1 addition & 0 deletions src/CompositeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use InvalidArgumentException;

use function in_array;
use function sprintf;

/**
* Composite rule allows combining multiple rules.
Expand Down
2 changes: 2 additions & 0 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Yiisoft\Rbac\Exception\ItemAlreadyExistsException;

use function is_array;
use function array_key_exists;
use function is_string;

/**
* Helps to manage RBAC hierarchy and check for permissions.
Expand Down Expand Up @@ -69,7 +71,7 @@
} else {
$guestRole = $this->getGuestRole();
if ($guestRole === null) {
return false;

Check warning on line 74 in src/Manager.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ } else { $guestRole = $this->getGuestRole(); if ($guestRole === null) { - return false; + } }
}
}

Expand Down Expand Up @@ -173,7 +175,7 @@
}

if ($this->assignmentsStorage->exists($itemName, $userId)) {
return $this;

Check warning on line 178 in src/Manager.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ } if ($this->assignmentsStorage->exists($itemName, $userId)) { - return $this; + } $assignment = new Assignment($userId, $itemName, $createdAt ?? $this->getCurrentTimestamp());
}

$assignment = new Assignment($userId, $itemName, $createdAt ?? $this->getCurrentTimestamp());
Expand Down Expand Up @@ -241,7 +243,7 @@
$userId = (string) $userId;
$assignments = $this->assignmentsStorage->getByUserId($userId);
if (empty($assignments)) {
return [];

Check warning on line 246 in src/Manager.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ $userId = (string) $userId; $assignments = $this->assignmentsStorage->getByUserId($userId); if (empty($assignments)) { - return []; + } $assignmentNames = array_keys($assignments);
}

$assignmentNames = array_keys($assignments);
Expand Down
2 changes: 2 additions & 0 deletions src/RuleContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Yiisoft\Rbac;

use function array_key_exists;

final class RuleContext
{
public function __construct(
Expand Down
1 change: 1 addition & 0 deletions src/SimpleAssignmentsStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Yiisoft\Rbac;

use function array_key_exists;
use function in_array;

/**
* @psalm-type RawAssignment = array{
Expand Down Expand Up @@ -59,7 +60,7 @@
{
$assignments = $this->getByUserId($userId);
if (empty($assignments)) {
return false;

Check warning on line 63 in src/SimpleAssignmentsStorage.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ { $assignments = $this->getByUserId($userId); if (empty($assignments)) { - return false; + } foreach ($itemNames as $itemName) {
}

foreach ($itemNames as $itemName) {
Expand All @@ -75,7 +76,7 @@
{
$assignments = $this->getByUserId($userId);
if (empty($assignments)) {
return [];

Check warning on line 79 in src/SimpleAssignmentsStorage.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ { $assignments = $this->getByUserId($userId); if (empty($assignments)) { - return []; + } $userItemNames = [];
}

$userItemNames = [];
Expand Down
3 changes: 3 additions & 0 deletions src/SimpleItemsStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Yiisoft\Rbac;

use function array_key_exists;
use function in_array;

/**
* @psalm-type RawItem = array{
* type: Item::TYPE_*,
Expand Down Expand Up @@ -170,7 +173,7 @@

$children = $this->getDirectChildren($parentName);
if (empty($children)) {
return false;

Check warning on line 176 in src/SimpleItemsStorage.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ $children = $this->getDirectChildren($parentName); if (empty($children)) { - return false; + } foreach ($children as $groupChild) {
}

foreach ($children as $groupChild) {
Expand Down
2 changes: 2 additions & 0 deletions tests/Common/AssignmentsStorageTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Yiisoft\Rbac\Tests\Support\FakeAssignmentsStorage;
use Yiisoft\Rbac\Tests\Support\FakeItemsStorage;

use function count;

trait AssignmentsStorageTestTrait
{
private ?ItemsStorageInterface $itemsStorage = null;
Expand Down
2 changes: 2 additions & 0 deletions tests/Common/ItemsStorageTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Yiisoft\Rbac\Tests\Support\FakeItemsStorage;
use Yiisoft\Rbac\Tests\Support\TrueRule;

use function count;

trait ItemsStorageTestTrait
{
private int $initialRolesCount = 0;
Expand Down
2 changes: 2 additions & 0 deletions tests/Common/ManagerLogicTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use Yiisoft\Rbac\Tests\Support\TrueRule;
use Yiisoft\Rbac\Tests\Support\WannabeRule;

use function count;

trait ManagerLogicTestTrait
{
public static function dataUserHasPermissionGeneric(): array
Expand Down
2 changes: 2 additions & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Yiisoft\Rbac\Tests\Support\FakeAssignmentsStorage;
use Yiisoft\Rbac\Tests\Support\FakeItemsStorage;

use function dirname;

final class ConfigTest extends TestCase
{
public function testBase(): void
Expand Down