77use App \{
88 Clock ,
99 PhpVersionFetcher ,
10- Repository \PDO \LastUpdateRepository ,
11- Repository \PDO \PdoPhpReleaseRepository ,
12- Repository \PDO \PdoPhpVersionRepository ,
10+ Storage ,
1311};
1412use Symfony \Component \Console \{
1513 Command \Command ,
@@ -21,33 +19,39 @@ final class SynchronizeCommand extends Command
2119{
2220 public function __construct (
2321 private Clock $ clock ,
24- private LastUpdateRepository $ lastUpdateRepository ,
25- private PdoPhpReleaseRepository $ releaseRepository ,
26- private PdoPhpVersionRepository $ versionRepository ,
2722 private PhpVersionFetcher $ fetcher ,
23+ private Storage $ storage ,
24+ string $ name
2825 ) {
29- parent ::__construct (' synchronize ' );
26+ parent ::__construct ($ name );
3027 }
3128
3229 protected function execute (InputInterface $ input , OutputInterface $ output ): int
3330 {
34- $ currentTime = $ this ->clock ->now ()->format ('Y-m-d H:i:s ' );
35- $ output ->writeln ("<info>[ $ currentTime] Process current versions</info> " );
36- $ currents = $ this ->fetcher ->currents ();
37- $ this ->versionRepository ->save (...$ currents );
31+ $ versions = [];
3832
39- $ currentTime = $ this ->clock -> now ()-> format ( ' Y-m-d H:i:s ' );
40- $ output -> writeln ( " <info>[ $ currentTime ] Process unmaintened versions</info> " );
41- $ eol = $ this -> fetcher -> eol () ;
42- $ this -> versionRepository -> save (... $ eol );
33+ $ this ->log ( $ output , ' Fetch current versions ' );
34+ foreach ( $ this -> fetcher -> currents () as $ version ) {
35+ $ versions [] = $ version ;
36+ }
4337
44- $ currentTime = $ this ->clock ->now ()->format ('Y-m-d H:i:s ' );
45- $ output ->writeln ("<info>[ $ currentTime] Process releases versions</info> " );
38+ $ this ->log ($ output , 'Fetch unmaintened versions ' );
39+ foreach ($ this ->fetcher ->eol () as $ version ) {
40+ $ versions [] = $ version ;
41+ }
42+
43+ $ this ->log ($ output , 'Fetch releases versions ' );
4644 $ releases = $ this ->fetcher ->releases ();
47- $ this ->releaseRepository ->save (...$ releases );
4845
49- $ this ->lastUpdateRepository ->save ();
46+ $ this ->log ($ output , 'Write data ' );
47+ $ this ->storage ->write ($ versions , $ releases );
5048
5149 return 0 ;
5250 }
51+
52+ private function log (OutputInterface $ output , string $ text ): void
53+ {
54+ $ currentTime = $ this ->clock ->now ()->format ('Y-m-d H:i:s ' );
55+ $ output ->writeln ("<info>[ $ currentTime] $ text</info> " );
56+ }
5357}
0 commit comments