Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3752197
D3228.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D3228.diff
View Options
diff --git a/omnitools/src/Booleans/Boolean.php b/omnitools/src/Booleans/Boolean.php
--- a/omnitools/src/Booleans/Boolean.php
+++ b/omnitools/src/Booleans/Boolean.php
@@ -3,7 +3,7 @@
namespace Keruald\OmniTools\Booleans;
-class Boolean {
+readonly class Boolean {
///
/// Properties
@@ -32,43 +32,41 @@
///
public function and (self|bool $other) : self {
- if ($this->value === true) {
- $this->value = self::toScalar($other);
- }
+ $newValue = match($this->value) {
+ true => self::toScalar($other),
+ false => false,
+ };
- return $this;
+ return new self($newValue);
}
public function or (self|bool $other) : self {
- if ($this->value === false) {
- $this->value = self::toScalar($other);
- }
+ $newValue = match($this->value) {
+ true => true,
+ false => self::toScalar($other),
+ };
- return $this;
+ return new self($newValue);
}
public function xor (self|bool $other) : self {
- $this->value = ($this->value xor self::toScalar($other));
+ $newValue = ($this->value xor self::toScalar($other));
- return $this;
+ return new self($newValue);
}
public function not () : self {
- $this->value = !$this->value;
-
- return $this;
+ return new self(!$this->value);
}
public function implication (self|bool $other) : self {
- $this->value = $this->value === false || self::toScalar($other);
+ $newValue = $this->value === false || self::toScalar($other);
- return $this;
+ return new self($newValue);
}
public function equivalence (self|bool $other) : self {
- $this->value = $this->isEqualsTo($other);
-
- return $this;
+ return new self($this->isEqualsTo($other));
}
///
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 18, 16:52 (21 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2250657
Default Alt Text
D3228.diff (1 KB)
Attached To
Mode
D3228: Make Boolean immutable
Attached
Detach File
Event Timeline
Log In to Comment