Up min PHP version from 7.3 to 8.0 - 3

This commit is contained in:
Visman 2023-04-28 10:58:24 +07:00
parent a191fbf789
commit 7c7e1a097f
18 changed files with 31 additions and 42 deletions

View file

@ -213,7 +213,7 @@ class FileCache implements CacheInterface
if (! \preg_match('%^[a-z0-9_\.]+$%Di', $key)) {
throw new InvalidArgumentException('Key is not a legal value');
}
if ('poll' == \substr($key, 0, 4)) {
if (\str_starts_with($key, 'poll')) {
return $this->cacheDir . "/polls/{$key}.php";
} else {
return $this->cacheDir . "/cache_{$key}.php";

View file

@ -339,9 +339,7 @@ class Config
$config[] = [];
$config = &$config[\array_key_last($config)];
} else {
if (! isset($config[$key])) {
$config[$key] = [];
}
$config[$key] ??= [];
if ($this->isFormat($config[$key])) {
$config = &$config[$key]['value'];

View file

@ -237,11 +237,9 @@ class DB
throw new PDOException("Expected array: key='{$key}', type='{$type}'");
}
if (! isset($map[$key])) {
$map[$key] = [$type];
}
$map[$key] ??= [$type];
$res = [];
$res = [];
foreach ($value as $val) {
$name = ':' . $idxOut++;
$res[] = $name;

View file

@ -179,10 +179,7 @@ abstract class AbstractStatement extends DBStatement
\array_shift($data);;
}
if (! isset($result[$key])) {
$result[$key] = [];
}
$result[$key] ??= [];
$result[$key][] = $data;
}

View file

@ -70,7 +70,7 @@ class Mysql
*/
protected function tName(string $name): string
{
if ('::' === \substr($name, 0, 2)) {
if (\str_starts_with($name, '::')) {
$name = $this->dbPrefix . \substr($name, 2);
}

View file

@ -77,7 +77,7 @@ class Pgsql
*/
protected function tName(string $name): string
{
if ('::' === \substr($name, 0, 2)) {
if (\str_starts_with($name, '::')) {
$name = $this->dbPrefix . \substr($name, 2);
}

View file

@ -76,7 +76,7 @@ class Sqlite
*/
protected function tName(string $name): string
{
if ('::' === \substr($name, 0, 2)) {
if (\str_starts_with($name, '::')) {
$name = $this->dbPrefix . \substr($name, 2);
}

View file

@ -124,7 +124,7 @@ class Log implements LoggerInterface
if (true === $ext) {
foreach ($_SERVER as $key => $value) {
if (
'HTTP_' === \substr($key, 0, 5)
\str_starts_with($key, 'HTTP_')
&& 'HTTP_USER_AGENT' !== $key
&& 'HTTP_COOKIE' !== $key
) {

View file

@ -173,10 +173,10 @@ class Mail
/**
* Добавляет заголовок To
*/
public function addTo(/* array|string */ $email, string $name = null): Mail
public function addTo(string|array $email, string $name = null): Mail
{
if (! \is_array($email)) {
$email = \preg_split('%[,\n\r]%', (string) $email, -1, \PREG_SPLIT_NO_EMPTY);
$email = \preg_split('%[,\n\r]%', $email, -1, \PREG_SPLIT_NO_EMPTY);
}
foreach ($email as $cur) {

View file

@ -37,7 +37,7 @@ class View extends Dirk
*/
protected function compileTransformations(string $value): string
{
if ('<?xml ' === \substr($value, 0, 6)) {
if (\str_starts_with($value, '<?xml ')) {
$value = \str_replace(' \\ENT_HTML5 | \\ENT_QUOTES | \\ENT_SUBSTITUTE,', ' \\ENT_XML1,', $value);
}

View file

@ -93,7 +93,7 @@ class DataModel extends Model
public function __set(string $name, mixed $value): void
{
// без отслеживания
if (0 === \strpos($name, '__')) {
if (\str_starts_with($name, '__')) {
$track = null;
$name = \substr($name, 2);
// с отслеживанием
@ -149,7 +149,7 @@ class DataModel extends Model
public function __get(string $name): mixed
{
// без вычисления
if (0 === \strpos($name, '__')) {
if (\str_starts_with($name, '__')) {
return $this->getAttr(\substr($name, 2));
// с вычислениями
} else {

View file

@ -28,14 +28,15 @@ class Forum extends DataModel
*/
protected function getparent(): ?Forum
{
if (
null === $this->parent_forum_id
&& 0 !== $this->id
) {
throw new RuntimeException('Parent is not defined');
}
if (null === $this->parent_forum_id) {
if (0 !== $this->id) {
throw new RuntimeException('Parent is not defined');
}
return $this->c->forums->get($this->parent_forum_id);
return null;
} else {
return $this->c->forums->get($this->parent_forum_id);
}
}
/**

View file

@ -83,7 +83,7 @@ class Forums extends Manager
/**
* Получение модели раздела
*/
public function get($id): ?Forum
public function get(int|string $id): ?Forum
{
$forum = parent::get($id);

View file

@ -121,7 +121,7 @@ class Model
} elseif (\array_key_exists($name, $this->zAttrs)) {
return $this->zAttrs[$name];
} elseif (
0 === \strpos($name, 'censor')
\str_starts_with($name, 'censor')
&& isset($this->zAttrs[$root = \lcfirst(\substr($name, 6))])
) {
return $this->zAttrsCalc[$name] = $this->c->censorship->censor($this->zAttrs[$root]);

View file

@ -361,7 +361,7 @@ abstract class Page extends Model
{
$key = \strtolower($header);
if ('http/' === \substr($key, 0, 5)) {
if (\str_starts_with($key, 'http/')) {
$key = 'http/';
$replace = true;

View file

@ -656,16 +656,11 @@ class BBCode extends Parser
/**
* Формирует данные для формы
*/
protected function formEditSub(
/* mixed */ $data,
string $name,
string $class,
/* string|array */ $legend,
/* string|array */ $info
): array {
protected function formEditSub(mixed $data, string $name, string $class, string|array $legend, string|array $info): array
{
$yn = [1 => __('Yes'), 0 => __('No')];
$fields = [];
$other = '_attr' !== \substr($name, -5);
$other = \str_ends_with($name, '_attr');
$key = $other ? "other_attrs[{$name}]" : $name;
if ('new_attr' === $name) {

View file

@ -275,7 +275,7 @@ class Update extends Admin
{
$this->okPass = true;
if (\substr($this->c->DB_DSN, 0, 6) === 'sqlite') {
if (\str_starts_with($this->c->DB_DSN, 'sqlite')) {
if (! \hash_equals($this->c->DB_DSN, "sqlite:{$dbpass}")) {
$this->okPass = false;

View file

@ -165,8 +165,8 @@ class Current extends Action
if (
0 === $status
&& 0 !== \substr_compare('Mozilla/', $agent, 0, 8)
&& 0 !== \substr_compare('Opera/', $agent, 0, 6)
&& ! \str_starts_with($agent, 'Mozilla/')
&& ! \str_starts_with($agent, 'Opera/')
) {
$status = 1;
}