chore: Добавлены аннотации к типам
This commit is contained in:
parent
48269bd424
commit
ad920f656c
14 changed files with 127 additions and 127 deletions
55
src/Path.php
55
src/Path.php
|
|
@ -12,14 +12,13 @@ class Path
|
|||
{
|
||||
const SEPARATOR = "/";
|
||||
|
||||
protected $path = array();
|
||||
protected $url = array();
|
||||
protected $absolute = false;
|
||||
protected array $path = [];
|
||||
protected array $url = [];
|
||||
protected bool $absolute = false;
|
||||
|
||||
public function __construct($path = '')
|
||||
public function __construct(string $path = '')
|
||||
{
|
||||
//assert(is_string($path));
|
||||
$this->url = parse_url($path ?? '');
|
||||
$this->url = parse_url($path);
|
||||
|
||||
if (isset($this->url['path'])) {
|
||||
$path = $this->url['path'];
|
||||
|
|
@ -36,16 +35,16 @@ class Path
|
|||
}
|
||||
}
|
||||
|
||||
static function factory($path) {
|
||||
static function factory(string $path): Path {
|
||||
return new Path($path);
|
||||
}
|
||||
|
||||
public function getParts()
|
||||
public function getParts(): array
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public static function normalize($pathName)
|
||||
public static function normalize(string $pathName): string
|
||||
{
|
||||
$path = new Path($pathName);
|
||||
return $path->__toString();
|
||||
|
|
@ -84,15 +83,9 @@ class Path
|
|||
|
||||
/**
|
||||
* Полное имя файла без расширения
|
||||
*
|
||||
* @param string $fileName Имя файла
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function skipExtension($fileName)
|
||||
static function skipExtension(string $fileName): string
|
||||
{
|
||||
assert(is_string($fileName));
|
||||
|
||||
$path = pathinfo($fileName);
|
||||
if ($path['dirname'] === ".") {
|
||||
return $path['filename'];
|
||||
|
|
@ -108,10 +101,8 @@ class Path
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getFileName($fileName)
|
||||
static function getFileName(string $fileName)
|
||||
{
|
||||
assert(is_string($fileName));
|
||||
|
||||
return pathinfo($fileName, PATHINFO_FILENAME);
|
||||
}
|
||||
|
||||
|
|
@ -121,15 +112,10 @@ class Path
|
|||
* Преобразует строку пути в массив
|
||||
*
|
||||
* @param string $path Путь
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function listFromString($path)
|
||||
public static function listFromString(string $path): array
|
||||
{
|
||||
assert(is_string($path));
|
||||
|
||||
$list = preg_split('#\\\\|/#s', $path);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
|
@ -154,11 +140,10 @@ class Path
|
|||
return $result;
|
||||
}
|
||||
|
||||
// Сравнение двух путей на равентство
|
||||
/**
|
||||
* @param Path $path
|
||||
* Сравнение двух путей на равентство
|
||||
*/
|
||||
public function equal($path)
|
||||
public function equal(Path $path): bool
|
||||
{
|
||||
$count = count($this->path);
|
||||
if ($count == count($path->path)) {
|
||||
|
|
@ -172,7 +157,7 @@ class Path
|
|||
return false;
|
||||
}
|
||||
|
||||
public static function makeUrl($path)
|
||||
public static function makeUrl($path): string
|
||||
{
|
||||
$slash = (isset($path['host']) && (strlen($path['path']) > 0) && ($path['path'][0] != '/')) ? '/' : '';
|
||||
|
||||
|
|
@ -189,10 +174,8 @@ class Path
|
|||
|
||||
/**
|
||||
* Преобразует путь в строку
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
$result = (($this->absolute) ? '/' : '') . implode(self::SEPARATOR, $this->path);
|
||||
$this->url['path'] = $result;
|
||||
|
|
@ -203,10 +186,8 @@ class Path
|
|||
* Проверяет является ли папка родительской для другой папки
|
||||
*
|
||||
* @param Path $path
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isParent($path)
|
||||
public function isParent($path): bool
|
||||
{
|
||||
if (isset($this->url['host']) && isset($path->url['host'])
|
||||
&& ($this->url['host'] != $path->url['host'])) return false;
|
||||
|
|
@ -223,7 +204,7 @@ class Path
|
|||
return false;
|
||||
}
|
||||
|
||||
public static function _isParent($path1, $path2)
|
||||
public static function _isParent(string $path1, string $path2): bool
|
||||
{
|
||||
$path = new Path($path1);
|
||||
return $path->isParent(new Path($path2));
|
||||
|
|
@ -421,7 +402,7 @@ class Path
|
|||
return $result;
|
||||
}
|
||||
|
||||
protected static function fileListAll(&$result, $base, &$allow, &$ignore)
|
||||
protected static function fileListAll(array &$result, string $base, ?array &$allow, array &$ignore)
|
||||
{
|
||||
$files = self::fileList($base, $allow, $ignore);
|
||||
foreach ($files as $name) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue