fix: noverify + типы для правил провеки

This commit is contained in:
origami11@yandex.ru 2025-01-21 19:33:33 +03:00
parent 9680409ba9
commit 90cbd3b2b6
10 changed files with 319 additions and 300 deletions

View file

@ -8,13 +8,13 @@
namespace ctiso;
class Path
class Path
{
const SEPARATOR = "/";
protected $path = array();
protected $url = array();
protected $absolute = false;
protected $absolute = false;
public function __construct($path = '')
{
@ -24,7 +24,7 @@ class Path
if (isset($this->url['path'])) {
$path = $this->url['path'];
// $path = preg_replace('/\/{2,}/', '/', $path);
$list = $this->listFromString($path);
$list = self::listFromString($path);
if (isset($this->url['scheme']) && !isset($this->url['host'])) {
$this->absolute = false;
@ -32,9 +32,9 @@ class Path
$this->absolute = true;
}
$this->path = $this->optimize($list);
$this->path = self::optimize($list);
}
}
}
static function factory($path) {
return new Path($path);
@ -87,14 +87,14 @@ class Path
*
* @param string $fileName Имя файла
*
* @return string
* @return string
*/
static function skipExtension($fileName)
{
assert(is_string($fileName));
$path = pathinfo($fileName);
if ($path['dirname'] == ".") {
if ($path['dirname'] === ".") {
return $path['filename'];
} else {
return self::join($path['dirname'], $path['filename']);
@ -134,22 +134,22 @@ class Path
}
/**
* Преобразует относительный путь в абсолютный
* Преобразует относительный путь в абсолютный
*/
public static function optimize($path) //
public static function optimize($path) //
{
$result = [];
foreach ($path as $n) {
switch ($n) {
// Может быть относительным или абсолютным путем
case "": break;
case ".": break;
case "": case ".": break;
case "..":
if (count($result) > 0 && $result[count($result) - 1] != '..') {
array_pop($result); break;
if (count($result) > 0 && $result[count($result) - 1] != '..') {
array_pop($result); break;
}
break;
default:
array_push($result, $n);
$result[] = $n;
}
}
return $result;
@ -162,7 +162,7 @@ class Path
if ($count == count($path->path)) {
for ($i = 0; $i < $count; $i++) {
if ($this->path[$i] != $path->path[$i]) {
return false;
return false;
}
}
return true;
@ -170,16 +170,16 @@ class Path
return false;
}
public static function makeUrl($path)
public static function makeUrl($path)
{
$slash = (isset($path['host']) && (strlen($path['path']) > 0) && ($path['path'][0] != '/')) ? '/' : '';
return (isset($path['scheme']) ? $path['scheme'] . ':/' : '')
. (isset($path['host']) ? ('/'
. (isset($path['user']) ? $path['user'] . (isset($path['pass']) ? ':' . $path['pass'] : '') . '@' : '')
. $path['host']
return (isset($path['scheme']) ? $path['scheme'] . ':/' : '')
. (isset($path['host']) ? ('/'
. (isset($path['user']) ? $path['user'] . (isset($path['pass']) ? ':' . $path['pass'] : '') . '@' : '')
. $path['host']
. (isset($path['port']) ? ':' . $path['port'] : '')) : '')
. $slash
. $slash
. $path['path']
. (isset($path['query']) ? '?' . $path['query'] : '')
. (isset($path['fragment']) ? '#' . $path['fragment'] : '');
@ -188,7 +188,7 @@ class Path
/**
* Преобразует путь в строку
*
* @return string
* @return string
*/
public function __toString()
{
@ -200,13 +200,13 @@ class Path
/**
* Проверяет является ли папка родительской для другой папки
*
* @parma Path $path
* @parma Path $path
*
* @return boolean
*/
public function isParent($path/*: Path*/)
{
if (isset($this->url['host']) && isset($path->url['host'])
if (isset($this->url['host']) && isset($path->url['host'])
&& ($this->url['host'] != $path->url['host'])) return false;
$count = count($this->path);
@ -226,11 +226,11 @@ class Path
$path = new Path($path1);
return $path->isParent(new Path($path2));
}
/**
* Находит путь относительно текущего путя
*
* @param string $name Полный путь к файлу
*
* @param string $name Полный путь к файлу
*
* @return string Относительный путь к файлу
*/
@ -257,10 +257,10 @@ class Path
$result = [];
$count = count($list_path);
for ($i = 0; $i < $count; $i++) {
if (($i >= count($self_path)) || $list_path[$i] != $self_path[$i]) {
break;
if (($i >= count($self_path)) || $list_path[$i] != $self_path[$i]) {
break;
}
}
}
$list_count = count($list_path);
for($j = $i; $j < $list_count; $j++) {
array_push($result, '..');
@ -281,7 +281,7 @@ class Path
/**
* Обьединяет строки в Path соединяя необходимым разделителем
* fixme не обрабатывает параметры урла, решение Path::join(SITE_WWW_PATH) . '?param=pampam'
* @return string
* @return string
*/
static function fromJoin($_rest) {
$args = func_get_args();
@ -295,7 +295,7 @@ class Path
}
// При обьединении ссылок можно обьеденить path, query, fragment
$path = implode(self::SEPARATOR, self::optimize(call_user_func_array('array_merge', $result)));
$path = implode(self::SEPARATOR, self::optimize(call_user_func_array('array_merge', $result)));
$parts0->url['path'] = ($parts0->isAbsolute()) ? '/' . $path : $path;
return $parts0;
}
@ -303,7 +303,7 @@ class Path
/**
* Обьединяет строки в строку пути соединяя необходимым разделителем
* fixme не обрабатывает параметры урла, решение Path::join(SITE_WWW_PATH) . '?param=pampam'
* @return string
* @return string
*/
static function join($_rest)
{
@ -324,11 +324,11 @@ class Path
return ((($ch >= ord('a')) && ($ch <= ord('z'))) || (strpos('-._', $char) !== false) || (($ch >= ord('0')) && ($ch <= ord('9'))));
}
// Проверка имени файла
// Проверка имени файла
static function isName($name) {
if (strlen(trim($name)) == 0) {
return false;
}
}
for ($i = 0; $i < strlen($name); $i++) {
if (!self::isCharName($name[$i])) {
return false;
@ -363,13 +363,13 @@ class Path
}
/**
* Список файлов в директории
/**
* Список файлов в директории
*
* @param array $allow массив расширений для файлов
* @param array $ignore массив имен пааок которые не нужно обрабатывать
* @param array $allow массив расширений для файлов
* @param array $ignore массив имен пааок которые не нужно обрабатывать
*
* @returnarray
* @returnarray
*/
public function getContent($allow = null, $ignore = [])
{
@ -379,12 +379,12 @@ class Path
/**
* Обьединяет строки в путь соединяя необходимым разделителем
*
* @param array $allow массив расширений разрешеных для файлов
* @param array $ignore массив имен пааок которые не нужно обрабатывать
*
* @param array $allow массив расширений разрешеных для файлов
* @param array $ignore массив имен пааок которые не нужно обрабатывать
*
* @return array
*/
*/
function getContentRec($allow = null, $ignore = [])
{
$result = [];
@ -406,7 +406,7 @@ class Path
if (! in_array($file, $ignore)) {
$isDir = is_dir(Path::join($base, $file));
if ($isDir || ($allow == null) || in_array(self::getExtension($file), $allow)) {
$result[] = $file;
$result[] = $file;
}
}
continue;
@ -418,7 +418,7 @@ class Path
// При обьединении ссылок можно обьеденить path, query, fragment
return $result;
}
protected static function fileListAll(&$result, $base, &$allow, &$ignore)
{
$files = self::fileList($base, $allow, $ignore);
@ -453,11 +453,11 @@ class Path
/**
* Обновить относительную ссылку при переносе файла
*
*
* @param string $relativePath - относительная ссылка до переноса
* @param string $srcFile - абсолютный путь к папке содержащей файл со ссылкой до переноса
* @param string $dstFile - абсолютный путь к папке содержащей файл со ссылкой после переноса
*
*
* @return string
*/
static function updateRelativePathOnFileMove($relativePath, $srcFile, $dstFile) {
@ -467,12 +467,12 @@ class Path
/**
* Обновить относительную ссылку в файле при переносе папки
*
*
* @param string $relativePath относительная ссылка до переноса
* @param string $fileDir абсолютный путь к директории файла содержащего ссылку до переноса
* @param string $srcDir абсолютный путь к переносимой директории до переноса
* @param string $dstDir абсолютный путь к переносимой директории после переноса
*
*
* @return string
*/
static function updateRelativePathOnDirectoryMove($relativePath, $fileDir, $srcDir, $dstDir) {