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
4 changes: 2 additions & 2 deletions .github/workflows/coding-conventions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:

- name: Run Mago
run: |
./vendor/bin/mago fmt --dry-run
./vendor/bin/mago lint --reporting-format=github
composer fmt -- --check
composer lint -- --reporting-format=github

- name: Setup Bun
uses: oven-sh/setup-bun@v2
Expand Down
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"require-dev": {
"aws/aws-sdk-php": "^3.338.0",
"azure-oss/storage-blob-flysystem": "^1.2",
"carthage-software/mago": "0.26.1",
"carthage-software/mago": "^1.0.0-beta.16",
"guzzlehttp/psr7": "^2.6.1",
"league/flysystem-aws-s3-v3": "^3.25.1",
"league/flysystem-ftp": "^3.25.1",
Expand Down Expand Up @@ -228,8 +228,9 @@
"scripts": {
"phpunit": "@php -d memory_limit=2G vendor/bin/phpunit --display-warnings --display-skipped --display-deprecations --display-errors --display-notices",
"coverage": "vendor/bin/phpunit --coverage-html build/reports/html --coverage-clover build/reports/clover.xml",
"fmt": "vendor/bin/mago fmt && vendor/bin/mago lint --fix --potentially-unsafe --fmt",
"lint": "vendor/bin/mago lint --minimum-level=note",
"fmt": "vendor/bin/mago fmt",
"lint:fix": "vendor/bin/mago lint --fix --format-after-fix",
"lint": "vendor/bin/mago lint --potentially-unsafe --minimum-fail-level=note",
"phpstan": "vendor/bin/phpstan analyse src tests --memory-limit=1G",
"rector": "vendor/bin/rector process --no-ansi",
"merge": "php -d\"error_reporting = E_ALL & ~E_DEPRECATED\" vendor/bin/monorepo-builder merge",
Expand All @@ -240,12 +241,13 @@
],
"qa": [
"composer fmt",
"composer lint:fix",
"composer lint",
"composer merge",
"composer rector",
"./bin/validate-packages",
"./tempest discovery:clear --no-interaction",
"composer rector",
"composer phpunit",
"composer lint",
"composer phpstan"
]
}
Expand Down
174 changes: 48 additions & 126 deletions mago.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
php_version = "8.4.0"
php-version = "8.4.0"

[source]
paths = ["src", "packages", "tests"]
Expand All @@ -15,130 +15,52 @@ excludes = [
"**/*.expected.php",
]

[format]
print_width = 180
tab_width = 4
use_tabs = false
space_after_logical_not_unary_prefix_operator = true
null_type_hint = "question"
space_before_arrow_function_parameter_list_parenthesis = true
always_break_named_arguments_list = false
preserve_breaking_member_access_chain = true
preserve_breaking_argument_list = true
preserve_breaking_array_like = true
preserve_breaking_parameter_list = true
preserve_breaking_attribute_list = true
preserve_breaking_conditional_expression = true
empty_line_after_opening_tag = false
[formatter]
print-width = 180
tab-width = 4
use-tabs = false
space-after-logical-not-unary-prefix-operator = true
null-type-hint = "question"
space-before-arrow-function-parameter-list-parenthesis = true
always-break-named-arguments-list = false
preserve-breaking-member-access-chain = true
preserve-breaking-argument-list = true
preserve-breaking-array-like = true
preserve-breaking-parameter-list = true
preserve-breaking-attribute-list = true
preserve-breaking-conditional-expression = true
empty-line-after-opening-tag = false

[linter]
default_plugins = true
plugins = ["symfony", "php-unit"]

# MAINTENABILITY
[[linter.rules]]
name = "maintainability/too-many-enum-cases"
level = "off"

[[linter.rules]]
name = "maintainability/excessive-parameter-list"
level = "off"

[[linter.rules]]
name = "maintainability/halstead"
level = "off"

[[linter.rules]]
name = "maintainability/too-many-methods"
level = "off"

[[linter.rules]]
name = "maintainability/kan-defect"
level = "off"

[[linter.rules]]
name = "maintainability/cyclomatic-complexity"
level = "off"

# STRICTNESS
[[linter.rules]]
name = "strictness/require-return-type"
ignore_arrow_function = true
ignore_closure = true

# https://github.com/carthage-software/mago/issues/206
[[linter.rules]]
name = "best-practices/literal-named-argument"
level = "off"

# https://github.com/carthage-software/mago/issues/146
[[linter.rules]]
name = "strictness/require-strict-types"
level = "off"

[[linter.rules]]
name = "strictness/require-parameter-type"
ignore_arrow_function = true
ignore_closure = true

[[linter.rules]]
name = "strictness/no-shorthand-ternary"
level = "off"

[[linter.rules]]
name = "strictness/no-assignment-in-condition"
level = "off"

# BEST PRACTICES
[[linter.rules]]
name = "best-practices/no-else-clause"
level = "off"

[[linter.rules]]
name = "best-practices/no-boolean-literal-comparison"
level = "off"

[[linter.rules]]
name = "best-practices/no-boolean-flag-parameter"
level = "off"

# SAFETY
[[linter.rules]]
name = "safety/no-error-control-operator"
level = "off"

# PHPUNIT
[[linter.rules]]
name = "php-unit/assertions-style"
style = "this"

[[linter.rules]]
name = "php-unit/strict-assertions"
level = "off"

# NAMING
[[linter.rules]]
name = "naming/interface"
psr = false

[[linter.rules]]
name = "naming/trait"
psr = false

[[linter.rules]]
name = "naming/class"
psr = false

# HELP
[[linter.rules]]
name = "redundancy/redundant-file"
level = "off"

# CONSIDER ENABLING
[[linter.rules]]
name = "analysis/override-attribute"
level = "off"

[[linter.rules]]
name = "comment/no-untagged-todo"
level = "off"
integrations = ["php-unit", "tempest"]

[linter.rules]
interface-name = { psr = false }
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 }
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 }
too-many-enum-cases = { enabled = false }
no-redundant-file = { enabled = false }
assertion-style = { style = "this" }
strict-assertions = { enabled = false }
no-else-clause = { enabled = false }
no-boolean-flag-parameter = { enabled = false }
no-shorthand-ternary = { enabled = false }
no-assign-in-condition = { enabled = false }
strict-types = { enabled = false } # https://github.com/carthage-software/mago/issues/146
tagged-todo = { enabled = false } # CONSIDER ENABLING
excessive-parameter-list = { enabled = false } # https://github.com/carthage-software/mago/issues/206
halstead = { enabled = false }
prefer-arrow-function = { enabled = false } # enable when references are fixed
prefer-first-class-callable = { enabled = false } # enable when arguments are fixed
strict-behavior = { allow-loose-behavior = true }

# [analyzer]
# override-attribute = { enabled = false } # CONSIDER ENABLING
2 changes: 1 addition & 1 deletion packages/cache/src/Commands/CacheClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __invoke(
#[ConsoleCommand(description: 'Whether to clear internal caches')]
bool $internal = false,
): void {
if (! ($this->container instanceof GenericContainer)) {
if (! $this->container instanceof GenericContainer) {
$this->console->error('Clearing caches is only available when using the default container.');
return;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cache/src/Commands/CacheStatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
#[ConsoleCommand(name: 'cache:status', description: 'Shows which caches are enabled')]
public function __invoke(bool $internal = true): void
{
if (! ($this->container instanceof GenericContainer)) {
if (! $this->container instanceof GenericContainer) {
$this->console->error('Clearing caches is only available when using the default container.');
return;
}
Expand Down Expand Up @@ -95,7 +95,7 @@ public function __invoke(bool $internal = true): void

private function getCacheName(Cache $cache): string
{
if (! ($cache instanceof GenericCache)) {
if (! $cache instanceof GenericCache) {
return $cache::class;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/cache/src/GenericCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function lock(Stringable|string $key, null|Duration|DateTimeInterface $ex

return new GenericLock(
key: (string) $key,
owner: $owner ? ((string) $owner) : Random\secure_string(length: 10),
owner: $owner ? (string) $owner : Random\secure_string(length: 10),
cache: $this,
expiration: $expiration,
);
Expand Down Expand Up @@ -90,7 +90,7 @@ public function increment(Stringable|string $key, int $by = 1): int
} elseif (! is_numeric($item->get())) {
throw new CacheKeyCouldNotBeIncremented((string) $key);
} else {
$item->set(((int) $item->get()) + $by);
$item->set((int) $item->get() + $by);
}

$this->adapter->save($item);
Expand All @@ -111,7 +111,7 @@ public function decrement(Stringable|string $key, int $by = 1): int
} elseif (! is_numeric($item->get())) {
throw new CacheKeyCouldNotBeIncremented((string) $key);
} else {
$item->set(((int) $item->get()) - $by);
$item->set((int) $item->get() - $by);
}

$this->adapter->save($item);
Expand Down
4 changes: 2 additions & 2 deletions packages/cache/src/GenericLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function locked(null|Stringable|string $by = null): bool
return $this->cache->has($this->key);
}

return $this->cache->get($this->key) === ((string) $by);
return $this->cache->get($this->key) === (string) $by;
}

public function acquire(): bool
Expand All @@ -44,7 +44,7 @@ public function acquire(): bool
public function execute(Closure $callback, null|DateTimeInterface|Duration $wait = null): mixed
{
$wait ??= Datetime::now();
$waitUntil = ($wait instanceof Duration)
$waitUntil = $wait instanceof Duration
? DateTime::now()->plus($wait)
: $wait;

Expand Down
2 changes: 1 addition & 1 deletion packages/cache/src/Testing/CacheTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function fake(null|string|UnitEnum $tag = null): TestingCache
*/
public function preventUsageWithoutFake(): void
{
if (! ($this->container instanceof GenericContainer)) {
if (! $this->container instanceof GenericContainer) {
throw new \RuntimeException('Container is not a GenericContainer, unable to prevent usage without fake.');
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cache/src/Testing/TestingCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function lock(Stringable|string $key, null|Duration|DateTimeInterface $ex
{
return new TestingLock(new GenericLock(
key: (string) $key,
owner: $owner ? ((string) $owner) : Random\secure_string(length: 10),
owner: $owner ? (string) $owner : Random\secure_string(length: 10),
cache: $this->cache,
expiration: $expiration,
));
Expand Down
6 changes: 3 additions & 3 deletions packages/cache/src/UserCacheInsightsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(

public function getInsights(): array
{
if (! ($this->container instanceof GenericContainer)) {
if (! $this->container instanceof GenericContainer) {
return [];
}

Expand All @@ -40,7 +40,7 @@ public function getInsights(): array
/** @var Insight[] */
private function getInsight(Cache $cache): array
{
$type = ($cache instanceof GenericCache)
$type = $cache instanceof GenericCache
? match (get_class($cache->adapter)) {
FilesystemAdapter::class => new Insight('Filesystem'),
PhpFilesAdapter::class => new Insight('PHP'),
Expand All @@ -59,7 +59,7 @@ private function getInsight(Cache $cache): array

private function getCacheName(Cache $cache): string
{
if (! ($cache instanceof GenericCache)) {
if (! $cache instanceof GenericCache) {
return $cache::class;
}

Expand Down
6 changes: 4 additions & 2 deletions packages/clock/src/MockClock.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ public function minus(int|Duration $duration): void
$this->now = $this->now->minus($duration);
}

/**
* @mago-expect lint:no-debug-symbols
*/
public function dd(): void
{
// @phpstan-ignore disallowed.function
dd($this->now); // @mago-expect best-practices/no-debug-symbols
dd($this->now);
}
}
3 changes: 2 additions & 1 deletion packages/console/src/Actions/ResolveConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function __invoke(array|string $command): ConsoleCommand
$command = array_find(
array: $this->consoleConfig->commands,
callback: fn (ConsoleCommand $consoleCommand) => (
$consoleCommand->handler->getDeclaringClass()->getName() === $command[0] && $consoleCommand->handler->getName() === $command[1]
$consoleCommand->handler->getDeclaringClass()->getName() === $command[0]
&& $consoleCommand->handler->getName() === $command[1]
),
);

Expand Down
2 changes: 1 addition & 1 deletion packages/console/src/Components/Concerns/OpensInEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait OpensInEditor
private function supportsOpeningInEditor(): bool
{
// @phpstan-ignore function.alreadyNarrowedType
return is_subclass_of(static::class, CanOpenInEditor::class) && ((bool) $this->getEditorCommand());
return is_subclass_of(static::class, CanOpenInEditor::class) && (bool) $this->getEditorCommand();
}

private function getEditorCommand(): ?string
Expand Down
2 changes: 1 addition & 1 deletion packages/console/src/Components/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class Option
/** @var T */
public mixed $displayValue {
get {
if (! ($this->value instanceof UnitEnum)) {
if (! $this->value instanceof UnitEnum) {
return $this->value;
}

Expand Down
Loading
Loading