From 18cc1cad01b0d60531717bc0302a3e61c3b7dc44 Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Tue, 2 Dec 2025 13:16:02 +0300 Subject: [PATCH] =?UTF-8?q?chore:=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BA=20=D1=82=D0=B8=D0=BF=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Action.php | 6 +++++- src/Excel/Table.php | 10 ++++++---- src/Filter/Login.php | 10 +++++++--- src/Functions.php | 11 ----------- src/Layout/Manager.php | 2 +- src/Process.php | 6 +++--- src/Tools/Drawing.php | 11 +++++++---- src/Tools/TemplateImage.php | 6 +++++- 8 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/Controller/Action.php b/src/Controller/Action.php index e26b41e..fab01da 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -220,7 +220,11 @@ class Action implements ActionInterface * @return mixed */ public function forward($action, HttpRequest $args) { - $value = call_user_func([$this, $action], $args); + $actionFn = [$this, $action]; + if (!is_callable($actionFn)) { + return false; + } + $value = call_user_func($actionFn, $args); return $value; } diff --git a/src/Excel/Table.php b/src/Excel/Table.php index b6c7977..395253e 100644 --- a/src/Excel/Table.php +++ b/src/Excel/Table.php @@ -118,7 +118,7 @@ class Table /** * Устанавливает высоту ряда * @param int $row Номер ряда - * @param numeric $value Высота ряда + * @param int $value Высота ряда */ function setRowHeight (int $row, $value): void { @@ -187,8 +187,9 @@ class Table */ function getRows() { + // Высчитываем максимальный индекс, массив может быть разрежен поэтому используем array_keys $keys = array_keys($this->rows); - return max($keys); + return $keys === [] ? 0 : max($keys); } /** @@ -199,7 +200,7 @@ class Table function getRowCells(TableRow $row) { $keys = array_keys($row->cells); - return max($keys); + return $keys === [] ? 0 :max($keys); } /** @@ -225,7 +226,8 @@ class Table * @return int */ function getColumns() { - return max(array_map([$this, 'getRowCells'], $this->rows)); + $columns = array_map($this->getRowCells(...), $this->rows); + return $columns === [] ? 0 : max($columns); } /** diff --git a/src/Filter/Login.php b/src/Filter/Login.php index d5195cb..93df732 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -205,11 +205,15 @@ class Login extends Filter $action = $request->get('action'); $moduleDir = explode('\\',$module)[0]; + // TODO: Параметр для белого списка перенести в install.json $file = Path::join($this->config->get('system', 'path'), 'modules', $moduleDir, 'filters', 'white.json'); if (file_exists($file)) { - $whiteList = json_decode(file_get_contents($file), true); - - if (in_array($action, $whiteList)) { + $text = file_get_contents($file); + if (!$text) { + return false; + } + $whiteList = json_decode($text, true); + if (is_array($whiteList) && in_array($action, $whiteList, true)) { return true; } } diff --git a/src/Functions.php b/src/Functions.php index 3e040c4..1d7dd87 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -233,17 +233,6 @@ class Functions { return ($a[$key] < $b[$key]) ? -1 : 1; } - /** - * @deprecated - * @param string $name Метод - * @param object $o - * - * @return mixed - */ - static function __self($name, $o) { - return call_user_func([$o, $name]); - } - /** * @param string ...$args * @return string diff --git a/src/Layout/Manager.php b/src/Layout/Manager.php index 45098d6..26537b0 100644 --- a/src/Layout/Manager.php +++ b/src/Layout/Manager.php @@ -56,7 +56,7 @@ class Manager extends Filter /** * @param HttpRequest $request - * @param array $get + * @param array|true $get * @return bool */ public function checkXHR($request, $get): bool diff --git a/src/Process.php b/src/Process.php index e0c9473..ce1c177 100644 --- a/src/Process.php +++ b/src/Process.php @@ -8,13 +8,13 @@ namespace ctiso; * @param string $delimiter * @param string $enclosure * @param string $escape - * @return array + * @return array|false */ function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") { $fiveMBs = 1024; $fp = fopen("php://temp/maxmemory:$fiveMBs", 'r+'); - $data = ''; + $data = []; if (is_resource($fp)) { fputs($fp, $input); rewind($fp); @@ -41,7 +41,7 @@ function process_exists($pid) foreach ($processes as $process) { if ($process != "") { $csv = str_getcsv($process); - if ($pid == $csv[1]) return true; + if ($csv && $pid == $csv[1]) return true; } } return false; diff --git a/src/Tools/Drawing.php b/src/Tools/Drawing.php index d950481..8a7568e 100644 --- a/src/Tools/Drawing.php +++ b/src/Tools/Drawing.php @@ -18,17 +18,20 @@ class Drawing * @param int $top * @param int $width * @param int $height - * @param list $rgb + * @param list> $rgb */ static function drawRectangle(GdImage &$image, int $left, int $top, int $width, int $height, array $rgb): void { $color = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]); + if ($color === false) { + throw new \RuntimeException("Can't allocate color"); + } $right = $left + $width; $bottom = $top + $height; - imageline($image, $left, $top, $right, $top, $color); - imageline($image, $right, $top, $right, $bottom, $color); + imageline($image, $left, $top, $right, $top, $color); + imageline($image, $right, $top, $right, $bottom, $color); imageline($image, $left, $bottom, $right, $bottom, $color); - imageline($image, $left, $top, $left, $bottom, $color); + imageline($image, $left, $top, $left, $bottom, $color); } /** diff --git a/src/Tools/TemplateImage.php b/src/Tools/TemplateImage.php index a076a02..690a4a4 100644 --- a/src/Tools/TemplateImage.php +++ b/src/Tools/TemplateImage.php @@ -106,7 +106,11 @@ class TemplateImage { $suffix = pathinfo($file, PATHINFO_EXTENSION); if (array_key_exists($suffix, self::$listfiles)) { - return call_user_func('imagecreatefrom' . self::$listfiles[$suffix], $file); + $imageFn = 'imagecreatefrom' . self::$listfiles[$suffix]; + if (!is_callable($imageFn)) { + return null; + } + return call_user_func($imageFn, $file); } return null; }