1- <?php
1+ <?php declare (strict_types= 1 );
22
33namespace Frosh \Tools \Command ;
44
55use Symfony \Component \Console \Command \Command ;
66use Symfony \Component \Console \Input \InputInterface ;
7+ use Symfony \Component \Console \Input \InputOption ;
78use Symfony \Component \Console \Output \OutputInterface ;
89use Symfony \Component \Console \Style \SymfonyStyle ;
9- use Symfony \Component \Console \Input \InputOption ;
1010
1111class DevRobotsTxtCommand extends Command
1212{
@@ -28,26 +28,27 @@ protected function configure(): void
2828 protected function execute (InputInterface $ input , OutputInterface $ output ): int
2929 {
3030 $ io = new SymfonyStyle ($ input , $ output );
31- $ robotsPath = $ this ->envPath . " /robots.txt " ;
31+ $ robotsPath = $ this ->envPath . ' /robots.txt ' ;
3232 $ originalState = $ input ->getOption ('remove ' );
3333 $ fileExists = file_exists ($ robotsPath );
3434
35- //robots.txt exists in public folder
36- if ($ fileExists ) {
37- if ($ originalState ) {
35+ // robots.txt exists in public folder
36+ if ($ fileExists ) {
37+ if ($ originalState ) {
3838 return $ this ->revertToOriginal ($ input , $ output , $ robotsPath );
3939 }
4040
4141 return $ this ->changeRobotsTxt ($ input , $ output , $ robotsPath );
4242 }
43-
44- //robots.txt does not exist in public folder
45- if ($ originalState ) {
43+
44+ // robots.txt does not exist in public folder
45+ if ($ originalState ) {
4646 $ io ->error ('There is no robots.txt in public folder ' );
47+
4748 return self ::SUCCESS ;
4849 }
4950
50- $ robotsFile = fopen ($ robotsPath , " w " );
51+ $ robotsFile = fopen ($ robotsPath , ' w ' );
5152 $ robotsContent = "#soc \nUser-agent: * \nDisallow: / \n#eoc " ;
5253 fwrite ($ robotsFile , $ robotsContent );
5354 fclose ($ robotsFile );
@@ -57,46 +58,50 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5758 return self ::SUCCESS ;
5859 }
5960
60- private function revertToOriginal ($ input , $ output , $ robotsPath ): int
61+ private function revertToOriginal ($ input , $ output , $ robotsPath ): int
6162 {
62- //returns robots.txt to original state
63+ // returns robots.txt to original state
6364 $ io = new SymfonyStyle ($ input , $ output );
6465 $ file = file_get_contents ($ robotsPath );
6566 $ createdString = "#soc \nUser-agent: * \nDisallow: / \n#eoc " ;
6667
67- //If only input from command is present
68- if ($ file === $ createdString ) {
68+ // If only input from command is present
69+ if ($ file === $ createdString ) {
6970 unlink ($ robotsPath );
7071 $ io ->success ('robots.txt file deleted :) ' );
72+
7173 return self ::SUCCESS ;
7274 }
7375
74- //removes everything between #soc & #eoc
76+ // removes everything between #soc & #eoc
7577 $ content = preg_replace ('/#soc[\s\S]+?#eoc/ ' , '' , $ file );
7678
7779 file_put_contents ($ robotsPath , $ content );
7880 $ io ->success ('robots.txt reverted to original :) ' );
81+
7982 return self ::SUCCESS ;
8083 }
8184
82- private function changeRobotsTxt (InputInterface $ input , OutputInterface $ output , string $ robotsPath ): int
85+ private function changeRobotsTxt (InputInterface $ input , OutputInterface $ output , string $ robotsPath ): int
8386 {
84- //change robots.txt to disable crawlers
87+ // change robots.txt to disable crawlers
8588 $ io = new SymfonyStyle ($ input , $ output );
8689
8790 $ file = file_get_contents ($ robotsPath );
8891 $ commandString = "#soc \nUser-agent: * \nDisallow: / \n#eoc " ;
8992
90- //If command is called multiple times
91- if (str_contains ($ file , $ commandString )) {
93+ // If command is called multiple times
94+ if (str_contains ($ file , $ commandString )) {
9295 $ io ->error ('Command was already executed before ' );
93- return self ::SUCCESS ;
96+
97+ return self ::SUCCESS ;
9498 }
9599
96- $ content = "#soc \nUser-agent: * \nDisallow: / \n#eoc \n" . $ file ;
100+ $ content = "#soc \nUser-agent: * \nDisallow: / \n#eoc \n" . $ file ;
97101 file_put_contents ($ robotsPath , $ content );
98102
99103 $ io ->success ('robots.txt changed :) ' );
104+
100105 return self ::SUCCESS ;
106+ }
101107}
102- }
0 commit comments