From 89913de4fe278b4e39c899a81ad1704099e185d8 Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Mon, 27 Oct 2025 16:39:44 +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/Adapter.php | 9 +++++++++ src/Arr.php | 6 ++++++ src/Collection.php | 5 +++++ src/ComponentRequest.php | 15 +++++++++++++++ src/Connection/HttpRequest.php | 14 ++++++++++---- src/Connection/HttpResponse.php | 16 +++++++++++----- src/Controller/Action.php | 4 ++++ src/Controller/Component.php | 5 +++++ src/Controller/Front.php | 9 ++++++++- src/Controller/Service.php | 1 + src/Database.php | 1 + src/Database/Manager.php | 2 -- src/Database/PDOStatement.php | 3 +++ src/Excel/Document.php | 15 ++++++++++----- src/Functions.php | 15 +++++++++++++++ src/Mail.php | 10 +++++++++- src/Primitive.php | 11 ++++++++++- src/Settings.php | 6 ++---- src/View/Composite.php | 1 - 19 files changed, 124 insertions(+), 24 deletions(-) diff --git a/src/Adapter.php b/src/Adapter.php index 2ba68f9..6ab0934 100644 --- a/src/Adapter.php +++ b/src/Adapter.php @@ -8,12 +8,21 @@ namespace ctiso; */ class Adapter { + /** @var array|object */ protected $adaptee; + + /** + * @param array|object $adaptee + */ public function __construct ($adaptee) { $this->adaptee = $adaptee; } + /** + * @param string $name + * @return mixed + */ public function get($name) { if (is_array ($this->adaptee)) { diff --git a/src/Arr.php b/src/Arr.php index 38cbb35..5d63ef8 100644 --- a/src/Arr.php +++ b/src/Arr.php @@ -4,6 +4,12 @@ namespace ctiso; class Arr { + /** + * @param array $data + * @param string $key + * @param mixed $default + * @return mixed + */ static function get($data, $key, $default = null) { return $data[$key] ?? $default; } diff --git a/src/Collection.php b/src/Collection.php index 58b725e..ca5e3ae 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -72,6 +72,11 @@ class Collection implements \ArrayAccess return (string)$this->get($key, $default); } + /** + * @param string $key + * @param int $default + * @return int + */ public function getNat($key, $default = 1) { $result = (int)$this->get($key, $default); diff --git a/src/ComponentRequest.php b/src/ComponentRequest.php index 6bc7dbc..9488184 100644 --- a/src/ComponentRequest.php +++ b/src/ComponentRequest.php @@ -6,15 +6,27 @@ use ctiso\HttpRequest, ctiso\Arr; class ComponentRequest { + /** @var string */ public $component_id; + /** @var string */ public $component_title; + /** @var HttpRequest */ public $r; + /** + * @param string $c + * @param HttpRequest $r + */ function __construct($c, HttpRequest $r) { $this->component_id = $c; $this->r = $r; } + /** + * @param string $key + * @param mixed $default + * @return mixed + */ function get($key, $default = null) { if ($key == 'active_page') { return $this->r->get($key); @@ -30,6 +42,9 @@ class ComponentRequest { return $default; } + /** + * @return string + */ function getAction() { return $this->r->getAction(); } diff --git a/src/Connection/HttpRequest.php b/src/Connection/HttpRequest.php index 0e2fcf3..c255f77 100644 --- a/src/Connection/HttpRequest.php +++ b/src/Connection/HttpRequest.php @@ -8,15 +8,21 @@ class HttpRequest const POST = "POST"; const GET = "GET"; - private $param = []; // Параметры запроса - public $data = null; // Содержание - public $url; // Адресс - public $method; // Метод + /** @var array Параметры запроса */ + private $param = []; + /** @var string Содержание */ + public $data = null; + /** @var string Адресс */ + public $url; + /** @var string Метод */ + public $method; /** @var int */ public $port = 80; /** @var string */ public $host = ""; + /** @var ?string */ public $proxy_host = null; + /** @var ?int */ public $proxy_port = null; /** @var string */ public $http_version = 'HTTP/1.1'; diff --git a/src/Connection/HttpResponse.php b/src/Connection/HttpResponse.php index 745091a..1dc2224 100644 --- a/src/Connection/HttpResponse.php +++ b/src/Connection/HttpResponse.php @@ -7,11 +7,17 @@ namespace ctiso\Connection; class HttpResponse { + /** @var int */ private $offset; + /** @var array */ private $param = []; + /** @var int */ private $code; + /** @var string */ public $response; + /** @var string */ public $version; + /** @var string */ public $data; public function __construct($response) @@ -28,7 +34,7 @@ class HttpResponse { $http = explode(" ", $this->getLine()); $this->version = $http[0]; - $this->code = $http[1]; + $this->code = (int)$http[1]; $line = $this->getLine(); while ($offset = strpos($line, ":")) { @@ -55,7 +61,7 @@ class HttpResponse /** * Обработка строки HTTP ответа */ - private function getLine() + private function getLine(): string { $begin = $this->offset; $offset = strpos($this->response, "\r\n", $this->offset); @@ -67,12 +73,12 @@ class HttpResponse /** * Значение параметра HTTP ответа */ - public function getParameter($name) + public function getParameter($name): string { return $this->param[$name]; } - public function getData() + public function getData(): string { return $this->data; } @@ -80,7 +86,7 @@ class HttpResponse /** * Состояние */ - public function getCode() + public function getCode(): int { return $this->code; } diff --git a/src/Controller/Action.php b/src/Controller/Action.php index 480eb86..b6b26f6 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -288,6 +288,7 @@ class Action implements ActionInterface /** * Добавление помошника контроллера + * @param class-string $class */ public function addHelper($class) { @@ -345,6 +346,7 @@ class Action implements ActionInterface /** * Установка заголовка для отображения + * @param string $title */ public function setTitle($title): void { @@ -353,6 +355,8 @@ class Action implements ActionInterface /** * Добавление widget к отображению + * @param $section + * @param $node */ public function addChild($section, $node): void { diff --git a/src/Controller/Component.php b/src/Controller/Component.php index d9a3a84..4f9c76f 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -17,9 +17,14 @@ use PHPTAL; use PHPTAL_PreFilter_Normalize; class FakeTemplate { + /** @var array */ public $_data = []; + /** @var string */ public $_name = ''; + /** + * @param string $name + */ function __construct($name) { $this->_name = $name; } diff --git a/src/Controller/Front.php b/src/Controller/Front.php index e640c13..4aef444 100644 --- a/src/Controller/Front.php +++ b/src/Controller/Front.php @@ -22,6 +22,7 @@ class Front extends Action protected $_param; // Параметр по которому выбирается модуль protected $default; // Значение параметра по умолчанию + /** @var array */ protected $modules = []; public function __construct(Database $db, Registry $config, User $user, $default) { @@ -32,7 +33,13 @@ class Front extends Action $this->default = $default; } - public function isLoaded($name) { + /** + * Проверяет загружен ли модуль + * @param string $name Имя модуля + * @return bool + */ + public function isLoaded($name): bool + { return isset($this->modules[$name]); } diff --git a/src/Controller/Service.php b/src/Controller/Service.php index 1c572aa..8ea4b19 100644 --- a/src/Controller/Service.php +++ b/src/Controller/Service.php @@ -47,6 +47,7 @@ class Service /** * @param string $name Имя модели + * @return string */ private function getModelPath($name) { diff --git a/src/Database.php b/src/Database.php index 37d6bc1..c885b1e 100644 --- a/src/Database.php +++ b/src/Database.php @@ -114,6 +114,7 @@ namespace ctiso { /** * Создает подготовленный запрос * @param string $query - запрос + * @return Statement */ public function prepareStatement($query) { diff --git a/src/Database/Manager.php b/src/Database/Manager.php index d31527f..b357288 100644 --- a/src/Database/Manager.php +++ b/src/Database/Manager.php @@ -199,8 +199,6 @@ class Manager if (strtolower($type) == "serial") { $type = "integer"; } - //if (strtolower($type)=="boolean") - // $type = "integer"; } return $name . " " . $type . $references . $constraint; } diff --git a/src/Database/PDOStatement.php b/src/Database/PDOStatement.php index a8b42d8..2811df2 100644 --- a/src/Database/PDOStatement.php +++ b/src/Database/PDOStatement.php @@ -78,6 +78,9 @@ class PDOStatement extends \PDOStatement implements \IteratorAggregate return $this->cache[$this->cursorPos]; } + /** + * @return array|null + */ function getRow() { return $this->fields; } diff --git a/src/Excel/Document.php b/src/Excel/Document.php index 4b11eec..3086f56 100644 --- a/src/Excel/Document.php +++ b/src/Excel/Document.php @@ -27,7 +27,7 @@ class Document { * @param array $values array Параметры стиля * @param string $type Тип стиля */ - function setStyle ($name, array $values, $type = 'Interior') + function setStyle ($name, array $values, $type = 'Interior'): void { if(!isset($this->styles[$name])) { $this->styles[$name] = []; @@ -38,7 +38,8 @@ class Document { /** * Генерация стилей */ - private function createStyles (XMLWriter $doc) { + private function createStyles (XMLWriter $doc): void + { $doc->startElement('Styles'); foreach ($this->styles as $name => $sn) { $doc->startElement('Style'); @@ -70,18 +71,22 @@ class Document { /** * Преобразует переводы строки в спец символы + * @param string $s + * @return string */ function clean ($s) { - assert(is_string($s)); - return strtr($s, ["\n" => " "]); } /** * Сохраняет таблицу в формате Office 2003 XML * http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats + * + * @param string $filename + * @throws Exception + * @return void */ - function save($filename) + function save($filename): void { $doc = new XMLWriter(); if (!$doc->openUri($filename)) { diff --git a/src/Functions.php b/src/Functions.php index a681669..83b370b 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -6,9 +6,14 @@ namespace ctiso; * Эмуляция каррированой функции */ class right { + /** @var array */ protected $params; + /** @var callable */ protected $fn; + /** + * @param array $params + */ public function __construct($params) { $this->fn = array_shift($params); $this->params = $params; @@ -22,9 +27,14 @@ class right { } class left { + /** @var array */ protected $params; + /** @var callable */ protected $fn; + /** + * @param array $params + */ public function __construct($params) { $this->fn = array_shift($params); $this->params = $params; @@ -44,6 +54,9 @@ class partial { /** @var callable */ protected $fn; + /** + * @param array $params + */ public function __construct($params) { $this->fn = array_shift($params); $this->params = $params; @@ -294,6 +307,8 @@ class Functions { /** * Логическа операция && ко всем элементам массива + * @param array $array Массив + * @param callable $callback Функция * @return bool */ static function every(array $array, $callback) { diff --git a/src/Mail.php b/src/Mail.php index ca785a0..697895a 100644 --- a/src/Mail.php +++ b/src/Mail.php @@ -100,10 +100,12 @@ class Mail /** * Добавление вложения из файла + * @param string $filename + * @param string|false $name */ function addAttachment(string $filename, $name = false): void { - if (file_exists($filename)) { // assert ?? + if (file_exists($filename)) { $file = fopen($filename, "rb"); if (is_resource($file)) { $data = fread($file, filesize($filename)); @@ -112,6 +114,10 @@ class Mail } } + /** + * Установка типа содержимого + * @param string $type + */ function setType($type): void { $this->type = $type; @@ -119,6 +125,8 @@ class Mail /** * Добавление вложения из строки с указанием имени файла + * @param string $data + * @param string $name */ function addAttachmentRaw($data, string $name): void { diff --git a/src/Primitive.php b/src/Primitive.php index 7f0f92a..d43921d 100644 --- a/src/Primitive.php +++ b/src/Primitive.php @@ -25,12 +25,21 @@ class Primitive { return filter_var($value, FILTER_VALIDATE_BOOLEAN);//(int)((bool) $value); } + /** + * Преобразование значения в булевое значение + * @param string $value + * @return bool + */ public static function from_bool($value): bool { return ((bool) $value); } - // int + /** + * Преобразование значения в целое число + * @param string $value + * @return int + */ public static function to_int($value): int { return ((int) $value); diff --git a/src/Settings.php b/src/Settings.php index e99bb98..666532f 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -70,7 +70,6 @@ class Settings */ public function writeKey(array $key, $value) { -// assert(count($key) >= 1); $data = &$this->data; while (count($key) > 1) { @@ -78,7 +77,6 @@ class Settings $data = &$data[$name]; } -// assert(count($key) == 1); $name = array_shift($key); if (is_array($value)) { if (!isset($data[$name])) { @@ -92,6 +90,8 @@ class Settings /** * Обновляет массив в соответствии со значением + * @param array $data Массив + * @param mixed $value Значение */ protected function merge(array &$data, $value): void { @@ -122,7 +122,6 @@ class Settings */ protected function readKeyData(array $key, $data) { -// assert(count($key) >= 1); while (count($key) > 1) { $name = array_shift($key); if (isset($data[$name])) { @@ -132,7 +131,6 @@ class Settings } } -// assert(count($key) == 1); $name = array_shift($key); if (isset($data[$name])) { return $data[$name]; diff --git a/src/View/Composite.php b/src/View/Composite.php index 278f798..531f470 100644 --- a/src/View/Composite.php +++ b/src/View/Composite.php @@ -8,7 +8,6 @@ use PHPTAL_TranslationService; class Composite extends View { private PHPTAL $tal; - public $config; function __construct(string $file) {