chore: Аннотация типов

This commit is contained in:
Wizard 2025-11-01 23:17:40 +03:00
parent f964472e62
commit cf0bc435ce
19 changed files with 96 additions and 37 deletions

View file

@ -48,6 +48,7 @@ class Collection implements \ArrayAccess
* Read stored "request data" by referencing a key. * Read stored "request data" by referencing a key.
* *
* @param string $key * @param string $key
* @param mixed $default
* @return mixed * @return mixed
*/ */
public function get($key, $default = null) public function get($key, $default = null)

View file

@ -31,27 +31,26 @@ class Action implements ActionInterface
public string $viewPathPrefix = ''; // Путь к шаблонам контроллера public string $viewPathPrefix = ''; // Путь к шаблонам контроллера
/** /** Соединение с базой данных */
* Соединение с базой данных
*/
public Database $db; public Database $db;
// Фильтры // Фильтры
/** @var ?\ctiso\Filter\ActionAccess */ /** @var ?\ctiso\Filter\ActionAccess Обьект хранит параметры доступа */
public $access = null; // Обьект хранит параметры доступа public $access = null;
/** @var ?\ctiso\Filter\ActionLogger */ /** @var ?\ctiso\Filter\ActionLogger Обьект для ведения лога */
public $logger = null; // Обьект для ведения лога public $logger = null;
/** @var Factory Обьект для создания моделей */
private $factory = null; // Ссылка на обьект создания модели private $factory = null; // Ссылка на обьект создания модели
private array $helpers = []; // Помошники для действий private array $helpers = []; // Помошники для действий
public $part = null; // Параметры для ссылки /** @var ?Url Параметры для ссылки */
public $part = null;
/** @var \ctiso\Registry */ /** @var \ctiso\Registry Ссылка на настройки */
public $config; // Ссылка на настройки public $config;
/** @var \ctiso\Role\User */ /** @var \ctiso\Role\User Обьект пользователя */
public $user; // Обьект пользователя public $user;
// Для Widgets /** @var \ctiso\View\View Для Widgets */
public $view = null; public $view = null;
public array $childNodes = []; public array $childNodes = [];
@ -307,6 +306,8 @@ class Action implements ActionInterface
/** /**
* Вызов помошников контроллера * Вызов помошников контроллера
* @param HttpRequest $request
* @return mixed
*/ */
public function callHelpers(HttpRequest $request) public function callHelpers(HttpRequest $request)
{ {
@ -430,7 +431,7 @@ class Action implements ActionInterface
/** /**
* Проверка идентификатора страницы * Проверка идентификатора страницы
* @param $page int Идентификатор страницы * @param int $page Идентификатор страницы
* @return bool * @return bool
*/ */
function checkPageId(HttpRequest $request, $page) function checkPageId(HttpRequest $request, $page)

View file

@ -15,6 +15,7 @@ interface ActionInterface {
/** /**
* @param string $name * @param string $name
* @param class-string<\ctiso\View\View> $class * @param class-string<\ctiso\View\View> $class
* @return \ctiso\View\View
*/ */
function getView($name, $class); function getView($name, $class);
/** /**

View file

@ -84,7 +84,7 @@ class Component
*/ */
public $site; public $site;
function before() { function before(): void {
} }
/** /**
@ -308,9 +308,9 @@ class Component
/** /**
* Генерация интерфейса для выбора галлереи фотографии * Генерация интерфейса для выбора галлереи фотографии
* @param Composite $view * @param Composite $view
* @param \ctiso\Form\OptionsFactory $options * @param ?\ctiso\Form\OptionsFactory $options
*/ */
public function setParameters(Composite $view, $options = null) public function setParameters(Composite $view, $options = null): void
{ {
$form = new Form(); $form = new Form();
@ -322,6 +322,10 @@ class Component
$view->component_title = $settings['title']; $view->component_title = $settings['title'];
} }
/**
* @param \ctiso\Form\OptionsFactory $options
* @return array
*/
public function getFields($options = null) { public function getFields($options = null) {
$form = new Form(); $form = new Form();
$form->addFieldList($this->getInfo()['parameter'], $options); $form->addFieldList($this->getInfo()['parameter'], $options);

View file

@ -33,7 +33,9 @@ class Front extends Action
/** @var array<string, Action> */ /** @var array<string, Action> */
protected $modules = []; protected $modules = [];
/**
* @param string $default
*/
public function __construct(Database $db, Registry $config, User $user, $default) { public function __construct(Database $db, Registry $config, User $user, $default) {
parent::__construct(); parent::__construct();
$this->config = $config; $this->config = $config;

View file

@ -15,7 +15,7 @@ class Installer
/** @var callable */ /** @var callable */
protected $installPath; protected $installPath;
/** @var Settings */ /** @var Settings */
public $_registry; public $_registry;
public function __construct(Settings $_registry) public function __construct(Settings $_registry)
{ {
@ -27,7 +27,7 @@ class Installer
* @param Manager $db_manager * @param Manager $db_manager
* @param callable $installPath * @param callable $installPath
*/ */
public function setUp($db_manager, $installPath) public function setUp($db_manager, $installPath): void
{ {
$this->db_manager = $db_manager; $this->db_manager = $db_manager;
$this->installPath = $installPath; $this->installPath = $installPath;

View file

@ -1,6 +1,10 @@
<?php <?php
namespace { namespace {
if (!function_exists('sqliteLower')) { if (!function_exists('sqliteLower')) {
/**
* @param string $str
* @return string
*/
function sqliteLower($str) function sqliteLower($str)
{ {
return mb_strtolower($str, 'UTF-8'); return mb_strtolower($str, 'UTF-8');
@ -183,7 +187,7 @@ namespace ctiso {
* @param array $values - значения * @param array $values - значения
* @param bool $return_id - возвращать id * @param bool $return_id - возвращать id
* @param string $index - индекс * @param string $index - индекс
* @return int|mixed * @return int|null
*/ */
function insertQuery($table, array $values, $return_id = false, $index = null) function insertQuery($table, array $values, $return_id = false, $index = null)
{ {
@ -208,6 +212,7 @@ namespace ctiso {
return $result['lastid']; return $result['lastid'];
} }
} }
return null;
} }
/** /**

View file

@ -46,7 +46,9 @@ class PDOStatement extends \PDOStatement implements \IteratorAggregate
return true; return true;
} }
/**
* @return bool
*/
public function first() { public function first() {
if ($this->cursorPos !== 0) { $this->seek(0); } if ($this->cursorPos !== 0) { $this->seek(0); }
return $this->next(); return $this->next();

View file

@ -5,7 +5,6 @@ use PDO;
class StatementIterator implements \Iterator class StatementIterator implements \Iterator
{ {
/** @var PDOStatement */ /** @var PDOStatement */
private $result; private $result;
/** @var int */ /** @var int */
@ -44,6 +43,9 @@ class StatementIterator implements \Iterator
$this->pos++; $this->pos++;
} }
/**
* @param int $index
*/
function seek($index): void { function seek($index): void {
$this->pos = $index; $this->pos = $index;
} }

View file

@ -82,6 +82,9 @@ class Table
/** /**
* Записать значение в клетку с заданными координатами * Записать значение в клетку с заданными координатами
* @param int $x Номер ряда
* @param int $y Номер столбца
* @param string $value Значение клетки
*/ */
function setCell(int $x, int $y, $value): void function setCell(int $x, int $y, $value): void
{ {
@ -137,16 +140,15 @@ class Table
/** /**
* Обьединяет клетки в строке * Обьединяет клетки в строке
* @param $row Номер ряда * @param int $x Номер ряда
* @param $cell Номер столбца * @param int $cell Номер столбца
* @param $merge Количество клеток для обьединения * @param int $merge Количество клеток для обьединения
*/ */
function setCellMerge(int $x, int $cell, $merge): void function setCellMerge(int $x, int $cell, $merge): void
{ {
assert($x > 0); assert($x > 0);
assert($cell > 0); assert($cell > 0);
/** @var TableRow $row */
$row = $this->rows[$x]; $row = $this->rows[$x];
$row->cells[$cell]->merge = $merge; $row->cells[$cell]->merge = $merge;
} }
@ -157,7 +159,7 @@ class Table
* @param int $y Номер столбца * @param int $y Номер столбца
* @param string $name Имя стиля * @param string $name Имя стиля
*/ */
function setCellStyle ($row, $y, $name) function setCellStyle ($row, $y, $name): void
{ {
if (isset($this->rows[$row])) { if (isset($this->rows[$row])) {
$this->rows[$row]->setCellStyle($y, $name); $this->rows[$row]->setCellStyle($y, $name);
@ -166,6 +168,7 @@ class Table
/** /**
* Добавляет строку к таблице * Добавляет строку к таблице
* @return int Номер добавленной строки
*/ */
function addRow(int $index = 1, array $data = [""]) function addRow(int $index = 1, array $data = [""])
{ {
@ -243,7 +246,7 @@ class Table
* @param mixed $value Значение клетки * @param mixed $value Значение клетки
* @param bool $setIndex Устанавливать индекс клетки в атрибут ss:Index * @param bool $setIndex Устанавливать индекс клетки в атрибут ss:Index
*/ */
function createCell (TableCell $ncell, XMLWriter $doc, $j, mixed $value, $setIndex) { function createCell (TableCell $ncell, XMLWriter $doc, $j, mixed $value, $setIndex): void {
$doc->startElement("Cell"); $doc->startElement("Cell");
if ($ncell->style) { if ($ncell->style) {

View file

@ -4,6 +4,8 @@
*/ */
namespace ctiso\Form; namespace ctiso\Form;
use ctiso\Form\OptionsFactory;
class Field class Field
{ {
/** @var bool */ /** @var bool */
@ -25,18 +27,26 @@ class Field
public $error = false; public $error = false;
/** @var bool */ /** @var bool */
public $require = false; public $require = false;
/** @var ?string */
public $hint = null; public $hint = null;
/** @var ?int */ /** @var ?int */
public $maxlength = null; public $maxlength = null;
/** @var ?string */
public $fieldset = null; public $fieldset = null;
// Блоки (Убрать в отдельный класс!!!) // Блоки (Убрать в отдельный класс!!!)
/** @var array */
public $_title = []; public $_title = [];
/** @var string */ /** @var string */
public $description = ""; public $description = "";
/** @var array */ /** @var array */
public $alias = []; public $alias = [];
/** @phpstan-ignore-next-line */
/**
* @param array $input
* @param OptionsFactory|null $factory
* @phpstan-ignore-next-line
*/
public function __construct ($input = [], $factory = null) public function __construct ($input = [], $factory = null)
{ {
$this->default = null; $this->default = null;

View file

@ -16,7 +16,7 @@ use ctiso\HttpRequest;
* Форма для ввода * Форма для ввода
*/ */
class Form { class Form {
/** @var array */ /** @var array<Field> */
public $field = []; //Поля формы public $field = []; //Поля формы
/** @var array */ /** @var array */
public $fieldsets = []; //Группы полей (fieldset). Некоторые поля могут не принадлежать никаким группам public $fieldsets = []; //Группы полей (fieldset). Некоторые поля могут не принадлежать никаким группам
@ -137,6 +137,7 @@ class Form {
/** /**
* Добавляет список полей для формы * Добавляет список полей для формы
* @param array $list * @param array $list
* @param OptionsFactory|null $factory
*/ */
public function addFieldList(array $list, $factory = null): void public function addFieldList(array $list, $factory = null): void
{ {
@ -191,6 +192,10 @@ class Form {
} }
} }
/**
* @param string $name
* @param mixed $value
*/
public function set($name, $value): void public function set($name, $value): void
{ {
$this->field[$name]->setValue($value); $this->field[$name]->setValue($value);

View file

@ -94,7 +94,12 @@ class partial {
* Композиция функций * Композиция функций
*/ */
class compose { class compose {
/** @var array<callable> */
protected $fns; protected $fns;
/**
* @param array<callable> $list
*/
function __construct($list) { function __construct($list) {
$this->fns = array_reverse($list); $this->fns = array_reverse($list);
} }
@ -275,6 +280,7 @@ class Functions {
/** /**
* @param string $key * @param string $key
* @param list<object>|\ArrayIterator $array * @param list<object>|\ArrayIterator $array
* @return array<mixed>
*/ */
static function key_values_object($key, $array) { static function key_values_object($key, $array) {
$result = []; $result = [];
@ -415,6 +421,7 @@ class Functions {
* Поиск элемента в массиве * Поиск элемента в массиве
* @param callable $cb сравнение с элементом массива * @param callable $cb сравнение с элементом массива
* @param array $hs массив в котором ищется значение * @param array $hs массив в котором ищется значение
* @param bool $strict
* *
* @return int|string|null ключ найденого элемента в массиве * @return int|string|null ключ найденого элемента в массиве
*/ */

View file

@ -14,7 +14,10 @@ class Numbers
return $i; return $i;
} }
static function prefix(callable $prefix, array $array, $key = false) /**
* @param array $array
*/
static function prefix(callable $prefix, array $array)
{ {
$result = []; $result = [];
$count = count($array); $count = count($array);

View file

@ -53,6 +53,9 @@ class Primitive {
return ((int) $value); return ((int) $value);
} }
/**
* @param mixed $value
*/
public static function from_int($value): string public static function from_int($value): string
{ {
return ((string) $value); return ((string) $value);

View file

@ -7,6 +7,6 @@ interface UserInterface {
function getUserByQuery(Statement $stmt); function getUserByQuery(Statement $stmt);
function getUserByLogin(string $login); function getUserByLogin(string $login);
function getUserById(int $id); function getUserById(int $id);
function getName(); function getName(): string;
function setSID(string $random, $result); function setSID(string $random, $result);
} }

View file

@ -212,6 +212,7 @@ class Settings
/** /**
* Получение значения ключа * Получение значения ключа
* @param string $key Ключ * @param string $key Ключ
* @param mixed $default Значение по умолчанию
* @return mixed * @return mixed
*/ */
public function get($key, $default = null) public function get($key, $default = null)

View file

@ -16,7 +16,7 @@ class FakeZipArchive {
/** @var string */ /** @var string */
public $base; public $base;
function open(string $path) { function open(string $path): void {
$this->base = $path; $this->base = $path;
} }
@ -95,6 +95,9 @@ class Setup
$this->context[$name] = $value; $this->context[$name] = $value;
} }
/**
* @return string
*/
function replaceFn(array $matches) { function replaceFn(array $matches) {
if (isset($this->context[$matches[2]])) { if (isset($this->context[$matches[2]])) {
$v = $this->context[$matches[2]]; $v = $this->context[$matches[2]];

View file

@ -29,9 +29,9 @@ class View extends \stdClass
/** @var string[] */ /** @var string[] */
public array $suggestions = []; //подсказки public array $suggestions = []; //подсказки
/** @var string[] $alias */ /** @var array<string, string|array<string, string>> */
public array $alias = []; public array $alias = [];
public $codeGenerator = null; // public $codeGenerator = null;
/** @var View|null */ /** @var View|null */
public $parent_view = null; public $parent_view = null;
@ -52,6 +52,9 @@ class View extends \stdClass
} }
} }
/**
* @param array $values
*/
public function assignValues($values): void public function assignValues($values): void
{ {
$this->_values = $values; $this->_values = $values;
@ -146,6 +149,9 @@ class View extends \stdClass
return $title !== null; return $title !== null;
} }
/**
* @param array<string, string|array<string, string>> $alias
*/
function setAlias($alias): void function setAlias($alias): void
{ {
$this->alias = $alias; $this->alias = $alias;