Browse Source

Up min PHP version from 7.3 to 8.0 - 3

Visman 2 years ago
parent
commit
7c7e1a097f

+ 1 - 1
app/Core/Cache/FileCache.php

@@ -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";

+ 1 - 3
app/Core/Config.php

@@ -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'];

+ 2 - 4
app/Core/DB.php

@@ -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;

+ 1 - 4
app/Core/DB/AbstractStatement.php

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

+ 1 - 1
app/Core/DB/Mysql.php

@@ -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);
         }
 

+ 1 - 1
app/Core/DB/Pgsql.php

@@ -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);
         }
 

+ 1 - 1
app/Core/DB/Sqlite.php

@@ -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);
         }
 

+ 1 - 1
app/Core/Log.php

@@ -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
                 ) {

+ 2 - 2
app/Core/Mail.php

@@ -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) {

+ 1 - 1
app/Core/View.php

@@ -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);
         }
 

+ 2 - 2
app/Models/DataModel.php

@@ -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 {

+ 8 - 7
app/Models/Forum/Forum.php

@@ -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);
+        }
     }
 
     /**

+ 1 - 1
app/Models/Forum/Forums.php

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

+ 1 - 1
app/Models/Model.php

@@ -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]);

+ 1 - 1
app/Models/Page.php

@@ -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;
 

+ 3 - 8
app/Models/Pages/Admin/Parser/BBCode.php

@@ -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) {

+ 1 - 1
app/Models/Pages/Admin/Update.php

@@ -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;
 

+ 2 - 2
app/Models/User/Current.php

@@ -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;
         }