From f964472e628cc91d01cce2e3e379367557275e62 Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Thu, 30 Oct 2025 12:59:36 +0300 Subject: [PATCH] =?UTF-8?q?chore:=20=D0=90=D0=BD=D0=BD=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=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/Collection.php | 3 ++ src/Connection/HttpRequest.php | 5 +-- src/Connection/HttpResponse.php | 3 ++ src/Controller/Action.php | 5 +-- src/Controller/Component.php | 17 ++++++++-- src/Controller/Service.php | 3 ++ src/Database.php | 2 +- src/Excel/Table.php | 3 ++ src/Filter/ActionAccess.php | 10 ++++-- src/Filter/Login.php | 5 ++- src/Form/Field.php | 2 ++ src/Form/Form.php | 2 ++ src/Functions.php | 3 ++ src/Layout/Manager.php | 5 ++- src/Mail.php | 9 ++++-- src/Path.php | 7 +++-- src/Registry.php | 5 +++ src/Role/User.php | 2 +- src/Settings.php | 12 ++++++++ src/Setup.php | 5 +++ src/SortRecord.php | 2 +- src/Tools/SQLStatementExtractor.php | 5 +++ src/Tools/TemplateImage.php | 48 ++++++++++++++++++++--------- src/Validator/Rule/AbstractRule.php | 4 +++ src/Validator/Rule/Count.php | 4 +++ src/Validator/Rule/MatchRule.php | 1 + src/Validator/Validator.php | 2 +- src/View/View.php | 2 +- 28 files changed, 140 insertions(+), 36 deletions(-) diff --git a/src/Collection.php b/src/Collection.php index ca5e3ae..1740ade 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -14,6 +14,7 @@ class Collection implements \ArrayAccess * Преобразование массива в коллекцию * * @param array $data + * @return bool */ public function import(array $data) { @@ -23,6 +24,8 @@ class Collection implements \ArrayAccess /** * Преобразование коллекции в массив + * + * @return array */ public function export() { diff --git a/src/Connection/HttpRequest.php b/src/Connection/HttpRequest.php index c255f77..5c71f1d 100644 --- a/src/Connection/HttpRequest.php +++ b/src/Connection/HttpRequest.php @@ -52,7 +52,7 @@ class HttpRequest * @param string $name * @param string $value */ - public function setParameter($name, $value) + public function setParameter($name, $value): void { $this->param[$name] = $value; } @@ -93,6 +93,7 @@ class HttpRequest /** * Посылает запрос и возвращает страницу + * @return string|null */ public function getPage() { @@ -105,7 +106,7 @@ class HttpRequest $header = $this->getHeader(); fwrite($socket, $header); - $result = null; + $result = ''; while (! feof($socket)) { $result .= fgets($socket, 128); } diff --git a/src/Connection/HttpResponse.php b/src/Connection/HttpResponse.php index d3cf5ac..9f0fe69 100644 --- a/src/Connection/HttpResponse.php +++ b/src/Connection/HttpResponse.php @@ -20,6 +20,9 @@ class HttpResponse /** @var string */ public $data; + /** + * @param string $response HTTP ответ + */ public function __construct($response) { $this->offset = 0; diff --git a/src/Controller/Action.php b/src/Controller/Action.php index dcb69fe..514b8cd 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -53,6 +53,7 @@ class Action implements ActionInterface // Для Widgets public $view = null; + public array $childNodes = []; public array $ctrlValues = []; public array $childViews = []; @@ -61,7 +62,7 @@ class Action implements ActionInterface $this->part = new Url(); } - public function setUp() { + public function setUp(): void { } /** @@ -338,7 +339,7 @@ class Action implements ActionInterface /** * Загрузка настроек - * @param $path + * @param string $path * @return array */ public function loadSettings($path) diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 6cd5c66..a6e0e4d 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -13,6 +13,7 @@ use ctiso\Database; use ctiso\Collection; use ctiso\Registry; use ctiso\Controller\SiteInterface; +use ctiso\Database\PDOStatement; use PHPTAL; use PHPTAL_PreFilter_Normalize; @@ -249,7 +250,8 @@ class Component /** * @param string $key * @param string $val - * @param $res + * @param PDOStatement $res + * @return array{value: string, name: string}[] */ public function options(string $key, string $val, $res) { $result = []; @@ -262,7 +264,7 @@ class Component /** * @param array $list * @param bool $selected - * @return array + * @return array{value: string, name: string, selected: bool}[] */ public function optionsPair(array $list, $selected = false) { $result = []; @@ -288,6 +290,10 @@ class Component return null; } + /** + * Получить информацию о параметрах + * @return array + */ function getInfo() { $filename = Path::join($this->viewPath[count($this->viewPath) - 1], 'install.json'); if (file_exists($filename)) { @@ -502,4 +508,11 @@ class Component return null; } + /** + * @param HttpRequest $request + * @return array + */ + function getDefaultPageEnvironment($request) { + return []; + } } diff --git a/src/Controller/Service.php b/src/Controller/Service.php index 923b4ad..47607a9 100644 --- a/src/Controller/Service.php +++ b/src/Controller/Service.php @@ -98,6 +98,9 @@ class Service return $result; } + /** + * @return array + */ function getInfo() { $filename = Path::join($this->viewPath[0], 'install.json'); if (file_exists($filename)) { diff --git a/src/Database.php b/src/Database.php index 194d3b4..5de9e52 100644 --- a/src/Database.php +++ b/src/Database.php @@ -216,7 +216,7 @@ namespace ctiso { * @param array $values - значения * @param string $cond - условие */ - function updateQuery($table, array $values, $cond) + function updateQuery($table, array $values, $cond): void { $prep = $this->prepareValues($values); $sql = "UPDATE $table SET " . implode( diff --git a/src/Excel/Table.php b/src/Excel/Table.php index 3009c64..2e8b7c4 100644 --- a/src/Excel/Table.php +++ b/src/Excel/Table.php @@ -16,6 +16,9 @@ class TableCell public $value; public $merge = false; + /** + * @param string $value Значение клетки + */ function __construct ($value) { $this->value = $value; diff --git a/src/Filter/ActionAccess.php b/src/Filter/ActionAccess.php index db82044..6dd44c3 100644 --- a/src/Filter/ActionAccess.php +++ b/src/Filter/ActionAccess.php @@ -4,9 +4,9 @@ * Фильтр действий */ namespace ctiso\Filter; -use ctiso\Filter\UserAccess, - ctiso\HttpRequest, - ctiso\Role\User; + +use ctiso\HttpRequest; +use ctiso\Role\User; class ActionAccess { @@ -39,6 +39,10 @@ class ActionAccess return (!isset($this->access[$action]) || in_array($this->user->access, $this->access[$action])); } + /** + * @param HttpRequest $request + * @return mixed + */ function execute(HttpRequest $request) { $action = $request->getAction(); if(! $this->checkAction($action)) { diff --git a/src/Filter/Login.php b/src/Filter/Login.php index d023db0..f2d0c4f 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -145,7 +145,10 @@ class Login extends Filter $_SESSION["time"] = time(); } - public function execute(HttpRequest $request): string + /** + * @return mixed + */ + public function execute(HttpRequest $request): mixed { $logged = $this->isLoggin($request); if ($request->get('action') == 'user_access') { diff --git a/src/Form/Field.php b/src/Form/Field.php index 30daf90..f7ae6f9 100644 --- a/src/Form/Field.php +++ b/src/Form/Field.php @@ -13,11 +13,13 @@ class Field /** @var string */ public $label; // Метка поля + /** @var mixed */ public $value; // Значение поля /** @var string */ public $type = ""; // Каждому типу элемента соответствует макрос TAL /** @var ?string */ public $error_msg = null; + /** @var ?mixed */ public $default = null; /** @var bool */ public $error = false; diff --git a/src/Form/Form.php b/src/Form/Form.php index d072288..4d0704f 100644 --- a/src/Form/Form.php +++ b/src/Form/Form.php @@ -28,7 +28,9 @@ class Form { /** @var string */ public $header; + /** @var array */ protected $replace; + /** @var array */ protected $before; /** @var array */ diff --git a/src/Functions.php b/src/Functions.php index 812175f..64fd100 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -289,6 +289,7 @@ class Functions { * @param string $key * @param string $value * @param list>|\ArrayIterator $array + * @return array */ static function assoc_key_values($key, $value, $array) { $result = []; @@ -301,6 +302,7 @@ class Functions { /** * @param string $key * @param list>|\ArrayIterator $array + * @return array */ static function assoc_key($key, $array) { $result = []; @@ -450,6 +452,7 @@ class Functions { * Сортировка двумерного массива по заданному ключу * @param array $array Массив * @param string $key Имя ключа по значению которого будет идти сравнение + * @param callable $fn Функция сравнения * @return array Отсортированный массив */ static function sortOn($array, $key, $fn = '\\ctiso\\Functions::__cmp') { diff --git a/src/Layout/Manager.php b/src/Layout/Manager.php index a3f9b26..c256afb 100644 --- a/src/Layout/Manager.php +++ b/src/Layout/Manager.php @@ -29,6 +29,8 @@ class Manager extends Filter /** * Условие для аякс запросов. Тоже самое что и addConditionGet но еще проверяется является ли запрос ajax + * @param array|true $get Ассоциативный массив ключей и значений для $_GET + * @param Filter $layout Макет */ public function addConditionXHR($get, Filter $layout): void { @@ -74,8 +76,9 @@ class Manager extends Filter /** * Выбирает и применяет макет для страницы + * @return mixed */ - public function execute(HttpRequest $request): string + public function execute(HttpRequest $request): mixed { foreach ($this->condition as $condition) { if (call_user_func($condition[0], $request)) { diff --git a/src/Mail.php b/src/Mail.php index 697895a..e965dfd 100644 --- a/src/Mail.php +++ b/src/Mail.php @@ -53,18 +53,21 @@ class Mail /** * Установка получателя */ - function to(string $name): void // recipient + function to(string $name): void { $this->_to = $name; } - function replyTo($name): void // recipient + /** + * @param string $name + */ + function replyTo($name): void {} /** * Установка получателей копии */ - function copy(string $name): void // recipient cc + function copy(string $name): void { $this->copy = $name; } diff --git a/src/Path.php b/src/Path.php index 787e2c7..8754f7f 100644 --- a/src/Path.php +++ b/src/Path.php @@ -55,8 +55,8 @@ class Path /** * Базовое имя - * @param $path - * @return mixed + * @param string $path + * @return string */ public static function basename($path) { @@ -120,6 +120,7 @@ class Path * Преобразует строку пути в массив * * @param string $path Путь + * @return array */ public static function listFromString(string $path): array { @@ -129,6 +130,8 @@ class Path /** * Преобразует относительный путь в абсолютный + * @param array $path Путь + * @return array */ public static function optimize($path) // { diff --git a/src/Registry.php b/src/Registry.php index 75924b4..5eda214 100644 --- a/src/Registry.php +++ b/src/Registry.php @@ -40,6 +40,11 @@ class Registry { throw new Exception('Unknown key ' . $ns . '::' . $key); } + /** + * @param string $ns + * @param string $key + * @return mixed|null + */ public function getOpt(string $ns, string $key) { if (isset($this->namespace[$ns]['data'][$key])) { return $this->namespace[$ns]['data'][$key]; diff --git a/src/Role/User.php b/src/Role/User.php index 972f35e..33cbc15 100644 --- a/src/Role/User.php +++ b/src/Role/User.php @@ -26,7 +26,7 @@ class User implements UserInterface $this->groups = $groups; } - public function setDB(Database $db) { + public function setDB(Database $db): void { $this->db = $db; } diff --git a/src/Settings.php b/src/Settings.php index 666532f..54491a9 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -67,6 +67,9 @@ class Settings /** * Запись ключа в реестр (Реестр это многомерный массив) + * @param array $key Путь к значению ключа + * @param mixed $value Значение + * @return void */ public function writeKey(array $key, $value) { @@ -216,10 +219,19 @@ class Settings return isset($this->data[$key]) && $this->data[$key] != '' ? $this->data[$key] : $default; } + /** + * Получение всех данных + * @return array + */ function export() { return $this->data; } + /** + * Импорт данных + * @param array $data Данные + * @return void + */ function import($data) { $this->data = $data; } diff --git a/src/Setup.php b/src/Setup.php index 935dabb..b520bd7 100644 --- a/src/Setup.php +++ b/src/Setup.php @@ -53,6 +53,9 @@ class Setup /** @var string */ public $source; + /** + * @param string $file + */ public function __construct($file) { $this->file = $file; @@ -150,6 +153,7 @@ class Setup * Выполняет список действий если для действия не указан аттрибут when то оно выполняется всегда * * @param string $action специальное действие + * @return void */ function executeActions($action = "install") { @@ -178,6 +182,7 @@ class Setup * dst Новый файл * * @param array{preserve?: string, template: string, src: string, dst: string} $attributes + * @return void */ public function copyFile(array $attributes) { diff --git a/src/SortRecord.php b/src/SortRecord.php index 855c85b..84604ea 100644 --- a/src/SortRecord.php +++ b/src/SortRecord.php @@ -44,7 +44,7 @@ class SortRecord return usort($list, [$this, 'compareKeys']); } - function group(array &$list, string $key, array $types) + function group(array &$list, string $key, array $types): void { $groups = []; foreach ($types as $name) { diff --git a/src/Tools/SQLStatementExtractor.php b/src/Tools/SQLStatementExtractor.php index 7ece534..c022ed8 100644 --- a/src/Tools/SQLStatementExtractor.php +++ b/src/Tools/SQLStatementExtractor.php @@ -34,6 +34,7 @@ use Exception; class SQLStatementExtractor { + /** @var string */ protected static $delimiter = ';'; /** @@ -144,6 +145,10 @@ class SQLStatementExtractor /** * a natural way of getting a subtring, php's circular string buffer and strange * return values suck if you want to program strict as of C or friends + * @param string $string The string to get the substring from. + * @param int $startpos The start position of the substring. + * @param int $endpos The end position of the substring. + * @return string The substring. */ protected static function substring(string $string, int $startpos, int $endpos = -1) { diff --git a/src/Tools/TemplateImage.php b/src/Tools/TemplateImage.php index 5d5bb06..01f3f99 100644 --- a/src/Tools/TemplateImage.php +++ b/src/Tools/TemplateImage.php @@ -3,7 +3,9 @@ /** * Формат для композиции изображений */ + namespace ctiso\Tools; + use ctiso\Tools\Drawing; use GdImage; @@ -27,7 +29,7 @@ class TemplateImage '' => 'arial.ttf', 'dejavu' => 'DejaVuCondensedSerif.ttf', 'dejavubd' => 'DejaVuCondensedSerifBold.ttf', - 'dejavuz' =>'DejaVuCondensedSerifBoldItalic.ttf', + 'dejavuz' => 'DejaVuCondensedSerifBoldItalic.ttf', 'dejavui' => 'DejaVuCondensedSerifItalic.ttf', 'miriad' => 'MyriadPro-Cond.ttf', 'miriadbd' => 'MyriadPro-BoldCond.ttf' @@ -47,7 +49,7 @@ class TemplateImage public string $resource; public string $filename; - function __construct (?array $template = null) + function __construct(?array $template = null) { if ($template) { $this->data = $template; @@ -70,9 +72,13 @@ class TemplateImage $this->base = $path; } + /** + * @param string $name + * @param mixed $value + */ function set(string $name, $value): void { - $this->context['['.$name.']'] = $value; + $this->context['[' . $name . ']'] = $value; } function setImage(string $name): void @@ -107,7 +113,7 @@ class TemplateImage function getFontFile(string $name): string { - if(array_key_exists(strtolower($name), self::$listfonts)) { + if (array_key_exists(strtolower($name), self::$listfonts)) { return $this->base . self::$listfonts[$name]; } return $this->base . 'arial.ttf'; @@ -115,15 +121,15 @@ class TemplateImage function fontSuffix(array $style): string { - if($style[0] && $style[1]) return "z"; + if ($style[0] && $style[1]) return "z"; - if($style[0]) return "bd"; - if($style[1]) return "i"; + if ($style[0]) return "bd"; + if ($style[1]) return "i"; return ""; } - function imageText(string $text, object $value) + function imageText(string $text, object $value): void { $text = strtr($text, $this->context); $size = $value->fontSize; @@ -140,15 +146,26 @@ class TemplateImage if ($value->valign[0]) { $valign = Drawing::ALIGN_TOP; - } elseif ($value->valign[1]) { + } elseif ($value->valign[1]) { $valign = Drawing::ALIGN_CENTER; } else { $valign = Drawing::ALIGN_BOTTOM; } - Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text, - $value->width, $value->height, - $align, $valign); + Drawing::imagettftextbox( + $this->image, + $size, + 0, + $value->left, + $value->top, + $color, + $fontfile, + $text, + $value->width, + $value->height, + $align, + $valign + ); } /** @@ -171,12 +188,13 @@ class TemplateImage // Resample $image_p = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); -// imagecopyresized($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); + // imagecopyresized($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); $this->image = $image_p; } - function prepare(): void { - if($this->_prepare) { + function prepare(): void + { + if ($this->_prepare) { $this->_prepare = false; foreach ($this->data as $value) { $this->imageText($value->text, $value); // break; diff --git a/src/Validator/Rule/AbstractRule.php b/src/Validator/Rule/AbstractRule.php index 0ca3438..fac4aad 100644 --- a/src/Validator/Rule/AbstractRule.php +++ b/src/Validator/Rule/AbstractRule.php @@ -7,6 +7,7 @@ abstract class AbstractRule { public string $field; protected ?string $errorMsg; + /** @var object */ protected $ctx; public function __construct(string $field, ?string $errorMsg = null) @@ -46,6 +47,9 @@ abstract class AbstractRule return true; } + /** + * @param object $ctx + */ public function setContext($ctx): void { $this->ctx = $ctx; diff --git a/src/Validator/Rule/Count.php b/src/Validator/Rule/Count.php index 7115587..fa650a8 100644 --- a/src/Validator/Rule/Count.php +++ b/src/Validator/Rule/Count.php @@ -17,6 +17,10 @@ class Count extends AbstractRule return "Количество записей должно быть не менне {$this->size} и не более {$this->max}"; } + /** + * @param string $s + * @return bool + */ function notEmpty($s): bool { return $s != ""; } diff --git a/src/Validator/Rule/MatchRule.php b/src/Validator/Rule/MatchRule.php index ab167d3..b0db64b 100644 --- a/src/Validator/Rule/MatchRule.php +++ b/src/Validator/Rule/MatchRule.php @@ -9,6 +9,7 @@ use ctiso\Validator\Rule\AbstractRule, class MatchRule extends AbstractRule { + /** @var string */ public $same; public function getErrorMsg(): string diff --git a/src/Validator/Validator.php b/src/Validator/Validator.php index 5d50dae..7576ca8 100644 --- a/src/Validator/Validator.php +++ b/src/Validator/Validator.php @@ -147,7 +147,7 @@ class Validator return $this->isValid(); } - public function addError(string $name, string $message) + public function addError(string $name, string $message): void { $this->errorMsg[$name] = $message; } diff --git a/src/View/View.php b/src/View/View.php index 4ff81db..e4a091d 100644 --- a/src/View/View.php +++ b/src/View/View.php @@ -119,7 +119,7 @@ class View extends \stdClass return $result; } - /*abstract*/ public function set(string $key, mixed $value) + /*abstract*/ public function set(string $key, mixed $value): void { }