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

View file

@ -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);
}

View file

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

View file

@ -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)

View file

@ -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<mixed>
*/
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 [];
}
}

View file

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

View file

@ -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(

View file

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

View file

@ -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)) {

View file

@ -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') {

View file

@ -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;

View file

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

View file

@ -289,6 +289,7 @@ class Functions {
* @param string $key
* @param string $value
* @param list<array<string, mixed>>|\ArrayIterator $array
* @return array<string, mixed>
*/
static function assoc_key_values($key, $value, $array) {
$result = [];
@ -301,6 +302,7 @@ class Functions {
/**
* @param string $key
* @param list<array<string, mixed>>|\ArrayIterator $array
* @return array<string, mixed>
*/
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') {

View file

@ -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)) {

View file

@ -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;
}

View file

@ -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<string>
*/
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) //
{

View file

@ -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];

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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)
{

View file

@ -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) {

View file

@ -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)
{

View file

@ -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;
@ -146,9 +152,20 @@ class TemplateImage
$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;

View file

@ -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;

View file

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

View file

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

View file

@ -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;
}

View file

@ -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
{
}