From 4fc2e2ac7dbbebbf07bce362f09c423b2e55fa3e Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Mon, 22 Jan 2024 19:56:45 +0300 Subject: [PATCH] fix: phpstan level=3 --- config.php | 4 ++++ phpstan.neon | 10 ++++++++++ src/Controller/Action.php | 2 +- src/Controller/Component.php | 12 +++++++----- src/Controller/Front.php | 4 ++-- src/Database.php | 6 +----- src/Functions.php | 18 +++++++++--------- src/HttpRequest.php | 2 +- src/Path.php | 10 +++++----- src/Process.php | 1 + src/Settings.php | 7 +++---- src/Setup.php | 20 ++++++++++++-------- src/Tools/SQLStatementExtractor.php | 6 +++--- src/Tools/TemplateImage.php | 3 --- src/View/Pages.php | 2 +- src/View/View.php | 16 +++++++++------- 16 files changed, 69 insertions(+), 54 deletions(-) create mode 100644 config.php create mode 100644 phpstan.neon diff --git a/config.php b/config.php new file mode 100644 index 0000000..502a2b4 --- /dev/null +++ b/config.php @@ -0,0 +1,4 @@ +template) ? $this->template : $this->getTemplateName($config); $selected = null; + $tpl = null; foreach ($this->viewPath as $index => $viewPath) { // Загружать шаблон по умолчанию если не найден текущий $dir = Path::join($this->viewPath[$index], 'templates', $template); @@ -147,7 +148,7 @@ class Component } public function getTemplatePath($name) { - $registry/*: \ctiso\Settings*/ = $this->config; + $registry = $this->config; // Брать настройки из куков если есть $template = ($this->template) ? $this->template : $this->getTemplateName($registry); foreach ($this->viewPath as $index => $viewPath) { @@ -167,7 +168,7 @@ class Component /** * Создает модель * @param string $name - * @return model + * @return mixed */ public function getModel($name) { @@ -302,6 +303,7 @@ class Component $component->component_id = $cid->getInt('id_component'); } else { $last = $db->getIdGenerator(); + $result = null; if ($last->isBeforeInsert()) { $result = $last->getId('component_id_component_seq'); diff --git a/src/Controller/Front.php b/src/Controller/Front.php index ed9148a..ac9bfdc 100644 --- a/src/Controller/Front.php +++ b/src/Controller/Front.php @@ -24,7 +24,7 @@ class Front extends Action protected $modules = array(); /** - * @param Settings $settings + * @param Settings $config */ public function __construct($db, $config, $user, $default) { parent::__construct(); @@ -41,7 +41,7 @@ class Front extends Action /** * Создает экземпляр модуля и выполняет действия для него * @param string $name Имя модуля - * @param Request $request Имя модуля + * @param Collection $request Имя модуля * @return string */ public function loadModule($name, Collection $request) diff --git a/src/Database.php b/src/Database.php index dc572d1..3c06748 100644 --- a/src/Database.php +++ b/src/Database.php @@ -48,6 +48,7 @@ class Database/**/ extends PDO static function getConnection(array $dsn) { + $connection = null; if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') { $port = (isset($dsn['port'])) ? "port={$dsn['port']};" : ""; $connection/*: Database*/ = new static("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']); @@ -107,11 +108,6 @@ class Database/**/ extends PDO return $sth->fetch(PDO::FETCH_ASSOC); } - private static function assignQuote($x, $y) - { - return $x . "=" . $this->quote($y); - } - private function prepareValues($values) { if (!$values) { diff --git a/src/Functions.php b/src/Functions.php index 1c64ed1..bab33e8 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -98,9 +98,7 @@ class Functions { /** * Композиция функций - * @param mixed $a - * @param mixed $b - * + * @param array $_rest * @return mixed */ static function compose($_rest) { @@ -330,19 +328,21 @@ class Functions { /** * Поиск элемента в массиве * @param mixed $cb сравнение с элементом массива - * @param Array $hs массив в котором ищется значение + * @param array $hs массив в котором ищется значение * - * @return int|string ключ найденого элемента в массиве + * @return int|string|null ключ найденого элемента в массиве */ static function array_usearch($cb, array $hs, $strict = false) { - foreach($hs as $key => $value) if (call_user_func_array($cb, array($value, $key, $strict))) return $key; + foreach($hs as $key => $value) { + if (call_user_func_array($cb, array($value, $key, $strict))) return $key; + } return null; } /** * Выбирает все сроки из таблицы с уникальными значениями ключа * @param string $name Имя ключа - * @param Array $table Двухмерный массив + * @param array $table Двухмерный массив * @example * key_unique_values ('name', array (array ('name' => 1), array ('name' => 2), array ('name' => 1))) => array (1, 2) @@ -360,9 +360,9 @@ class Functions { /** * Сортировка двумерного массива по заданному ключу - * @param Array $array Массив + * @param array $array Массив * @param string $key Имя ключа по значению которого будет идти сравнение - * @return Array Отсортированный массив + * @return array Отсортированный массив */ static function sortOn($array, $key, $fn = '\\ctiso\\Functions::__cmp') { usort ($array, Functions::rcurry($fn, $key)); diff --git a/src/HttpRequest.php b/src/HttpRequest.php index 048c33b..186ae12 100644 --- a/src/HttpRequest.php +++ b/src/HttpRequest.php @@ -59,7 +59,7 @@ class HttpRequest extends Collection function set($key, $value/*: any*/) { - return parent::get('data')->set($key, $value); + parent::get('data')->set($key, $value); } function export($key = 'data') diff --git a/src/Path.php b/src/Path.php index d7d0d04..f285116 100644 --- a/src/Path.php +++ b/src/Path.php @@ -471,12 +471,12 @@ class Path /** * Обновить относительную ссылку в файле при переносе папки * - * @param String $relativePath - относительная ссылка до переноса - * @param String $fileDir - абсолютный путь к директории файла содержащего ссылку до переноса - * @param String $srcDir - абсолютный путь к переносимой директории до переноса - * @param String $dstDir - абсолютный путь к переносимой директории после переноса + * @param string $relativePath относительная ссылка до переноса + * @param string $fileDir абсолютный путь к директории файла содержащего ссылку до переноса + * @param string $srcDir абсолютный путь к переносимой директории до переноса + * @param string $dstDir абсолютный путь к переносимой директории после переноса * - * @return + * @return string */ static function updateRelativePathOnDirectoryMove($relativePath, $fileDir, $srcDir, $dstDir) { $relativePath = self::normalize($relativePath); diff --git a/src/Process.php b/src/Process.php index 18f813d..a1728f5 100644 --- a/src/Process.php +++ b/src/Process.php @@ -6,6 +6,7 @@ if (!function_exists('str_getcsv')) { function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") { $fiveMBs = 1024; $fp = fopen("php://temp/maxmemory:$fiveMBs", 'r+'); + $data = ''; if (is_resource($fp)) { fputs($fp, $input); rewind($fp); diff --git a/src/Settings.php b/src/Settings.php index 8345c1c..6033c71 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -98,7 +98,7 @@ class Settings /** * Чтение ключа из реестра - * @param mixed $args Путь к значению ключа + * @param array $key Путь к значению ключа */ public function readKey(array $key) { @@ -130,9 +130,8 @@ class Settings * Чтение ключа из реестра (Собирает все ключи с определенным значением во всех модулях) * @param mixed $key Путь к значению ключа внутри модуля */ - public function readKeyList($_rest) - { - $key = func_get_args(); + public function readKeyList(...$key) + { $result = array(); foreach ($this->data as $name => $value) { $output = $this->readKeyData($key, $value); diff --git a/src/Setup.php b/src/Setup.php index cfad705..52958f8 100644 --- a/src/Setup.php +++ b/src/Setup.php @@ -114,7 +114,7 @@ class Setup /** * Выполняет список действий если для действия не указан аттрибут when то оно выполняется всегда * - * @param $action специальное действие + * @param string $action специальное действие */ function executeActions($action = "install") { @@ -136,10 +136,12 @@ class Setup /** * Копирования файла - * @param preserve Не переписывать файл если он существует - * @param template Файл является шаблоном подставить параметры до копирования - * @param src Исходный файл - * @param dst Новый файл + * preserver - Не переписывать файл если он существует + * template Файл является шаблоном подставить параметры до копирования + * src Исходный файл + * dst Новый файл + * + * @param array{preserve: string, template: string, src: string, dst: string} $attributes */ public function copyFile(array $attributes) { @@ -152,7 +154,7 @@ class Setup /** * Создает символическую ссылку на папку/файл - * @param dst Имя папки + * @param array{target: string, link: string} $attributes */ public function makeLink(array $attributes) { @@ -163,7 +165,7 @@ class Setup /** * Подключение файла установки - * @param file Имя подключаемого файла + * @param array{file: string} $attributes Имя подключаемого файла */ public function includeFile(array $attributes) { @@ -180,7 +182,9 @@ class Setup /** * Создает новую папку - * @param dst Имя папки + * dst Имя папки + * + * @param array{dst:string} $attributes */ public function makeDirectory(array $attributes) { diff --git a/src/Tools/SQLStatementExtractor.php b/src/Tools/SQLStatementExtractor.php index a084113..746423b 100644 --- a/src/Tools/SQLStatementExtractor.php +++ b/src/Tools/SQLStatementExtractor.php @@ -50,7 +50,7 @@ class SQLStatementExtractor { /** * Extract statements from string. * - * @param string $txt + * @param string $buffer * @return array */ public static function extract($buffer) { @@ -61,7 +61,7 @@ class SQLStatementExtractor { * Extract SQL statements from array of lines. * * @param array $lines Lines of the read-in file. - * @return string + * @return array */ protected static function extractStatements($lines) { @@ -156,7 +156,7 @@ class SQLStatementExtractor { /** * Convert string buffer into array of lines. * - * @param string $filename + * @param string $buffer * @return array string[] lines of file. */ protected static function getLines($buffer) { diff --git a/src/Tools/TemplateImage.php b/src/Tools/TemplateImage.php index 478b3df..ad9d8f0 100644 --- a/src/Tools/TemplateImage.php +++ b/src/Tools/TemplateImage.php @@ -38,9 +38,6 @@ class TemplateImage protected $image; protected $_prepare = true; public $debug = false; - public $filename; - public $resource; - public $resource; public $filename; diff --git a/src/View/Pages.php b/src/View/Pages.php index 1bba197..f621cef 100644 --- a/src/View/Pages.php +++ b/src/View/Pages.php @@ -7,7 +7,7 @@ namespace ctiso\View; class Pages { - static $range = 5; + static int $range = 5; static function getPages($page, $onpage, $count, $prefix = '?') { $n = ceil($count / $onpage); diff --git a/src/View/View.php b/src/View/View.php index 7acbebb..0151523 100644 --- a/src/View/View.php +++ b/src/View/View.php @@ -120,8 +120,6 @@ class View extends \stdClass /** * Обработка всех вложенных шаблонов - * - * @return string */ public function execute() { @@ -166,16 +164,20 @@ class View extends \stdClass throw new Exception("file not found: $file"); } + // FIXME: Префикс, конфликтует с протоколом function resolveName($alias, $file) { list($type, $filename) = explode(":", $file, 2); // Сделать поиск а не просто замену папки при совпадении имени - if (is_array($alias[$type])) { - $output = $this->find_file($alias[$type], $filename); - } else { - $output = $alias[$type] . '/' . $filename; + if (isset($alias[$type])) { + if (is_array($alias[$type])) { + $output = $this->find_file($alias[$type], $filename); + } else { + $output = $alias[$type] . '/' . $filename; + } + return $output; } - return $output; + return $file; } function loadImports($importFile)