@@ -7,10 +7,7 @@ class RotativeProcessor extends AbstractProcessor
77 private $ maxFiles = 366 ;
88
99 /**
10- * Log files are rotated count times before being removed
11- *
12- * @param int $count
13- * @return self
10+ * Log files are rotated count times before being removed.
1411 */
1512 public function files (int $ count ): self
1613 {
@@ -19,47 +16,37 @@ public function files(int $count): self
1916 return $ this ;
2017 }
2118
22- public function handler ($ file ): ?string
19+ public function handler (string $ filename ): ?string
2320 {
24- $ nextFile = "{$ this ->fileOriginal }.1 " ;
21+ $ filenameTarget = "{$ this ->filenameSource }.1 " ;
2522
2623 $ this ->rotate ();
2724
28- rename ($ file , $ nextFile );
25+ rename ($ filename , $ filenameTarget );
2926
30- return $ this ->processed ($ nextFile );
27+ return $ this ->processed ($ filenameTarget );
3128 }
3229
3330 private function rotate (int $ number = 1 ): string
3431 {
35- $ file = "{$ this ->fileOriginal }. {$ number }{$ this ->suffix }" ;
32+ $ filenameTarget = "{$ this ->filenameSource }. {$ number }{$ this ->extension }" ;
3633
37- if (!file_exists ($ file )) {
38- return "{ $ this -> fileOriginal } . { $ number }{ $ this -> suffix }" ;
34+ if (!file_exists ($ filenameTarget )) {
35+ return $ filenameTarget ;
3936 }
4037
41- if ($ this ->maxFiles > 0 && $ number >= $ this ->maxFiles ) {
42- if (file_exists ($ file )) {
43- unlink ($ file );
38+ if ($ this ->maxFiles > 0 && $ number >= $ this ->maxFiles ) {
39+ if (file_exists ($ filenameTarget )) {
40+ unlink ($ filenameTarget );
4441 }
4542
46- return "{ $ this -> fileOriginal } . { $ number }{ $ this -> suffix }" ;
43+ return $ filenameTarget ;
4744 }
4845
49- $ nextFile = $ this ->rotate ($ number + 1 );
46+ $ nextFilename = $ this ->rotate ($ number + 1 );
5047
51- rename ($ file , $ nextFile );
48+ rename ($ filenameTarget , $ nextFilename );
5249
53- return "{$ this ->fileOriginal }. {$ number }{$ this ->suffix }" ;
54- }
55-
56- private function getnumber (string $ file ): ?int
57- {
58- $ fileName = basename ($ file );
59- $ fileOriginaleName = basename ($ this ->fileOriginal );
60-
61- preg_match ("/ {$ fileOriginaleName }.([0-9]+) {$ this ->suffix }/ " , $ fileName , $ output );
62-
63- return $ output [1 ] ?? null ;
50+ return $ filenameTarget ;
6451 }
6552}
0 commit comments