Skip to content

Commit

Permalink
Added regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Oct 6, 2023
1 parent 5ac13df commit 94ad039
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -568,4 +568,10 @@ public function testWritingReadonlyProperty(): void
]);
}

public function testBug8190(): void
{
$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-8190.php'], []);
}

}
57 changes: 57 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-8190.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Bug8190;

/**
* @phpstan-type OwnerBackup array{name: string, isTest?: bool}
*/
class ClassA
{
/** @var OwnerBackup */
public array $ownerBackup;

/**
* @param OwnerBackup|null $ownerBackup
*/
public function __construct(?array $ownerBackup)
{
$this->ownerBackup = $ownerBackup ?? [
'name' => 'Deleted',
];
}


/**
* @param OwnerBackup|null $ownerBackup
*/
public function setOwnerBackup(?array $ownerBackup): void
{
$this->ownerBackup = $ownerBackup ?: [
'name' => 'Deleted',
];
}

/**
* @param OwnerBackup|null $ownerBackup
*/
public function setOwnerBackupWorksForSomeReason(?array $ownerBackup): void
{
$this->ownerBackup = $ownerBackup !== null ? $ownerBackup : [
'name' => 'Deleted',
];
}

/**
* @param OwnerBackup|null $ownerBackup
*/
public function setOwnerBackupAlsoWorksForSomeReason(?array $ownerBackup): void
{
if ($ownerBackup) {
$this->ownerBackup = $ownerBackup;
} else {
$this->ownerBackup = [
'name' => 'Deleted',
];
}
}
}

0 comments on commit 94ad039

Please sign in to comment.