Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslavche committed Jun 21, 2024
1 parent ba147a6 commit 45a325f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ $bitmask->set(Permissions::EXECUTE);
$bitmask->set(Unknown::Case); // throws an exception, only Permissions cases available
```

`EnumBitMask` have a factory methods:
```php
# Create a bit mask using one or multiple enum cases
$bitmask = EnumBitMask::create(Permissions::class, Permissions::EXECUTE);

# Create a bit mask using all enum cases
$bitmask = EnumBitMask::all(Permissions::class);

# Create a bit mask with no flags on (equivalent to create with no additional flags)
$bitmask = EnumBitMask::none(Permissions::class);

# Create a bit mask without specific flags
$bitmask = EnumBitMask::without(Permissions::class, Permissions::EXECUTE);
```

Exists [Bits](/src/Util/Bits.php) helper with static methods:

```php
Expand Down Expand Up @@ -103,6 +118,12 @@ $ ./vendor/bin/phpbench run benchmarks --report=default
$ composer phpstan
$ ./vendor/bin/phpstan analyse src/ -c phpstan.neon --level=9 --no-progress -vvv --memory-limit=1024M
```

##### Psalm
```bash
$ composer psalm
$ ./vendor/bin/psalm
```
##### PHP-CS
###### Code style check
```bash
Expand Down
16 changes: 6 additions & 10 deletions src/EnumBitMask.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(
throw new UnknownEnumException('EnumBitMask enum must be subclass of UnitEnum');
}
foreach ($this->enum::cases() as $index => $case) {
$this->map[strval($case->name)] = Bits::indexToBit($index);
$this->map[$case->name] = Bits::indexToBit($index);
}
$this->bitmask = new BitMask($mask, count($this->enum::cases()) - 1);
}
Expand All @@ -38,21 +38,19 @@ public function __construct(
* Create an instance with given flags on
*
* @param class-string $enum
* @throws NotSingleBitException
* @throws UnknownEnumException
* @throws UnknownEnumException|NotSingleBitException
*/
public static function create(string $enum, UnitEnum ...$bits): self
{
return (new static($enum))->set(...$bits);
return (new EnumBitMask($enum))->set(...$bits);
}

/**
* Create an instance with all flags on
*
* @psalm-suppress MixedMethodCall, MixedArgument
* @param class-string $enum
* @throws NotSingleBitException
* @throws UnknownEnumException
* @throws UnknownEnumException|NotSingleBitException
*/
public static function all(string $enum): self
{
Expand All @@ -64,8 +62,7 @@ public static function all(string $enum): self
*
* @psalm-suppress PossiblyUnusedMethod
* @param class-string $enum
* @throws NotSingleBitException
* @throws UnknownEnumException
* @throws UnknownEnumException|NotSingleBitException
*/
public static function none(string $enum): self
{
Expand All @@ -77,8 +74,7 @@ public static function none(string $enum): self
*
* @psalm-suppress PossiblyUnusedMethod
* @param class-string $enum
* @throws NotSingleBitException
* @throws UnknownEnumException
* @throws UnknownEnumException|NotSingleBitException
*/
public static function without(string $enum, UnitEnum ...$bits): self
{
Expand Down

0 comments on commit 45a325f

Please sign in to comment.