diff --git a/classes/phing/tasks/ext/TarFileSet.php b/classes/phing/tasks/ext/TarFileSet.php index 676143b1b4..23b03c3aec 100644 --- a/classes/phing/tasks/ext/TarFileSet.php +++ b/classes/phing/tasks/ext/TarFileSet.php @@ -26,15 +26,16 @@ class TarFileSet extends FileSet * @param Project $p * @param bool $includeEmpty * - * @throws BuildException - * * @return array a list of file and directory names, relative to * the baseDir for the project. + * + * @throws BuildException + * @throws Exception */ - public function getFiles(Project $p, $includeEmpty = true) + protected function getFiles($includeEmpty = true, ...$options) { if ($this->files === null) { - $ds = $this->getDirectoryScanner($p); + $ds = $this->getDirectoryScanner($this->getProject()); $this->files = $ds->getIncludedFiles(); if ($includeEmpty) { @@ -64,7 +65,7 @@ public function getFiles(Project $p, $includeEmpty = true) // to the files array. foreach ($incDirs as $dir) { // we cannot simply use array_diff() since we want to disregard empty/. dirs - if ($dir != "" && $dir != "." && !in_array($dir, $implicitDirs)) { + if ($dir != "" && $dir !== "." && !in_array($dir, $implicitDirs)) { // it's an empty dir, so we'll add it. $this->files[] = $dir; } diff --git a/classes/phing/tasks/ext/TarTask.php b/classes/phing/tasks/ext/TarTask.php index 3069879dd8..c3b4b2e08e 100644 --- a/classes/phing/tasks/ext/TarTask.php +++ b/classes/phing/tasks/ext/TarTask.php @@ -251,12 +251,12 @@ public function main() $tar = new Archive_Tar($this->tarFile->getAbsolutePath(), $this->compression); $pear = new PEAR(); - if ($pear->isError($tar->error_object)) { + if ($pear::isError($tar->error_object)) { throw new BuildException($tar->error_object->getMessage()); } foreach ($this->filesets as $fs) { - $files = $fs->getFiles($this->project, $this->includeEmpty); + $files = $fs->getIterator($this->includeEmpty); if (count($files) > 1 && strlen($fs->getFullpath()) > 0) { throw new BuildException("fullpath attribute may only " . "be specified for " @@ -272,7 +272,7 @@ public function main() } $tar->addModify($filesToTar, $this->prefix, $fsBasedir->getAbsolutePath()); - if ($pear->isError($tar->error_object)) { + if ($pear::isError($tar->error_object)) { throw new BuildException($tar->error_object->getMessage()); } } @@ -286,7 +286,7 @@ public function main() } /** - * @param array $files array of filenames + * @param ArrayIterator $files array of filenames * @param PhingFile $dir * * @return boolean @@ -307,7 +307,7 @@ protected function areFilesUpToDate($files, $dir) private function isArchiveUpToDate() { foreach ($this->filesets as $fs) { - $files = $fs->getFiles($this->project, $this->includeEmpty); + $files = $fs->getIterator($this->includeEmpty); if (!$this->areFilesUpToDate($files, $fs->getDir($this->project))) { return false; } diff --git a/classes/phing/tasks/ext/ZipFileSet.php b/classes/phing/tasks/ext/ZipFileSet.php index 148b2f2806..f72ef982b4 100644 --- a/classes/phing/tasks/ext/ZipFileSet.php +++ b/classes/phing/tasks/ext/ZipFileSet.php @@ -31,16 +31,19 @@ class ZipFileSet extends FileSet /** * Get a list of files and directories specified in the fileset. - * @param Project $p + * * @param bool $includeEmpty - * @throws BuildException + * @param array ...$options + * * @return array a list of file and directory names, relative to * the baseDir for the project. + * + * @throws Exception */ - public function getFiles(Project $p, $includeEmpty = true) + protected function getFiles($includeEmpty = true, ...$options) { if ($this->files === null) { - $ds = $this->getDirectoryScanner($p); + $ds = $this->getDirectoryScanner($this->getProject()); $this->files = $ds->getIncludedFiles(); // build a list of directories implicitly added by any of the files @@ -71,7 +74,7 @@ public function getFiles(Project $p, $includeEmpty = true) // to the files array. foreach ($incDirs as $dir) { // we cannot simply use array_diff() since we want to disregard empty/. dirs - if ($dir != "" && $dir != "." && !in_array($dir, $implicitDirs)) { + if ($dir != "" && $dir !== "." && !in_array($dir, $implicitDirs)) { // it's an empty dir, so we'll add it. $emptyDirectories[] = $dir; } diff --git a/classes/phing/tasks/ext/ZipTask.php b/classes/phing/tasks/ext/ZipTask.php index cdeacd2f7b..edfe4dbf15 100644 --- a/classes/phing/tasks/ext/ZipTask.php +++ b/classes/phing/tasks/ext/ZipTask.php @@ -246,7 +246,7 @@ public function areFilesetsUpToDate() { /** @var FileSet $fs */ foreach ($this->filesets as $fs) { - $files = $fs->getFiles($this->project, $this->includeEmpty); + $files = $fs->getIterator($this->includeEmpty); if (!$this->archiveIsUpToDate($files, $fs->getDir($this->project))) { return false; } @@ -268,10 +268,10 @@ private function addFilesetsToArchive($zip) $fsBasedir = (null != $this->baseDir) ? $this->baseDir : $fs->getDir($this->project); - $files = $fs->getFiles($this->project, $this->includeEmpty); + $files = $fs->getIterator($this->includeEmpty); - for ($i = 0, $fcount = count($files); $i < $fcount; $i++) { - $f = new PhingFile($fsBasedir, $files[$i]); + foreach ($files as $file) { + $f = new PhingFile($fsBasedir, $file); $pathInZip = $this->prefix . $f->getPathWithoutBase($fsBasedir); diff --git a/classes/phing/tasks/ext/phar/PharDataTask.php b/classes/phing/tasks/ext/phar/PharDataTask.php index 29848df5a7..d436fa8f57 100644 --- a/classes/phing/tasks/ext/phar/PharDataTask.php +++ b/classes/phing/tasks/ext/phar/PharDataTask.php @@ -20,7 +20,6 @@ */ require_once 'phing/tasks/system/MatchingTask.php'; -require_once 'phing/types/IterableFileSet.php'; /** * Data task for {@link http://php.net/manual/en/class.phardata.php PharData class}. @@ -48,7 +47,7 @@ class PharDataTask extends MatchingTask private $baseDirectory; /** - * @var IterableFileSet[] + * @var FileSet[] */ private $filesets = []; @@ -57,7 +56,7 @@ class PharDataTask extends MatchingTask */ public function createFileSet() { - $this->fileset = new IterableFileSet(); + $this->fileset = new FileSet(); $this->filesets[] = $this->fileset; return $this->fileset; } diff --git a/classes/phing/tasks/ext/phar/PharPackageTask.php b/classes/phing/tasks/ext/phar/PharPackageTask.php index 8d667d6b15..d43b54b2ae 100644 --- a/classes/phing/tasks/ext/phar/PharPackageTask.php +++ b/classes/phing/tasks/ext/phar/PharPackageTask.php @@ -20,7 +20,6 @@ */ require_once 'phing/tasks/system/MatchingTask.php'; -require_once 'phing/types/IterableFileSet.php'; require_once 'phing/tasks/ext/phar/PharMetadata.php'; /** @@ -111,7 +110,7 @@ public function createMetadata() */ public function createFileSet() { - $this->fileset = new IterableFileSet(); + $this->fileset = new FileSet(); $this->filesets[] = $this->fileset; return $this->fileset; diff --git a/classes/phing/tasks/ext/zendguard/ZendGuardEncodeTask.php b/classes/phing/tasks/ext/zendguard/ZendGuardEncodeTask.php index c8ea3d37dc..b863d4637a 100644 --- a/classes/phing/tasks/ext/zendguard/ZendGuardEncodeTask.php +++ b/classes/phing/tasks/ext/zendguard/ZendGuardEncodeTask.php @@ -408,7 +408,7 @@ public function main() /* @var $fsBasedir PhingFile */ $fsBasedir = $fs->getDir($this->project)->getAbsolutePath(); - $files = $fs->getFiles($this->project, false); + $files = $fs->getIterator(false); foreach ($files as $file) { $f = new PhingFile($fsBasedir, $file); diff --git a/classes/phing/types/AbstractFileSet.php b/classes/phing/types/AbstractFileSet.php index 949d67effd..ad9ed6665f 100644 --- a/classes/phing/types/AbstractFileSet.php +++ b/classes/phing/types/AbstractFileSet.php @@ -531,5 +531,14 @@ public function appendSelector(FileSelector $selector) $this->setChecked(false); } - abstract public function getIterator(); + /** + * @param array ...$options + * @return ArrayIterator + */ + public function getIterator(...$options): \ArrayIterator + { + return new ArrayIterator($this->getFiles($options)); + } + + abstract protected function getFiles(...$options); } diff --git a/classes/phing/types/DirSet.php b/classes/phing/types/DirSet.php index 419464f53e..14a906bb5b 100644 --- a/classes/phing/types/DirSet.php +++ b/classes/phing/types/DirSet.php @@ -1,5 +1,4 @@ getDirectoryScanner($this->getProject())->getIncludedDirectories(); } diff --git a/classes/phing/types/FileSet.php b/classes/phing/types/FileSet.php index 102d3f73aa..5c5fe5d6c8 100644 --- a/classes/phing/types/FileSet.php +++ b/classes/phing/types/FileSet.php @@ -38,10 +38,18 @@ class FileSet extends AbstractFileSet { /** * @return array + * @throws Exception */ - public function getIterator() + protected function getFiles(...$options) { - $ds = $this->getDirectoryScanner($this->getProject()); - return $ds->getIncludedFiles() + $ds->getIncludedDirectories(); + $directoryScanner = $this->getDirectoryScanner($this->getProject()); + $files = $directoryScanner->getIncludedFiles(); + + $baseDirectory = $directoryScanner->getBasedir(); + foreach ($files as $index => $file) { + $files[$index] = realpath($baseDirectory . '/' . $file); + } + + return $files; } } diff --git a/classes/phing/types/IterableFileSet.php b/classes/phing/types/IterableFileSet.php deleted file mode 100644 index 2fe0da9ca1..0000000000 --- a/classes/phing/types/IterableFileSet.php +++ /dev/null @@ -1,55 +0,0 @@ -. - */ - -/** - * FileSet adapter to SPL's Iterator. - * - * @package phing.types - * @author Alexey Shockov - * @since 2.4.0 - * @internal - */ -class IterableFileSet extends FileSet implements IteratorAggregate -{ - /** - * @return Iterator - */ - public function getIterator() - { - return new ArrayIterator($this->getFiles()); - } - - /** - * @return array - */ - private function getFiles() - { - $directoryScanner = $this->getDirectoryScanner($this->getProject()); - $files = $directoryScanner->getIncludedFiles(); - - $baseDirectory = $directoryScanner->getBasedir(); - foreach ($files as $index => $file) { - $files[$index] = realpath($baseDirectory . '/' . $file); - } - - return $files; - } -} diff --git a/classes/phing/util/SourceFileScanner.php b/classes/phing/util/SourceFileScanner.php index a25c1804ae..68c78ae22f 100644 --- a/classes/phing/util/SourceFileScanner.php +++ b/classes/phing/util/SourceFileScanner.php @@ -50,7 +50,7 @@ public function __construct($task) * Restrict the given set of files to those that are newer than * their corresponding target files. * - * @param array $files the original set of files + * @param iterable $files the original set of files * @param PhingFile $srcDir all files are relative to this directory * @param PhingFile $destDir target files live here. if null file names * returned by the mapper are assumed to be absolute. diff --git a/test/classes/phing/tasks/ext/ZipUnzipTaskTest.php b/test/classes/phing/tasks/ext/ZipUnzipTaskTest.php index 4898fce0ee..b8a315d9ef 100644 --- a/test/classes/phing/tasks/ext/ZipUnzipTaskTest.php +++ b/test/classes/phing/tasks/ext/ZipUnzipTaskTest.php @@ -82,6 +82,6 @@ public function testUnzipSimpleZip() $this->executeTarget(__FUNCTION__); $this->assertFileExists($filename); - $this->assertEquals('TEST', file_get_contents($filename)); + $this->assertStringEqualsFile($filename, 'TEST'); } }