chore: Проверки к типам

This commit is contained in:
origami11@yandex.ru 2025-12-02 13:16:02 +03:00
parent 8786e84568
commit 18cc1cad01
8 changed files with 34 additions and 28 deletions

View file

@ -220,7 +220,11 @@ class Action implements ActionInterface
* @return mixed * @return mixed
*/ */
public function forward($action, HttpRequest $args) { 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; return $value;
} }

View file

@ -118,7 +118,7 @@ class Table
/** /**
* Устанавливает высоту ряда * Устанавливает высоту ряда
* @param int $row Номер ряда * @param int $row Номер ряда
* @param numeric $value Высота ряда * @param int $value Высота ряда
*/ */
function setRowHeight (int $row, $value): void function setRowHeight (int $row, $value): void
{ {
@ -187,8 +187,9 @@ class Table
*/ */
function getRows() function getRows()
{ {
// Высчитываем максимальный индекс, массив может быть разрежен поэтому используем array_keys
$keys = array_keys($this->rows); $keys = array_keys($this->rows);
return max($keys); return $keys === [] ? 0 : max($keys);
} }
/** /**
@ -199,7 +200,7 @@ class Table
function getRowCells(TableRow $row) function getRowCells(TableRow $row)
{ {
$keys = array_keys($row->cells); $keys = array_keys($row->cells);
return max($keys); return $keys === [] ? 0 :max($keys);
} }
/** /**
@ -225,7 +226,8 @@ class Table
* @return int * @return int
*/ */
function getColumns() { function getColumns() {
return max(array_map([$this, 'getRowCells'], $this->rows)); $columns = array_map($this->getRowCells(...), $this->rows);
return $columns === [] ? 0 : max($columns);
} }
/** /**

View file

@ -205,11 +205,15 @@ class Login extends Filter
$action = $request->get('action'); $action = $request->get('action');
$moduleDir = explode('\\',$module)[0]; $moduleDir = explode('\\',$module)[0];
// TODO: Параметр для белого списка перенести в install.json
$file = Path::join($this->config->get('system', 'path'), 'modules', $moduleDir, 'filters', 'white.json'); $file = Path::join($this->config->get('system', 'path'), 'modules', $moduleDir, 'filters', 'white.json');
if (file_exists($file)) { if (file_exists($file)) {
$whiteList = json_decode(file_get_contents($file), true); $text = file_get_contents($file);
if (!$text) {
if (in_array($action, $whiteList)) { return false;
}
$whiteList = json_decode($text, true);
if (is_array($whiteList) && in_array($action, $whiteList, true)) {
return true; return true;
} }
} }

View file

@ -233,17 +233,6 @@ class Functions {
return ($a[$key] < $b[$key]) ? -1 : 1; 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 * @param string ...$args
* @return string * @return string

View file

@ -56,7 +56,7 @@ class Manager extends Filter
/** /**
* @param HttpRequest $request * @param HttpRequest $request
* @param array $get * @param array|true $get
* @return bool * @return bool
*/ */
public function checkXHR($request, $get): bool public function checkXHR($request, $get): bool

View file

@ -8,13 +8,13 @@ namespace ctiso;
* @param string $delimiter * @param string $delimiter
* @param string $enclosure * @param string $enclosure
* @param string $escape * @param string $escape
* @return array * @return array|false
*/ */
function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\")
{ {
$fiveMBs = 1024; $fiveMBs = 1024;
$fp = fopen("php://temp/maxmemory:$fiveMBs", 'r+'); $fp = fopen("php://temp/maxmemory:$fiveMBs", 'r+');
$data = ''; $data = [];
if (is_resource($fp)) { if (is_resource($fp)) {
fputs($fp, $input); fputs($fp, $input);
rewind($fp); rewind($fp);
@ -41,7 +41,7 @@ function process_exists($pid)
foreach ($processes as $process) { foreach ($processes as $process) {
if ($process != "") { if ($process != "") {
$csv = str_getcsv($process); $csv = str_getcsv($process);
if ($pid == $csv[1]) return true; if ($csv && $pid == $csv[1]) return true;
} }
} }
return false; return false;

View file

@ -18,11 +18,14 @@ class Drawing
* @param int $top * @param int $top
* @param int $width * @param int $width
* @param int $height * @param int $height
* @param list<int> $rgb * @param list<int<0, 255>> $rgb
*/ */
static function drawRectangle(GdImage &$image, int $left, int $top, int $width, int $height, array $rgb): void 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]); $color = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);
if ($color === false) {
throw new \RuntimeException("Can't allocate color");
}
$right = $left + $width; $right = $left + $width;
$bottom = $top + $height; $bottom = $top + $height;
imageline($image, $left, $top, $right, $top, $color); imageline($image, $left, $top, $right, $top, $color);

View file

@ -106,7 +106,11 @@ class TemplateImage
{ {
$suffix = pathinfo($file, PATHINFO_EXTENSION); $suffix = pathinfo($file, PATHINFO_EXTENSION);
if (array_key_exists($suffix, self::$listfiles)) { 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; return null;
} }