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

Regression test #1749

Merged
merged 3 commits into from Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/PHPStan/Rules/Classes/InstantiationRuleTest.php
Expand Up @@ -422,4 +422,13 @@ public function testBug7048(): void
]);
}

public function testBug7594(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Test requires PHP 8.0.');
}

$this->analyse([__DIR__ . '/data/bug-7594.php'], []);
}

}
57 changes: 57 additions & 0 deletions tests/PHPStan/Rules/Classes/data/bug-7594.php
@@ -0,0 +1,57 @@
<?php declare(strict_types = 1); // lint >= 8.0

namespace Bug7594;

class HelloWorld
{

public const ABILITY_BUILD = 0;
public const ABILITY_MINE = 1;
public const ABILITY_DOORS_AND_SWITCHES = 2;
public const ABILITY_OPEN_CONTAINERS = 3;
public const ABILITY_ATTACK_PLAYERS = 4;
public const ABILITY_ATTACK_MOBS = 5;
public const ABILITY_OPERATOR = 6;
public const ABILITY_TELEPORT = 7;
public const ABILITY_INVULNERABLE = 8;
public const ABILITY_FLYING = 9;
public const ABILITY_ALLOW_FLIGHT = 10;
public const ABILITY_INSTABUILD = 11; //???
public const ABILITY_LIGHTNING = 12; //???
private const ABILITY_FLY_SPEED = 13;
private const ABILITY_WALK_SPEED = 14;
public const ABILITY_MUTED = 15;
public const ABILITY_WORLD_BUILDER = 16;
public const ABILITY_NO_CLIP = 17;

public const NUMBER_OF_ABILITIES = 18;

/**
* @param bool[] $boolAbilities
* @phpstan-param array<self::ABILITY_*, bool> $boolAbilities
*/
public function __construct(
private array $boolAbilities,
){}

/**
* Returns a list of abilities set/overridden by this layer. If the ability value is not set, the index is omitted.
* @return bool[]
* @phpstan-return array<self::ABILITY_*, bool>
*/
public function getBoolAbilities() : array{ return $this->boolAbilities; }

public static function decode(int $setAbilities, int $setAbilityValues) : self{
$boolAbilities = [];
for($i = 0; $i < self::NUMBER_OF_ABILITIES; $i++){
if($i === self::ABILITY_FLY_SPEED || $i === self::ABILITY_WALK_SPEED){
continue;
}
if(($setAbilities & (1 << $i)) !== 0){
$boolAbilities[$i] = ($setAbilityValues & (1 << $i)) !== 0;
}
}

return new self($boolAbilities);
}
}