Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3769047
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/omnitools/src/Booleans/Boolean.php b/omnitools/src/Booleans/Boolean.php
index 5a42405..b038414 100644
--- a/omnitools/src/Booleans/Boolean.php
+++ b/omnitools/src/Booleans/Boolean.php
@@ -1,109 +1,107 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Booleans;
-class Boolean {
+readonly class Boolean {
///
/// Properties
///
private bool $value;
///
/// Constructors
///
public function __construct (bool $value) {
$this->value = $value;
}
public static function true () : self {
return new self(true);
}
public static function false () : self {
return new self(false);
}
///
/// Basic logic operators
///
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));
}
///
/// Comparison
///
public function isEqualsTo (self|bool $other) : bool {
return $this->value === self::toScalar($other);
}
///
/// Type convert
///
public function asBool () : bool {
return $this->value;
}
public function asInteger () : int {
return (int)$this->value;
}
public function asString () : string {
return match ($this->value) {
true => "true",
false => "false",
};
}
public static function toScalar (self|bool $bool) : bool {
if ($bool instanceof self) {
return $bool->value;
}
return (bool)$bool;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 25, 12:19 (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260157
Default Alt Text
(3 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment