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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -6,9 +6,14 @@ namespace ctiso;
* Эмуляция каррированой функции
*/
class right {
/** @var array<mixed> */
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<mixed> */
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) {

View file

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

View file

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

View file

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

View file

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