Skip to content

Commit

Permalink
Merge pull request #593 from wmde/fix-phpstan-array-errors
Browse files Browse the repository at this point in the history
Add types for arrays
  • Loading branch information
moiikana authored Jan 20, 2025
2 parents e6f45ad + c06675b commit 5b9b0f5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
3 changes: 0 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
parameters:
inferPrivatePropertyTypeFromConstructor: true
ignoreErrors:
-
identifier: missingType.iterableValue

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
3 changes: 0 additions & 3 deletions phpstan.prod.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
parameters:
inferPrivatePropertyTypeFromConstructor: true
ignoreErrors:
-
identifier: missingType.iterableValue
4 changes: 3 additions & 1 deletion src/Entity/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Visitor {

private int $totalImpressionCount = 0;
private ?string $bucketIdentifier;
/** @var string[] */
private array $activeCategories;
private int $displayWidth;

Expand All @@ -24,7 +25,8 @@ public function __construct(
int $totalImpressionCount,
?string $bucketIdentifier,
int $displayWidth,
string ...$activeCategories ) {
string ...$activeCategories
) {
$this->totalImpressionCount = $totalImpressionCount;
$this->bucketIdentifier = $bucketIdentifier;
$this->displayWidth = $displayWidth;
Expand Down
22 changes: 22 additions & 0 deletions src/Utils/CampaignConfigurationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function getCampaignCollection(): CampaignCollection {
return new CampaignCollection( ...$campaigns );
}

/**
* @param string $campaignName
* @param array<string,mixed> $campaignData
*/
private function buildCampaignFromData( string $campaignName, array $campaignData ): Campaign {
$buckets = $this->buildBucketsFromData( $campaignData );
if ( empty( $buckets ) ) {
Expand Down Expand Up @@ -60,6 +64,10 @@ private function buildCampaignFromData( string $campaignName, array $campaignDat
);
}

/**
* @param array<string,mixed> $campaignData
* @return Bucket[]
*/
private function buildBucketsFromData( array $campaignData ): array {
$buckets = [];
foreach ( $campaignData['buckets'] as $bucketData ) {
Expand All @@ -69,6 +77,10 @@ private function buildBucketsFromData( array $campaignData ): array {
return $buckets;
}

/**
* @param array<string,mixed> $bucketData
* @return Bucket
*/
private function buildBucketFromData( array $bucketData ): Bucket {
if ( !isset( $bucketData['name'] ) ) {
throw new InvalidConfigurationValueException( 'A configured bucket has no name.' );
Expand All @@ -83,6 +95,10 @@ private function buildBucketFromData( array $bucketData ): Bucket {
return new Bucket( $bucketData['name'], array_shift( $banners ), ...$banners );
}

/**
* @param string[] $bannerData
* @return Banner[]
*/
private function buildBannersFromData( array $bannerData ): array {
$banners = [];
foreach ( $bannerData as $bannerIdentifier ) {
Expand All @@ -94,10 +110,16 @@ private function buildBannersFromData( array $bannerData ): array {
return $banners;
}

/**
* @return array<string,mixed>
*/
private function parseConfiguration(): array {
return Yaml::parseFile( $this->configFile );
}

/**
* @param array<string,mixed> $campaignData
*/
private function integerOrNullValue( array $campaignData, string $key ): ?int {
if ( !isset( $campaignData[$key] ) ) {
return null;
Expand Down
5 changes: 5 additions & 0 deletions tests/Unit/EventListener/ExceptionListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public function setUp(): void {
$this->dispatcher = new EventDispatcher();
}

/** solves tests marked as "risky" by phpunit, error was: "Test code or tested code did not remove its own exception handlers" */
public function tearDown(): void {
restore_exception_handler();
}

public function testGivenExceptionForJavaScriptUrl_thenEmptyInternalServerErrorMessageIsReturned(): void {
$this->withExceptionListener( new TestHandler() );

Expand Down

0 comments on commit 5b9b0f5

Please sign in to comment.