Skip to content

Commit

Permalink
Merge branch 'hotfix/v2.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanmade committed Nov 28, 2021
2 parents e8a1abb + 6f09799 commit a31b521
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Updated after reading this blog post: https://aaronfrancis.com/2021/bitmasking-i
I just used it in Laravel so far, but you should be able to use it anywhere else with minor modifications.

## PHP Version
Version v2.* requires PHP 8+. If you're stuck to an older version, please use v1.*
Version v2.* requires PHP 7.4+. If you're stuck to an older version, please use v1.*

## Installation

Expand Down Expand Up @@ -89,20 +89,14 @@ Maybe you want to define that in a constant or variable.

To make your life easier, I recommend to use custom getters and setters.
```php

/**
* @param bool $sent
* @return bool
*/
public function setSentAttribute($sent = true)
public function setSentAttribute($sent = true): self
{
return $this->setFlag('status', self::MESSAGE_SENT, $sent);
$this->setFlag('status', self::MESSAGE_SENT, $sent);

return $this;
}

/**
* @return bool
*/
public function getSentAttribute()
public function getSentAttribute(): bool
{
return $this->getFlag('status', self::MESSAGE_SENT);
}
Expand Down
10 changes: 5 additions & 5 deletions src/BitwiseFlagTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ protected function getFlag(string $name, int $flag): bool
return ($this->$name & $flag) === $flag;
}

protected function setFlag(string $name, int $flag, bool $value): self
protected function setFlag(string $name, int $flag, bool $value): bool
{
if ($value) {
$this->$name |= $flag;
} else {
$this->$name &= ~$flag;
}
return $this;

return ($this->$name & $flag) === $flag;
}

protected function toggleFlag(string $name, int $flag): self
protected function toggleFlag(string $name, int $flag): bool
{
$this->$name ^= $flag;

return $this;
return $this->getFlag($name, $flag);
}
}

0 comments on commit a31b521

Please sign in to comment.