Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
101 lines
2.7 KiB
PHP
101 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace CBOR;
|
|
|
|
use Brick\Math\BigInteger;
|
|
use InvalidArgumentException;
|
|
|
|
final class NegativeIntegerObject extends AbstractCBORObject implements Normalizable
|
|
{
|
|
use IntegerPayloadTrait;
|
|
|
|
private const MAJOR_TYPE = self::MAJOR_TYPE_NEGATIVE_INTEGER;
|
|
|
|
public function __construct(
|
|
int $additionalInformation,
|
|
private ?string $data
|
|
) {
|
|
parent::__construct(self::MAJOR_TYPE, $additionalInformation);
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
$result = parent::__toString();
|
|
if ($this->data !== null) {
|
|
$result .= $this->data;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
public static function createObjectForValue(int $additionalInformation, ?string $data): self
|
|
{
|
|
return new self($additionalInformation, $data);
|
|
}
|
|
|
|
public static function create(int $value): self
|
|
{
|
|
if ($value >= 0) {
|
|
throw new InvalidArgumentException('The value must be a negative integer.');
|
|
}
|
|
|
|
// Exact for every negative PHP integer: -1 - PHP_INT_MIN is PHP_INT_MAX, so the argument never overflows.
|
|
[$additionalInformation, $data] = self::payloadForInt(-1 - $value);
|
|
|
|
return new self($additionalInformation, $data);
|
|
}
|
|
|
|
public static function createFromString(string $value): self
|
|
{
|
|
$integer = BigInteger::of($value);
|
|
|
|
return self::createBigInteger($integer);
|
|
}
|
|
|
|
/**
|
|
* @return numeric-string
|
|
*/
|
|
public function getValue(): string
|
|
{
|
|
if ($this->data === null) {
|
|
return (string) (-1 - $this->additionalInformation);
|
|
}
|
|
|
|
$argument = self::argumentFromPayload($this->data);
|
|
if ($argument >= 0) {
|
|
return (string) (-1 - $argument);
|
|
}
|
|
|
|
return BigInteger::of(-1)->minus(Utils::binToBigInteger($this->data))
|
|
->toBase(10)
|
|
;
|
|
}
|
|
|
|
/**
|
|
* @return numeric-string
|
|
*/
|
|
public function normalize(): string
|
|
{
|
|
return $this->getValue();
|
|
}
|
|
|
|
private static function createBigInteger(BigInteger $integer): self
|
|
{
|
|
if ($integer->isGreaterThanOrEqualTo(BigInteger::zero())) {
|
|
throw new InvalidArgumentException('The value must be a negative integer.');
|
|
}
|
|
|
|
$argument = BigInteger::of(-1)->minus($integer);
|
|
if ($argument->isGreaterThan(self::maximumArgument())) {
|
|
throw new InvalidArgumentException(
|
|
'Out of range. Please use NegativeBigIntegerTag tag with ByteStringObject object instead.'
|
|
);
|
|
}
|
|
|
|
[$additionalInformation, $data] = self::payloadForBigInteger($argument);
|
|
|
|
return new self($additionalInformation, $data);
|
|
}
|
|
}
|