1818use Stolt \LeanPackage \Exceptions \NoLicenseFilePresent ;
1919use Stolt \LeanPackage \Exceptions \NonExistentGlobPatternFile ;
2020use Stolt \LeanPackage \Exceptions \PresetNotAvailable ;
21+ use Stolt \LeanPackage \GitattributesFileRepository ;
2122use Stolt \LeanPackage \Helpers \InputReader ;
2223use Symfony \Component \Console \Command \Command ;
2324use Symfony \Component \Console \Input \InputArgument ;
@@ -54,6 +55,8 @@ final class ValidateCommand extends Command
5455 */
5556 protected Validator $ archiveValidator ;
5657
58+ protected GitattributesFileRepository $ gitattributesFileRepository ;
59+
5760 /**
5861 * Input reader.
5962 *
@@ -70,6 +73,7 @@ public function __construct(Analyser $analyser, Validator $archiveValidator, Inp
7073 {
7174 $ this ->analyser = $ analyser ;
7275 $ this ->archiveValidator = $ archiveValidator ;
76+ $ this ->gitattributesFileRepository = new GitattributesFileRepository ($ this ->analyser );
7377 $ this ->inputReader = $ inputReader ;
7478
7579 parent ::__construct ();
@@ -453,7 +457,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
453457 $ expectedGitattributesFileContent = $ this ->generatedHeader . PHP_EOL . PHP_EOL . $ expectedGitattributesFileContent ;
454458 }
455459
456- $ outputContent .= $ this ->createGitattributesFile (
460+ $ outputContent .= $ this ->gitattributesFileRepository -> createGitattributesFile (
457461 $ expectedGitattributesFileContent
458462 );
459463
@@ -555,7 +559,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
555559 $ expectedGitattributesFileContent = $ this ->modifiedHeader . PHP_EOL . PHP_EOL . $ expectedGitattributesFileContent ;
556560 }
557561
558- $ outputContent .= $ this ->overwriteGitattributesFile (
562+ $ outputContent .= $ this ->gitattributesFileRepository -> overwriteGitattributesFile (
559563 $ expectedGitattributesFileContent
560564 );
561565
@@ -658,8 +662,8 @@ protected function isDefaultGlobPatternFilePresent(): bool
658662 * Validate archive of current Git HEAD.
659663 *
660664 * @param boolean $validateLicenseFilePresence Whether the archive should have a license file or not.
665+ * @throws GitNotAvailable|NoLicenseFilePresent
661666 * @throws GitHeadNotAvailable
662- * @throws GitNotAvailable
663667 * @return boolean
664668 */
665669 protected function isValidArchive (bool $ validateLicenseFilePresence = false ): bool
@@ -708,56 +712,4 @@ protected function getSuggestGitattributesFileCreationOptionOutput(
708712
709713 return PHP_EOL . PHP_EOL . $ content ;
710714 }
711-
712- /**
713- * Create the gitattributes file.
714- *
715- * @param string $content The content of the gitattributes file
716- * @throws GitattributesCreationFailed
717- *
718- * @return string
719- */
720- protected function createGitattributesFile (string $ content ): string
721- {
722- $ bytesWritten = file_put_contents (
723- $ this ->analyser ->getGitattributesFilePath (),
724- $ content
725- );
726-
727- if ($ bytesWritten ) {
728- $ content = 'Created a .gitattributes file with the shown content: '
729- . PHP_EOL . '<info> ' . $ content . '</info> ' ;
730-
731- return PHP_EOL . PHP_EOL . $ content ;
732- }
733-
734- $ message = 'Creation of .gitattributes file failed. ' ;
735- throw new GitattributesCreationFailed ($ message );
736- }
737-
738- /**
739- * Overwrite an existing gitattributes file.
740- *
741- * @param string $content The content of the gitattributes file
742- * @throws GitattributesCreationFailed
743- *
744- * @return string
745- */
746- protected function overwriteGitattributesFile (string $ content ): string
747- {
748- $ bytesWritten = file_put_contents (
749- $ this ->analyser ->getGitattributesFilePath (),
750- $ content
751- );
752-
753- if ($ bytesWritten ) {
754- $ content = 'Overwrote it with the shown content: '
755- . PHP_EOL . '<info> ' . $ content . '</info> ' ;
756-
757- return PHP_EOL . PHP_EOL . $ content ;
758- }
759-
760- $ message = 'Overwrite of .gitattributes file failed. ' ;
761- throw new GitattributesCreationFailed ($ message );
762- }
763715}
0 commit comments