Skip to content

Commit

Permalink
added regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
clxmstaab committed Sep 23, 2022
1 parent 0f2225c commit d1d2b00
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Expand Up @@ -451,4 +451,10 @@ public function testBug3383(): void
$this->analyse([__DIR__ . '/data/bug-3383.php'], []);
}

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

}
57 changes: 57 additions & 0 deletions tests/PHPStan/Rules/Properties/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);
}
}

0 comments on commit d1d2b00

Please sign in to comment.