Skip to content
Closed
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 .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ phpunit.xml export-ignore
phpunit.xml.dist export-ignore
README.md export-ignore
rector.php export-ignore
structarmed.php export-ignore
cliff.toml export-ignore
.commitlintrc.json export-ignore

Expand Down
21 changes: 20 additions & 1 deletion .github/workflows/coding-conventions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
phpstan-result-cache-

- name: Run PHPStan
run: vendor/bin/phpstan --error-format=github -vv
run: vendor/bin/phpstan --error-format=github -vv

- name: Save PHPStan result cache
uses: actions/cache/save@v4
Expand All @@ -92,3 +92,22 @@ jobs:
#
# - name: Run Rector
# run: vendor/bin/rector process --no-ansi --dry-run --no-progress-bar


structarmed:
name: "Run static analysis: StructArmed"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.5
coverage: none

- name: Install composer dependencies
uses: ramsey/composer-install@v3

- name: Run StructArmed
run: vendor/bin/structarmed analyze
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
"thenetworg/oauth2-azure": "^2.2",
"twig/twig": "^3.16",
"vertisan/oauth2-twitch-helix": "^2.0",
"wohali/oauth2-discord-new": "^1.2"
"wohali/oauth2-discord-new": "^1.2",
"boundwize/structarmed": "^0.17.9"
},
"replace": {
"tempest/auth": "self.version",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function findPoliciesForResourceAction(object|string $resource, UnitEnum
$actionBeingEvaluated = Str\parse($action);

return new ImmutableArray($this->authConfig->policies[$resource] ?? [])
->filter(fn ($_, string $action) => $action === $actionBeingEvaluated)
->filter(static fn ($_, string $action) => $action === $actionBeingEvaluated)
->flatten();
}

Expand All @@ -97,13 +97,13 @@ private function evaluatePolicy(MethodReflector $policy, ?object $resource, ?obj
$this->ensureParameterAcceptsInput(
reflector: $policy->getParameter(key: 0),
input: $resource,
throw: fn (string $expected) => throw PolicyMethodWasInvalid::resourceParameterIsInvalid($policyName, $expected),
throw: static fn (string $expected) => throw PolicyMethodWasInvalid::resourceParameterIsInvalid($policyName, $expected),
);

$this->ensureParameterAcceptsInput(
reflector: $policy->getParameter(key: 1),
input: $subject,
throw: fn (string $expected) => throw PolicyMethodWasInvalid::subjectParameterIsInvalid($policyName, $expected),
throw: static fn (string $expected) => throw PolicyMethodWasInvalid::subjectParameterIsInvalid($policyName, $expected),
);

$decision = $policy->invokeArgs(
Expand Down
6 changes: 3 additions & 3 deletions packages/auth/src/OAuth/Testing/TestingOAuthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public function assertAuthorizationUrlGenerated(?array $scopes = null, ?array $o
public function assertUserFetched(string $code): void
{
Assert::assertNotEmpty(
actual: array_filter($this->users, fn (array $user) => $user['code'] === $code),
actual: array_filter($this->users, static fn (array $user) => $user['code'] === $code),
message: sprintf('User with code "%s" was not handled.', $code),
);
}
Expand All @@ -259,7 +259,7 @@ public function assertAccessTokenRetrieved(?string $code = null): void

if ($code !== null) {
Assert::assertNotEmpty(
actual: array_filter($this->accessTokens, fn (array $token) => $token['code'] === $code),
actual: array_filter($this->accessTokens, static fn (array $token) => $token['code'] === $code),
message: sprintf('No access token was retrieved for code "%s".', $code),
);
}
Expand All @@ -275,7 +275,7 @@ public function assertAccessTokenRefreshed(?string $refreshToken = null): void
if ($refreshToken !== null) {
// @mago-expect lint:no-insecure-comparison
Assert::assertNotEmpty(
actual: array_filter($this->refreshedTokens, fn (array $token) => $token['refresh_token'] === $refreshToken),
actual: array_filter($this->refreshedTokens, static fn (array $token) => $token['refresh_token'] === $refreshToken),
message: sprintf('No access token was refreshed for refresh token "%s".', $refreshToken),
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cache/src/Commands/CacheClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ private function clearUserCaches(?string $tag = null, bool $all = false): void
/** @var GenericContainer $container */
$container = $this->container;
$cacheTags = arr($container->getSingletons(CacheConfig::class))
->map(fn ($_, string $key) => $key === CacheConfig::class ? self::DEFAULT_CACHE : Str\after_last($key, '#'))
->filter(fn (string $value) => $tag === null || $value === $tag)
->map(static fn ($_, string $key) => $key === CacheConfig::class ? self::DEFAULT_CACHE : Str\after_last($key, '#'))
->filter(static fn (string $value) => $tag === null || $value === $tag)
->values();

if ($all === false && count($cacheTags) > 1) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/src/GenericCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function getMany(iterable $key): array
if (! $this->enabled) {
return Arr\map_with_keys(
array: $key,
map: fn (string|Stringable $key) => yield (string) $key => null,
map: static fn (string|Stringable $key) => yield (string) $key => null,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function markAsFailed(string $uuid): void
public function getPendingCommands(): array
{
return arr(glob(__DIR__ . '/../stored-commands/*.pending.txt'))
->mapWithKeys(function (string $path) {
->mapWithKeys(static function (string $path) {
if (! Filesystem\is_file($path)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/command-bus/src/MonitorAsyncCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __invoke(): void
}

$availableCommands = arr($this->repository->getPendingCommands())
->filter(fn (object $_, string $uuid) => ! array_key_exists($uuid, $processes));
->filter(static fn (object $_, string $uuid) => ! array_key_exists($uuid, $processes));

if (count($processes) === 5) {
$this->sleep(0.5);
Expand Down
2 changes: 1 addition & 1 deletion packages/console/src/Actions/RenderConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private function renderArgument(ConsoleArgumentDefinition $argument): string
private function renderEnumArgument(ConsoleArgumentDefinition $argument): string
{
$parts = array_map(
callback: fn (BackedEnum $case) => $case->value,
callback: static fn (BackedEnum $case) => $case->value,
array: $argument->type::cases(),
);

Expand Down
2 changes: 1 addition & 1 deletion packages/console/src/Actions/ResolveConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __invoke(array|string $command): ConsoleCommand
if (is_array($command)) {
$command = array_find(
array: $this->consoleConfig->commands,
callback: fn (ConsoleCommand $consoleCommand) => (
callback: static fn (ConsoleCommand $consoleCommand) => (
$consoleCommand->handler->getDeclaringClass()->getName() === $command[0]
&& $consoleCommand->handler->getName() === $command[1]
),
Expand Down
4 changes: 2 additions & 2 deletions packages/console/src/Commands/AboutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private function formatInsight(Stringable|Insight|array|string $value): string
{
return arr($value)
->filter()
->map(function (Stringable|Insight|string $value) {
->map(static function (Stringable|Insight|string $value) {
if ($value instanceof Insight) {
return $value->formattedValue;
}
Expand All @@ -91,7 +91,7 @@ private function rawInsight(Stringable|Insight|array|string $value): array
{
return arr($value)
->filter()
->map(function (Stringable|Insight|string $value) {
->map(static function (Stringable|Insight|string $value) {
if ($value instanceof Insight) {
return $value->value;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/console/src/Commands/MakeCommandCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __invoke(
'dummy-command-slug' => str($className)->kebab()->toString(),
],
manipulations: [
fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class),
static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class),
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __invoke(
'dummy-command-slug' => str($className)->kebab()->toString(),
],
manipulations: [
fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class),
static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class),
],
);

Expand Down
2 changes: 1 addition & 1 deletion packages/console/src/Commands/MakeMiddlewareCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __invoke(
targetPath: $targetPath,
shouldOverride: $shouldOverride,
manipulations: [
fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class),
static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class),
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private function renderControls(array $controls, int $maxWidth): string
$separator = ' <style="dim fg-gray">·</style> ';
$marginLeft = ' ';
$render = arr($controls)
->map(fn (string $label, string $shortcut) => "<style=\"dim\"><style=\"fg-gray\">{$shortcut}</style> {$label}</style>")
->map(static fn (string $label, string $shortcut) => "<style=\"dim\"><style=\"fg-gray\">{$shortcut}</style> {$label}</style>")
->implode($separator)
->prepend($marginLeft);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function render(Terminal $terminal): Generator
$count = iterator_count($this->data);
$step = 1;

$format = $this->format ?? function (int $step, int $count): string {
$format = $this->format ?? static function (int $step, int $count): string {
$width = 30;

$progress = (int) round(($step / $count) * $width);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private function executeHandler(): never
{
$log = function (string ...$lines): void {
arr($lines)
->flatMap(fn (string $line) => explode("\n", $line))
->flatMap(static fn (string $line) => explode("\n", $line))
->each(function (string $line): void {
fwrite($this->sockets[0], $line);
});
Expand All @@ -173,7 +173,7 @@ private function resolveHandler(Process|Closure|null $handler): ?Closure
}

if ($handler instanceof Process) {
return static fn (Closure $log): bool => $handler->run(function (string $type, string $buffer) use ($log): void {
return static fn (Closure $log): bool => $handler->run(static function (string $type, string $buffer) use ($log): void {
if ($type === Process::ERR) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ private function applyKey(InteractiveConsoleComponent $component, Console $conso

// If we have multiple handlers, we put the ones that return nothing
// first because the ones that return something will be overridden otherwise.
usort($handlersForKey, fn (MethodReflector $a, MethodReflector $b) => $b->getReturnType()->equals('void') <=> $a->getReturnType()->equals('void'));
usort($handlersForKey, static fn (MethodReflector $a, MethodReflector $b) => $b->getReturnType()->equals('void') <=> $a->getReturnType()->equals('void'));

// CTRL+C and CTRL+D means we exit the CLI, but only if there is no custom
// handler. When we exit, we want one last render to display pretty
// styles, so we will throw the exception in the next loop.
if ($handlersForKey === [] && ($key === Key::CTRL_C->value || $key === Key::CTRL_D->value)) {
$component->setState(ComponentState::CANCELLED);
$this->afterRenderCallbacks[] = fn () => throw new InterruptException();
$this->afterRenderCallbacks[] = static fn () => throw new InterruptException();
$this->shouldRerender = true;
Fiber::suspend();

Expand Down Expand Up @@ -324,7 +324,7 @@ private function validate(mixed $value, array $validation): ?string

public function isComponentSupported(Console $console, InteractiveConsoleComponent $component): bool
{
if (! arr($component->extensions ?? [])->every(fn (string $ext) => extension_loaded($ext))) {
if (! arr($component->extensions ?? [])->every(static fn (string $ext) => extension_loaded($ext))) {
return false;
}

Expand Down
10 changes: 5 additions & 5 deletions packages/console/src/Components/OptionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function setCollection(iterable $options): void

$this->preserveKeys = $options->isAssociative();
$this->options = $options
->map(fn (mixed $value, string|int $key) => new Option($key, $value))
->map(static fn (mixed $value, string|int $key) => new Option($key, $value))
->toArray();

$this->filter(null);
Expand All @@ -50,11 +50,11 @@ public function filter(?string $query): void
$previouslySelectedOptions = $this->selectedOptions;

$this->filteredOptions = arr($this->options)
->filter(fn (Option $option) => ! $query || str_contains(mb_strtolower((string) $option->value), mb_strtolower(trim($query))))
->filter(static fn (Option $option) => ! $query || str_contains(mb_strtolower((string) $option->value), mb_strtolower(trim($query))))
->values()
->toArray();

$this->selectedOptions = array_filter($this->filteredOptions, fn (Option $option) => in_array($option, $previouslySelectedOptions, strict: true));
$this->selectedOptions = array_filter($this->filteredOptions, static fn (Option $option) => in_array($option, $previouslySelectedOptions, strict: true));
$this->activeOption = array_search($previouslyActiveOption ?? $this->filteredOptions[0] ?? '', $this->filteredOptions, strict: true) ?: 0;
}

Expand Down Expand Up @@ -90,7 +90,7 @@ public function toggleCurrent(): void
if (! $this->isSelected($active)) {
$this->selectedOptions[] = $active;
} else {
$this->selectedOptions = array_filter($this->selectedOptions, fn (Option $option) => ! $active->equals($option));
$this->selectedOptions = array_filter($this->selectedOptions, static fn (Option $option) => ! $active->equals($option));
}
}

Expand Down Expand Up @@ -186,7 +186,7 @@ public function setActive(Stringable|UnitEnum|string|null $value): void
};

$this->activeOption = array_search(
array_find($this->filteredOptions, fn (Option $option) => $option->key === $value || $option->value === $value),
array_find($this->filteredOptions, static fn (Option $option) => $option->key === $value || $option->value === $value),
$this->filteredOptions,
strict: true,
) ?: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function render(string|array $lines): string
{
$lines = arr($lines)
->filter()
->flatMap(fn (string $string) => str($string)->chunk(self::MAX_WIDTH)->toArray())
->flatMap(static fn (string $string) => str($string)->chunk(self::MAX_WIDTH)->toArray())
->toArray();

$text = str(PHP_EOL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public function render(Stringable|string $key, Stringable|string|null $value = n
{
$key = $this->cleanText($key)->append(' ');
$value = $this->cleanText($value)->when(
condition: fn ($s) => $s->stripTags()->length() !== 0,
callback: fn ($s) => $s->prepend(' '),
condition: static fn ($s) => $s->stripTags()->length() !== 0,
callback: static fn ($s) => $s->prepend(' '),
);

$maximumWidth = $useAvailableWidth
Expand Down Expand Up @@ -58,7 +58,7 @@ private function cleanText(Stringable|string|null $text): ImmutableString

return $text
->replaceRegex('/\[([^]]+)]/', '<em>[$1]</em>')
->when(fn ($s) => $s->endsWith(['.', '?', '!', ':']), fn ($s) => $s->replaceAt(-1, 1, ''))
->when(static fn ($s) => $s->endsWith(['.', '?', '!', ':']), static fn ($s) => $s->replaceAt(-1, 1, ''))
->erase(root_path())
->trim();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function render(string $contents, ?string $title = null): string
{
$title = str($title ?? $this->label)->toString();
$lines = ImmutableArray::explode($contents, "\n")
->map(fn ($s, $i) => str_repeat(' ', $i === 0 ? 1 : strlen($title) + 4) . $s)
->map(static fn ($s, $i) => str_repeat(' ', $i === 0 ? 1 : strlen($title) + 4) . $s)
->implode("\n");

return str()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function render(Terminal $terminal, ComponentState $state, float $started
$this->prepareRender($terminal, $state);
$this->label($this->label);

$runtime = fn (float $finishedAt) => $finishedAt !== 0.0
$runtime = static fn (float $finishedAt) => $finishedAt !== 0.0
? number_format(($finishedAt - $startedAt) / 1_000_000, decimals: 0)
: null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function render(

// if there is nothing to display after the component is done, show "no input"
// TODO(innocenzi): clean up
if ($this->state->isFinished() && $lines->filter(fn (ImmutableString $line) => $line->trim()->isNotEmpty())->isEmpty()) {
$displayLines = $displayLines->filter(fn (ImmutableString $line) => $line->trim()->isNotEmpty());
if ($this->state->isFinished() && $lines->filter(static fn (ImmutableString $line) => $line->trim()->isNotEmpty())->isEmpty()) {
$displayLines = $displayLines->filter(static fn (ImmutableString $line) => $line->trim()->isNotEmpty());

$this->line($this->style('italic dim', 'No input.'))->newLine();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function render(Console $console): array
$answers = $this->askQuestion($console);

$answerAsString = arr($answers)
->map(fn (Option $option) => $option->displayValue)
->map(static fn (Option $option) => $option->displayValue)
->join(', ', ' and ')
->trim()
->toString() ?: 'no option';
Expand All @@ -52,7 +52,7 @@ public function render(Console $console): array
return $this->default;
}

return array_map(fn (Option $option) => $option->value, $answers);
return array_map(static fn (Option $option) => $option->value, $answers);
}

private function askQuestion(Console $console): array
Expand All @@ -66,7 +66,7 @@ private function askQuestion(Console $console): array
fn (Option $option, int $index) => str($index)
->when(
condition: in_array($option->value, $this->default, strict: true),
callback: fn ($s) => $s->wrap('<style="fg-blue">', '</style>'),
callback: static fn ($s) => $s->wrap('<style="fg-blue">', '</style>'),
)
->wrap('[', ']')
->prepend('- ')
Expand Down Expand Up @@ -101,7 +101,7 @@ private function askQuestion(Console $console): array
});
})
->filter()
->unique(fn (Option $option) => $option->value)
->unique(static fn (Option $option) => $option->value)
->toArray();
}
}
Loading
Loading