Skip to content

Commit

Permalink
Apply Rector
Browse files Browse the repository at this point in the history
  • Loading branch information
MGatner committed Feb 3, 2022
1 parent 366dc1d commit c7ca018
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 62 deletions.
2 changes: 2 additions & 0 deletions UPGRADING.md
Expand Up @@ -5,6 +5,8 @@

> Note: This is a complete refactor! Please be sure to read the docs carefully before upgrading.
* Minimum PHP version has been bumped to `7.4` to match the upcoming framework changes
* All properties that can be typed have been
* Now requires a verified authentication system via `codeigniter4/authentication-implementation`
* Switches to `Tatter\Users` for interface handling; [read the docs](https://github.com/tattersoftware/codeigniter4-users) to be sure your Models and Entities are configured
* No longer handles explicit permissions - these should now handled by your Auth library; read more below
Expand Down
48 changes: 24 additions & 24 deletions src/Config/Permits.php
Expand Up @@ -37,6 +37,30 @@ class Permits extends BaseConfig
*/
public const ANYBODY = 1000;

/**
* The default set of attributes to use for unspecified
* properties and values.
* Verbs correspond to each access type.
* Remaining keys are used to identify ownership:
* - userKey: Field for the user ID in the item or its pivot table
* - pivotKey: Field for the item's ID in the pivot tables
* - pivotTable: Table that joins the items to their owners
* Setting ownership fields to `null` will disable owner lookup.
*
* @var array<string,mixed>
*/
public array $default = [
'admin' => self::NOBODY,
'create' => self::USERS,
'list' => self::ANYBODY,
'read' => self::ANYBODY,
'update' => self::OWNERS,
'delete' => self::OWNERS,
'userKey' => null,
'pivotKey' => null,
'pivotTable' => null,
];

/**
* Verifies a permission against the supplied values.
*
Expand All @@ -60,28 +84,4 @@ final public static function check(int $access, ?int $userId, ?bool $owner = nul

throw new DomainException('Undefined access value: ' . $access);
}

/**
* The default set of attributes to use for unspecified
* properties and values.
* Verbs correspond to each access type.
* Remaining keys are used to identify ownership:
* - userKey: Field for the user ID in the item or its pivot table
* - pivotKey: Field for the item's ID in the pivot tables
* - pivotTable: Table that joins the items to their owners
* Setting ownership fields to `null` will disable owner lookup.
*
* @var array<string,mixed>
*/
public $default = [
'admin' => self::NOBODY,
'create' => self::USERS,
'list' => self::ANYBODY,
'read' => self::ANYBODY,
'update' => self::OWNERS,
'delete' => self::OWNERS,
'userKey' => null,
'pivotKey' => null,
'pivotTable' => null,
];
}
4 changes: 2 additions & 2 deletions src/Traits/PermitsTrait.php
Expand Up @@ -23,7 +23,7 @@ trait PermitsTrait
*
* @var array<string,mixed>|null
*/
private $permits;
private ?array $permits = null;

/**
* Checks whether the current/supplied user may perform any of the other actions.
Expand Down Expand Up @@ -94,7 +94,7 @@ public function mayDelete($item, ?int $userId = null): bool
final protected function permissible(string $verb, ?int $userId, $item = null): bool
{
// Determine the user (if any)
$userId = $userId ?? user_id();
$userId ??= user_id();

if ($userId !== null) {
$user = service('users')->findById($userId);
Expand Down
2 changes: 1 addition & 1 deletion tests/ConfigTest.php
Expand Up @@ -13,7 +13,7 @@ public function testInvalidAccess()
$this->expectException('DomainException');
$this->expectExceptionMessage('Undefined access value: 42');

$result = Permits::check(42, null);
Permits::check(42, null);
}

/**
Expand Down
5 changes: 1 addition & 4 deletions tests/InferredTest.php
Expand Up @@ -11,10 +11,7 @@
*/
final class InferredTest extends TestCase
{
/**
* @var User|null
*/
protected $user;
protected ?User $user = null;

protected function setUp(): void
{
Expand Down
34 changes: 7 additions & 27 deletions tests/OwnershipTest.php
Expand Up @@ -14,33 +14,13 @@ final class OwnershipTest extends TestCase
{
use DatabaseTestTrait;

protected $refresh = false;
protected $namespace = 'Tests\Support';

/**
* @var User|null
*/
protected $user;

/**
* @var FactoryModel
*/
protected $model;

/**
* @var object
*/
protected $byKey;

/**
* @var object
*/
protected $byPivot;

/**
* @var object
*/
protected $unowned;
protected $refresh = false;
protected $namespace = 'Tests\Support';
protected ?User $user = null;
protected FactoryModel $model;
protected object $byKey;
protected object $byPivot;
protected object $unowned;

protected function setUp(): void
{
Expand Down
5 changes: 1 addition & 4 deletions tests/TraitTest.php
Expand Up @@ -13,10 +13,7 @@
*/
final class TraitTest extends TestCase
{
/**
* @var FactoryModel
*/
protected $model;
protected FactoryModel $model;

protected function setUp(): void
{
Expand Down

0 comments on commit c7ca018

Please sign in to comment.