protected function copy($source, $target): void
    {
        // skip, if not exists
        if (!file_exists($source)) {
            return;
        }
        // skip, if target exists
        if (is_file($target) && !is_dir($target)) {
            $this->installer->getIo()->write(
                sprintf('  - File <comment>%s</comment> already exists', $target),
                true,
                IOInterface::VERBOSE
            );
            return;
        }

        // Check the renaming of file for direct moving (file-to-file)
        $isRenameFile = substr($target, -1) !== '/' && !is_dir($source);

        if (file_exists($target) && !is_dir($target) && !$isRenameFile) {
            throw new \InvalidArgumentException('Destination directory is not a directory');
        }

        try {
            if ($isRenameFile) {
                $this->getFilesystem()->mkdir(\dirname($target));
            } else {
                $this->getFilesystem()->mkdir($target);
            }
        } catch (IOException $e) {
            throw new \InvalidArgumentException(
                sprintf('Could not create directory `%s`', $target)
            );
        }

        if (false === file_exists($source)) {
            throw new \InvalidArgumentException(
                sprintf('Source directory or file `%s` does not exist', $source)
            );
        }

        if (is_dir($source)) {
            $finder = new Finder;
            $finder->files()->in($source);

            foreach ($finder as $file) {
                try {
                    $this->getFilesystem()->copy($file, $target . DS . $file->getRelativePathname());
                } catch (IOException $e) {
                    throw new \InvalidArgumentException(
                        sprintf('Could not copy `%s`', $file->getBaseName())
                    );
                }
            }
        } else {
            try {
                if ($isRenameFile) {
                    $this->getFilesystem()->copy($source, $target);
                } else {
                    $this->getFilesystem()->copy($source, $target . '/' . basename($source));
                }
            } catch (IOException $e) {
                throw new \InvalidArgumentException(sprintf('Could not copy `%s`', $source));
            }
        }

        $this->installer->getIo()->write(
            sprintf('  - Copied file(s) from <comment>%s</comment> to <comment>%s</comment>', $source, $target),
            true,
            IOInterface::VERBOSE
        );
    }
protected function copy($source, $target): void
    {
        // skip, if not exists
        if (!file_exists($source)) {
            return;
        }
        // skip, if target exists
        if (is_file($target) && !is_dir($target)) {
            $this->installer->getIo()->write(
                sprintf('  - File <comment>%s</comment> already exists', $target),
                true,
                IOInterface::VERBOSE
            );
            return;
        }

        // Check the renaming of file for direct moving (file-to-file)
        $isRenameFile = substr($target, -1) !== '/' && !is_dir($source);

        if (file_exists($target) && !is_dir($target) && !$isRenameFile) {
            throw new \InvalidArgumentException('Destination directory is not a directory');
        }

        try {
            if ($isRenameFile) {
                $this->getFilesystem()->mkdir(\dirname($target));
            } else {
                $this->getFilesystem()->mkdir($target);
            }
        } catch (IOException $e) {
            throw new \InvalidArgumentException(
                sprintf('Could not create directory `%s`', $target)
            );
        }

        if (false === file_exists($source)) {
            throw new \InvalidArgumentException(
                sprintf('Source directory or file `%s` does not exist', $source)
            );
        }

        if (is_dir($source)) {
            $finder = new Finder;
            $finder->files()->in($source);

            foreach ($finder as $file) {
                try {
                    $this->getFilesystem()->copy($file, $target . DS . $file->getRelativePathname());
                } catch (IOException $e) {
                    throw new \InvalidArgumentException(
                        sprintf('Could not copy `%s`', $file->getBaseName())
                    );
                }
            }
        } else {
            try {
                if ($isRenameFile) {
                    $this->getFilesystem()->copy($source, $target);
                } else {
                    $this->getFilesystem()->copy($source, $target . '/' . basename($source));
                }
            } catch (IOException $e) {
                throw new \InvalidArgumentException(sprintf('Could not copy `%s`', $source));
            }
        }

        $this->installer->getIo()->write(
            sprintf('  - Copied file(s) from <comment>%s</comment> to <comment>%s</comment>', $source, $target),
            true,
            IOInterface::VERBOSE
        );
    }
protected function copy ( $ source , $ target ) : void { // skip, if not exists if ( ! file_exists ( $ source ) ) { return ; } // skip, if target exists if ( is_file ( $ target ) && ! is_dir ( $ target ) ) { $ this -> installer -> getIo ( ) -> write ( sprintf ( '  - File <comment>%s</comment> already exists' , $ target ) , true , IOInterface :: VERBOSE ) ; return ; } // Check the renaming of file for direct moving (file-to-file) $ isRenameFile = substr ( $ target , - 1 ) !== '/' && ! is_dir ( $ source ) ; if ( file_exists ( $ target ) && ! is_dir ( $ target ) && ! $ isRenameFile ) { throw new \ InvalidArgumentException ( 'Destination directory is not a directory' ) ; } try { if ( $ isRenameFile ) { $ this -> getFilesystem ( ) -> mkdir ( \ dirname ( $ target ) ) ; } else { $ this -> getFilesystem ( ) -> mkdir ( $ target ) ; } } catch ( IOException $ e ) { throw new \ InvalidArgumentException ( sprintf ( 'Could not create directory `%s`' , $ target ) ) ; } if ( false === file_exists ( $ source ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Source directory or file `%s` does not exist' , $ source ) ) ; } if ( is_dir ( $ source ) ) { $ finder = new Finder ; $ finder -> files ( ) -> in ( $ source ) ; foreach ( $ finder as $ file ) { try { $ this -> getFilesystem ( ) -> copy ( $ file , $ target . DS . $ file -> getRelativePathname ( ) ) ; } catch ( IOException $ e ) { throw new \ InvalidArgumentException ( sprintf ( 'Could not copy `%s`' , $ file -> getBaseName ( ) ) ) ; } } } else { try { if ( $ isRenameFile ) { $ this -> getFilesystem ( ) -> copy ( $ source , $ target ) ; } else { $ this -> getFilesystem ( ) -> copy ( $ source , $ target . '/' . basename ( $ source ) ) ; } } catch ( IOException $ e ) { throw new \ InvalidArgumentException ( sprintf ( 'Could not copy `%s`' , $ source ) ) ; } } $ this -> installer -> getIo ( ) -> write ( sprintf ( '  - Copied file(s) from <comment>%s</comment> to <comment>%s</comment>' , $ source , $ target ) , true , IOInterface :: VERBOSE ) ; }
It recursively copies the files and directories

@param string $source
@param string $target

@return void
@throws \InvalidArgumentException
It recursively copies the files and directories