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

This commit is contained in:
origami11@yandex.ru 2025-10-27 16:39:44 +03:00
parent 730a608f9b
commit 89913de4fe
19 changed files with 124 additions and 24 deletions

View file

@ -8,12 +8,21 @@ namespace ctiso;
*/ */
class Adapter class Adapter
{ {
/** @var array|object */
protected $adaptee; protected $adaptee;
/**
* @param array|object $adaptee
*/
public function __construct ($adaptee) public function __construct ($adaptee)
{ {
$this->adaptee = $adaptee; $this->adaptee = $adaptee;
} }
/**
* @param string $name
* @return mixed
*/
public function get($name) public function get($name)
{ {
if (is_array ($this->adaptee)) { if (is_array ($this->adaptee)) {

View file

@ -4,6 +4,12 @@
namespace ctiso; namespace ctiso;
class Arr { class Arr {
/**
* @param array $data
* @param string $key
* @param mixed $default
* @return mixed
*/
static function get($data, $key, $default = null) { static function get($data, $key, $default = null) {
return $data[$key] ?? $default; return $data[$key] ?? $default;
} }

View file

@ -72,6 +72,11 @@ class Collection implements \ArrayAccess
return (string)$this->get($key, $default); return (string)$this->get($key, $default);
} }
/**
* @param string $key
* @param int $default
* @return int
*/
public function getNat($key, $default = 1) public function getNat($key, $default = 1)
{ {
$result = (int)$this->get($key, $default); $result = (int)$this->get($key, $default);

View file

@ -6,15 +6,27 @@ use ctiso\HttpRequest,
ctiso\Arr; ctiso\Arr;
class ComponentRequest { class ComponentRequest {
/** @var string */
public $component_id; public $component_id;
/** @var string */
public $component_title; public $component_title;
/** @var HttpRequest */
public $r; public $r;
/**
* @param string $c
* @param HttpRequest $r
*/
function __construct($c, HttpRequest $r) { function __construct($c, HttpRequest $r) {
$this->component_id = $c; $this->component_id = $c;
$this->r = $r; $this->r = $r;
} }
/**
* @param string $key
* @param mixed $default
* @return mixed
*/
function get($key, $default = null) { function get($key, $default = null) {
if ($key == 'active_page') { if ($key == 'active_page') {
return $this->r->get($key); return $this->r->get($key);
@ -30,6 +42,9 @@ class ComponentRequest {
return $default; return $default;
} }
/**
* @return string
*/
function getAction() { function getAction() {
return $this->r->getAction(); return $this->r->getAction();
} }

View file

@ -8,15 +8,21 @@ class HttpRequest
const POST = "POST"; const POST = "POST";
const GET = "GET"; const GET = "GET";
private $param = []; // Параметры запроса /** @var array Параметры запроса */
public $data = null; // Содержание private $param = [];
public $url; // Адресс /** @var string Содержание */
public $method; // Метод public $data = null;
/** @var string Адресс */
public $url;
/** @var string Метод */
public $method;
/** @var int */ /** @var int */
public $port = 80; public $port = 80;
/** @var string */ /** @var string */
public $host = ""; public $host = "";
/** @var ?string */
public $proxy_host = null; public $proxy_host = null;
/** @var ?int */
public $proxy_port = null; public $proxy_port = null;
/** @var string */ /** @var string */
public $http_version = 'HTTP/1.1'; public $http_version = 'HTTP/1.1';

View file

@ -7,11 +7,17 @@ namespace ctiso\Connection;
class HttpResponse class HttpResponse
{ {
/** @var int */
private $offset; private $offset;
/** @var array */
private $param = []; private $param = [];
/** @var int */
private $code; private $code;
/** @var string */
public $response; public $response;
/** @var string */
public $version; public $version;
/** @var string */
public $data; public $data;
public function __construct($response) public function __construct($response)
@ -28,7 +34,7 @@ class HttpResponse
{ {
$http = explode(" ", $this->getLine()); $http = explode(" ", $this->getLine());
$this->version = $http[0]; $this->version = $http[0];
$this->code = $http[1]; $this->code = (int)$http[1];
$line = $this->getLine(); $line = $this->getLine();
while ($offset = strpos($line, ":")) { while ($offset = strpos($line, ":")) {
@ -55,7 +61,7 @@ class HttpResponse
/** /**
* Обработка строки HTTP ответа * Обработка строки HTTP ответа
*/ */
private function getLine() private function getLine(): string
{ {
$begin = $this->offset; $begin = $this->offset;
$offset = strpos($this->response, "\r\n", $this->offset); $offset = strpos($this->response, "\r\n", $this->offset);
@ -67,12 +73,12 @@ class HttpResponse
/** /**
* Значение параметра HTTP ответа * Значение параметра HTTP ответа
*/ */
public function getParameter($name) public function getParameter($name): string
{ {
return $this->param[$name]; return $this->param[$name];
} }
public function getData() public function getData(): string
{ {
return $this->data; return $this->data;
} }
@ -80,7 +86,7 @@ class HttpResponse
/** /**
* Состояние * Состояние
*/ */
public function getCode() public function getCode(): int
{ {
return $this->code; return $this->code;
} }

View file

@ -288,6 +288,7 @@ class Action implements ActionInterface
/** /**
* Добавление помошника контроллера * Добавление помошника контроллера
* @param class-string $class
*/ */
public function addHelper($class) public function addHelper($class)
{ {
@ -345,6 +346,7 @@ class Action implements ActionInterface
/** /**
* Установка заголовка для отображения * Установка заголовка для отображения
* @param string $title
*/ */
public function setTitle($title): void public function setTitle($title): void
{ {
@ -353,6 +355,8 @@ class Action implements ActionInterface
/** /**
* Добавление widget к отображению * Добавление widget к отображению
* @param $section
* @param $node
*/ */
public function addChild($section, $node): void public function addChild($section, $node): void
{ {

View file

@ -17,9 +17,14 @@ use PHPTAL;
use PHPTAL_PreFilter_Normalize; use PHPTAL_PreFilter_Normalize;
class FakeTemplate { class FakeTemplate {
/** @var array */
public $_data = []; public $_data = [];
/** @var string */
public $_name = ''; public $_name = '';
/**
* @param string $name
*/
function __construct($name) { function __construct($name) {
$this->_name = $name; $this->_name = $name;
} }

View file

@ -22,6 +22,7 @@ class Front extends Action
protected $_param; // Параметр по которому выбирается модуль protected $_param; // Параметр по которому выбирается модуль
protected $default; // Значение параметра по умолчанию protected $default; // Значение параметра по умолчанию
/** @var array */
protected $modules = []; protected $modules = [];
public function __construct(Database $db, Registry $config, User $user, $default) { public function __construct(Database $db, Registry $config, User $user, $default) {
@ -32,7 +33,13 @@ class Front extends Action
$this->default = $default; $this->default = $default;
} }
public function isLoaded($name) { /**
* Проверяет загружен ли модуль
* @param string $name Имя модуля
* @return bool
*/
public function isLoaded($name): bool
{
return isset($this->modules[$name]); return isset($this->modules[$name]);
} }

View file

@ -47,6 +47,7 @@ class Service
/** /**
* @param string $name Имя модели * @param string $name Имя модели
* @return string
*/ */
private function getModelPath($name) private function getModelPath($name)
{ {

View file

@ -114,6 +114,7 @@ namespace ctiso {
/** /**
* Создает подготовленный запрос * Создает подготовленный запрос
* @param string $query - запрос * @param string $query - запрос
* @return Statement
*/ */
public function prepareStatement($query) public function prepareStatement($query)
{ {

View file

@ -199,8 +199,6 @@ class Manager
if (strtolower($type) == "serial") { if (strtolower($type) == "serial") {
$type = "integer"; $type = "integer";
} }
//if (strtolower($type)=="boolean")
// $type = "integer";
} }
return $name . " " . $type . $references . $constraint; return $name . " " . $type . $references . $constraint;
} }

View file

@ -78,6 +78,9 @@ class PDOStatement extends \PDOStatement implements \IteratorAggregate
return $this->cache[$this->cursorPos]; return $this->cache[$this->cursorPos];
} }
/**
* @return array|null
*/
function getRow() { function getRow() {
return $this->fields; return $this->fields;
} }

View file

@ -27,7 +27,7 @@ class Document {
* @param array $values array Параметры стиля * @param array $values array Параметры стиля
* @param string $type Тип стиля * @param string $type Тип стиля
*/ */
function setStyle ($name, array $values, $type = 'Interior') function setStyle ($name, array $values, $type = 'Interior'): void
{ {
if(!isset($this->styles[$name])) { if(!isset($this->styles[$name])) {
$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'); $doc->startElement('Styles');
foreach ($this->styles as $name => $sn) { foreach ($this->styles as $name => $sn) {
$doc->startElement('Style'); $doc->startElement('Style');
@ -70,18 +71,22 @@ class Document {
/** /**
* Преобразует переводы строки в спец символы * Преобразует переводы строки в спец символы
* @param string $s
* @return string
*/ */
function clean ($s) { function clean ($s) {
assert(is_string($s));
return strtr($s, ["\n" => "
"]); return strtr($s, ["\n" => "
"]);
} }
/** /**
* Сохраняет таблицу в формате Office 2003 XML * Сохраняет таблицу в формате Office 2003 XML
* http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats * 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(); $doc = new XMLWriter();
if (!$doc->openUri($filename)) { if (!$doc->openUri($filename)) {

View file

@ -6,9 +6,14 @@ namespace ctiso;
* Эмуляция каррированой функции * Эмуляция каррированой функции
*/ */
class right { class right {
/** @var array<mixed> */
protected $params; protected $params;
/** @var callable */
protected $fn; protected $fn;
/**
* @param array $params
*/
public function __construct($params) { public function __construct($params) {
$this->fn = array_shift($params); $this->fn = array_shift($params);
$this->params = $params; $this->params = $params;
@ -22,9 +27,14 @@ class right {
} }
class left { class left {
/** @var array<mixed> */
protected $params; protected $params;
/** @var callable */
protected $fn; protected $fn;
/**
* @param array $params
*/
public function __construct($params) { public function __construct($params) {
$this->fn = array_shift($params); $this->fn = array_shift($params);
$this->params = $params; $this->params = $params;
@ -44,6 +54,9 @@ class partial {
/** @var callable */ /** @var callable */
protected $fn; protected $fn;
/**
* @param array $params
*/
public function __construct($params) { public function __construct($params) {
$this->fn = array_shift($params); $this->fn = array_shift($params);
$this->params = $params; $this->params = $params;
@ -294,6 +307,8 @@ class Functions {
/** /**
* Логическа операция && ко всем элементам массива * Логическа операция && ко всем элементам массива
* @param array $array Массив
* @param callable $callback Функция
* @return bool * @return bool
*/ */
static function every(array $array, $callback) { static function every(array $array, $callback) {

View file

@ -100,10 +100,12 @@ class Mail
/** /**
* Добавление вложения из файла * Добавление вложения из файла
* @param string $filename
* @param string|false $name
*/ */
function addAttachment(string $filename, $name = false): void function addAttachment(string $filename, $name = false): void
{ {
if (file_exists($filename)) { // assert ?? if (file_exists($filename)) {
$file = fopen($filename, "rb"); $file = fopen($filename, "rb");
if (is_resource($file)) { if (is_resource($file)) {
$data = fread($file, filesize($filename)); $data = fread($file, filesize($filename));
@ -112,6 +114,10 @@ class Mail
} }
} }
/**
* Установка типа содержимого
* @param string $type
*/
function setType($type): void function setType($type): void
{ {
$this->type = $type; $this->type = $type;
@ -119,6 +125,8 @@ class Mail
/** /**
* Добавление вложения из строки с указанием имени файла * Добавление вложения из строки с указанием имени файла
* @param string $data
* @param string $name
*/ */
function addAttachmentRaw($data, string $name): void function addAttachmentRaw($data, string $name): void
{ {

View file

@ -25,12 +25,21 @@ class Primitive {
return filter_var($value, FILTER_VALIDATE_BOOLEAN);//(int)((bool) $value); return filter_var($value, FILTER_VALIDATE_BOOLEAN);//(int)((bool) $value);
} }
/**
* Преобразование значения в булевое значение
* @param string $value
* @return bool
*/
public static function from_bool($value): bool public static function from_bool($value): bool
{ {
return ((bool) $value); return ((bool) $value);
} }
// int /**
* Преобразование значения в целое число
* @param string $value
* @return int
*/
public static function to_int($value): int public static function to_int($value): int
{ {
return ((int) $value); return ((int) $value);

View file

@ -70,7 +70,6 @@ class Settings
*/ */
public function writeKey(array $key, $value) public function writeKey(array $key, $value)
{ {
// assert(count($key) >= 1);
$data = &$this->data; $data = &$this->data;
while (count($key) > 1) { while (count($key) > 1) {
@ -78,7 +77,6 @@ class Settings
$data = &$data[$name]; $data = &$data[$name];
} }
// assert(count($key) == 1);
$name = array_shift($key); $name = array_shift($key);
if (is_array($value)) { if (is_array($value)) {
if (!isset($data[$name])) { if (!isset($data[$name])) {
@ -92,6 +90,8 @@ class Settings
/** /**
* Обновляет массив в соответствии со значением * Обновляет массив в соответствии со значением
* @param array $data Массив
* @param mixed $value Значение
*/ */
protected function merge(array &$data, $value): void protected function merge(array &$data, $value): void
{ {
@ -122,7 +122,6 @@ class Settings
*/ */
protected function readKeyData(array $key, $data) protected function readKeyData(array $key, $data)
{ {
// assert(count($key) >= 1);
while (count($key) > 1) { while (count($key) > 1) {
$name = array_shift($key); $name = array_shift($key);
if (isset($data[$name])) { if (isset($data[$name])) {
@ -132,7 +131,6 @@ class Settings
} }
} }
// assert(count($key) == 1);
$name = array_shift($key); $name = array_shift($key);
if (isset($data[$name])) { if (isset($data[$name])) {
return $data[$name]; return $data[$name];

View file

@ -8,7 +8,6 @@ use PHPTAL_TranslationService;
class Composite extends View class Composite extends View
{ {
private PHPTAL $tal; private PHPTAL $tal;
public $config;
function __construct(string $file) function __construct(string $file)
{ {