@@ -93,25 +93,16 @@ public function rotate(string $filename): bool
9393 return false ;
9494 }
9595
96- $ fileNameTemp = $ this ->moveContentToTempFile ($ filename );
96+ $ filenameRotated = $ this ->runProcessor (
97+ $ filename ,
98+ $ this ->moveContentToTempFile ($ filename )
99+ );
97100
98- $ filenameRotated = $ this ->runProcessor ($ filename , $ fileNameTemp );
101+ $ filenameRotated = is_null ($ filenameRotated )
102+ ? $ filenameRotated
103+ : $ this ->runCompress ($ filenameRotated );
99104
100- if ($ filenameRotated && $ this ->_compress ) {
101- $ gz = new Gz ();
102-
103- try {
104- $ filenameRotated = $ gz ->handler ($ filenameRotated );
105- } catch (Exception $ error ) {
106- $ this ->exception ($ error );
107-
108- $ filenameRotated = null ;
109- }
110- }
111-
112- if ($ filenameRotated && $ this ->thenCallback ) {
113- call_user_func ($ this ->thenCallback , $ filenameRotated , $ filename );
114- }
105+ $ this ->sucessfull ($ filename , $ filenameRotated );
115106
116107 return !empty ($ filenameRotated );
117108 }
@@ -130,6 +121,32 @@ private function runProcessor(string $filenameSource, ?string $filenameTarget):
130121 return $ this ->processor ->handler ($ filenameTarget );
131122 }
132123
124+ private function runCompress (string $ filename ): ?string
125+ {
126+ if (!$ this ->_compress ) {
127+ return $ filename ;
128+ }
129+
130+ $ gz = new Gz ();
131+
132+ try {
133+ return $ gz ->handler ($ filename );
134+ } catch (Exception $ error ) {
135+ $ this ->exception ($ error );
136+
137+ return null ;
138+ }
139+ }
140+
141+ private function sucessfull (string $ filenameSource , ?string $ filenameRotated ): void
142+ {
143+ if (is_null ($ this ->thenCallback ) || is_null ($ filenameRotated )) {
144+ return ;
145+ }
146+
147+ call_user_func ($ this ->thenCallback , $ filenameRotated , $ filenameSource );
148+ }
149+
133150 /**
134151 * check if file need rotate.
135152 */
0 commit comments