From 98306f446a0df4ce26e49c3fa951d397c941694a Mon Sep 17 00:00:00 2001 From: siad007 Date: Sat, 30 Jun 2018 22:08:40 +0200 Subject: [PATCH] Added count methods for included dirs or files. --- classes/phing/util/DirectoryScanner.php | 53 +++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/classes/phing/util/DirectoryScanner.php b/classes/phing/util/DirectoryScanner.php index 5a525aff3d..c9df6a7425 100644 --- a/classes/phing/util/DirectoryScanner.php +++ b/classes/phing/util/DirectoryScanner.php @@ -714,15 +714,37 @@ protected function isExcluded($_name) return false; } + /** + * Return the count of included files. + * + * @return int + * + * @throws UnexpectedValueException + */ + public function getIncludedFilesCount(): int + { + if ($this->filesIncluded === null) { + throw new UnexpectedValueException('Must call scan() first'); + } + return count($this->filesIncluded); + } + /** * Get the names of the files that matched at least one of the include * patterns, and matched none of the exclude patterns. * The names are relative to the basedir. * * @return array names of the files + * @throws \UnexpectedValueException */ - public function getIncludedFiles() + public function getIncludedFiles(): array { + if ($this->filesIncluded === null) { + throw new UnexpectedValueException('Must call scan() first'); + } + + sort($this->filesIncluded); + return $this->filesIncluded; } @@ -778,13 +800,35 @@ public function getDeselectedFiles() * The names are relative to the basedir. * * @return array the names of the directories + * @throws \UnexpectedValueException */ public function getIncludedDirectories() { + if ($this->dirsIncluded === null) { + throw new UnexpectedValueException('Must call scan() first'); + } + + sort($this->dirsIncluded); + return $this->dirsIncluded; } + /** + * Return the count of included directories. + * + * @return int + * + * @throws UnexpectedValueException + */ + public function getIncludedDirectoriesCount(): int + { + if ($this->dirsIncluded === null) { + throw new UnexpectedValueException('Must call scan() first'); + } + return count($this->dirsIncluded); + } + /** * Get the names of the directories that matched at none of the include * patterns. @@ -869,10 +913,13 @@ public function isEverythingIncluded() /** * Tests whether a name should be selected. * - * @param string $name The filename to check for selecting. - * @param string $file The full file path. + * @param string $name The filename to check for selecting. + * @param string $file The full file path. * @return boolean False when the selectors says that the file * should not be selected, True otherwise. + * @throws \BuildException + * @throws \IOException + * @throws NullPointerException */ protected function isSelected($name, $file) {