Skip to content

Commit 1efdd51

Browse files
committed
refactor: cover core static analysis with mago
1 parent f3b3d11 commit 1efdd51

269 files changed

Lines changed: 1725 additions & 785 deletions

File tree

Some content is hidden

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

Justfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ analyze-mago *args:
6060
src/lib/azure-sdk \
6161
src/lib/doctrine-dbal-bulk \
6262
src/lib/snappy \
63-
src/lib/parquet
63+
src/lib/parquet \
64+
src/core/etl
6465

6566
# Auto-fix code style with Mago (format + lint --fix).
6667
fix:

composer.lock

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mago.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ ignore = [
4343
"src/lib/types/tests/Flow/Types/Tests/Unit/Type/Logical/HTMLTypeTest.php",
4444
"src/lib/types/tests/Flow/Types/Tests/Unit/Type/Native/StringTypeTest.php",
4545
"src/lib/types/tests/Flow/Types/Tests/Unit/Type/TypeDetectorTest.php",
46+
"src/core/etl/src/Flow/ETL/Row/Entry/HTMLEntry.php",
47+
"src/core/etl/src/Flow/ETL/Row/Entry/HTMLElementEntry.php",
4648
] },
4749
]
4850

shell.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ assert (!(with-c && with-pg-query-ext)) || builtins.throw "Cannot use --arg with
1919

2020
let
2121
nixpkgs = fetchTarball {
22-
url = "https://github.com/NixOS/nixpkgs/archive/03158cb739fc4a09babe7949900bfc221871d642.tar.gz";
23-
sha256 = "0vl4iwqcpbczhzb3xbckjb86brcsxkcz4wcbqzidia2fyhm9llmx";
22+
url = "https://github.com/NixOS/nixpkgs/archive/0c4e77908e1204498184d81cda8716e1ba4c47af.tar.gz";
23+
sha256 = "0mbr776gj2qk9klvara4zlww3g0da4nfbnrmi114nnmmayx3pyj4";
2424
};
2525

2626
pkgs = import nixpkgs {

src/bridge/symfony/postgresql-bundle/src/Flow/Bridge/Symfony/PostgreSqlBundle/FlowPostgreSqlBundle.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,7 @@ private function registerCatalogProviders(array $catalogProviders, ContainerBuil
474474
$providerDef = new Definition(ArrayCatalogProvider::class, [$providerConfig['catalog']]);
475475
$providerDef->addTag('flow.postgresql.catalog_provider');
476476
$container->setDefinition("flow.postgresql.catalog_provider.{$i}", $providerDef);
477-
} elseif (
478-
array_key_exists('catalog_provider_id', $providerConfig)
479-
&& $providerConfig['catalog_provider_id'] !== null
480-
) {
477+
} elseif ($providerConfig['catalog_provider_id'] !== null) {
481478
$configProviderServiceIds[] = type_string()->assert($providerConfig['catalog_provider_id']);
482479
}
483480
}

src/core/etl/src/Flow/ArrayComparison/ArrayComparison.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ private function valueEquals($a, $b): bool
5555
return false;
5656
}
5757

58+
// @mago-ignore analysis:mixed-assignment
5859
foreach ($b as $key => $value) {
5960
if (!array_key_exists($key, $a)) {
6061
return false;

src/core/etl/src/Flow/Calculator/Calculator.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,29 @@ public function divide(
5656
$useNewNaming = defined('Brick\Math\RoundingMode::Up');
5757

5858
$brickMode = match ($rounding) {
59+
// @mago-ignore analysis:non-existent-class-constant
5960
Rounding::UP => $useNewNaming ? RoundingMode::Up : RoundingMode::UP,
61+
// @mago-ignore analysis:non-existent-class-constant
6062
Rounding::DOWN => $useNewNaming ? RoundingMode::Down : RoundingMode::DOWN,
63+
// @mago-ignore analysis:non-existent-class-constant
6164
Rounding::CEILING => $useNewNaming ? RoundingMode::Ceiling : RoundingMode::CEILING,
65+
// @mago-ignore analysis:non-existent-class-constant
6266
Rounding::FLOOR => $useNewNaming ? RoundingMode::Floor : RoundingMode::FLOOR,
67+
// @mago-ignore analysis:non-existent-class-constant
6368
Rounding::HALF_UP => $useNewNaming ? RoundingMode::HalfUp : RoundingMode::HALF_UP,
69+
// @mago-ignore analysis:non-existent-class-constant
6470
Rounding::HALF_DOWN => $useNewNaming ? RoundingMode::HalfDown : RoundingMode::HALF_DOWN,
71+
// @mago-ignore analysis:non-existent-class-constant
6572
Rounding::HALF_CEILING => $useNewNaming ? RoundingMode::HalfCeiling : RoundingMode::HALF_CEILING,
73+
// @mago-ignore analysis:non-existent-class-constant
6674
Rounding::HALF_FLOOR => $useNewNaming ? RoundingMode::HalfFloor : RoundingMode::HALF_FLOOR,
75+
// @mago-ignore analysis:non-existent-class-constant
6776
Rounding::HALF_EVEN => $useNewNaming ? RoundingMode::HalfEven : RoundingMode::HALF_EVEN,
77+
// @mago-ignore analysis:non-existent-class-constant
6878
default => $useNewNaming ? RoundingMode::Unnecessary : RoundingMode::UNNECESSARY,
6979
};
7080

81+
// @mago-ignore analysis:possibly-invalid-argument
7182
$result = $aDecimal->dividedBy(BigDecimal::of((string) $b), $effectiveScale, $brickMode);
7283

7384
if (!self::hasNonZeroFractionalPart($result)) {
@@ -76,9 +87,9 @@ public function divide(
7687

7788
return $result->toFloat();
7889
} catch (DivisionByZeroException $e) {
79-
throw new DivisionByZeroError('Division by zero.', $e->getCode(), $e);
90+
throw new DivisionByZeroError('Division by zero.', (int) $e->getCode(), $e);
8091
} catch (RoundingNecessaryException $e) {
81-
throw new Exception\RoundingNecessaryException($e->getMessage(), $e->getCode(), $e);
92+
throw new Exception\RoundingNecessaryException($e->getMessage(), (int) $e->getCode(), $e);
8293
}
8394
}
8495

@@ -112,6 +123,7 @@ public function multiply(int|float|string $a, int|float|string $b): int|float
112123
*/
113124
public function power(int|float|string $a, int|string $b): int|float
114125
{
126+
// @mago-ignore analysis:possibly-invalid-argument
115127
$result = BigDecimal::of((string) $a)->power(BigInteger::of((string) $b)->toInt());
116128

117129
if (!self::hasNonZeroFractionalPart($result)) {
@@ -139,6 +151,7 @@ public function subtract(int|float|string $a, int|float|string $b): int|float
139151
private static function hasNonZeroFractionalPart(BigDecimal $result): bool
140152
{
141153
if (method_exists($result, 'hasNonZeroFractionalPart')) {
154+
// @mago-ignore analysis:mixed-return-statement
142155
return $result->hasNonZeroFractionalPart();
143156
}
144157

src/core/etl/src/Flow/Calculator/NumberNormalizer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ final class NumberNormalizer
2424
*/
2525
public static function toNumber(string $number): float|int
2626
{
27+
// @mago-ignore analysis:impossible-condition,redundant-type-comparison
2728
if (!is_numeric($number)) {
2829
throw new NonNumericValueException((string) $number);
2930
}
@@ -33,6 +34,7 @@ public static function toNumber(string $number): float|int
3334
}
3435

3536
if (str_contains($number, '.')) {
37+
// @mago-ignore analysis:invalid-type-cast
3638
return (float) $number;
3739
}
3840

@@ -50,6 +52,7 @@ public static function toString(string|float|int $number, int $scale): string
5052
throw new InvalidScaleException($scale);
5153
}
5254

55+
// @mago-ignore analysis:impossible-condition,redundant-type-comparison
5356
if (!is_numeric($number)) {
5457
throw new NonNumericValueException((string) $number);
5558
}

src/core/etl/src/Flow/ETL/Cache/Implementation/PSRSimpleCache.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function delete(string $key): void
3737

3838
public function get(string $key): Row|Rows|CacheIndex
3939
{
40+
// @mago-ignore analysis:mixed-assignment
4041
$serializedValue = $this->cache->get($key);
4142

4243
if (!$serializedValue) {

src/core/etl/src/Flow/ETL/Config/Cache/CacheConfigBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function cache(Cache $cache): self
6666
*/
6767
public function externalSortBucketsCount(int $externalSortBucketsCount): self
6868
{
69+
// @mago-ignore analysis:impossible-condition,redundant-comparison
6970
if ($externalSortBucketsCount < 1) {
7071
throw new InvalidArgumentException('External sort buckets count must be greater than 0');
7172
}

0 commit comments

Comments
 (0)