upgraded dependencies

This commit is contained in:
RafficMohammed
2023-01-08 01:59:16 +05:30
parent 51056e3aad
commit f9ae387337
6895 changed files with 133617 additions and 178680 deletions

View File

@@ -1,35 +1,38 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of php-file-iterator.
* This file is part of phpunit/php-file-iterator.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\FileIterator;
use const DIRECTORY_SEPARATOR;
use function array_unique;
use function count;
use function dirname;
use function explode;
use function is_file;
use function is_string;
use function realpath;
use function sort;
class Facade
{
/**
* @param array|string $paths
* @param array|string $suffixes
* @param array|string $prefixes
* @param array $exclude
* @param bool $commonPath
*
* @return array
*/
public function getFilesAsArray($paths, $suffixes = '', $prefixes = '', array $exclude = [], bool $commonPath = false): array
{
if (\is_string($paths)) {
if (is_string($paths)) {
$paths = [$paths];
}
$factory = new Factory;
$iterator = $factory->getFileIterator($paths, $suffixes, $prefixes, $exclude);
$iterator = (new Factory)->getFileIterator($paths, $suffixes, $prefixes, $exclude);
$files = [];
@@ -42,18 +45,18 @@ class Facade
}
foreach ($paths as $path) {
if (\is_file($path)) {
$files[] = \realpath($path);
if (is_file($path)) {
$files[] = realpath($path);
}
}
$files = \array_unique($files);
\sort($files);
$files = array_unique($files);
sort($files);
if ($commonPath) {
return [
'commonPath' => $this->getCommonPath($files),
'files' => $files
'commonPath' => $this->getCommonPath($files),
'files' => $files,
];
}
@@ -62,20 +65,20 @@ class Facade
protected function getCommonPath(array $files): string
{
$count = \count($files);
$count = count($files);
if ($count === 0) {
return '';
}
if ($count === 1) {
return \dirname($files[0]) . DIRECTORY_SEPARATOR;
return dirname($files[0]) . DIRECTORY_SEPARATOR;
}
$_files = [];
foreach ($files as $file) {
$_files[] = $_fileParts = \explode(DIRECTORY_SEPARATOR, $file);
$_files[] = $_fileParts = explode(DIRECTORY_SEPARATOR, $file);
if (empty($_fileParts[0])) {
$_fileParts[0] = DIRECTORY_SEPARATOR;

View File

@@ -1,35 +1,43 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of php-file-iterator.
* This file is part of phpunit/php-file-iterator.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\FileIterator;
use const GLOB_ONLYDIR;
use function array_filter;
use function array_map;
use function array_merge;
use function glob;
use function is_dir;
use function is_string;
use function realpath;
use AppendIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
class Factory
{
/**
* @param array|string $paths
* @param array|string $suffixes
* @param array|string $prefixes
* @param array $exclude
*
* @return \AppendIterator
*/
public function getFileIterator($paths, $suffixes = '', $prefixes = '', array $exclude = []): \AppendIterator
public function getFileIterator($paths, $suffixes = '', $prefixes = '', array $exclude = []): AppendIterator
{
if (\is_string($paths)) {
if (is_string($paths)) {
$paths = [$paths];
}
$paths = $this->getPathsAfterResolvingWildcards($paths);
$exclude = $this->getPathsAfterResolvingWildcards($exclude);
if (\is_string($prefixes)) {
if (is_string($prefixes)) {
if ($prefixes !== '') {
$prefixes = [$prefixes];
} else {
@@ -37,7 +45,7 @@ class Factory
}
}
if (\is_string($suffixes)) {
if (is_string($suffixes)) {
if ($suffixes !== '') {
$suffixes = [$suffixes];
} else {
@@ -45,15 +53,15 @@ class Factory
}
}
$iterator = new \AppendIterator;
$iterator = new AppendIterator;
foreach ($paths as $path) {
if (\is_dir($path)) {
if (is_dir($path)) {
$iterator->append(
new Iterator(
$path,
new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS | \RecursiveDirectoryIterator::SKIP_DOTS)
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::FOLLOW_SYMLINKS | RecursiveDirectoryIterator::SKIP_DOTS)
),
$suffixes,
$prefixes,
@@ -71,13 +79,13 @@ class Factory
$_paths = [[]];
foreach ($paths as $path) {
if ($locals = \glob($path, GLOB_ONLYDIR)) {
$_paths[] = \array_map('\realpath', $locals);
if ($locals = glob($path, GLOB_ONLYDIR)) {
$_paths[] = array_map('\realpath', $locals);
} else {
$_paths[] = [\realpath($path)];
$_paths[] = [realpath($path)];
}
}
return \array_filter(\array_merge(...$_paths));
return array_filter(array_merge(...$_paths));
}
}

View File

@@ -1,19 +1,29 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of php-file-iterator.
* This file is part of phpunit/php-file-iterator.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\FileIterator;
class Iterator extends \FilterIterator
use function array_filter;
use function array_map;
use function preg_match;
use function realpath;
use function str_replace;
use function strlen;
use function strpos;
use function substr;
use FilterIterator;
class Iterator extends FilterIterator
{
const PREFIX = 0;
const SUFFIX = 1;
public const PREFIX = 0;
public const SUFFIX = 1;
/**
* @var string
@@ -35,33 +45,26 @@ class Iterator extends \FilterIterator
*/
private $exclude = [];
/**
* @param string $basePath
* @param \Iterator $iterator
* @param array $suffixes
* @param array $prefixes
* @param array $exclude
*/
public function __construct(string $basePath, \Iterator $iterator, array $suffixes = [], array $prefixes = [], array $exclude = [])
{
$this->basePath = \realpath($basePath);
$this->basePath = realpath($basePath);
$this->prefixes = $prefixes;
$this->suffixes = $suffixes;
$this->exclude = \array_filter(\array_map('realpath', $exclude));
$this->exclude = array_filter(array_map('realpath', $exclude));
parent::__construct($iterator);
}
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function accept()
public function accept(): bool
{
$current = $this->getInnerIterator()->current();
$filename = $current->getFilename();
$realPath = $current->getRealPath();
if ($realPath === false) {
return false;
}
return $this->acceptPath($realPath) &&
$this->acceptPrefix($filename) &&
$this->acceptSuffix($filename);
@@ -70,12 +73,12 @@ class Iterator extends \FilterIterator
private function acceptPath(string $path): bool
{
// Filter files in hidden directories by checking path that is relative to the base path.
if (\preg_match('=/\.[^/]*/=', \str_replace($this->basePath, '', $path))) {
if (preg_match('=/\.[^/]*/=', str_replace($this->basePath, '', $path))) {
return false;
}
foreach ($this->exclude as $exclude) {
if (\strpos($path, $exclude) === 0) {
if (strpos($path, $exclude) === 0) {
return false;
}
}
@@ -102,9 +105,9 @@ class Iterator extends \FilterIterator
$matched = false;
foreach ($subStrings as $string) {
if (($type === self::PREFIX && \strpos($filename, $string) === 0) ||
if (($type === self::PREFIX && strpos($filename, $string) === 0) ||
($type === self::SUFFIX &&
\substr($filename, -1 * \strlen($string)) === $string)) {
substr($filename, -1 * strlen($string)) === $string)) {
$matched = true;
break;