chore: Аннотации к типам

This commit is contained in:
origami11@yandex.ru 2025-10-30 12:59:36 +03:00
parent 5e8958969f
commit f964472e62
28 changed files with 140 additions and 36 deletions

View file

@ -14,6 +14,7 @@ class Collection implements \ArrayAccess
* Преобразование массива в коллекцию * Преобразование массива в коллекцию
* *
* @param array $data * @param array $data
* @return bool
*/ */
public function import(array $data) public function import(array $data)
{ {
@ -23,6 +24,8 @@ class Collection implements \ArrayAccess
/** /**
* Преобразование коллекции в массив * Преобразование коллекции в массив
*
* @return array
*/ */
public function export() public function export()
{ {

View file

@ -52,7 +52,7 @@ class HttpRequest
* @param string $name * @param string $name
* @param string $value * @param string $value
*/ */
public function setParameter($name, $value) public function setParameter($name, $value): void
{ {
$this->param[$name] = $value; $this->param[$name] = $value;
} }
@ -93,6 +93,7 @@ class HttpRequest
/** /**
* Посылает запрос и возвращает страницу * Посылает запрос и возвращает страницу
* @return string|null
*/ */
public function getPage() public function getPage()
{ {
@ -105,7 +106,7 @@ class HttpRequest
$header = $this->getHeader(); $header = $this->getHeader();
fwrite($socket, $header); fwrite($socket, $header);
$result = null; $result = '';
while (! feof($socket)) { while (! feof($socket)) {
$result .= fgets($socket, 128); $result .= fgets($socket, 128);
} }

View file

@ -20,6 +20,9 @@ class HttpResponse
/** @var string */ /** @var string */
public $data; public $data;
/**
* @param string $response HTTP ответ
*/
public function __construct($response) public function __construct($response)
{ {
$this->offset = 0; $this->offset = 0;

View file

@ -53,6 +53,7 @@ class Action implements ActionInterface
// Для Widgets // Для Widgets
public $view = null; public $view = null;
public array $childNodes = []; public array $childNodes = [];
public array $ctrlValues = []; public array $ctrlValues = [];
public array $childViews = []; public array $childViews = [];
@ -61,7 +62,7 @@ class Action implements ActionInterface
$this->part = new Url(); $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 * @return array
*/ */
public function loadSettings($path) public function loadSettings($path)

View file

@ -13,6 +13,7 @@ use ctiso\Database;
use ctiso\Collection; use ctiso\Collection;
use ctiso\Registry; use ctiso\Registry;
use ctiso\Controller\SiteInterface; use ctiso\Controller\SiteInterface;
use ctiso\Database\PDOStatement;
use PHPTAL; use PHPTAL;
use PHPTAL_PreFilter_Normalize; use PHPTAL_PreFilter_Normalize;
@ -249,7 +250,8 @@ class Component
/** /**
* @param string $key * @param string $key
* @param string $val * @param string $val
* @param $res * @param PDOStatement $res
* @return array{value: string, name: string}[]
*/ */
public function options(string $key, string $val, $res) { public function options(string $key, string $val, $res) {
$result = []; $result = [];
@ -262,7 +264,7 @@ class Component
/** /**
* @param array $list * @param array $list
* @param bool $selected * @param bool $selected
* @return array * @return array{value: string, name: string, selected: bool}[]
*/ */
public function optionsPair(array $list, $selected = false) { public function optionsPair(array $list, $selected = false) {
$result = []; $result = [];
@ -288,6 +290,10 @@ class Component
return null; return null;
} }
/**
* Получить информацию о параметрах
* @return array<mixed>
*/
function getInfo() { function getInfo() {
$filename = Path::join($this->viewPath[count($this->viewPath) - 1], 'install.json'); $filename = Path::join($this->viewPath[count($this->viewPath) - 1], 'install.json');
if (file_exists($filename)) { if (file_exists($filename)) {
@ -502,4 +508,11 @@ class Component
return null; return null;
} }
/**
* @param HttpRequest $request
* @return array
*/
function getDefaultPageEnvironment($request) {
return [];
}
} }

View file

@ -98,6 +98,9 @@ class Service
return $result; return $result;
} }
/**
* @return array
*/
function getInfo() { function getInfo() {
$filename = Path::join($this->viewPath[0], 'install.json'); $filename = Path::join($this->viewPath[0], 'install.json');
if (file_exists($filename)) { if (file_exists($filename)) {

View file

@ -216,7 +216,7 @@ namespace ctiso {
* @param array $values - значения * @param array $values - значения
* @param string $cond - условие * @param string $cond - условие
*/ */
function updateQuery($table, array $values, $cond) function updateQuery($table, array $values, $cond): void
{ {
$prep = $this->prepareValues($values); $prep = $this->prepareValues($values);
$sql = "UPDATE $table SET " . implode( $sql = "UPDATE $table SET " . implode(

View file

@ -16,6 +16,9 @@ class TableCell
public $value; public $value;
public $merge = false; public $merge = false;
/**
* @param string $value Значение клетки
*/
function __construct ($value) function __construct ($value)
{ {
$this->value = $value; $this->value = $value;

View file

@ -4,9 +4,9 @@
* Фильтр действий * Фильтр действий
*/ */
namespace ctiso\Filter; namespace ctiso\Filter;
use ctiso\Filter\UserAccess,
ctiso\HttpRequest, use ctiso\HttpRequest;
ctiso\Role\User; use ctiso\Role\User;
class ActionAccess class ActionAccess
{ {
@ -39,6 +39,10 @@ class ActionAccess
return (!isset($this->access[$action]) || in_array($this->user->access, $this->access[$action])); return (!isset($this->access[$action]) || in_array($this->user->access, $this->access[$action]));
} }
/**
* @param HttpRequest $request
* @return mixed
*/
function execute(HttpRequest $request) { function execute(HttpRequest $request) {
$action = $request->getAction(); $action = $request->getAction();
if(! $this->checkAction($action)) { if(! $this->checkAction($action)) {

View file

@ -145,7 +145,10 @@ class Login extends Filter
$_SESSION["time"] = time(); $_SESSION["time"] = time();
} }
public function execute(HttpRequest $request): string /**
* @return mixed
*/
public function execute(HttpRequest $request): mixed
{ {
$logged = $this->isLoggin($request); $logged = $this->isLoggin($request);
if ($request->get('action') == 'user_access') { if ($request->get('action') == 'user_access') {

View file

@ -13,11 +13,13 @@ class Field
/** @var string */ /** @var string */
public $label; // Метка поля public $label; // Метка поля
/** @var mixed */
public $value; // Значение поля public $value; // Значение поля
/** @var string */ /** @var string */
public $type = ""; // Каждому типу элемента соответствует макрос TAL public $type = ""; // Каждому типу элемента соответствует макрос TAL
/** @var ?string */ /** @var ?string */
public $error_msg = null; public $error_msg = null;
/** @var ?mixed */
public $default = null; public $default = null;
/** @var bool */ /** @var bool */
public $error = false; public $error = false;

View file

@ -28,7 +28,9 @@ class Form {
/** @var string */ /** @var string */
public $header; public $header;
/** @var array */
protected $replace; protected $replace;
/** @var array */
protected $before; protected $before;
/** @var array<string> */ /** @var array<string> */

View file

@ -289,6 +289,7 @@ class Functions {
* @param string $key * @param string $key
* @param string $value * @param string $value
* @param list<array<string, mixed>>|\ArrayIterator $array * @param list<array<string, mixed>>|\ArrayIterator $array
* @return array<string, mixed>
*/ */
static function assoc_key_values($key, $value, $array) { static function assoc_key_values($key, $value, $array) {
$result = []; $result = [];
@ -301,6 +302,7 @@ class Functions {
/** /**
* @param string $key * @param string $key
* @param list<array<string, mixed>>|\ArrayIterator $array * @param list<array<string, mixed>>|\ArrayIterator $array
* @return array<string, mixed>
*/ */
static function assoc_key($key, $array) { static function assoc_key($key, $array) {
$result = []; $result = [];
@ -450,6 +452,7 @@ class Functions {
* Сортировка двумерного массива по заданному ключу * Сортировка двумерного массива по заданному ключу
* @param array $array Массив * @param array $array Массив
* @param string $key Имя ключа по значению которого будет идти сравнение * @param string $key Имя ключа по значению которого будет идти сравнение
* @param callable $fn Функция сравнения
* @return array Отсортированный массив * @return array Отсортированный массив
*/ */
static function sortOn($array, $key, $fn = '\\ctiso\\Functions::__cmp') { static function sortOn($array, $key, $fn = '\\ctiso\\Functions::__cmp') {

View file

@ -29,6 +29,8 @@ class Manager extends Filter
/** /**
* Условие для аякс запросов. Тоже самое что и addConditionGet но еще проверяется является ли запрос ajax * Условие для аякс запросов. Тоже самое что и addConditionGet но еще проверяется является ли запрос ajax
* @param array|true $get Ассоциативный массив ключей и значений для $_GET
* @param Filter $layout Макет
*/ */
public function addConditionXHR($get, Filter $layout): void 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) { foreach ($this->condition as $condition) {
if (call_user_func($condition[0], $request)) { if (call_user_func($condition[0], $request)) {

View file

@ -53,18 +53,21 @@ class Mail
/** /**
* Установка получателя * Установка получателя
*/ */
function to(string $name): void // recipient function to(string $name): void
{ {
$this->_to = $name; $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; $this->copy = $name;
} }

View file

@ -55,8 +55,8 @@ class Path
/** /**
* Базовое имя * Базовое имя
* @param $path * @param string $path
* @return mixed * @return string
*/ */
public static function basename($path) public static function basename($path)
{ {
@ -120,6 +120,7 @@ class Path
* Преобразует строку пути в массив * Преобразует строку пути в массив
* *
* @param string $path Путь * @param string $path Путь
* @return array<string>
*/ */
public static function listFromString(string $path): array public static function listFromString(string $path): array
{ {
@ -129,6 +130,8 @@ class Path
/** /**
* Преобразует относительный путь в абсолютный * Преобразует относительный путь в абсолютный
* @param array<string> $path Путь
* @return array<string>
*/ */
public static function optimize($path) // public static function optimize($path) //
{ {

View file

@ -40,6 +40,11 @@ class Registry {
throw new Exception('Unknown key ' . $ns . '::' . $key); throw new Exception('Unknown key ' . $ns . '::' . $key);
} }
/**
* @param string $ns
* @param string $key
* @return mixed|null
*/
public function getOpt(string $ns, string $key) { public function getOpt(string $ns, string $key) {
if (isset($this->namespace[$ns]['data'][$key])) { if (isset($this->namespace[$ns]['data'][$key])) {
return $this->namespace[$ns]['data'][$key]; return $this->namespace[$ns]['data'][$key];

View file

@ -26,7 +26,7 @@ class User implements UserInterface
$this->groups = $groups; $this->groups = $groups;
} }
public function setDB(Database $db) { public function setDB(Database $db): void {
$this->db = $db; $this->db = $db;
} }

View file

@ -67,6 +67,9 @@ class Settings
/** /**
* Запись ключа в реестр (Реестр это многомерный массив) * Запись ключа в реестр (Реестр это многомерный массив)
* @param array $key Путь к значению ключа
* @param mixed $value Значение
* @return void
*/ */
public function writeKey(array $key, $value) 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 isset($this->data[$key]) && $this->data[$key] != '' ? $this->data[$key] : $default;
} }
/**
* Получение всех данных
* @return array
*/
function export() { function export() {
return $this->data; return $this->data;
} }
/**
* Импорт данных
* @param array $data Данные
* @return void
*/
function import($data) { function import($data) {
$this->data = $data; $this->data = $data;
} }

View file

@ -53,6 +53,9 @@ class Setup
/** @var string */ /** @var string */
public $source; public $source;
/**
* @param string $file
*/
public function __construct($file) public function __construct($file)
{ {
$this->file = $file; $this->file = $file;
@ -150,6 +153,7 @@ class Setup
* Выполняет список действий если для действия не указан аттрибут when то оно выполняется всегда * Выполняет список действий если для действия не указан аттрибут when то оно выполняется всегда
* *
* @param string $action специальное действие * @param string $action специальное действие
* @return void
*/ */
function executeActions($action = "install") function executeActions($action = "install")
{ {
@ -178,6 +182,7 @@ class Setup
* dst Новый файл * dst Новый файл
* *
* @param array{preserve?: string, template: string, src: string, dst: string} $attributes * @param array{preserve?: string, template: string, src: string, dst: string} $attributes
* @return void
*/ */
public function copyFile(array $attributes) public function copyFile(array $attributes)
{ {

View file

@ -44,7 +44,7 @@ class SortRecord
return usort($list, [$this, 'compareKeys']); return usort($list, [$this, 'compareKeys']);
} }
function group(array &$list, string $key, array $types) function group(array &$list, string $key, array $types): void
{ {
$groups = []; $groups = [];
foreach ($types as $name) { foreach ($types as $name) {

View file

@ -34,6 +34,7 @@ use Exception;
class SQLStatementExtractor class SQLStatementExtractor
{ {
/** @var string */
protected static $delimiter = ';'; protected static $delimiter = ';';
/** /**
@ -144,6 +145,10 @@ class SQLStatementExtractor
/** /**
* a natural way of getting a subtring, php's circular string buffer and strange * 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 * 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) protected static function substring(string $string, int $startpos, int $endpos = -1)
{ {

View file

@ -3,7 +3,9 @@
/** /**
* Формат для композиции изображений * Формат для композиции изображений
*/ */
namespace ctiso\Tools; namespace ctiso\Tools;
use ctiso\Tools\Drawing; use ctiso\Tools\Drawing;
use GdImage; use GdImage;
@ -27,7 +29,7 @@ class TemplateImage
'' => 'arial.ttf', '' => 'arial.ttf',
'dejavu' => 'DejaVuCondensedSerif.ttf', 'dejavu' => 'DejaVuCondensedSerif.ttf',
'dejavubd' => 'DejaVuCondensedSerifBold.ttf', 'dejavubd' => 'DejaVuCondensedSerifBold.ttf',
'dejavuz' =>'DejaVuCondensedSerifBoldItalic.ttf', 'dejavuz' => 'DejaVuCondensedSerifBoldItalic.ttf',
'dejavui' => 'DejaVuCondensedSerifItalic.ttf', 'dejavui' => 'DejaVuCondensedSerifItalic.ttf',
'miriad' => 'MyriadPro-Cond.ttf', 'miriad' => 'MyriadPro-Cond.ttf',
'miriadbd' => 'MyriadPro-BoldCond.ttf' 'miriadbd' => 'MyriadPro-BoldCond.ttf'
@ -47,7 +49,7 @@ class TemplateImage
public string $resource; public string $resource;
public string $filename; public string $filename;
function __construct (?array $template = null) function __construct(?array $template = null)
{ {
if ($template) { if ($template) {
$this->data = $template; $this->data = $template;
@ -70,9 +72,13 @@ class TemplateImage
$this->base = $path; $this->base = $path;
} }
/**
* @param string $name
* @param mixed $value
*/
function set(string $name, $value): void function set(string $name, $value): void
{ {
$this->context['['.$name.']'] = $value; $this->context['[' . $name . ']'] = $value;
} }
function setImage(string $name): void function setImage(string $name): void
@ -107,7 +113,7 @@ class TemplateImage
function getFontFile(string $name): string 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 . self::$listfonts[$name];
} }
return $this->base . 'arial.ttf'; return $this->base . 'arial.ttf';
@ -115,15 +121,15 @@ class TemplateImage
function fontSuffix(array $style): string 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[0]) return "bd";
if($style[1]) return "i"; if ($style[1]) return "i";
return ""; return "";
} }
function imageText(string $text, object $value) function imageText(string $text, object $value): void
{ {
$text = strtr($text, $this->context); $text = strtr($text, $this->context);
$size = $value->fontSize; $size = $value->fontSize;
@ -140,15 +146,26 @@ class TemplateImage
if ($value->valign[0]) { if ($value->valign[0]) {
$valign = Drawing::ALIGN_TOP; $valign = Drawing::ALIGN_TOP;
} elseif ($value->valign[1]) { } elseif ($value->valign[1]) {
$valign = Drawing::ALIGN_CENTER; $valign = Drawing::ALIGN_CENTER;
} else { } else {
$valign = Drawing::ALIGN_BOTTOM; $valign = Drawing::ALIGN_BOTTOM;
} }
Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text, Drawing::imagettftextbox(
$value->width, $value->height, $this->image,
$align, $valign); $size,
0,
$value->left,
$value->top,
$color,
$fontfile,
$text,
$value->width,
$value->height,
$align,
$valign
);
} }
/** /**
@ -171,12 +188,13 @@ class TemplateImage
// Resample // Resample
$image_p = imagecreatetruecolor($new_width, $new_height); $image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $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; $this->image = $image_p;
} }
function prepare(): void { function prepare(): void
if($this->_prepare) { {
if ($this->_prepare) {
$this->_prepare = false; $this->_prepare = false;
foreach ($this->data as $value) { foreach ($this->data as $value) {
$this->imageText($value->text, $value); // break; $this->imageText($value->text, $value); // break;

View file

@ -7,6 +7,7 @@ abstract class AbstractRule
{ {
public string $field; public string $field;
protected ?string $errorMsg; protected ?string $errorMsg;
/** @var object */
protected $ctx; protected $ctx;
public function __construct(string $field, ?string $errorMsg = null) public function __construct(string $field, ?string $errorMsg = null)
@ -46,6 +47,9 @@ abstract class AbstractRule
return true; return true;
} }
/**
* @param object $ctx
*/
public function setContext($ctx): void public function setContext($ctx): void
{ {
$this->ctx = $ctx; $this->ctx = $ctx;

View file

@ -17,6 +17,10 @@ class Count extends AbstractRule
return "Количество записей должно быть не менне {$this->size} и не более {$this->max}"; return "Количество записей должно быть не менне {$this->size} и не более {$this->max}";
} }
/**
* @param string $s
* @return bool
*/
function notEmpty($s): bool { function notEmpty($s): bool {
return $s != ""; return $s != "";
} }

View file

@ -9,6 +9,7 @@ use ctiso\Validator\Rule\AbstractRule,
class MatchRule extends AbstractRule class MatchRule extends AbstractRule
{ {
/** @var string */
public $same; public $same;
public function getErrorMsg(): string public function getErrorMsg(): string

View file

@ -147,7 +147,7 @@ class Validator
return $this->isValid(); return $this->isValid();
} }
public function addError(string $name, string $message) public function addError(string $name, string $message): void
{ {
$this->errorMsg[$name] = $message; $this->errorMsg[$name] = $message;
} }

View file

@ -119,7 +119,7 @@ class View extends \stdClass
return $result; return $result;
} }
/*abstract*/ public function set(string $key, mixed $value) /*abstract*/ public function set(string $key, mixed $value): void
{ {
} }