Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Rebuild_File | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
7 | |
100.00% |
1 / 1 |
| apply_to_path | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
7 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\Jetpack_Boost\Modules\Optimizations\Page_Cache\Pre_WordPress\Path_Actions; |
| 4 | |
| 5 | use Automattic\Jetpack_Boost\Modules\Optimizations\Page_Cache\Pre_WordPress\Filesystem_Utils; |
| 6 | use SplFileInfo; |
| 7 | |
| 8 | /** |
| 9 | * Rebuild a file. |
| 10 | */ |
| 11 | class Rebuild_File implements Path_Action { |
| 12 | public function apply_to_path( SplFileInfo $file ) { |
| 13 | if ( $file->isDir() && Filesystem_Utils::is_dir_empty( $file->getPathname() ) ) { |
| 14 | Filesystem_Utils::delete_empty_dir( $file->getPathname() ); |
| 15 | return false; |
| 16 | } |
| 17 | |
| 18 | if ( $file->isDir() || $file->getFilename() === 'index.html' ) { |
| 19 | return false; |
| 20 | } |
| 21 | |
| 22 | // If it's already a rebuild file, delete it because it expired long ago. |
| 23 | if ( Filesystem_Utils::is_rebuild_file( $file->getFilename() ) ) { |
| 24 | $action = new Simple_Delete(); |
| 25 | return $action->apply_to_path( $file ); |
| 26 | } |
| 27 | |
| 28 | $rebuilt = Filesystem_Utils::rebuild_file( $file->getPathname() ); |
| 29 | return $rebuilt ? 1 : false; |
| 30 | } |
| 31 | } |