Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Psalm errors #16

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<RedundantCastGivenDocblockType errorLevel="suppress" />
<RedundantCondition errorLevel="suppress" />
<DocblockTypeContradiction errorLevel="suppress" />
<MissingClassConstType errorLevel="suppress" />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider the implications of suppressing MissingClassConstType errors.

Suppressing MissingClassConstType errors means that Psalm will no longer report issues when class constants are declared without explicit type annotations. While this allows for more flexibility, it may also introduce potential type-related issues that could go undetected.

It's generally recommended to maintain strict type checking to catch potential issues early and improve code quality. Instead of suppressing these errors, consider refactoring the codebase to use typed class constants.

If you need assistance in refactoring the codebase to use typed class constants, I'd be happy to help. We can work together to identify the affected class constants and add appropriate type annotations to ensure better type safety. Let me know if you'd like me to open a GitHub issue to track this refactoring effort.

</issueHandlers>
<projectFiles>
<directory name="src" />
Expand Down
2 changes: 2 additions & 0 deletions src/AbstractMetrics.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Spiral\RoadRunner\Metrics;

use Spiral\Goridge\RPC\RPCInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/Collector.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Spiral\RoadRunner\Metrics;

use JetBrains\PhpStorm\Pure;
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/MetricsException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Spiral\RoadRunner\Metrics\Exception;

use Spiral\Goridge\RPC\Exception\ServiceException;
Expand Down
2 changes: 2 additions & 0 deletions src/MetricsFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Spiral\RoadRunner\Metrics;

use Psr\Log\LoggerInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/MetricsIgnoreResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Spiral\RoadRunner\Metrics;

use Spiral\Goridge\RPC\AsyncRPCInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/MetricsOptions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Spiral\RoadRunner\Metrics;

class MetricsOptions
Expand Down
2 changes: 2 additions & 0 deletions src/RetryMetrics.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Spiral\RoadRunner\Metrics;

use Spiral\RoadRunner\Metrics\Exception\MetricsException;
Expand Down
2 changes: 2 additions & 0 deletions src/SuppressExceptionsMetrics.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Spiral\RoadRunner\Metrics;

use Psr\Log\LoggerInterface;
Expand Down
26 changes: 13 additions & 13 deletions tests/Unit/RetryMetricsTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

declare(strict_types=1);

namespace Spiral\RoadRunner\Metrics\Tests\Unit;

use PHPUnit\Framework\MockObject\Rule\InvokedCount;
use PHPUnit\Framework\TestCase;
use Spiral\RoadRunner\Metrics\Collector;
use Spiral\RoadRunner\Metrics\Exception\MetricsException;
Expand All @@ -21,7 +22,7 @@ public function testAddWithMetricsException(): void
1,
);

self::expectException(MetricsException::class);
$this->expectException(MetricsException::class);

$retryMetrics->add('counter', 1);
}
Expand Down Expand Up @@ -49,7 +50,7 @@ public function testSubWithMetricsException(): void
1,
);

self::expectException(MetricsException::class);
$this->expectException(MetricsException::class);

$retryMetrics->sub('counter', 1);
}
Expand Down Expand Up @@ -77,7 +78,7 @@ public function testObserveWithMetricsException(): void
1,
);

self::expectException(MetricsException::class);
$this->expectException(MetricsException::class);

$retryMetrics->observe('counter', 1);
}
Expand Down Expand Up @@ -105,7 +106,7 @@ public function testSetWithMetricsException(): void
1,
);

self::expectException(MetricsException::class);
$this->expectException(MetricsException::class);

$retryMetrics->set('counter', 1);
}
Expand Down Expand Up @@ -133,7 +134,7 @@ public function testDeclareWithMetricsException(): void
1,
);

self::expectException(MetricsException::class);
$this->expectException(MetricsException::class);

$retryMetrics->declare('counter', Collector::counter());
}
Expand Down Expand Up @@ -161,7 +162,7 @@ public function testUnregisterWithMetricsException(): void
1,
);

self::expectException(MetricsException::class);
$this->expectException(MetricsException::class);

$retryMetrics->unregister('counter');
}
Expand All @@ -183,14 +184,13 @@ private function createMetricsMock(string $method, int $expectedCalls, int $exce
{
$metrics = $this->createMock(MetricsInterface::class);

$returnValues = \array_fill(0, $exceptions, $this->throwException(new MetricsException()));
$returnValues[] = null;

$metrics
->expects(new InvokedCount($expectedCalls))
->expects($this->exactly($expectedCalls))
->method($method)
->willReturnOnConsecutiveCalls(...array_fill(
0,
$exceptions,
$this->throwException(new MetricsException()),
));
->willReturnOnConsecutiveCalls(...$returnValues);

return $metrics;
}
Expand Down
Loading