1414
1515class Processor
1616{
17- const WAIT_TIMEOUT = 15 ;
17+ const WAIT_TIMEOUT = 30 ;
1818 private $ personalAccessToken ;
1919
2020 private $ prefixerClient ;
@@ -25,47 +25,54 @@ public function __construct($personalAccessToken)
2525 $ this ->prefixerClient = (new PrefixerClient ())->authenticate ($ this ->personalAccessToken );
2626 }
2727
28- public function run ($ sourcePath , $ targetPath , $ projectId , $ githubAccessToken = null )
28+ public function run ($ sourcePath , $ targetPath , int $ projectId , $ githubAccessToken = null )
2929 {
30- $ tmpZip = $ this ->temporaryZipFilename ($ sourcePath , $ targetPath , $ projectId , $ githubAccessToken );
31-
3230 $ zipManager = new ZipManager ();
33- $ zipManager ->compress ($ this ->sourcePath , $ tmpZip );
31+ $ tmpZip = $ this ->temporaryZipFilename ($ targetPath );
32+ $ zipManager ->compress ($ sourcePath , $ tmpZip );
33+
34+ $ response = $ this ->prefixerClient ->createBuild ($ projectId , $ tmpZip , $ githubAccessToken );
35+
36+ $ build = $ response ->build ;
37+ unlink ($ tmpZip );
3438
35- $ build = $ this ->prefixerClient ->createBuild ($ tmpZip , $ projectId , $ this ->githubAccessToken );
36- $ build = $ this ->waitForProcessing ($ build );
37- $ downloadedZip = $ this ->download ($ build );
38- $ zipManager ->uncompress ($ downloadedZip , $ this ->targetPath );
39+ $ this ->waitForProcessing ($ build );
40+ $ downloadedZip = $ this ->download ($ build , $ targetPath );
41+ $ zipManager ->uncompress ($ downloadedZip , $ targetPath );
42+ unlink ($ downloadedZip );
43+
44+ $ response = $ this ->prefixerClient ->build ($ build ->project_id , $ build ->id );
45+
46+ return $ build ;
3947 }
4048
41- private function temporaryZipFilename ()
49+ private function temporaryZipFilename ($ targetPath )
4250 {
43- return tempnam ( $ this -> targetPath , ' PPP ' ).'.zip ' ;
51+ return $ targetPath. ' / ' . basename ( $ targetPath ).'.zip ' ;
4452 }
4553
4654 private function waitForProcessing ($ build )
4755 {
48- while ($ updatedBuild = $ this ->isProcessing ($ build )) {
56+ while ($ this ->isProcessing ($ build )) {
4957 sleep (self ::WAIT_TIMEOUT );
5058 }
51-
52- return $ updatedBuild ;
5359 }
5460
5561 private function isProcessing ($ build )
5662 {
57- $ nuild = $ this ->prefixerClient ->build ($ build ->project_id , $ build ->build_id );
63+ $ response = $ this ->prefixerClient ->build ($ build ->project_id , $ build ->id );
64+ $ build = $ response ->build ;
5865
5966 return !\in_array ($ build ->state , ['success ' , 'failed ' ], true );
6067 }
6168
62- private function download ($ build )
69+ private function download ($ build, $ targetPath )
6370 {
6471 if ('success ' === $ build ->state ) {
65- return $ this ->prefixerClient ->download ($ build ->project_id , $ build ->build_id );
72+ return $ this ->prefixerClient ->download ($ build ->project_id , $ build ->id , $ targetPath );
6673 }
6774
6875 // Failed
69- return $ this ->prefixerClient ->downloadLog ($ build ->project_id , $ build ->build_id );
76+ return $ this ->prefixerClient ->downloadLog ($ build ->project_id , $ build ->id , $ targetPath );
7077 }
7178}
0 commit comments