diff --git a/.gitignore b/.gitignore
index cc16f0c..20b0590 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
vendor/
.idea
-.php_cs.cache
+.php-cs-fixer.cache
infection.log
composer.lock
build
diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php
new file mode 100644
index 0000000..7b30a5d
--- /dev/null
+++ b/.php-cs-fixer.dist.php
@@ -0,0 +1,13 @@
+in(__DIR__)
+;
+
+return (new PhpCsFixer\Config())
+ ->setRules([
+ '@PER-CS2.0' => true,
+ '@PHP82Migration' => true,
+ ])
+ ->setFinder($finder)
+ ;
\ No newline at end of file
diff --git a/README.md b/README.md
index e2364bd..3ca147e 100644
--- a/README.md
+++ b/README.md
@@ -106,13 +106,14 @@ $ ./vendor/bin/phpstan analyse src/ -c phpstan.neon --level=9 --no-progress -vvv
##### PHP-CS
###### Code style check
```bash
-$ composer phpcs
-$ ./vendor/bin/phpcs
+$ composer phpcs-check
+$ ./vendor/bin/php-cs-fixer check --diff
+
```
###### Code style fix
```bash
-$ composer phpcbf
-$ ./vendor/bin/phpcbf
+$ composer phpcs-fix
+$ ./vendor/bin/php-cs-fixer fix
```
## License
diff --git a/benchmarks/GetSetBitsIndexBench.php b/benchmarks/GetSetBitsIndexBench.php
index b28c42d..d9a3725 100644
--- a/benchmarks/GetSetBitsIndexBench.php
+++ b/benchmarks/GetSetBitsIndexBench.php
@@ -1,4 +1,5 @@
-
-
-
-
-
-
-
-
-
-
- src/
-
-
diff --git a/psalm.xml b/psalm.xml
new file mode 100644
index 0000000..b56fa64
--- /dev/null
+++ b/psalm.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/BitMask.php b/src/BitMask.php
index d4ab0d7..d85507b 100644
--- a/src/BitMask.php
+++ b/src/BitMask.php
@@ -19,7 +19,7 @@ public function __construct(
public function __toString(): string
{
- return (string)$this->mask;
+ return (string) $this->mask;
}
public function get(): int
@@ -52,8 +52,11 @@ public function has(int ...$bits): bool
/** @throws OutOfRangeException */
private function checkMask(int $mask): void
{
- if ($mask < 0 || $this->mostSignificantBit && $mask >= Bits::indexToBit($this->mostSignificantBit + 1)) {
- throw new OutOfRangeException((string)$mask);
+ if (
+ $mask < 0 ||
+ null !== $this->mostSignificantBit && $mask >= Bits::indexToBit($this->mostSignificantBit + 1)
+ ) {
+ throw new OutOfRangeException((string) $mask);
}
}
@@ -65,7 +68,7 @@ private function checkBit(int $bit): void
{
$this->checkMask($bit);
if (!Bits::isSingleBit($bit)) {
- throw new NotSingleBitException((string)$bit);
+ throw new NotSingleBitException((string) $bit);
}
}
}
diff --git a/src/EnumBitMask.php b/src/EnumBitMask.php
index b7f9ea7..a154f5c 100644
--- a/src/EnumBitMask.php
+++ b/src/EnumBitMask.php
@@ -9,6 +9,7 @@
use BitMask\Util\Bits;
use UnitEnum;
+/** @psalm-suppress UnusedClass */
final class EnumBitMask implements BitMaskInterface
{
private BitMask $bitmask;
@@ -60,6 +61,7 @@ public function has(UnitEnum ...$bits): bool
$bit instanceof $this->enum ?:
throw new UnknownEnumException(sprintf('Expected %s enum, %s provided', $this->enum, $bit::class))
);
+ /** @psalm-var UnitEnum[] $bits */
return $this->bitmask->has(...$this->enumToInt(...$bits));
}
diff --git a/src/Exception/BitMaskExceptionInterface.php b/src/Exception/BitMaskExceptionInterface.php
index 5bc5fc9..ab4a45d 100644
--- a/src/Exception/BitMaskExceptionInterface.php
+++ b/src/Exception/BitMaskExceptionInterface.php
@@ -4,6 +4,4 @@
use Throwable;
-interface BitMaskExceptionInterface extends Throwable
-{
-}
+interface BitMaskExceptionInterface extends Throwable {}
diff --git a/src/Exception/NotSingleBitException.php b/src/Exception/NotSingleBitException.php
index 996deaf..7600b1f 100644
--- a/src/Exception/NotSingleBitException.php
+++ b/src/Exception/NotSingleBitException.php
@@ -6,6 +6,4 @@
use Exception;
-final class NotSingleBitException extends Exception implements BitMaskExceptionInterface
-{
-}
+final class NotSingleBitException extends Exception implements BitMaskExceptionInterface {}
diff --git a/src/Exception/OutOfRangeException.php b/src/Exception/OutOfRangeException.php
index 4f4db35..8f37815 100644
--- a/src/Exception/OutOfRangeException.php
+++ b/src/Exception/OutOfRangeException.php
@@ -6,6 +6,4 @@
use OutOfRangeException as SplOutOfRangeException;
-final class OutOfRangeException extends SplOutOfRangeException implements BitMaskExceptionInterface
-{
-}
+final class OutOfRangeException extends SplOutOfRangeException implements BitMaskExceptionInterface {}
diff --git a/src/Exception/UnknownEnumException.php b/src/Exception/UnknownEnumException.php
index ee54a08..56033fd 100644
--- a/src/Exception/UnknownEnumException.php
+++ b/src/Exception/UnknownEnumException.php
@@ -6,6 +6,4 @@
use Exception;
-final class UnknownEnumException extends Exception implements BitMaskExceptionInterface
-{
-}
+final class UnknownEnumException extends Exception implements BitMaskExceptionInterface {}
diff --git a/src/Util/Bits.php b/src/Util/Bits.php
index 9e3d118..a2f517f 100644
--- a/src/Util/Bits.php
+++ b/src/Util/Bits.php
@@ -15,7 +15,7 @@ final class Bits
*/
public static function getMostSignificantBit(int $mask): int
{
- return (int)log($mask, 2);
+ return (int) log($mask, 2);
}
/**
@@ -50,6 +50,7 @@ public static function isSingleBit(int $mask): bool
/**
* single bit to index (left > right)
* @throws NotSingleBitException
+ * @psalm-suppress PossiblyUnusedMethod
*/
public static function bitToIndex(int $mask): int
{
@@ -70,11 +71,12 @@ public static function bitToIndex(int $mask): int
public static function indexToBit(int $index): int
{
if ($index < 0) {
- throw new OutOfRangeException((string)$index);
+ throw new OutOfRangeException((string) $index);
}
return intval(abs(1 << $index));
}
+ /** @psalm-suppress PossiblyUnusedMethod */
public static function toString(int $mask): string
{
return decbin($mask);
@@ -84,6 +86,7 @@ public static function toString(int $mask): string
* @return int[]
* @see benchmarks/GetSetBitsIndexBench.php
* ./vendor/bin/phpbench run benchmarks/GetSetBitsIndexBench.php --report=default
+ * @psalm-suppress PossiblyUnusedMethod
*/
public static function getSetBitsIndexes(int $mask): array
{
@@ -98,6 +101,7 @@ public static function getSetBitsIndexes(int $mask): array
* Bitwise-based check if given number is even
* @see benchmarks/EvenOddBench.php
* ./vendor/bin/phpbench run benchmarks/EvenOddBench.php --report=default
+ * @psalm-suppress PossiblyUnusedMethod
*/
public static function isEvenNumber(int $number): bool
{
@@ -108,6 +112,7 @@ public static function isEvenNumber(int $number): bool
* Bitwise-based check if given number is odd
* @see benchmarks/EvenOddBench.php
* ./vendor/bin/phpbench run benchmarks/EvenOddBench.php --report=default
+ * @psalm-suppress PossiblyUnusedMethod
*/
public static function isOddNumber(int $number): bool
{
diff --git a/tests/BitMaskTest.php b/tests/BitMaskTest.php
index 4f30e87..827ef66 100644
--- a/tests/BitMaskTest.php
+++ b/tests/BitMaskTest.php
@@ -45,7 +45,7 @@ public function testSet(): void
$bitmask->set(self::READ);
assertEquals(self::READ, $bitmask->get());
$this->expectException(OutOfRangeException::class);
- $this->expectExceptionMessage((string)self::EXECUTE);
+ $this->expectExceptionMessage((string) self::EXECUTE);
$bitmask->set(self::EXECUTE);
}
@@ -65,7 +65,7 @@ public function testHasNotSingleBit(): void
{
$bitmask = new BitMask();
$this->expectException(NotSingleBitException::class);
- $this->expectExceptionMessage((string)(self::READ | self::WRITE));
+ $this->expectExceptionMessage((string) (self::READ | self::WRITE));
$bitmask->has(self::READ | self::WRITE);
}
@@ -73,7 +73,7 @@ public function testIsSetBitOutOfRange(): void
{
$bitmask = new BitMask(0, 1);
$this->expectException(OutOfRangeException::class);
- $this->expectExceptionMessage((string)self::EXECUTE);
+ $this->expectExceptionMessage((string) self::EXECUTE);
$bitmask->has(self::EXECUTE);
}
@@ -91,7 +91,7 @@ public function testSetNotSingleBit(): void
{
$bitmask = new BitMask();
$this->expectException(NotSingleBitException::class);
- $this->expectExceptionMessage((string)(self::READ | self::WRITE));
+ $this->expectExceptionMessage((string) (self::READ | self::WRITE));
$bitmask->set(self::READ | self::WRITE);
}
@@ -99,7 +99,7 @@ public function testSetBitOutOfRange(): void
{
$bitmask = new BitMask(0, 1);
$this->expectException(OutOfRangeException::class);
- $this->expectExceptionMessage((string)self::EXECUTE);
+ $this->expectExceptionMessage((string) self::EXECUTE);
$bitmask->set(self::EXECUTE);
}
@@ -118,7 +118,7 @@ public function testUnsetBitNotSingleBit(): void
{
$bitmask = new BitMask(self::EXECUTE);
$this->expectException(NotSingleBitException::class);
- $this->expectExceptionMessage((string)(self::READ | self::WRITE));
+ $this->expectExceptionMessage((string) (self::READ | self::WRITE));
$bitmask->remove(self::READ | self::WRITE);
}
@@ -126,15 +126,15 @@ public function testUnsetBitOutOfRange(): void
{
$bitmask = new BitMask(self::WRITE, 1);
$this->expectException(OutOfRangeException::class);
- $this->expectExceptionMessage((string)self::EXECUTE);
+ $this->expectExceptionMessage((string) self::EXECUTE);
$bitmask->remove(self::EXECUTE);
}
public function testToString(): void
{
$bitmask = new BitMask(7);
- assertSame('7', (string)$bitmask);
+ assertSame('7', (string) $bitmask);
$bitmask->set(8);
- assertSame('15', (string)$bitmask);
+ assertSame('15', (string) $bitmask);
}
}
diff --git a/tests/Util/BitsTest.php b/tests/Util/BitsTest.php
index 63465c4..7494035 100644
--- a/tests/Util/BitsTest.php
+++ b/tests/Util/BitsTest.php
@@ -17,7 +17,6 @@
class BitsTest extends TestCase
{
-
public function testGetMostSignificantBit(): void
{
assertEquals(0, Bits::getMostSignificantBit(0));