From 245b5c6c198d103db78f8fd992345f325b407a6b Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Tue, 28 Oct 2025 16:32:00 +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/Connection/HttpResponse.php | 3 +- src/Controller/Action.php | 55 +++++++++------ src/Controller/Component.php | 11 ++- src/Controller/Service.php | 3 + src/Controller/SiteInterface.php | 15 ++-- src/Database.php | 8 +-- src/Database/Manager.php | 2 +- src/Form/OptionsFactory.php | 2 +- src/Functions.php | 22 ++++-- src/Role/User.php | 7 ++ src/Setup.php | 6 +- src/Tales.php | 27 +++---- src/Tools/Drawing.php | 2 +- src/Tools/SQLStatementExtractor.php | 106 +++++++++++++++------------- src/Validator/Rule/AbstractRule.php | 5 ++ src/Validator/Validator.php | 17 +++-- src/View/Top.php | 1 - src/View/View.php | 3 + 18 files changed, 191 insertions(+), 104 deletions(-) diff --git a/src/Connection/HttpResponse.php b/src/Connection/HttpResponse.php index 1dc2224..d3cf5ac 100644 --- a/src/Connection/HttpResponse.php +++ b/src/Connection/HttpResponse.php @@ -30,7 +30,7 @@ class HttpResponse /** * Обработка HTTP ответа */ - private function parseMessage() + private function parseMessage(): void { $http = explode(" ", $this->getLine()); $this->version = $http[0]; @@ -72,6 +72,7 @@ class HttpResponse /** * Значение параметра HTTP ответа + * @param string $name Имя параметра */ public function getParameter($name): string { diff --git a/src/Controller/Action.php b/src/Controller/Action.php index b6b26f6..dcb69fe 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -1,16 +1,18 @@ modulePath, 'help', $name . '.suggest'); if (file_exists($file)) { @@ -188,6 +191,7 @@ class Action implements ActionInterface * 1. Можно переопределить действия * 2. Использовать наследование чтобы добавить к старому обработчику новое поведение * @param HttpRequest $request запроса + * @return View|string */ public function preProcess(HttpRequest $request) { @@ -203,6 +207,11 @@ class Action implements ActionInterface return $view; } + /** + * Выполнение действия + * @param HttpRequest $request + * @return View|string + */ public function execute(HttpRequest $request) { $result = $this->preProcess($request); @@ -227,7 +236,7 @@ class Action implements ActionInterface /** * Страница по умолчанию * @param HttpRequest $request - * @return string|\ctiso\View\View + * @return View|string */ public function actionIndex(HttpRequest $request) { return ""; @@ -355,14 +364,19 @@ class Action implements ActionInterface /** * Добавление widget к отображению - * @param $section - * @param $node + * @param string $section + * @param View $node */ public function addChild($section, $node): void { $this->childNodes[$section] = $node; } + /** + * Установка значения контроллера + * @param string $name + * @param mixed $value + */ public function setValue($name, $value): void { $this->ctrlValues[$name] = $value; @@ -370,6 +384,8 @@ class Action implements ActionInterface /** * Добавление дочернего отображения к текущему отображению + * @param string $section + * @param View $node */ public function addView($section, $node): void { @@ -379,6 +395,7 @@ class Action implements ActionInterface /** * Генерация содержания * Путаница c execute и render + * @return View|string */ public function render() { @@ -426,16 +443,14 @@ class Action implements ActionInterface return $result; } + /** + * @return State + */ function _getActionPath() { return new State('index'); } - // Тоже убрать в метод Controller_Model - function getActionPath(HttpRequest $request, $action = null) { - $this->_getActionPath()->getPath($this, ($action) ? $action : $request->getAction()); - } - - function redirect(string $action) { + function redirect(string $action): void { header('location: ' . $action); exit(); } diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 4f9c76f..5ebffc2 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -29,10 +29,17 @@ class FakeTemplate { $this->_name = $name; } - function __set($key, $value) { + /** + * @param string $key + * @param mixed $value + */ + function __set($key, $value): void { $this->_data[$key] = $value; } + /** + * @return string + */ function execute() { return json_encode($this->_data); } @@ -56,7 +63,7 @@ class Component public $component_id; /** @var string */ public $component_title; - + /** @var string */ public $COMPONENTS_WEB; public Registry $config; diff --git a/src/Controller/Service.php b/src/Controller/Service.php index 8ea4b19..923b4ad 100644 --- a/src/Controller/Service.php +++ b/src/Controller/Service.php @@ -20,8 +20,11 @@ class Service public $webPath = []; /** @var Registry */ public $config; + /** @var string */ public $template; + /** @var string */ public $templatePath; + /** @var string */ public $COMPONENTS_WEB; /** @var Database */ public $db; diff --git a/src/Controller/SiteInterface.php b/src/Controller/SiteInterface.php index d176e34..4fd6ff4 100644 --- a/src/Controller/SiteInterface.php +++ b/src/Controller/SiteInterface.php @@ -4,15 +4,22 @@ namespace ctiso\Controller; interface SiteInterface { function getResource(); + /** + * @return \ctiso\Database + */ function getDatabase(); function getConfig(); function getTheme(); - function addComponentConfig($config); - function addRequireJsPath(string $name, string $path, ?array $shim = null); - function addStyleSheet(string $url); + function addComponentConfig($config): void; + function addRequireJsPath(string $name, string $path, ?array $shim = null): void; + function addStyleSheet(string $url): void; + /** + * @param string $expression + * @return ?Component + */ function loadComponent(string $expression); function findTemplate(string $name); function replaceImg(string $src, int $width, int $height); - function updatePageTime(int $time); + function updatePageTime(int $time): void; } diff --git a/src/Database.php b/src/Database.php index c885b1e..35a56e9 100644 --- a/src/Database.php +++ b/src/Database.php @@ -124,8 +124,8 @@ namespace ctiso { /** * Извлекает из базы все элементы по запросу (Для совместимости со старым представлением баз данных CIS) * @param string $query - запрос - * @param array $values - значения - * @return array + * @param array $values - значения + * @return list> */ public function fetchAllArray($query, $values = null) { @@ -138,8 +138,8 @@ namespace ctiso { /** * Извлекает из базы первый элемент по запросу * @param string $query - запрос - * @param array $values - значения - * @return array|false + * @param array $values - значения + * @return array|false */ public function fetchOneArray($query, $values = null) { diff --git a/src/Database/Manager.php b/src/Database/Manager.php index b357288..91c6f64 100644 --- a/src/Database/Manager.php +++ b/src/Database/Manager.php @@ -294,7 +294,7 @@ class Manager /** * Возвращает все имена таблиц - * @return array + * @return list */ public function getAllTableNames() { diff --git a/src/Form/OptionsFactory.php b/src/Form/OptionsFactory.php index 8921b56..79be2e0 100644 --- a/src/Form/OptionsFactory.php +++ b/src/Form/OptionsFactory.php @@ -3,5 +3,5 @@ namespace ctiso\Form; interface OptionsFactory { - function create(Select $field, array $options); + function create(Select $field, array $options): void; } \ No newline at end of file diff --git a/src/Functions.php b/src/Functions.php index 700f893..cb38f96 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -217,15 +217,29 @@ 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]); } - static function concat(/* $args ...*/) { - $args = func_get_args(); + /** + * @param string ...$args + * @return string + */ + static function concat(...$args) { return implode("", $args); } + /** + * @param mixed $x + * @return bool + */ static function __empty($x) { return empty($x); } @@ -235,7 +249,7 @@ class Functions { * @example key_values('a', array(1 => array('a' => 1, 'b' => 2))) => array(1) * * @param string $key - * @param array|\ArrayIterator $array + * @param list|\ArrayIterator $array * @return mixed */ static function key_values($key, $array) { @@ -249,7 +263,7 @@ class Functions { /** * @param string $key - * @param array|\ArrayIterator $array + * @param list|\ArrayIterator $array */ static function key_values_object($key, $array) { $result = []; diff --git a/src/Role/User.php b/src/Role/User.php index c9d68cc..174de9e 100644 --- a/src/Role/User.php +++ b/src/Role/User.php @@ -34,6 +34,9 @@ class User implements UserInterface return $this->name; } + /** + * @return bool + */ function isLogged() { return \ctiso\Filter\Authorization::isLogged(); } @@ -55,6 +58,10 @@ class User implements UserInterface return null; } + /** + * @param PDOStatement $result + * @return string + */ function getUserPassword($result) { return $result->get('password'); } diff --git a/src/Setup.php b/src/Setup.php index eac9518..935dabb 100644 --- a/src/Setup.php +++ b/src/Setup.php @@ -121,6 +121,8 @@ class Setup /** * Заменяет переменные на их значения в строке + * @param list $match массив совпадения + * @return string */ function replaceVariable(array $match) { @@ -132,12 +134,14 @@ class Setup /** * Для всех аттрибутов заменяет переменные на их значения + * @param SimpleXMLElement $attributes аттрибуты + * @return array */ function resolve(SimpleXMLElement $attributes): array { $result = []; foreach ($attributes as $key => $value) { - $result [$key] = preg_replace_callback("/\\\${(\w+)}/", [$this, 'replaceVariable'], $value); + $result[$key] = preg_replace_callback("/\\\${(\w+)}/", [$this, 'replaceVariable'], $value); } return $result; } diff --git a/src/Tales.php b/src/Tales.php index 214991b..2e3529f 100644 --- a/src/Tales.php +++ b/src/Tales.php @@ -4,12 +4,13 @@ * Расширения для PHPTAL для отображения времени и даты */ namespace ctiso; -use PHPTAL_Php_TalesInternal, - ctiso\Controller\SiteInterface, - ctiso\Controller\Component, - ctiso\HttpRequest, - PHPTAL_Tales, - PHPTAL_TalesRegistry; + +use PHPTAL_Php_TalesInternal; +use ctiso\Controller\SiteInterface; +use ctiso\Controller\Component; +use ctiso\HttpRequest; +use PHPTAL_Tales; +use PHPTAL_TalesRegistry; class Tales_DateTime implements PHPTAL_Tales { @@ -61,8 +62,10 @@ class Tales { /** * Функция подключения компонента + * @param string $expression + * @return string */ - static function phptal_component($expression) { + static function phptal_component($expression): string { $begin = floatval(microtime(true)); /** @var Component */ $component = self::$site->loadComponent($expression); @@ -74,14 +77,14 @@ class Tales { } - static function register(?SiteInterface $site) { + static function register(?SiteInterface $site): void { self::$site = $site; /* Регистрация нового префикса для подключения компонента */ $tales = PHPTAL_TalesRegistry::getInstance(); - $tales->registerPrefix('component', ['ctiso\\Tales_Component', 'component']); - $tales->registerPrefix('date', ['ctiso\\Tales_DateTime', 'date']); - $tales->registerPrefix('time', ['ctiso\\Tales_DateTime', 'time']); - $tales->registerPrefix('assets', ['ctiso\\Tales_Assets', 'assets']); + $tales->registerPrefix('component', [\ctiso\Tales_Component::class, 'component']); + $tales->registerPrefix('date', [\ctiso\Tales_DateTime::class, 'date']); + $tales->registerPrefix('time', [\ctiso\Tales_DateTime::class, 'time']); + $tales->registerPrefix('assets', [\ctiso\Tales_Assets::class, 'assets']); } } diff --git a/src/Tools/Drawing.php b/src/Tools/Drawing.php index dbfcd8a..75b2eab 100644 --- a/src/Tools/Drawing.php +++ b/src/Tools/Drawing.php @@ -18,7 +18,7 @@ class Drawing * @param int $top * @param int $width * @param int $height - * @param array $rgb + * @param list $rgb */ static function drawRectangle(GdImage &$image, int $left, int $top, int $width, int $height, array $rgb): void { diff --git a/src/Tools/SQLStatementExtractor.php b/src/Tools/SQLStatementExtractor.php index 3759953..7ece534 100644 --- a/src/Tools/SQLStatementExtractor.php +++ b/src/Tools/SQLStatementExtractor.php @@ -26,10 +26,13 @@ * @version $Revision: 1.5 $ * @package creole.util.sql */ + namespace ctiso\Tools; + use Exception; -class SQLStatementExtractor { +class SQLStatementExtractor +{ protected static $delimiter = ';'; @@ -39,10 +42,11 @@ class SQLStatementExtractor { * @param string $filename Path to file to read. * @return array SQL statements */ - public static function extractFile($filename) { + public static function extractFile($filename) + { $buffer = file_get_contents($filename); if ($buffer !== false) { - return self::extractStatements(self::getLines($buffer)); + return self::extractStatements(self::getLines($buffer)); } throw new Exception("Unable to read file: " . $filename); } @@ -53,50 +57,53 @@ class SQLStatementExtractor { * @param string $buffer * @return array */ - public static function extract($buffer) { + public static function extract($buffer) + { return self::extractStatements(self::getLines($buffer)); } /** * Extract SQL statements from array of lines. * - * @param array $lines Lines of the read-in file. - * @return array + * @param list $lines Lines of the read-in file. + * @return list */ - protected static function extractStatements($lines) { + protected static function extractStatements($lines) + { $statements = []; $sql = ""; - foreach($lines as $line) { + foreach ($lines as $line) { + $line = trim($line); - $line = trim($line); - - if (self::startsWith("//", $line) || - self::startsWith("--", $line) || - self::startsWith("#", $line)) { - continue; - } - - if (strlen($line) > 4 && strtoupper(substr($line,0, 4)) == "REM ") { - continue; - } - - $sql .= " " . $line; - $sql = trim($sql); - - // SQL defines "--" as a comment to EOL - // and in Oracle it may contain a hint - // so we cannot just remove it, instead we must end it - if (strpos($line, "--") !== false) { - $sql .= "\n"; - } - - if (self::endsWith(self::$delimiter, $sql)) { - $statements[] = self::substring($sql, 0, strlen($sql)-1 - strlen(self::$delimiter)); - $sql = ""; - } + if ( + self::startsWith("//", $line) || + self::startsWith("--", $line) || + self::startsWith("#", $line) + ) { + continue; } + + if (strlen($line) > 4 && strtoupper(substr($line, 0, 4)) == "REM ") { + continue; + } + + $sql .= " " . $line; + $sql = trim($sql); + + // SQL defines "--" as a comment to EOL + // and in Oracle it may contain a hint + // so we cannot just remove it, instead we must end it + if (strpos($line, "--") !== false) { + $sql .= "\n"; + } + + if (self::endsWith(self::$delimiter, $sql)) { + $statements[] = self::substring($sql, 0, strlen($sql) - 1 - strlen(self::$delimiter)); + $sql = ""; + } + } return $statements; } @@ -110,7 +117,8 @@ class SQLStatementExtractor { * @param string $string The string to check in (haystack). * @return boolean True if $string starts with $check, or they are equal, or $check is empty. */ - protected static function startsWith($check, $string) { + protected static function startsWith($check, $string) + { if ($check === "" || $check === $string) { return true; } else { @@ -124,7 +132,8 @@ class SQLStatementExtractor { * @param string $string The string to check in (haystack). * @return boolean True if $string ends with $check, or they are equal, or $check is empty. */ - protected static function endsWith(string $check, string $string) { + protected static function endsWith(string $check, string $string) + { if ($check === "" || $check === $string) { return true; } else { @@ -136,21 +145,22 @@ 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 */ - protected static function substring(string $string, int $startpos, int $endpos = -1) { + protected static function substring(string $string, int $startpos, int $endpos = -1) + { $len = strlen($string); - $endpos = (int) (($endpos === -1) ? $len-1 : $endpos); - if ($startpos > $len-1 || $startpos < 0) { + $endpos = (int) (($endpos === -1) ? $len - 1 : $endpos); + if ($startpos > $len - 1 || $startpos < 0) { trigger_error("substring(), Startindex out of bounds must be 0 $len-1 || $endpos < $startpos) { - trigger_error("substring(), Endindex out of bounds must be $startpos $len - 1 || $endpos < $startpos) { + trigger_error("substring(), Endindex out of bounds must be $startposerrorMsg; } + /** + * @param Collection $container + * @param bool|null $status + * @return bool + */ public function isValid(Collection $container, $status = null): bool { return true; diff --git a/src/Validator/Validator.php b/src/Validator/Validator.php index 6407ab3..5d50dae 100644 --- a/src/Validator/Validator.php +++ b/src/Validator/Validator.php @@ -123,11 +123,17 @@ class Validator $this->errorMsg = []; } - public function validate(Collection $container, $rule = null, $status = null): bool + /** + * @param Collection $container + * @param AbstractRule[]|null $rules + * @param bool|null $status + * @return bool + */ + public function validate(Collection $container, $rules = null, $status = null): bool { $fields = []; - if ($rule) { - $this->chain = $rule; + if ($rules) { + $this->chain = $rules; } foreach ($this->chain as $rule) { @@ -156,7 +162,10 @@ class Validator return empty($this->errorMsg); } - public function getErrorMsg() + /** + * @return array + */ + public function getErrorMsg(): array { return $this->errorMsg; } diff --git a/src/View/Top.php b/src/View/Top.php index fbefed0..e753401 100644 --- a/src/View/Top.php +++ b/src/View/Top.php @@ -147,5 +147,4 @@ class Top extends Composite { return $this->doTree('_stylesheet'); } - } \ No newline at end of file diff --git a/src/View/View.php b/src/View/View.php index 5ecfe7f..4ff81db 100644 --- a/src/View/View.php +++ b/src/View/View.php @@ -32,6 +32,7 @@ class View extends \stdClass /** @var string[] $alias */ public array $alias = []; public $codeGenerator = null; + /** @var View|null */ public $parent_view = null; function __construct() { @@ -191,6 +192,8 @@ class View extends \stdClass /** * @param string[][] $alias + * @param string[] $list + * @return string[] */ public function resolveAllNames($alias, array $list): array { $result = [];