mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
Add isNegative() to the Type\NumberInterface
This commit is contained in:
@@ -37,6 +37,11 @@ final class Decimal implements NumberInterface
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isNegative = false;
|
||||
|
||||
/**
|
||||
* @param mixed $value The decimal value to store
|
||||
*/
|
||||
@@ -61,9 +66,18 @@ final class Decimal implements NumberInterface
|
||||
$value = '0';
|
||||
}
|
||||
|
||||
if (strpos($value, '-') === 0) {
|
||||
$this->isNegative = true;
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function isNegative(): bool
|
||||
{
|
||||
return $this->isNegative;
|
||||
}
|
||||
|
||||
public function toString(): string
|
||||
{
|
||||
return $this->value;
|
||||
|
||||
@@ -40,6 +40,11 @@ final class Integer implements NumberInterface
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isNegative = false;
|
||||
|
||||
/**
|
||||
* @param mixed $value The integer value to store
|
||||
*/
|
||||
@@ -72,11 +77,17 @@ final class Integer implements NumberInterface
|
||||
// Add the negative sign back to the value.
|
||||
if ($sign === '-' && $value !== '0') {
|
||||
$value = $sign . $value;
|
||||
$this->isNegative = true;
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function isNegative(): bool
|
||||
{
|
||||
return $this->isNegative;
|
||||
}
|
||||
|
||||
public function toString(): string
|
||||
{
|
||||
return $this->value;
|
||||
|
||||
@@ -21,4 +21,8 @@ namespace Ramsey\Uuid\Type;
|
||||
*/
|
||||
interface NumberInterface extends TypeInterface
|
||||
{
|
||||
/**
|
||||
* Returns true if this number is less than zero
|
||||
*/
|
||||
public function isNegative(): bool;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user