Merge all files.

@param string $directory
@param Finder $finder
@param bool $noSuffix

@return fDOMDocument
182036
private function mergeFiles($directory, Finder $finder, $noSuffix)
    {
        $outXml = new fDOMDocument;
        $outXml->formatOutput = true;

        $outTestSuites = $outXml->createElement('testsuites');
        $outXml->appendChild($outTestSuites);

        $outTestSuite = $outXml->createElement('testsuite');
        $outTestSuites->appendChild($outTestSuite);

        $tests = 0;
        $assertions = 0;
        $failures = 0;
        $errors = 0;
        $time = 0;

        /** @var SplFileInfo $file */
        foreach ($finder as $file) {
            if ($this->isFileEmpty($file)) {
                continue;
            }

            $inXml = $this->loadFile($file->getRealpath());
            foreach ($inXml->query('//testsuites/testsuite') as $inElement) {

				if (!$noSuffix) {
					$inName = $inElement->getAttribute('name');
					$outName = $inName;
					$suffix = 2;
					while ($outTestSuite->query('//testsuite[@name="' . $outName . '"]')->length !== 0) {
						$outName = $inName . '_' . $suffix;
						$suffix++;
					}
				}

                $outElement = $outXml->importNode($inElement, true);
				if (!$noSuffix) {
					$outElement->setAttribute('name', $outName);
				}
                $outTestSuite->appendChild($outElement);

                $tests += $inElement->getAttribute('tests');
                $assertions += $inElement->getAttribute('assertions');
                $failures += $inElement->getAttribute('failures');
                $errors += $inElement->getAttribute('errors');
                $time += $inElement->getAttribute('time');
            }
        }

        $outTestSuite->setAttribute('name', $directory);
        $outTestSuite->setAttribute('tests', $tests);
        $outTestSuite->setAttribute('assertions', $assertions);
        $outTestSuite->setAttribute('failures', $failures);
        $outTestSuite->setAttribute('errors', $errors);
        $outTestSuite->setAttribute('time', $time);

        return $outXml;
    }
1067722
public function withDir(string $dir): self
    {
        $builder = clone $this;
        $builder->dir = $dir;
        
        return $builder;
    }
1298310
public function allFiles($directory, $hidden = false)
    {
        return iterator_to_array(Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory), false);
    }
790743
protected function appendFileSet(Finder $finder, array $fileSet)
    {
        /** @var SplFileInfo[] $files */
        foreach ($finder as $file) {
            $fileSet[] = $file;
        }

        return $fileSet;
    }
957172
public static CreateFileContext mergeFrom(CreateFilePOptions.Builder optionsBuilder) {
    CreateFilePOptions masterOptions =
        FileSystemOptions.createFileDefaults(ServerConfiguration.global());
    CreateFilePOptions.Builder mergedOptionsBuilder =
        masterOptions.toBuilder().mergeFrom(optionsBuilder.build());
    return new CreateFileContext(mergedOptionsBuilder);
  }
42369
public function getFiles($directory)
    {
        $path = $this->base_path."/{$directory}";

        if (!is_dir($path)) {

            return file_exists($path) ? collect([$path]) : collect();
        }

        try { 
            return collect(File::allFiles($path));
        } catch (\Exception $e) {
            return collect();
        }
    }
1295238
public static function directoryToArray($directory, $recursive = FALSE, $extension = NULL) {
    $array_items = array();
    if ($handle = opendir($directory)) {
      while (FALSE !== ($file = readdir($handle))) {
        if ($file != "." && $file != ".." && (empty($extension) ||
            (!empty($extension) && substr($file, -strlen($extension)) === $extension))
        ) {

          if (is_dir($directory . "/" . $file)) {
            if ($recursive) {
              $array_items = array_merge($array_items, self::directoryToArray($directory . "/" . $file, $recursive));
            }
          }
          else {
            $file = $directory . "/" . $file;
            $array_items[] = preg_replace("/\/\//si", "/", $file);
          }
        }
      }
      closedir($handle);
    }
    return $array_items;
  }
831197
public function scanDirectory($directory)
    {
        $extensions = $this->getOption('extensions');

        foreach (scandir($directory) as $object) {
            if ($object === '.' || $object === '..') {
                continue;
            }
            $inputFile = $directory.DIRECTORY_SEPARATOR.$object;
            if (is_dir($inputFile)) {
                foreach ($this->scanDirectory($inputFile) as $file) {
                    yield $file;
                }

                continue;
            }
            if ($this->fileMatchExtensions($object, $extensions)) {
                yield $inputFile;
            }
        }
    }
1105682
public function toDirectory($directory)
    {
        $this->directory = trim($this->sanitizePath($directory), DIRECTORY_SEPARATOR);

        return $this;
    }
377186
private function mergeWith(string $namespaceToRegex, array $autoload, array $paths, string $rootProjectDir, bool $loadSrc)
    {
        $regex = "#{$namespaceToRegex}#";
        $resolvedPathToSrc = realpath($rootProjectDir) . '/src';
        foreach ($autoload as $namespace => $namespacePath) {
            if ($loadSrc && (in_array($resolvedPathToSrc, $namespacePath)) || preg_match($regex, $namespace)) {
                foreach ($namespacePath as $pathForNamespace) {
                    $paths[] = $pathForNamespace;
                }
            }
        }

        return $paths;
    }
131331
public function addDirectory($path)
    {
        $finder = new \Symfony\Component\Finder\Finder();

        $patterns = $this->getIgnorePatterns()->getRegularExpression();

        if ($this->follow_symlinks) {
            $finder->followLinks();
        }

        // restrict names to those ending in the given extensions
        $finder
            ->files()
            ->in($path)
            ->name(
                '/\.('.implode('|', $this->allowed_extensions->getArrayCopy()).')$/'
            )
            ->ignoreDotFiles($this->getIgnoreHidden())
            ->filter(
                function(\SplFileInfo $file) use ($patterns) {
                    if (!$patterns) {
                        return true;
                    }

                    // apply ignore list on path instead of file, finder
                    // can't do that by default
                    return !preg_match($patterns, $file->getPathname());
                }
            );

        try {
            /** @var \SplFileInfo $file */
            foreach ($finder as $file) {
                $file = new File($file);
                $path = $file->getRealPath()
                    ? $file->getRealPath()
                    : $file->getPathname();

                $this[$path] = $file;
            }
        } catch(\LogicException $e)
        {
            // if a logic exception is thrown then no folders were included
            // for phpDocumentor this is not an issue since we accept separate
            // files as well
        }
    }
409358
public function copyDir($from,$to,Finder $finder)
    {
        /* @var \Symfony\Component\Finder\SplFileInfo $path */

        $finder->in($from);
        foreach ($finder->files() as $path) {
            $targetDir = $to.DIRECTORY_SEPARATOR.$path->getRelativePath();
            if (!is_dir($targetDir)) {
                mkdir($targetDir,0755,true);
            }
            $target = $to.DIRECTORY_SEPARATOR.$path->getRelativePathname();
            copy($path->getRealPath(),$target);
        }
    }
726518
private function directoryContains(Finder $dir, $resource)
    {
        foreach ($dir as $containedResource) {
            /* @var $containedResource \SplFileInfo */
            if (substr($containedResource->getRealPath(), 0, strlen($resource)) == $resource) {
                return true;
            }
        }

        return false;
    }
1047135
public function generate(Finder $finder): Result
    {
        $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);

        $traverser = new NodeTraverser();
        $visitor = new NodeVisitor($this->symbols, $this->config);
        $traverser->addVisitor(new NameResolver());
        $traverser->addVisitor($visitor);

        $unparsed = [];
        foreach ($finder as $file) {
            $stmts = null;
            try {
                $stmts = $parser->parse($file->getContents());
            } catch (Error|RuntimeException $e) {
                $unparsed[$file->getPathname()] = $e;
            }

            if ($stmts) {
                $traverser->traverse($stmts);
            }
        }

        return new Result($visitor, $unparsed);
    }
1041801
public function addFolder(string $directory, string $alias = '')
	{
		$this->getRenderer()->addLocation($directory);

		return $this;
	}
974946
public function emptyDir($directory)
    {
        [$fs, $directory] = $this->getFilesystemAndPath($directory);

        $fs->emptyDir($directory);
    }
963578
private function createOrGetFolder($directory, ContainerBuilder $container)
    {
        $filesystem = new Filesystem();

        $directory = $container->getParameterBag()->resolveValue($directory);
        if (!file_exists($directory)) {
            $filesystem->mkdir($directory);
        }

        return $directory;
    }