fix: Определения типов

This commit is contained in:
origami11@yandex.ru 2025-10-01 12:37:39 +03:00
parent 9f6fd74b17
commit dd74a97894
28 changed files with 334 additions and 249 deletions

View file

@ -41,7 +41,7 @@ class Collection implements \ArrayAccess
*
* @return void
*/
public function set($key/*: string*/, $value/*: any*/)
public function set($key, $value)
{
$this->data[$key] = $value;
}

View file

@ -35,6 +35,7 @@ class Action
public Database $db;
// Фильтры
/** @var ?ActionAccess */
public $access = null; // Обьект хранит параметры доступа
public $logger = null; // Обьект для ведения лога
@ -42,8 +43,10 @@ class Action
private $helpers = array(); // Помошники для действий
public $part = null; // Параметры для ссылки
public $config/*: Registry*/; // Ссылка на настройки
public $user/*: User*/; // Обьект пользователя
/** @var \ctiso\Registry */
public $config; // Ссылка на настройки
/** @var \ctiso\Role\User */
public $user; // Обьект пользователя
// Для Widgets
public $view = null;
@ -214,7 +217,7 @@ class Action
*/
public function nUrl($actionName, array $param = [])
{
$access/*: ActionAccess*/ = $this->access;
$access = $this->access;
$url = new Url();
//print_r([$name, $param]);
@ -337,7 +340,8 @@ class Action
if ($view instanceof View) {
$this->view->assignValues($this->ctrlValues);
$node/*: Composite*/ = null;
/** @var ?Composite $node */
$node = null;
foreach ($this->childNodes as $name => $node) {
$node->make($this);
$this->view->setView($name, $node->view);
@ -376,7 +380,7 @@ class Action
$this->_getActionPath()->getPath($this, ($action) ? $action : $request->getAction());
}
function redirect($action/*: string*/) {
function redirect(string $action) {
header('location: ' . $action);
exit();
}

View file

@ -7,7 +7,10 @@ class Request {
public $r;
public $id;
function __construct($request/*: HttpRequest*/, $id) {
/**
* @param HttpRequest $request
*/
function __construct($request, $id) {
$this->r = $request;
$this->id = $id;
}

View file

@ -14,7 +14,8 @@ class Service
{
public $viewPath = [];
public $webPath = [];
public $config/*: Registry*/;
/** @var Registry */
public $config;
public $template;
public $templatePath;
public $COMPONENTS_WEB;
@ -53,7 +54,12 @@ class Service
return $model;
}
public function options($key, $val, $res/*: PDOStatement*/) {
/**
* @param string $key
* @param string $val
* @param PDOStatement $res
*/
public function options($key, $val, $res) {
$result = [];
while($res->next()) {
$result[] = ['value' => $res->getInt($key), 'name' => $res->getString($val)];

View file

@ -31,7 +31,8 @@ namespace ctiso {
function prepare(string $sql, array $options = []): PDOStatement|false
{
$result/*: PDOStatement*/ = parent::prepare($sql, $options);
/** @var PDOStatement $result */
$result = parent::prepare($sql, $options);
return $result;
}
@ -49,10 +50,11 @@ namespace ctiso {
static function getConnection(array $dsn)
{
/** @var ?Database */
$connection = null;
if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') {
$port = (isset($dsn['port'])) ? "port={$dsn['port']};" : "";
$connection/*: Database*/ = new self("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']);
$connection = new self("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']);
if ($dsn['phptype'] == 'pgsql') {
$connection->query('SET client_encoding="UTF-8"');
}
@ -64,9 +66,9 @@ namespace ctiso {
$connection = new self("{$dsn['phptype']}:");
$connection->sqliteCreateFunction('LOWER', 'sqliteLower', 1);
} elseif ($dsn['phptype'] == 'sqlite') {
$connection/*: Database*/ = new self("{$dsn['phptype']}:{$dsn['database']}");
$connection = new self("{$dsn['phptype']}:{$dsn['database']}");
$connection->setAttribute(PDO::ATTR_TIMEOUT, 5);
$mode = defined('SQLITE_JOURNAL_MODE') ? SQLITE_JOURNAL_MODE : 'WAL';
$mode = defined('SQLITE_JOURNAL_MODE') ? \SQLITE_JOURNAL_MODE : 'WAL';
$connection->query("PRAGMA journal_mode=$mode");
$connection->sqliteCreateFunction('LOWER', 'sqliteLower', 1);
}

View file

@ -43,7 +43,7 @@ class JsonInstall {
}
// Создать таблицы
function initDataBase($initActions/*: array*/, $dbinit_path) {
function initDataBase(array $initActions, $dbinit_path) {
$pg = $this->db_manager->db->isPostgres();
if (!$pg) {
$refs = [];

View file

@ -9,14 +9,15 @@ use Exception;
class Manager
{
public $db/*: Database*/;
/** @var Database */
public $db;
public function __construct(Database $db)
{
$this->db = $db;
}
public function executeAction($action/*: array*/, $db_file = "")
public function executeAction(array $action, $db_file = "")
{
switch($action["type"]) {
case "dropTable":
@ -117,7 +118,7 @@ class Manager
return;
}
$data/*: array*/ = $this->dumpTable($table);
$data = $this->dumpTable($table);
$this->db->query("ALTER TABLE ".$table." RENAME TO ".$tmp_table.";");
$table_info[$new_name] = $table_info[$old_name];
@ -169,7 +170,7 @@ class Manager
$this->db->query($q);
}
public function getConstraintDef($c/*: array*/)
public function getConstraintDef(array $c)
{
if ($c['type'] == 'unique') {
return "UNIQUE(" . implode(", ", $c['fields']) . ")";

View file

@ -16,7 +16,11 @@ class Statement
protected $conn;
protected $query;
function __construct($query, $conn/*: Database*/) {
/**
* @param string $query
* @param Database $conn
*/
function __construct($query, $conn) {
$this->query = $query;
$this->conn = $conn;
}
@ -45,7 +49,7 @@ class Statement
if ($this->limit) {
$this->query .= " LIMIT {$this->limit} OFFSET {$this->offset}";
}
$stmt/*: PDOStatement*/ = $this->conn->prepare($this->query);
$stmt = $this->conn->prepare($this->query);
foreach ($this->binds as $bind) {
list($n, $value, $type) = $bind;
$stmt->bindValue($n, $value, (int) $type);

View file

@ -10,7 +10,10 @@ class StatementIterator implements \Iterator
private $pos = 0;
private $row_count;
public function __construct($rs/*: PDOStatement*/) {
/**
* @param PDOStatement $rs
*/
public function __construct($rs) {
$this->result = $rs;
$this->row_count = $rs->getRecordCount();
}

View file

@ -61,25 +61,26 @@ class Table
/**
* Записать значение в клетку с заданными координатами
*/
function setCell($x, $y, $value)
function setCell(int $x, int $y, $value)
{
assert(is_numeric($x) && $x > 0);
assert(is_numeric($y) && $y > 0);
assert($x > 0);
assert($y > 0);
if(! isset($this->rows[$x])) {
$this->rows[$x] = new TableRow();
}
$row/*: TableRow*/ = $this->rows[$x];
/** @var TableRow $row */
$row = $this->rows[$x];
$row->setCell($y, $value);
}
/**
* Заполняет ряд начиная с указанного столбца значениями из массива
*/
function setRow($row, $index, array $data)
function setRow(int $row, int $index, array $data)
{
assert(is_numeric($index) && $index > 0);
assert(is_numeric($row) && $row > 0);
assert($index > 0);
assert($row > 0);
reset($data);
for ($i = $index; $i < $index + count($data); $i++) {
@ -90,20 +91,20 @@ class Table
/**
* Устанавливает высоту ряда
* @param $row integer Номер ряда
* @parma $value real Высота ряда
* @param int $row Номер ряда
* @param number $value Высота ряда
*/
function setRowHeight ($row, $value)
function setRowHeight (int $row, $value)
{
assert(is_numeric($row) && $row > 0);
assert($row > 0);
$this->rows[$row]->height = $value;
}
/**
* Устанавливает стиль ряда
* @param $row integer Номер ряда
* @parma $name string Имя стиля
* @param int $row Номер ряда
* @param string $name Имя стиля
*/
function setRowStyle ($row, $name)
{
@ -118,12 +119,13 @@ class Table
* @param $cell Номер столбца
* @param $merge Количество клеток для обьединения
*/
function setCellMerge($x, $cell, $merge)
function setCellMerge(int $x, int $cell, $merge)
{
assert(is_numeric($x) && $x > 0);
assert(is_numeric($cell) && $cell > 0);
assert($x > 0);
assert($cell > 0);
$row/*: TableRow*/ = $this->rows[$x];
/** @var TableRow $row */
$row = $this->rows[$x];
$row->cells[$cell]->merge = $merge;
}
@ -135,14 +137,15 @@ class Table
*/
function setCellStyle ($row, $y, $name)
{
if (isset($this->rows[$row]))
if (isset($this->rows[$row])) {
$this->rows[$row]->setCellStyle($y, $name);
}
}
/**
* Добавляет строку к таблице
*/
function addRow($index = 1, array $data = [""])
function addRow(int $index = 1, array $data = [""])
{
assert(is_numeric($index) && $index > 0);
$offset = $this->getRows() + 1;
@ -158,7 +161,7 @@ class Table
*/
function getRows()
{
$keys/*: array*/ = array_keys($this->rows);
$keys = array_keys($this->rows);
return max($keys);
}
@ -169,7 +172,7 @@ class Table
*/
function getRowCells(TableRow $row)
{
$keys/*: array*/ = array_keys($row->cells);
$keys = array_keys($row->cells);
return max($keys);
}
@ -207,7 +210,7 @@ class Table
/**
* Генерация клетки таблицы (Переработать)
*/
function createCell (TableCell $ncell, XMLWriter $doc, $j, $value/*: any*/, $setIndex) {
function createCell (TableCell $ncell, XMLWriter $doc, $j, mixed $value, $setIndex) {
$doc->startElement("Cell");
if ($ncell->style) {
@ -266,8 +269,8 @@ class Table
if ($this->rows[$i]->height) {
$doc->writeAttribute('ss:Height', $this->rows[$i]->height);
}
$nrow/*: TableRow*/ = $this->rows[$i];
/** @var TableRow $nrow */
$nrow = $this->rows[$i];
// Флаг индикатор подстановки номера столбца
$setIndex = false;
for ($j = 1; $j <= $columns; $j++) {

View file

@ -12,9 +12,13 @@ class ActionAccess
{
public $access = array();
public $processor;
public $user/*: User*/;
/** @var User */
public $user;
function __construct($processor/*: Filter*/, $user) {
/**
* @param Filter $processor
*/
function __construct($processor, $user) {
$this->processor = $processor;
$this->user = $user;
}

View file

@ -13,7 +13,12 @@ class ActionLogger
public $action;
public $processor;
function __construct($processor/*: Filter*/, $logPath, $user/*: UserInterface*/) {
/**
* @param $processor Filter
* @param $logPath string
* @param $user UserInterface
*/
function __construct($processor, $logPath, $user) {
$this->processor = $processor;
$this->user = $user;

View file

@ -10,8 +10,13 @@ use ctiso\Controller\Action,
class Filter
{
/** @var Action */
public $processor;
public function __construct($processor/*: Action*/)
/**
* @param Action $processor
*/
public function __construct($processor)
{
$this->processor = $processor;
}

View file

@ -41,7 +41,10 @@ class Field
}
}
function setValue($value/*: any*/)
/**
* @param mixed $value
*/
function setValue($value)
{
$this->value = $value;
}

View file

@ -222,9 +222,11 @@ class Functions {
* Извлекает из многомерого массива значения с определенным ключом
* @example key_values('a', array(1 => array('a' => 1, 'b' => 2))) => array(1)
*
* @param string $key
* @param array|ArrayIterator $array
* @return mixed
*/
static function key_values($key, $array/*: array|ArrayIterator*/) {
static function key_values($key, $array) {
$result = [];
foreach($array as $item) {
@ -233,7 +235,11 @@ class Functions {
return $result;
}
static function key_values_object($key, $array/*: array|ArrayIterator*/) {
/**
* @param string $key
* @param array|ArrayIterator $array
*/
static function key_values_object($key, $array) {
$result = [];
foreach($array as $item) {
@ -258,7 +264,13 @@ class Functions {
return $result;
}
static function _get($key, $value/*: any*/, $array/*: array*/) {
/**
* @param string $key
* @param mixed $value
* @param array $array
* @return mixed
*/
static function _get($key, $value, $array) {
foreach ($array as $item) {
if ($item[$key] == $value) return $item;
}
@ -345,7 +357,7 @@ class Functions {
* @param array $table Двухмерный массив
* @example
* key_unique_values ('name', array (array ('name' => 1), array ('name' => 2), array ('name' => 1)))
=> array (1, 2)
* => array (1, 2)
* @end example
*/
static function key_unique_values ($name, $table) {
@ -372,9 +384,11 @@ class Functions {
/**
* Преобразует ключи элементов для многомерного массива
* @param string $key_name Имя ключа
* @param array $array Многомерный массив
* @return mixed
*/
static function hash_key ($key_name,$array/*: array */) {
static function hash_key ($key_name, $array) {
$result = [];
foreach($array as $value) {

View file

@ -55,7 +55,7 @@ class HttpRequest extends Collection
return parent::get('data')->get($key, $default);
}
function session(Session $value = null)
function session(?Session $value = null)
{
if ($value) {
$this->_session = $value;
@ -63,7 +63,7 @@ class HttpRequest extends Collection
return $this->_session;
}
function set($key, $value/*: any*/)
function set($key, mixed $value)
{
parent::get('data')->set($key, $value);
}

View file

@ -35,7 +35,12 @@ class Manager extends Filter
$this->addCondition(Functions::rcurry([$this, 'checkXHR'], $get), $layout);
}
public function checkGet($request/*: HttpRequest*/, $get)
/**
* @param HttpRequest $request
* @param array $get
* @return bool
*/
public function checkGet($request, $get)
{
if (is_array($get)) {
foreach ($get as $key => $value) {
@ -47,7 +52,12 @@ class Manager extends Filter
return true;
}
public function checkXHR($request/*: HttpRequest*/, $get)
/**
* @param HttpRequest $request
* @param array $get
* @return bool
*/
public function checkXHR($request, $get)
{
return $request->isAjax() && $this->checkGet($request, $get);
}

View file

@ -37,6 +37,7 @@ class MailAlt
/**
* Установка получателей копии
* @param string $name
*/
function copy($name) // recipient cc
{
@ -50,14 +51,16 @@ class MailAlt
/**
* Тема письма
* @param string $subject
*/
function subject($subject/*: string*/)
function subject($subject)
{
$this->mailer->Subject = $subject;
}
/**
* Текст письма
* @param string $text
*/
function setContent($text)
{

View file

@ -155,7 +155,10 @@ class Path
}
// Сравнение двух путей на равентство
public function equal($path/*: Path*/)
/**
* @param Path $path
*/
public function equal($path)
{
$count = count($this->path);
if ($count == count($path->path)) {
@ -199,11 +202,11 @@ class Path
/**
* Проверяет является ли папка родительской для другой папки
*
* @parma Path $path
* @param Path $path
*
* @return boolean
*/
public function isParent($path/*: Path*/)
public function isParent($path)
{
if (isset($this->url['host']) && isset($path->url['host'])
&& ($this->url['host'] != $path->url['host'])) return false;

View file

@ -133,7 +133,8 @@ class Setup
return;
}
$item/*: \SimpleXMLElement*/ = $this->stack[count($this->stack) - 1];
/** @var \SimpleXMLElement */
$item = $this->stack[count($this->stack) - 1];
$root = $item->children();
foreach ($root as $node)
{
@ -212,9 +213,11 @@ class Setup
}
/**
* Выполнение Списка SQL команд
* Выполнение Списка SQL команд из ZIP файла
* @param Database $conn
* @param string $file
*/
function batchSQLZip($conn/*: Database*/, $file)
function batchSQLZip($conn, $file)
{
$stmtList = SQLStatementExtractor::extract($this->zip->getFromName($file));
foreach ($stmtList as $stmt) {
@ -222,7 +225,12 @@ class Setup
}
}
static function batchSQL($conn/*: Database*/, $file)
/**
* Выполнение Списка SQL команд
* @param Database $conn
* @param string $file
*/
static function batchSQL($conn, $file)
{
$stmtList = SQLStatementExtractor::extractFile($file);
foreach ($stmtList as $stmt) {

View file

@ -41,7 +41,8 @@ class Tales_Assets implements PHPTAL_Tales
}
class Tales {
static $site/*: SiteInterface*/;
/** @var SiteInterface */
static $site;
static function phptal_date ($e) {
return date("d.m.Y", $e);
@ -61,8 +62,7 @@ class Tales {
*/
static function phptal_component($expression) {
$begin = floatval(microtime(true));
$component/*: Component*/ = null;
/** @var Component */
$component = self::$site->loadComponent($expression);
$req = new HttpRequest();
$result = $component->execute($req);

View file

@ -124,7 +124,7 @@ class SQLStatementExtractor {
* @param string $string The string to check in (haystack).
* @return boolean True if $string ends with $check, or they are equal, or $check is empty.
*/
protected static function endsWith($check/*: string*/, $string) {
protected static function endsWith(string $check, $string) {
if ($check === "" || $check === $string) {
return true;
} else {

View file

@ -41,9 +41,8 @@ class TemplateImage
public $resource;
public $filename;
function __construct ($template = null)
function __construct (?string $template = null)
{
// assert(is_string($src));
if ($template) {
$this->data = $template;
}
@ -52,27 +51,21 @@ class TemplateImage
/**
* Путь к изображению
*/
function resourcePath($path)
function resourcePath(string $path)
{
assert(is_string($path));
$this->resource = $path;
}
/**
* Путь у шрифтам
*/
function fontPath($path)
function fontPath(string $path)
{
assert(is_string($path));
$this->base = $path;
}
function set($name, $value)
function set(string $name, $value)
{
assert(is_string($name));
$this->context['['.$name.']'] = $this->encode($value);
}
@ -90,10 +83,8 @@ class TemplateImage
/**
* Создает изображение из файла
*/
function imagefromfile($file)
function imagefromfile(string $file)
{
assert(is_string($file));
$suffix = pathinfo($file, PATHINFO_EXTENSION);
if (array_key_exists($suffix, self::$listfiles)) {
return call_user_func('imagecreatefrom' . self::$listfiles[$suffix], $file);
@ -101,17 +92,15 @@ class TemplateImage
return null;
}
function getFontFile($name)
function getFontFile(string $name)
{
assert(is_string($name));
if(array_key_exists(strtolower($name), self::$listfonts)) {
return $this->base . self::$listfonts[$name];
}
return $this->base . 'arial.ttf';
}
function fontSuffix($style)
function fontSuffix(array $style)
{
if($style[0] && $style[1]) return "z";
@ -121,7 +110,11 @@ class TemplateImage
return "";
}
function imageText($text, $value/*: \stdClass*/)
/**
* @param string $text
* @param object $value
*/
function imageText($text, $value)
{
assert(is_string($text));
@ -153,6 +146,7 @@ class TemplateImage
/**
* Перекодировка текста
* @deprecated
*/
function encode($text)
{
@ -160,6 +154,10 @@ class TemplateImage
return $text; //iconv("WINDOWS-1251", "UTF-8", $text);
}
/**
* @param int $new_width
* @param int $new_height
*/
function setSize($new_width, $new_height)
{
$width = imagesx($this->image);

View file

@ -4,7 +4,8 @@ namespace ctiso;
class Url {
public $parts = [];
public $parent/*: Url*/;
/** @var Url */
public $parent;
function __construct() {
}

View file

@ -83,7 +83,7 @@ class Validator
}
}
public function addRule($rule/*:z any*/) {
public function addRule($rule) {
if (is_array($rule)) {
$this->chain = array_merge($this->chain, $rule);
} else {
@ -91,7 +91,11 @@ class Validator
}
}
public function skip($rule/*z: AbstractRule*/, $container/*: Collection*/) // -> Rule_Abstract
/**
* @param AbstractRule $rule
* @param Collection $container
*/
public function skip($rule, $container) // -> Rule_Abstract
{
if ($rule->skipEmpty()) {
$data = $container->get($rule->field);

View file

@ -29,21 +29,21 @@ class Pages
/**
* @deprecated
* @param $page int номер страницы
* @param $onpage int количество элем на странице
* @param int $page номер страницы
* @param int $onpage количество элем на странице
* @return string
*/
static function getLimit($page/*: number*/, $onpage/*: number*/) {
static function getLimit(int $page, int $onpage) {
if ($page <= 0) { $page = 1; }
return "LIMIT $onpage OFFSET " . ($page - 1) * $onpage;
}
/**
* @param $page int номер страницы
* @param $onpage int количество элем на странице
* @param int $page номер страницы
* @param int $onpage количество элем на странице
* @return array
*/
static function _getLimit($page, $onpage) {
static function _getLimit(int $page, int $onpage) {
if ($page <= 0) { $page = 1; }
return [
'count' => $onpage,

View file

@ -68,11 +68,12 @@ class Top extends Composite
}
$init = [];
/** @var View $item */
foreach ($s->_section as $key => $item) {
$ss /*: View*/= $item;
if ($ss->codeGenerator !== null) {
if ($item->codeGenerator !== null) {
// функцию которая вычисляет а не результат
$part = call_user_func($ss->codeGenerator, $this, $key, $value);
$part = call_user_func($item->codeGenerator, $this, $key, $value);
$init[] = $part;
}
}

View file

@ -160,7 +160,7 @@ class View extends \stdClass
}
// FIXME: Префикс, конфликтует с протоколом
function resolveName($alias, $file) {
function resolveName($alias, $file): string {
list($type, $filename) = explode(":", $file, 2);
// Сделать поиск а не просто замену папки при совпадении имени