Skip to content

Commit a0acdbd

Browse files
authored
style: upgrade mago and apply formatting (#1561)
1 parent 6bd1b47 commit a0acdbd

File tree

176 files changed

+1017
-951
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+1017
-951
lines changed

.github/workflows/coding-conventions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ jobs:
2525
2626
- name: Run Mago
2727
run: |
28-
./vendor/bin/mago fmt --dry-run
29-
./vendor/bin/mago lint --reporting-format=github
28+
composer fmt -- --check
29+
composer lint -- --reporting-format=github
3030
3131
- name: Setup Bun
3232
uses: oven-sh/setup-bun@v2

composer.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"require-dev": {
4848
"aws/aws-sdk-php": "^3.338.0",
4949
"azure-oss/storage-blob-flysystem": "^1.2",
50-
"carthage-software/mago": "0.26.1",
50+
"carthage-software/mago": "^1.0.0-beta.16",
5151
"guzzlehttp/psr7": "^2.6.1",
5252
"league/flysystem-aws-s3-v3": "^3.25.1",
5353
"league/flysystem-ftp": "^3.25.1",
@@ -228,8 +228,9 @@
228228
"scripts": {
229229
"phpunit": "@php -d memory_limit=2G vendor/bin/phpunit --display-warnings --display-skipped --display-deprecations --display-errors --display-notices",
230230
"coverage": "vendor/bin/phpunit --coverage-html build/reports/html --coverage-clover build/reports/clover.xml",
231-
"fmt": "vendor/bin/mago fmt && vendor/bin/mago lint --fix --potentially-unsafe --fmt",
232-
"lint": "vendor/bin/mago lint --minimum-level=note",
231+
"fmt": "vendor/bin/mago fmt",
232+
"lint:fix": "vendor/bin/mago lint --fix --format-after-fix",
233+
"lint": "vendor/bin/mago lint --potentially-unsafe --minimum-fail-level=note",
233234
"phpstan": "vendor/bin/phpstan analyse src tests --memory-limit=1G",
234235
"rector": "vendor/bin/rector process --no-ansi",
235236
"merge": "php -d\"error_reporting = E_ALL & ~E_DEPRECATED\" vendor/bin/monorepo-builder merge",
@@ -240,12 +241,13 @@
240241
],
241242
"qa": [
242243
"composer fmt",
244+
"composer lint:fix",
245+
"composer lint",
243246
"composer merge",
247+
"composer rector",
244248
"./bin/validate-packages",
245249
"./tempest discovery:clear --no-interaction",
246-
"composer rector",
247250
"composer phpunit",
248-
"composer lint",
249251
"composer phpstan"
250252
]
251253
}

mago.toml

Lines changed: 48 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
php_version = "8.4.0"
1+
php-version = "8.4.0"
22

33
[source]
44
paths = ["src", "packages", "tests"]
@@ -15,130 +15,52 @@ excludes = [
1515
"**/*.expected.php",
1616
]
1717

18-
[format]
19-
print_width = 180
20-
tab_width = 4
21-
use_tabs = false
22-
space_after_logical_not_unary_prefix_operator = true
23-
null_type_hint = "question"
24-
space_before_arrow_function_parameter_list_parenthesis = true
25-
always_break_named_arguments_list = false
26-
preserve_breaking_member_access_chain = true
27-
preserve_breaking_argument_list = true
28-
preserve_breaking_array_like = true
29-
preserve_breaking_parameter_list = true
30-
preserve_breaking_attribute_list = true
31-
preserve_breaking_conditional_expression = true
32-
empty_line_after_opening_tag = false
18+
[formatter]
19+
print-width = 180
20+
tab-width = 4
21+
use-tabs = false
22+
space-after-logical-not-unary-prefix-operator = true
23+
null-type-hint = "question"
24+
space-before-arrow-function-parameter-list-parenthesis = true
25+
always-break-named-arguments-list = false
26+
preserve-breaking-member-access-chain = true
27+
preserve-breaking-argument-list = true
28+
preserve-breaking-array-like = true
29+
preserve-breaking-parameter-list = true
30+
preserve-breaking-attribute-list = true
31+
preserve-breaking-conditional-expression = true
32+
empty-line-after-opening-tag = false
3333

3434
[linter]
35-
default_plugins = true
36-
plugins = ["symfony", "php-unit"]
37-
38-
# MAINTENABILITY
39-
[[linter.rules]]
40-
name = "maintainability/too-many-enum-cases"
41-
level = "off"
42-
43-
[[linter.rules]]
44-
name = "maintainability/excessive-parameter-list"
45-
level = "off"
46-
47-
[[linter.rules]]
48-
name = "maintainability/halstead"
49-
level = "off"
50-
51-
[[linter.rules]]
52-
name = "maintainability/too-many-methods"
53-
level = "off"
54-
55-
[[linter.rules]]
56-
name = "maintainability/kan-defect"
57-
level = "off"
58-
59-
[[linter.rules]]
60-
name = "maintainability/cyclomatic-complexity"
61-
level = "off"
62-
63-
# STRICTNESS
64-
[[linter.rules]]
65-
name = "strictness/require-return-type"
66-
ignore_arrow_function = true
67-
ignore_closure = true
68-
69-
# https://github.com/carthage-software/mago/issues/206
70-
[[linter.rules]]
71-
name = "best-practices/literal-named-argument"
72-
level = "off"
73-
74-
# https://github.com/carthage-software/mago/issues/146
75-
[[linter.rules]]
76-
name = "strictness/require-strict-types"
77-
level = "off"
78-
79-
[[linter.rules]]
80-
name = "strictness/require-parameter-type"
81-
ignore_arrow_function = true
82-
ignore_closure = true
83-
84-
[[linter.rules]]
85-
name = "strictness/no-shorthand-ternary"
86-
level = "off"
87-
88-
[[linter.rules]]
89-
name = "strictness/no-assignment-in-condition"
90-
level = "off"
91-
92-
# BEST PRACTICES
93-
[[linter.rules]]
94-
name = "best-practices/no-else-clause"
95-
level = "off"
96-
97-
[[linter.rules]]
98-
name = "best-practices/no-boolean-literal-comparison"
99-
level = "off"
100-
101-
[[linter.rules]]
102-
name = "best-practices/no-boolean-flag-parameter"
103-
level = "off"
104-
105-
# SAFETY
106-
[[linter.rules]]
107-
name = "safety/no-error-control-operator"
108-
level = "off"
109-
110-
# PHPUNIT
111-
[[linter.rules]]
112-
name = "php-unit/assertions-style"
113-
style = "this"
114-
115-
[[linter.rules]]
116-
name = "php-unit/strict-assertions"
117-
level = "off"
118-
119-
# NAMING
120-
[[linter.rules]]
121-
name = "naming/interface"
122-
psr = false
123-
124-
[[linter.rules]]
125-
name = "naming/trait"
126-
psr = false
127-
128-
[[linter.rules]]
129-
name = "naming/class"
130-
psr = false
131-
132-
# HELP
133-
[[linter.rules]]
134-
name = "redundancy/redundant-file"
135-
level = "off"
136-
137-
# CONSIDER ENABLING
138-
[[linter.rules]]
139-
name = "analysis/override-attribute"
140-
level = "off"
141-
142-
[[linter.rules]]
143-
name = "comment/no-untagged-todo"
144-
level = "off"
35+
integrations = ["php-unit", "tempest"]
36+
37+
[linter.rules]
38+
interface-name = { psr = false }
39+
trait-name = { psr = false }
40+
class-name = { psr = false }
41+
literal-named-argument = { enabled = false } # todo
42+
no-error-control-operator = { enabled = false }
43+
no-boolean-literal-comparison = { enabled = false }
44+
too-many-methods = { enabled = false }
45+
kan-defect = { enabled = false }
46+
cyclomatic-complexity = { enabled = false }
47+
return-type = { ignore-arrow-function = true, ignore-closure = true }
48+
parameter-type = { ignore-arrow-function = true, ignore-closure = true }
49+
too-many-enum-cases = { enabled = false }
50+
no-redundant-file = { enabled = false }
51+
assertion-style = { style = "this" }
52+
strict-assertions = { enabled = false }
53+
no-else-clause = { enabled = false }
54+
no-boolean-flag-parameter = { enabled = false }
55+
no-shorthand-ternary = { enabled = false }
56+
no-assign-in-condition = { enabled = false }
57+
strict-types = { enabled = false } # https://github.com/carthage-software/mago/issues/146
58+
tagged-todo = { enabled = false } # CONSIDER ENABLING
59+
excessive-parameter-list = { enabled = false } # https://github.com/carthage-software/mago/issues/206
60+
halstead = { enabled = false }
61+
prefer-arrow-function = { enabled = false } # enable when references are fixed
62+
prefer-first-class-callable = { enabled = false } # enable when arguments are fixed
63+
strict-behavior = { allow-loose-behavior = true }
64+
65+
# [analyzer]
66+
# override-attribute = { enabled = false } # CONSIDER ENABLING

packages/cache/src/Commands/CacheClearCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __invoke(
4242
#[ConsoleCommand(description: 'Whether to clear internal caches')]
4343
bool $internal = false,
4444
): void {
45-
if (! ($this->container instanceof GenericContainer)) {
45+
if (! $this->container instanceof GenericContainer) {
4646
$this->console->error('Clearing caches is only available when using the default container.');
4747
return;
4848
}

packages/cache/src/Commands/CacheStatusCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(
3737
#[ConsoleCommand(name: 'cache:status', description: 'Shows which caches are enabled')]
3838
public function __invoke(bool $internal = true): void
3939
{
40-
if (! ($this->container instanceof GenericContainer)) {
40+
if (! $this->container instanceof GenericContainer) {
4141
$this->console->error('Clearing caches is only available when using the default container.');
4242
return;
4343
}
@@ -95,7 +95,7 @@ public function __invoke(bool $internal = true): void
9595

9696
private function getCacheName(Cache $cache): string
9797
{
98-
if (! ($cache instanceof GenericCache)) {
98+
if (! $cache instanceof GenericCache) {
9999
return $cache::class;
100100
}
101101

packages/cache/src/GenericCache.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function lock(Stringable|string $key, null|Duration|DateTimeInterface $ex
3131

3232
return new GenericLock(
3333
key: (string) $key,
34-
owner: $owner ? ((string) $owner) : Random\secure_string(length: 10),
34+
owner: $owner ? (string) $owner : Random\secure_string(length: 10),
3535
cache: $this,
3636
expiration: $expiration,
3737
);
@@ -90,7 +90,7 @@ public function increment(Stringable|string $key, int $by = 1): int
9090
} elseif (! is_numeric($item->get())) {
9191
throw new CacheKeyCouldNotBeIncremented((string) $key);
9292
} else {
93-
$item->set(((int) $item->get()) + $by);
93+
$item->set((int) $item->get() + $by);
9494
}
9595

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

117117
$this->adapter->save($item);

packages/cache/src/GenericLock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function locked(null|Stringable|string $by = null): bool
2323
return $this->cache->has($this->key);
2424
}
2525

26-
return $this->cache->get($this->key) === ((string) $by);
26+
return $this->cache->get($this->key) === (string) $by;
2727
}
2828

2929
public function acquire(): bool
@@ -44,7 +44,7 @@ public function acquire(): bool
4444
public function execute(Closure $callback, null|DateTimeInterface|Duration $wait = null): mixed
4545
{
4646
$wait ??= Datetime::now();
47-
$waitUntil = ($wait instanceof Duration)
47+
$waitUntil = $wait instanceof Duration
4848
? DateTime::now()->plus($wait)
4949
: $wait;
5050

packages/cache/src/Testing/CacheTester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function fake(null|string|UnitEnum $tag = null): TestingCache
4141
*/
4242
public function preventUsageWithoutFake(): void
4343
{
44-
if (! ($this->container instanceof GenericContainer)) {
44+
if (! $this->container instanceof GenericContainer) {
4545
throw new \RuntimeException('Container is not a GenericContainer, unable to prevent usage without fake.');
4646
}
4747

packages/cache/src/Testing/TestingCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function lock(Stringable|string $key, null|Duration|DateTimeInterface $ex
3737
{
3838
return new TestingLock(new GenericLock(
3939
key: (string) $key,
40-
owner: $owner ? ((string) $owner) : Random\secure_string(length: 10),
40+
owner: $owner ? (string) $owner : Random\secure_string(length: 10),
4141
cache: $this->cache,
4242
expiration: $expiration,
4343
));

packages/cache/src/UserCacheInsightsProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(
2727

2828
public function getInsights(): array
2929
{
30-
if (! ($this->container instanceof GenericContainer)) {
30+
if (! $this->container instanceof GenericContainer) {
3131
return [];
3232
}
3333

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

6060
private function getCacheName(Cache $cache): string
6161
{
62-
if (! ($cache instanceof GenericCache)) {
62+
if (! $cache instanceof GenericCache) {
6363
return $cache::class;
6464
}
6565

0 commit comments

Comments
 (0)