Skip to content

Commit 6f09799

Browse files
committed
📝 Fixed wrong PHP requirement in readme
📝 Improved examples in readme 💥 Changed return values of trait methods (makes more sense to me like this)
1 parent e8a1abb commit 6f09799

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Updated after reading this blog post: https://aaronfrancis.com/2021/bitmasking-i
77
I just used it in Laravel so far, but you should be able to use it anywhere else with minor modifications.
88

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

1212
## Installation
1313

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

9090
To make your life easier, I recommend to use custom getters and setters.
9191
```php
92-
93-
/**
94-
* @param bool $sent
95-
* @return bool
96-
*/
97-
public function setSentAttribute($sent = true)
92+
public function setSentAttribute($sent = true): self
9893
{
99-
return $this->setFlag('status', self::MESSAGE_SENT, $sent);
94+
$this->setFlag('status', self::MESSAGE_SENT, $sent);
95+
96+
return $this;
10097
}
10198

102-
/**
103-
* @return bool
104-
*/
105-
public function getSentAttribute()
99+
public function getSentAttribute(): bool
106100
{
107101
return $this->getFlag('status', self::MESSAGE_SENT);
108102
}

src/BitwiseFlagTrait.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ protected function getFlag(string $name, int $flag): bool
1515
return ($this->$name & $flag) === $flag;
1616
}
1717

18-
protected function setFlag(string $name, int $flag, bool $value): self
18+
protected function setFlag(string $name, int $flag, bool $value): bool
1919
{
2020
if ($value) {
2121
$this->$name |= $flag;
2222
} else {
2323
$this->$name &= ~$flag;
2424
}
25-
26-
return $this;
25+
26+
return ($this->$name & $flag) === $flag;
2727
}
2828

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

33-
return $this;
33+
return $this->getFlag($name, $flag);
3434
}
3535
}

0 commit comments

Comments
 (0)