Files
FreshRSS/cli/i18n/I18nValue.php
Alexandre Alapetite a81656c3ed Upgrade to PHP 8.1 (#6711)
* Upgrade to PHP 8.1
As discussed in https://github.com/FreshRSS/FreshRSS/discussions/5474

https://www.php.net/releases/8.0/en.php
https://www.php.net/releases/8.1/en.php

Upgrade to available native type declarations
https://php.net/language.types.declarations

Upgrade to https://phpunit.de/announcements/phpunit-10.html which requires PHP 8.1+ (good timing, as version 9 was not maintained anymore)

Upgrade `:oldest` Docker dev image to oldest Alpine version supporting PHP 8.1: Alpine 3.16, which includes PHP 8.1.22.

* Include 6736
https://github.com/FreshRSS/FreshRSS/pull/6736
2024-09-06 09:06:46 +02:00

82 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
class I18nValue {
private const STATE_DIRTY = 'dirty';
public const STATE_IGNORE = 'ignore';
private const STATE_TODO = 'todo';
private const STATES = [
self::STATE_DIRTY,
self::STATE_IGNORE,
self::STATE_TODO,
];
private string $value;
private ?string $state = null;
/** @param I18nValue|string $data */
public function __construct($data) {
if ($data instanceof I18nValue) {
$data = $data->__toString();
}
$data = explode(' -> ', $data);
$this->value = (string)(array_shift($data) ?? '');
if (count($data) === 0) {
return;
}
$state = array_shift($data);
if (in_array($state, self::STATES, true)) {
$this->state = $state;
}
}
public function __clone(): void {
$this->markAsTodo();
}
public function equal(I18nValue $value): bool {
return $this->value === $value->getValue();
}
public function isIgnore(): bool {
return $this->state === self::STATE_IGNORE;
}
public function isTodo(): bool {
return $this->state === self::STATE_TODO;
}
public function markAsDirty(): void {
$this->state = self::STATE_DIRTY;
}
public function markAsIgnore(): void {
$this->state = self::STATE_IGNORE;
}
public function markAsTodo(): void {
$this->state = self::STATE_TODO;
}
public function unmarkAsIgnore(): void {
if ($this->state === self::STATE_IGNORE) {
$this->state = null;
}
}
#[\Override]
public function __toString(): string {
if ($this->state === null) {
return $this->value;
}
return "{$this->value} -> {$this->state}";
}
public function getValue(): string {
return $this->value;
}
}