Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/.github/workflows/benchmark.yml @xHeaven
/.github/workflows/benchmark-comment.yml @xHeaven
/src/ @brendt
/utils/rector/ @xHeaven
/docs/ @brendt @innocenzi
/packages/auth/ @innocenzi
/packages/cache/ @innocenzi
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/coding-conventions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
- name: Install dependencies
run: |
composer update --prefer-dist --no-interaction --ignore-platform-reqs
composer mago:install-binary

- name: Run Mago
run: |
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"aws/aws-sdk-php": "^3.338.0",
"azure-oss/storage-blob-flysystem": "^1.2",
"brianium/paratest": "^7.14",
"carthage-software/mago": "1.0.0-beta.28",
"carthage-software/mago": "^1.0",
"guzzlehttp/psr7": "^2.6.1",
"league/flysystem-aws-s3-v3": "^3.25.1",
"league/flysystem-ftp": "^3.25.1",
Expand Down Expand Up @@ -237,7 +237,8 @@
"Tempest\\Validation\\Tests\\": "packages/validation/tests",
"Tempest\\View\\Tests\\": "packages/view/tests",
"Tempest\\Vite\\Tests\\": "packages/vite/tests",
"Tests\\Tempest\\": "tests"
"Tests\\Tempest\\": "tests",
"Tempest\\Rector\\": "utils/rector/src"
}
},
"bin": [
Expand Down
12 changes: 9 additions & 3 deletions mago.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ excludes = [
"**/*.expected.php",
"**/.tempest",
"./vendor/rector", #see https://github.com/carthage-software/mago/issues/1237 rector clashes and throws errors in tests
"packages/intl/bin/plural-rules.php",
]

[formatter]
Expand Down Expand Up @@ -42,12 +43,12 @@ trait-name = { psr = false }
class-name = { psr = false }
literal-named-argument = { enabled = false } # todo
no-error-control-operator = { enabled = false }
no-boolean-literal-comparison = { enabled = false }
#no-boolean-literal-comparison = { enabled = false }
too-many-methods = { enabled = false }
kan-defect = { enabled = false }
cyclomatic-complexity = { enabled = false }
return-type = { ignore-arrow-function = true, ignore-closure = true }
parameter-type = { ignore-arrow-function = true, ignore-closure = true }
#return-type = { ignore-arrow-function = true, ignore-closure = true }
#parameter-type = { ignore-arrow-function = true, ignore-closure = true }
too-many-enum-cases = { enabled = false }
no-redundant-file = { enabled = false }
assertion-style = { style = "this" }
Expand All @@ -65,3 +66,8 @@ prefer-first-class-callable = { enabled = false } # enable when arguments are fi
strict-behavior = { allow-loose-behavior = true }
no-redundant-use = { enabled = true }
no-empty-comment = { enabled = false }
single-class-per-file = { enabled = false }
no-isset = { enabled = false }
instanceof-stringable = { enabled = false }
prefer-static-closure = { enabled = false }
sensitive-parameter = { enabled = false }
11 changes: 6 additions & 5 deletions packages/auth/src/AccessControl/PolicyBasedAccessControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Tempest\Reflection\ParameterReflector;
use Tempest\Support\Arr\ImmutableArray;
use Tempest\Support\Str;
use Throwable;
use UnitEnum;

/**
Expand Down Expand Up @@ -45,7 +46,7 @@ public function isGranted(UnitEnum|string $action, object|string $resource, ?obj
throw new NoPolicyWereFoundForResource($resource);
}

$resource = ! is_object($resource) ? null : $resource;
$resource = is_object($resource) ? $resource : null;

foreach ($policies as $policy) {
$decision = $this->evaluatePolicy($policy, $resource, $subject);
Expand All @@ -60,13 +61,13 @@ public function isGranted(UnitEnum|string $action, object|string $resource, ?obj

private function resolveSubject(?object $subject): ?object
{
if ($subject) {
if ($subject !== null) {
return $subject;
}

try {
return $this->container->get(Authenticator::class)->current();
} catch (\Throwable) {
} catch (Throwable) {
return null;
}
}
Expand Down Expand Up @@ -113,9 +114,9 @@ private function evaluatePolicy(MethodReflector $policy, ?object $resource, ?obj
return AccessDecision::from($decision);
}

private function ensureParameterAcceptsInput(?ParameterReflector $reflector, mixed $input, \Closure $throw): void
private function ensureParameterAcceptsInput(?ParameterReflector $reflector, mixed $input, Closure $throw): void
{
if ($reflector === null || $input === null) {
if (! $reflector instanceof ParameterReflector || $input === null) {
return;
}

Expand Down
1 change: 0 additions & 1 deletion packages/auth/src/AccessControl/PolicyDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tempest\Auth\AccessControl;

use Tempest\Auth\AccessControl\Policy;
use Tempest\Auth\AuthConfig;
use Tempest\Discovery\Discovery;
use Tempest\Discovery\DiscoveryLocation;
Expand Down
4 changes: 1 addition & 3 deletions packages/auth/src/Authentication/Authenticatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
/**
* Represents an entity that may be authenticated.
*/
interface Authenticatable
{
}
interface Authenticatable {}
2 changes: 2 additions & 0 deletions packages/auth/src/Authentication/SessionAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
final readonly class SessionAuthenticator implements Authenticator
{
public const string AUTHENTICATABLE_KEY = '#authenticatable:id';

public const string AUTHENTICATABLE_CLASS = '#authenticatable:class';

public function __construct(
Expand All @@ -35,6 +36,7 @@ public function deauthenticate(): void
{
$this->session->remove(self::AUTHENTICATABLE_KEY);
$this->session->remove(self::AUTHENTICATABLE_CLASS);

$this->sessionManager->save($this->session);
}

Expand Down
4 changes: 1 addition & 3 deletions packages/auth/src/Exceptions/AuthenticationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace Tempest\Auth\Exceptions;

interface AuthenticationException
{
}
interface AuthenticationException {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ final class NoPolicyWereFoundForResource extends Exception implements Authentica
public function __construct(
public readonly string|object $resource,
) {
parent::__construct(sprintf('No policies were found for resource `%s`.', is_object($resource) ? get_class($resource) : $resource));
parent::__construct(sprintf('No policies were found for resource `%s`.', is_object($resource) ? $resource::class : $resource));
}
}
4 changes: 1 addition & 3 deletions packages/auth/src/Exceptions/OAuthStateWasInvalid.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use Exception;

final class OAuthStateWasInvalid extends Exception implements AuthenticationException
{
}
final class OAuthStateWasInvalid extends Exception implements AuthenticationException {}
5 changes: 3 additions & 2 deletions packages/auth/src/Installer/AuthenticationInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Tempest\Console\Console;
use Tempest\Console\ConsoleCommand;
use Tempest\Console\Input\ConsoleArgumentBag;
use Tempest\Console\Input\ConsoleInputArgument;
use Tempest\Container\Container;
use Tempest\Core\Installer;
use Tempest\Core\PublishesFiles;
Expand Down Expand Up @@ -47,7 +48,7 @@ private function shouldMigrate(): bool
{
$argument = $this->consoleArgumentBag->get('migrate');

if ($argument === null || ! is_bool($argument->value)) {
if (! $argument instanceof ConsoleInputArgument || ! is_bool($argument->value)) {
return $this->console->confirm('Do you want to execute migrations?', default: false);
}

Expand All @@ -58,7 +59,7 @@ private function shouldInstallOAuth(): bool
{
$argument = $this->consoleArgumentBag->get('oauth');

if ($argument === null || ! is_bool($argument->value)) {
if (! $argument instanceof ConsoleInputArgument || ! is_bool($argument->value)) {
return $this->console->confirm('Do you want to install OAuth?', default: false);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/Installer/OAuthInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function install(): void
{
$providers = $this->getProviders();

if (count($providers) === 0) {
if ($providers === []) {
return;
}

Expand Down
16 changes: 4 additions & 12 deletions packages/auth/src/OAuth/OAuthConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,24 @@ interface OAuthConfig extends HasTag
/**
* The OAuth provider class name.
*/
public string $provider {
get;
}
public string $provider { get; }

/**
* The authorization scopes for this OAuth provider.
*
* @return string[]
*/
public array $scopes {
get;
}
public array $scopes { get; }

/**
* The client ID for the OAuth provider.
*/
public string $clientId {
get;
}
public string $clientId { get; }

/**
* The controller action to redirect to after the user authorizes the application.
*/
public string|array $redirectTo {
get;
}
public string|array $redirectTo { get; }

/**
* Creates the OAuth provider instance.
Expand Down
3 changes: 2 additions & 1 deletion packages/auth/tests/AuthenticationAndOAuthSafetyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionMethod;
use stdClass;
use Tempest\Auth\Authentication\DatabaseAuthenticatableResolver;
use Tempest\Auth\Exceptions\ModelWasNotAuthenticatable;
use Tempest\Auth\OAuth\GenericOAuthClient;
Expand All @@ -23,7 +24,7 @@ public function database_authenticatable_resolver_rejects_non_authenticatable_cl

$this->expectException(ModelWasNotAuthenticatable::class);

$resolve->invoke($resolver, 1, \stdClass::class);
$resolve->invoke($resolver, 1, stdClass::class);
}

#[Test]
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/tests/OAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function oauth_user_creation(): void
avatar: 'https://example.com/avatar.jpg',
provider: 'github',
raw: [
'id' => 123456,
'id' => 123_456,
'login' => 'frieren',
'name' => 'Frieren the Mage',
'email' => 'frieren@elven-mage.magic',
Expand Down
5 changes: 1 addition & 4 deletions packages/cache/src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ interface Cache
/**
* Whether the cache is enabled.
*/
public bool $enabled {
get;
set;
}
public bool $enabled { get; set; }

/**
* Returns a lock for the specified key. The lock is not acquired until `acquire()` is called.
Expand Down
4 changes: 1 addition & 3 deletions packages/cache/src/CacheCouldNotBeCleared.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use Exception;

final class CacheCouldNotBeCleared extends Exception implements CacheException
{
}
final class CacheCouldNotBeCleared extends Exception implements CacheException {}
4 changes: 1 addition & 3 deletions packages/cache/src/CacheException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace Tempest\Cache;

interface CacheException
{
}
interface CacheException {}
2 changes: 1 addition & 1 deletion packages/cache/src/CacheInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private function shouldCacheBeEnabled(null|string|UnitEnum $tag): bool
{
$globalCacheEnabled = (bool) env('CACHE_ENABLED', default: true);

if (! $tag) {
if ($tag === null) {
return $globalCacheEnabled;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cache/src/Commands/CacheClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

use function Tempest\Support\arr;

if (class_exists(\Tempest\Console\ConsoleCommand::class)) {
if (class_exists(ConsoleCommand::class)) {
final readonly class CacheClearCommand
{
use HasConsole;
Expand Down
7 changes: 4 additions & 3 deletions packages/cache/src/GenericCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function put(Stringable|string $key, mixed $value, null|Duration|DateTime
$expiration = DateTime::now()->plus($expiration);
}

if ($expiration !== null) {
if ($expiration instanceof DateTimeInterface) {
$item = $item->expiresAt($expiration->toNativeDateTime());
}

Expand All @@ -74,6 +74,7 @@ public function putMany(iterable $values, null|Duration|DateTimeInterface $expir
foreach ($values as $key => $value) {
$items[(string) $key] = $this->put($key, $value, $expiration);
}

return $items;
}

Expand Down Expand Up @@ -149,7 +150,7 @@ public function resolve(Stringable|string $key, Closure $callback, null|Duration
return $callback();
}

if ($stale) {
if ($stale instanceof Duration) {
if ($expiration instanceof Duration) {
$expiration = DateTime::now()->plus($expiration);
}
Expand All @@ -168,7 +169,7 @@ public function resolve(Stringable|string $key, Closure $callback, null|Duration

private function resolveAllowingStale(Stringable|string $key, Closure $callback, DateTimeInterface $expiration, Duration $stale): mixed
{
if (! $this->deferredTasks) {
if (! $this->deferredTasks instanceof DeferredTasks) {
return $this->resolve($key, $callback, $expiration);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cache/src/GenericLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function acquire(): bool
return false;
}

$expiration = $this->duration !== null
$expiration = $this->duration instanceof Duration
? DateTime::now()->plus($this->duration)
: null;

Expand Down
12 changes: 3 additions & 9 deletions packages/cache/src/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,17 @@ interface Lock
/**
* The key used to identify the lock. This should be unique across all locks.
*/
public string $key {
get;
}
public string $key { get; }

/**
* The duration of the lock. If null, the lock will not expire.
*/
public ?Duration $duration {
get;
}
public ?Duration $duration { get; }

/**
* The owner of the lock. This is used to verify that the lock is being released by the correct owner.
*/
public string $owner {
get;
}
public string $owner { get; }

/**
* Attempts to acquire a lock.
Expand Down
Loading
Loading