| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace phpbu\App\Result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use phpbu\App\Cli\Statistics; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use phpbu\App\Event; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use phpbu\App\Listener; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use phpbu\App\Result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use phpbu\App\Util; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use SebastianBergmann\Environment\Console; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use SebastianBergmann\Environment\Runtime; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * Default app output. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * Heavily 'inspired' by Sebastian Bergmann's phpunit PHPUnit_TextUI_ResultPrinter. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @package    phpbu | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @subpackage Result | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @author     Sebastian Feldmann <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @copyright  Sebastian Feldmann <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @license    https://opensource.org/licenses/MIT The MIT License (MIT) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @link       http://phpbu.de/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @since      Class available since Release 1.0.0 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 25 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  | class PrinterCli implements Listener | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |      * Verbose output | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |      * @var bool | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     protected $verbose = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * Output with colors | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |      * @var bool | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     protected $colors = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      * Is debug active | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |      * @var bool | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     protected $debug = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |      * Amount of executed backups | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      * @var integer | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     private $numBackups = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |      * Amount of executed checks | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |      * @var integer | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |     private $numChecks = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |      * Amount of executed crypts | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |      * @var integer | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     private $numCrypts = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |      * Amount of executed Syncs | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |      * @var integer | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |     private $numSyncs = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |      * Amount of executed Cleanups | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |      * @var integer | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     private $numCleanups = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |      * Console | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |      * @var \SebastianBergmann\Environment\Console | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |     private $console; | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |      * PHP Runtime | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |      * @var \SebastianBergmann\Environment\Runtime | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |     private $runtime; | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |      * @var Event\Check\Failed[] | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |     private $failedChecks = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |      * Constructor | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |      * @param bool $verbose | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |      * @param bool $colors | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |      * @param bool $debug | 
            
                                                                        
                            
            
                                    
            
            
                | 109 | 3 |  |      * @throws \InvalidArgumentException | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |     public function __construct(bool $verbose = false, bool $colors = false, bool $debug = false) | 
            
                                                                        
                            
            
                                    
            
            
                | 112 | 3 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |         $this->console = new Console; | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |         $this->runtime = new Runtime; | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |         $this->debug = $debug; | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |         $this->verbose = $verbose; | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |         $this->colors = $colors && $this->console->hasColorSupport(); | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |      * Returns an array of event names this subscriber wants to listen to. | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |      * The array keys are event names and the value can be: | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |      *  * The method name to call (priority defaults to 0) | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |      *  * An array composed of the method name to call and the priority | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |      *  * An array of arrays composed of the method names to call and respective | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |      *    priorities, or 0 if unset | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |      * @return array The event names to listen to | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |     public static function getSubscribedEvents(): array | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |         return [ | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |             'phpbu.debug'           => 'onDebug', | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |             'phpbu.warning'         => 'onWarning', | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |             'phpbu.app_start'       => 'onPhpbuStart', | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |             'phpbu.backup_start'    => 'onBackupStart', | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |             'phpbu.backup_failed'   => 'onBackupFailed', | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |             'phpbu.backup_end'      => 'onBackupEnd', | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |             'phpbu.check_start'     => 'onCheckStart', | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |             'phpbu.check_failed'    => 'onCheckFailed', | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |             'phpbu.check_end'       => 'onCheckEnd', | 
            
                                                                        
                            
            
                                    
            
            
                | 144 | 29 |  |             'phpbu.crypt_start'     => 'onCryptStart', | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |             'phpbu.crypt_skipped'   => 'onCryptSkipped', | 
            
                                                                        
                            
            
                                    
            
            
                | 146 | 29 |  |             'phpbu.crypt_failed'    => 'onCryptFailed', | 
            
                                                                        
                            
            
                                    
            
            
                | 147 | 29 |  |             'phpbu.crypt_end'       => 'onCryptEnd', | 
            
                                                                        
                            
            
                                    
            
            
                | 148 | 29 |  |             'phpbu.sync_start'      => 'onSyncStart', | 
            
                                                                        
                            
            
                                    
            
            
                | 149 | 29 |  |             'phpbu.sync_skipped'    => 'onSyncSkipped', | 
            
                                                                        
                            
            
                                    
            
            
                | 150 | 29 |  |             'phpbu.sync_failed'     => 'onSyncFailed', | 
            
                                                                        
                            
            
                                    
            
            
                | 151 | 29 |  |             'phpbu.sync_end'        => 'onSyncEnd', | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  |             'phpbu.cleanup_start'   => 'onCleanupStart', | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |             'phpbu.cleanup_skipped' => 'onCleanupSkipped', | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  |             'phpbu.cleanup_failed'  => 'onCleanupFailed', | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  |             'phpbu.cleanup_end'     => 'onCleanupEnd', | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |             'phpbu.app_end'         => 'onPhpbuEnd', | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 158 | 2 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 160 | 2 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 161 | 2 |  |      * phpbu start event. | 
            
                                                                        
                            
            
                                    
            
            
                | 162 | 1 |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 163 | 1 |  |      * @param \phpbu\App\Event\App\Start $event | 
            
                                                                        
                            
            
                                    
            
            
                | 164 | 1 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 165 | 1 |  |     public function onPhpbuStart(Event\App\Start $event): void | 
            
                                                                        
                            
            
                                    
            
            
                | 166 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 167 |  |  |         $configuration = $event->getConfiguration(); | 
            
                                                                        
                            
            
                                    
            
            
                | 168 | 2 |  |         if ($this->verbose) { | 
            
                                                                        
                            
            
                                    
            
            
                | 169 |  |  |             $this->write( | 
            
                                                                        
                            
            
                                    
            
            
                | 170 |  |  |                 'Runtime:       ' . $this->runtime->getNameWithVersion() . PHP_EOL . | 
            
                                                                        
                            
            
                                    
            
            
                | 171 |  |  |                 'Configuration: ' . $configuration->getFilename() . PHP_EOL . | 
            
                                                                        
                            
            
                                    
            
            
                | 172 |  |  |                 PHP_EOL | 
            
                                                                        
                            
            
                                    
            
            
                | 173 |  |  |             ); | 
            
                                                                        
                            
            
                                    
            
            
                | 174 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 175 | 3 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 177 | 3 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 178 | 3 |  |      * Writes a buffer. | 
            
                                                                        
                            
            
                                    
            
            
                | 179 | 2 |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 180 | 2 |  |      * @param string $buffer | 
            
                                                                        
                            
            
                                    
            
            
                | 181 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 182 | 3 |  |     public function write($buffer): void | 
            
                                                                        
                            
            
                                    
            
            
                | 183 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 184 |  |  |         if (PHP_SAPI != 'cli') { | 
            
                                                                        
                            
            
                                    
            
            
                | 185 |  |  |             $buffer = htmlspecialchars($buffer); | 
            
                                                                        
                            
            
                                    
            
            
                | 186 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 187 |  |  |         echo $buffer; | 
            
                                                                        
                            
            
                                    
            
            
                | 188 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 189 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 190 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 191 | 1 |  |      * Backup start event. | 
            
                                                                        
                            
            
                                    
            
            
                | 192 | 1 |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 193 |  |  |      * @param \phpbu\App\Event\Backup\Start $event | 
            
                                                                        
                            
            
                                    
            
            
                | 194 | 1 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 195 |  |  |     public function onBackupStart(Event\Backup\Start $event): void | 
            
                                                                        
                            
            
                                    
            
            
                | 196 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 197 |  |  |         $this->numBackups ++; | 
            
                                                                        
                            
            
                                    
            
            
                | 198 |  |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 199 |  |  |             $backup = $event->getConfiguration(); | 
            
                                                                        
                            
            
                                    
            
            
                | 200 |  |  |             $this->writeWithAsterisk('backup: [' . $backup->getSource()->type . '] '); | 
            
                                                                        
                            
            
                                    
            
            
                | 201 | 2 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 202 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 203 | 2 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 204 | 1 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 205 |  |  |      * Writes a buffer with Ansible like asterisk decoration. | 
            
                                                                        
                            
            
                                    
            
            
                | 206 | 2 |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 207 |  |  |      * @param string $buffer | 
            
                                                                        
                            
            
                                    
            
            
                | 208 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 209 |  |  |     protected function writeWithAsterisk($buffer): void | 
            
                                                                        
                            
            
                                    
            
            
                | 210 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 211 |  |  |         $this->write(Util\Cli::formatWithAsterisk($buffer)); | 
            
                                                                        
                            
            
                                    
            
            
                | 212 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 213 | 3 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 214 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 215 | 3 |  |      * Backup failed event. | 
            
                                                                        
                            
            
                                    
            
            
                | 216 | 3 |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 217 | 2 |  |      * @param \phpbu\App\Event\Backup\Failed $event | 
            
                                                                        
                            
            
                                    
            
            
                | 218 | 2 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 219 | 2 |  |     public function onBackupFailed(Event\Backup\Failed $event): void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 220 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 221 | 3 |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 222 |  |  |             $this->writeWithColor('fg-white, bg-red, bold', 'failed' . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 223 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 224 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 225 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 226 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 227 |  |  |      * Writes a buffer out with a color sequence if colors are enabled. | 
            
                                                                        
                            
            
                                    
            
            
                | 228 | 1 |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 229 |  |  |      * @param string $color | 
            
                                                                        
                            
            
                                    
            
            
                | 230 | 1 |  |      * @param string $buffer | 
            
                                                                        
                            
            
                                    
            
            
                | 231 | 1 |  |      * @author Sebastian Bergmann <[email protected]> | 
            
                                                                        
                            
            
                                    
            
            
                | 232 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 233 | 1 |  |     protected function writeWithColor($color, $buffer): void | 
            
                                                                        
                            
            
                                    
            
            
                | 234 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 235 |  |  |         if ($this->colors) { | 
            
                                                                        
                            
            
                                    
            
            
                | 236 |  |  |             $buffer = Util\Cli::formatWithColor($color, $buffer); | 
            
                                                                        
                            
            
                                    
            
            
                | 237 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 238 |  |  |         $this->write($buffer . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 239 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 240 | 2 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 241 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 242 | 2 |  |      * Backup end event. | 
            
                                                                        
                            
            
                                    
            
            
                | 243 | 1 |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 244 |  |  |      * @param \phpbu\App\Event\Backup\End $event | 
            
                                                                        
                            
            
                                    
            
            
                | 245 | 2 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 246 |  |  |     public function onBackupEnd(Event\Backup\End $event): void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 247 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 248 |  |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 249 |  |  |             $this->writeWithColor('fg-black, bg-green', 'ok' . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 250 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 251 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 252 | 4 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 253 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 254 | 4 |  |      * Check start event. | 
            
                                                                        
                            
            
                                    
            
            
                | 255 | 4 |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 256 | 3 |  |      * @param \phpbu\App\Event\Check\Start $event | 
            
                                                                        
                            
            
                                    
            
            
                | 257 | 3 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 258 |  |  |     public function onCheckStart(Event\Check\Start $event): void | 
            
                                                                        
                            
            
                                    
            
            
                | 259 | 4 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 260 |  |  |         $this->numChecks ++; | 
            
                                                                        
                            
            
                                    
            
            
                | 261 |  |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 262 |  |  |             $check = $event->getConfiguration(); | 
            
                                                                        
                            
            
                                    
            
            
                | 263 |  |  |             $this->writeWithAsterisk('check: [' . $check->type . '] '); | 
            
                                                                        
                            
            
                                    
            
            
                | 264 |  |  |             $this->write('checking: [' . $check->value . '] '); | 
            
                                                                        
                            
            
                                    
            
            
                | 265 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 266 | 1 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 267 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 268 | 1 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 269 | 1 |  |      * Check failed event. | 
            
                                                                        
                            
            
                                    
            
            
                | 270 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 271 | 1 |  |      * @param \phpbu\App\Event\Check\Failed $event | 
            
                                                                        
                            
            
                                    
            
            
                | 272 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 273 |  |  |     public function onCheckFailed(Event\Check\Failed $event): void | 
            
                                                                        
                            
            
                                    
            
            
                | 274 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 275 |  |  |         $this->failedChecks[] = $event; | 
            
                                                                        
                            
            
                                    
            
            
                | 276 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 277 |  |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 278 | 1 |  |             $this->writeWithColor('fg-white, bg-red, bold', 'failed' . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 279 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 280 | 1 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 281 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 282 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 283 | 1 |  |      * Check end event. | 
            
                                                                        
                            
            
                                    
            
            
                | 284 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 285 |  |  |      * @param \phpbu\App\Event\Check\End $event | 
            
                                                                        
                            
            
                                    
            
            
                | 286 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 287 |  |  |     public function onCheckEnd(Event\Check\End $event): void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 288 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 289 |  |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 290 | 2 |  |             $this->writeWithColor('fg-black, bg-green', 'ok' . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 291 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 292 | 2 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 293 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 294 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 295 | 2 |  |      * Crypt start event. | 
            
                                                                        
                            
            
                                    
            
            
                | 296 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 297 |  |  |      * @param \phpbu\App\Event\Crypt\Start $event | 
            
                                                                        
                            
            
                                    
            
            
                | 298 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 299 |  |  |     public function onCryptStart(Event\Crypt\Start $event): void | 
            
                                                                        
                            
            
                                    
            
            
                | 300 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 301 |  |  |         $this->numCrypts ++; | 
            
                                                                        
                            
            
                                    
            
            
                | 302 | 4 |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 303 |  |  |             $crypt = $event->getConfiguration(); | 
            
                                                                        
                            
            
                                    
            
            
                | 304 | 4 |  |             $this->writeWithAsterisk('crypt: [' . $crypt->type . '] '); | 
            
                                                                        
                            
            
                                    
            
            
                | 305 | 4 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 306 | 3 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 307 | 3 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 308 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 309 | 4 |  |      * Crypt skipped event. | 
            
                                                                        
                            
            
                                    
            
            
                | 310 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 311 |  |  |      * @param \phpbu\App\Event\Crypt\Skipped $event | 
            
                                                                        
                            
            
                                    
            
            
                | 312 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 313 |  |  |     public function onCryptSkipped(Event\Crypt\Skipped $event): void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 314 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 315 |  |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 316 | 1 |  |             $this->writeWithColor('fg-black, bg-yellow', 'skipped' . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 317 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 318 | 1 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 319 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 320 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 321 | 1 |  |      * Crypt failed event. | 
            
                                                                        
                            
            
                                    
            
            
                | 322 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 323 |  |  |      * @param \phpbu\App\Event\Crypt\Failed $event | 
            
                                                                        
                            
            
                                    
            
            
                | 324 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 325 |  |  |     public function onCryptFailed(Event\Crypt\Failed $event): void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 326 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 327 |  |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 328 | 1 |  |             $this->writeWithColor('fg-white, bg-red, bold', 'failed' . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 329 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 330 | 1 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 331 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 332 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 333 | 1 |  |      * Crypt end event. | 
            
                                                                        
                            
            
                                    
            
            
                | 334 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 335 |  |  |      * @param \phpbu\App\Event\Crypt\End $event | 
            
                                                                        
                            
            
                                    
            
            
                | 336 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 337 |  |  |     public function onCryptEnd(Event\Crypt\End $event): void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 338 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 339 |  |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 340 | 2 |  |             $this->writeWithColor('fg-black, bg-green', 'ok' . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 341 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 342 | 2 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 343 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 344 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 345 | 2 |  |      * Sync start event. | 
            
                                                                        
                            
            
                                    
            
            
                | 346 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 347 |  |  |      * @param \phpbu\App\Event\Sync\Start $event | 
            
                                                                        
                            
            
                                    
            
            
                | 348 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 349 |  |  |     public function onSyncStart(Event\Sync\Start $event): void | 
            
                                                                        
                            
            
                                    
            
            
                | 350 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 351 |  |  |         $this->numSyncs ++; | 
            
                                                                        
                            
            
                                    
            
            
                | 352 | 4 |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 353 |  |  |             $sync = $event->getConfiguration(); | 
            
                                                                        
                            
            
                                    
            
            
                | 354 | 4 |  |             $this->writeWithAsterisk('sync: [' . $sync->type . '] '); | 
            
                                                                        
                            
            
                                    
            
            
                | 355 | 4 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 356 | 3 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 357 | 3 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 358 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 359 | 4 |  |      * Sync skipped event. | 
            
                                                                        
                            
            
                                    
            
            
                | 360 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 361 |  |  |      * @param \phpbu\App\Event\Sync\Skipped $event | 
            
                                                                        
                            
            
                                    
            
            
                | 362 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 363 |  |  |     public function onSyncSkipped(Event\Sync\Skipped $event): void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 364 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 365 |  |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 366 | 1 |  |             $this->writeWithColor('fg-black, bg-yellow', 'skipped' . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 367 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 368 | 1 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 369 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 370 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 371 | 1 |  |      * Sync failed event. | 
            
                                                                        
                            
            
                                    
            
            
                | 372 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 373 |  |  |      * @param \phpbu\App\Event\Sync\Failed $event | 
            
                                                                        
                            
            
                                    
            
            
                | 374 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 375 |  |  |     public function onSyncFailed(Event\Sync\Failed $event): void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 376 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 377 |  |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 378 | 1 |  |             $this->writeWithColor('fg-white, bg-red, bold', 'failed' . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 379 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 380 | 1 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 381 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 382 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 383 | 1 |  |      * Sync end event. | 
            
                                                                        
                            
            
                                    
            
            
                | 384 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 385 |  |  |      * @param \phpbu\App\Event\Sync\End $event | 
            
                                                                        
                            
            
                                    
            
            
                | 386 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 387 |  |  |     public function onSyncEnd(Event\Sync\End $event): void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 388 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 389 |  |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 390 | 2 |  |             $this->writeWithColor('fg-black, bg-green', 'ok' . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 391 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 392 | 2 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 393 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 394 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 395 | 2 |  |      * Cleanup start event. | 
            
                                                                        
                            
            
                                    
            
            
                | 396 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 397 |  |  |      * @param \phpbu\App\Event\Cleanup\Start $event | 
            
                                                                        
                            
            
                                    
            
            
                | 398 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 399 |  |  |     public function onCleanupStart(Event\Cleanup\Start $event): void | 
            
                                                                        
                            
            
                                    
            
            
                | 400 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 401 |  |  |         $this->numCleanups ++; | 
            
                                                                        
                            
            
                                    
            
            
                | 402 | 1 |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 403 |  |  |             $cleanup = $event->getConfiguration(); | 
            
                                                                        
                            
            
                                    
            
            
                | 404 | 1 |  |             $this->writeWithAsterisk('cleanup: [' . $cleanup->type . '] '); | 
            
                                                                        
                            
            
                                    
            
            
                | 405 | 1 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 406 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 407 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 408 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 409 |  |  |      * Cleanup skipped event. | 
            
                                                                        
                            
            
                                    
            
            
                | 410 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 411 |  |  |      * @param \phpbu\App\Event\Cleanup\Skipped $event | 
            
                                                                        
                            
            
                                    
            
            
                | 412 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 413 |  |  |     public function onCleanupSkipped(Event\Cleanup\Skipped $event): void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 414 | 1 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 415 |  |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 416 | 1 |  |             $this->writeWithColor('fg-black, bg-yellow', 'skipped' . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 417 | 1 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 418 | 1 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 419 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 420 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 421 |  |  |      * Cleanup failed event. | 
            
                                                                        
                            
            
                                    
            
            
                | 422 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 423 |  |  |      * @param \phpbu\App\Event\Cleanup\Failed $event | 
            
                                                                        
                            
            
                                    
            
            
                | 424 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 425 | 5 |  |     public function onCleanupFailed(Event\Cleanup\Failed $event): void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 426 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 427 | 5 |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 428 | 5 |  |             $this->writeWithColor('fg-white, bg-red, bold', 'failed' . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 429 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 430 | 5 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 431 | 3 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 432 | 3 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 433 |  |  |      * Cleanup end event. | 
            
                                                                        
                            
            
                                    
            
            
                | 434 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 435 | 5 |  |      * @param \phpbu\App\Event\Cleanup\End $event | 
            
                                                                        
                            
            
                                    
            
            
                | 436 | 5 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 437 |  |  |     public function onCleanupEnd(Event\Cleanup\End $event): void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 438 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 439 |  |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 440 |  |  |             $this->writeWithColor('fg-black, bg-green', 'ok' . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 441 | 5 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 442 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 443 | 5 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 444 | 5 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 445 |  |  |      * Debugging. | 
            
                                                                        
                            
            
                                    
            
            
                | 446 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 447 |  |  |      * @param \phpbu\App\Event\Debug $event | 
            
                                                                        
                            
            
                                    
            
            
                | 448 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 449 |  |  |     public function onDebug(Event\Debug $event): void | 
            
                                                                        
                            
            
                                    
            
            
                | 450 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 451 | 5 |  |         if ($this->debug) { | 
            
                                                                        
                            
            
                                    
            
            
                | 452 |  |  |             $this->write($event->getMessage() . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 453 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 454 | 5 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 455 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 456 | 1 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 457 | 1 |  |      * Warnings. | 
            
                                                                        
                            
            
                                    
            
            
                | 458 | 1 |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 459 | 1 |  |      * @param \phpbu\App\Event\Warning $event | 
            
                                                                        
                            
            
                                    
            
            
                | 460 | 1 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 461 | 1 |  |     public function onWarning(Event\Warning $event): void | 
            
                                                                        
                            
            
                                    
            
            
                | 462 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 463 |  |  |         $this->writeWithColor('fg-black, bg-yellow', $event->getMessage() . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 464 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 465 | 5 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 466 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 467 |  |  |      * phpbu end event. | 
            
                                                                        
                            
            
                                    
            
            
                | 468 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 469 |  |  |      * @param \phpbu\App\Event\App\End $event | 
            
                                                                        
                            
            
                                    
            
            
                | 470 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 471 |  |  |     public function onPhpbuEnd(Event\App\End $event): void | 
            
                                                                        
                            
            
                                    
            
            
                | 472 | 3 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 473 |  |  |         $result = $event->getResult(); | 
            
                                                                        
                            
            
                                    
            
            
                | 474 | 3 |  |         $this->printResult($result); | 
            
                                                                        
                            
            
                                    
            
            
                | 475 | 3 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 476 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 477 | 1 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 478 | 1 |  |      * Prints a result summary. | 
            
                                                                        
                            
            
                                    
            
            
                | 479 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 480 | 2 |  |      * @param \phpbu\App\Result $result | 
            
                                                                        
                            
            
                                    
            
            
                | 481 | 1 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 482 | 1 |  |     public function printResult(Result $result): void | 
            
                                                                        
                            
            
                                    
            
            
                | 483 | 1 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 484 |  |  |         $this->printHeader(); | 
            
                                                                        
                            
            
                                    
            
            
                | 485 |  |  |         $this->printErrors($result); | 
            
                                                                        
                            
            
                                    
            
            
                | 486 | 1 |  |         $this->printFailedChecks($result); | 
            
                                                                        
                            
            
                                    
            
            
                | 487 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 488 | 1 |  |         if ($this->verbose) { | 
            
                                                                        
                            
            
                                    
            
            
                | 489 |  |  |             foreach ($result->getBackups() as $backup) { | 
            
                                                                        
                            
            
                                    
            
            
                | 490 |  |  |                 $this->printBackupVerbose($backup); | 
            
                                                                        
                            
            
                                    
            
            
                | 491 | 3 |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 492 | 3 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 493 | 3 |  |         $this->printFooter($result); | 
            
                                                                        
                            
            
                                    
            
            
                | 494 | 3 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 495 | 3 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 496 | 3 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 497 | 3 |  |      * Prints the result header with memory usage info. | 
            
                                                                        
                            
            
                                    
            
            
                | 498 | 3 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 499 | 3 |  |     protected function printHeader(): void | 
            
                                                                        
                            
            
                                    
            
            
                | 500 | 3 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 501 | 3 |  |         $this->write(Statistics::resourceUsage() . PHP_EOL . PHP_EOL); | 
            
                                                                        
                            
            
                                    
            
            
                | 502 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 503 | 3 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 504 | 3 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 505 | 3 |  |      * Print error information. | 
            
                                                                        
                            
            
                                    
            
            
                | 506 | 3 |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 507 | 3 |  |      * @param \phpbu\App\Result $result | 
            
                                                                        
                            
            
                                    
            
            
                | 508 | 3 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 509 | 3 |  |     protected function printErrors(Result $result): void | 
            
                                                                        
                            
            
                                    
            
            
                | 510 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 511 | 3 |  |         /* @var $e \Exception */ | 
            
                                                                        
                            
            
                                    
            
            
                | 512 | 3 |  |         foreach ($result->getErrors() as $e) { | 
            
                                                                        
                            
            
                                    
            
            
                | 513 |  |  |             $this->write( | 
            
                                                                        
                            
            
                                    
            
            
                | 514 |  |  |                 sprintf( | 
            
                                                                        
                            
            
                                    
            
            
                | 515 |  |  |                     "Exception '%s' with message '%s'\nin %s:%d\n\n", | 
            
                                                                        
                            
            
                                    
            
            
                | 516 |  |  |                     get_class($e), | 
            
                                                                        
                            
            
                                    
            
            
                | 517 |  |  |                     $e->getMessage(), | 
            
                                                                        
                            
            
                                    
            
            
                | 518 |  |  |                     $e->getFile(), | 
            
                                                                        
                            
            
                                    
            
            
                | 519 | 5 |  |                     $e->getLine() | 
            
                                                                        
                            
            
                                    
            
            
                | 520 |  |  |                 ) | 
            
                                                                        
                            
            
                                    
            
            
                | 521 | 5 |  |             ); | 
            
                                                                        
                            
            
                                    
            
            
                | 522 | 2 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 523 | 2 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 524 | 2 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 525 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 526 | 3 |  |      * Print information on failed checks. | 
            
                                                                        
                            
            
                                    
            
            
                | 527 | 1 |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 528 | 1 |  |      * @param \phpbu\App\Result $result | 
            
                                                                        
                            
            
                                    
            
            
                | 529 | 1 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 530 | 1 |  |     protected function printFailedChecks(Result $result): void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 531 | 1 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 532 | 1 |  |         foreach ($this->failedChecks as $failedCheck) { | 
            
                                                                        
                            
            
                                    
            
            
                | 533 | 1 |  |             /** @var \phpbu\App\Configuration\Backup\Check $configuration */ | 
            
                                                                        
                            
            
                                    
            
            
                | 534 | 1 |  |             $configuration = $failedCheck->getConfiguration(); | 
            
                                                                        
                            
            
                                    
            
            
                | 535 | 1 |  |             $this->write( | 
            
                                                                        
                            
            
                                    
            
            
                | 536 | 1 |  |                 sprintf( | 
            
                                                                        
                            
            
                                    
            
            
                | 537 | 1 |  |                     "Check %s (%s) FAILED \n\n", | 
            
                                                                        
                            
            
                                    
            
            
                | 538 | 1 |  |                     $configuration->type, | 
            
                                                                        
                            
            
                                    
            
            
                | 539 | 1 |  |                     $configuration->value | 
            
                                                                        
                            
            
                                    
            
            
                | 540 | 1 |  |                 ) | 
            
                                                                        
                            
            
                                    
            
            
                | 541 |  |  |             ); | 
            
                                                                        
                            
            
                                    
            
            
                | 542 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 543 | 2 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 544 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 545 | 1 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 546 | 1 |  |      * Prints verbose backup information. | 
            
                                                                        
                            
            
                                    
            
            
                | 547 | 1 |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 548 | 1 |  |      * @param \phpbu\App\Result\Backup $backup | 
            
                                                                        
                            
            
                                    
            
            
                | 549 | 1 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 550 | 1 |  |     protected function printBackupVerbose(Result\Backup $backup): void | 
            
                                                                        
                            
            
                                    
            
            
                | 551 | 1 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 552 | 1 |  |         $this->write(sprintf('backup %s: ', $backup->getName())); | 
            
                                                                        
                            
            
                                    
            
            
                | 553 | 1 |  |         if ($backup->allOk()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 554 | 1 |  |             $this->writeWithColor( | 
            
                                                                        
                            
            
                                    
            
            
                | 555 | 1 |  |                 'fg-green', | 
            
                                                                        
                            
            
                                    
            
            
                | 556 |  |  |                 'OK' | 
            
                                                                        
                            
            
                                    
            
            
                | 557 |  |  |             ); | 
            
                                                                        
                            
            
                                    
            
            
                | 558 |  |  |         } elseif ($backup->okButSkipsOrFails()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 559 | 1 |  |             $this->writeWithColor( | 
            
                                                                        
                            
            
                                    
            
            
                | 560 | 1 |  |                 'fg-yellow', | 
            
                                                                        
                            
            
                                    
            
            
                | 561 | 1 |  |                 'OK, but skipped or failed Crypts, Syncs or Cleanups!' | 
            
                                                                        
                            
            
                                    
            
            
                | 562 | 1 |  |             ); | 
            
                                                                        
                            
            
                                    
            
            
                | 563 | 1 |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 564 | 1 |  |             $this->writeWithColor( | 
            
                                                                        
                            
            
                                    
            
            
                | 565 | 1 |  |                 'fg-red', | 
            
                                                                        
                            
            
                                    
            
            
                | 566 | 1 |  |                 'FAILED' | 
            
                                                                        
                            
            
                                    
            
            
                | 567 | 1 |  |             ); | 
            
                                                                        
                            
            
                                    
            
            
                | 568 | 1 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 569 | 1 |  |         $chExecuted = str_pad($backup->checkCount(), 8, ' ', STR_PAD_LEFT); | 
            
                                                                        
                            
            
                                    
            
            
                | 570 | 1 |  |         $chFailed = str_pad($backup->checkCountFailed(), 6, ' ', STR_PAD_LEFT); | 
            
                                                                        
                            
            
                                    
            
            
                | 571 | 1 |  |         $crExecuted = str_pad($backup->cryptCount(), 8, ' ', STR_PAD_LEFT); | 
            
                                                                        
                            
            
                                    
            
            
                | 572 | 1 |  |         $crSkipped = str_pad($backup->cryptCountSkipped(), 7, ' ', STR_PAD_LEFT); | 
            
                                                                        
                            
            
                                    
            
            
                | 573 |  |  |         $crFailed = str_pad($backup->cryptCountFailed(), 6, ' ', STR_PAD_LEFT); | 
            
                                                                        
                            
            
                                    
            
            
                | 574 |  |  |         $syExecuted = str_pad($backup->syncCount(), 8, ' ', STR_PAD_LEFT); | 
            
                                                                        
                            
            
                                    
            
            
                | 575 |  |  |         $sySkipped = str_pad($backup->syncCountSkipped(), 7, ' ', STR_PAD_LEFT); | 
            
                                                                        
                            
            
                                    
            
            
                | 576 | 5 |  |         $syFailed = str_pad($backup->syncCountFailed(), 6, ' ', STR_PAD_LEFT); | 
            
                                                                        
                            
            
                                    
            
            
                | 577 |  |  |         $clExecuted = str_pad($backup->cleanupCount(), 8, ' ', STR_PAD_LEFT); | 
            
                                                                        
                            
            
                                    
            
            
                | 578 |  |  |         $clSkipped = str_pad($backup->cleanupCountSkipped(), 7, ' ', STR_PAD_LEFT); | 
            
                                                                        
                            
            
                                    
            
            
                | 579 |  |  |         $clFailed = str_pad($backup->cleanupCountFailed(), 6, ' ', STR_PAD_LEFT); | 
            
                                                                        
                            
            
                                    
            
            
                | 580 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 581 |  |  |         $out = PHP_EOL . '          | executed | skipped | failed |' . PHP_EOL | 
            
                                                                        
                            
            
                                    
            
            
                | 582 |  |  |             . '----------+----------+---------+--------+' . PHP_EOL | 
            
                                                                        
                            
            
                                    
            
            
                | 583 |  |  |             . ' checks   | ' . $chExecuted . ' |         | ' . $chFailed . ' |' . PHP_EOL | 
            
                                                                        
                            
            
                                    
            
            
                | 584 |  |  |             . ' crypts   | ' . $crExecuted . ' | ' . $crSkipped . ' | ' . $crFailed . ' |' . PHP_EOL | 
            
                                                                        
                            
            
                                    
            
            
                | 585 | 18 |  |             . ' syncs    | ' . $syExecuted . ' | ' . $sySkipped . ' | ' . $syFailed . ' |' . PHP_EOL | 
            
                                                                        
                            
            
                                    
            
            
                | 586 |  |  |             . ' cleanups | ' . $clExecuted . ' | ' . $clSkipped . ' | ' . $clFailed . ' |' . PHP_EOL | 
            
                                                                        
                            
            
                                    
            
            
                | 587 | 18 |  |             . '----------+----------+---------+--------+' . PHP_EOL . PHP_EOL; | 
            
                                                                        
                            
            
                                    
            
            
                | 588 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 589 |  |  |         $this->write($out); | 
            
                                                                        
                            
            
                                    
            
            
                | 590 | 18 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 591 | 18 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 592 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 593 |  |  |      * Prints 'OK' or 'FAILURE' footer. | 
            
                                                                        
                            
            
                                    
            
            
                | 594 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 595 |  |  |      * @param Result $result | 
            
                                                                        
                            
            
                                    
            
            
                | 596 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 597 |  |  |     protected function printFooter(Result $result): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 598 | 13 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 599 |  |  |         if (count($result->getBackups()) === 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 600 | 13 |  |             $this->writeWithColor( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 601 | 13 |  |                 'fg-yellow', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 602 |  |  |                 'No backups executed!' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 603 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 604 |  |  |         } elseif ($result->allOk()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 605 |  |  |             $this->writeWithColor( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 606 |  |  |                 'fg-green', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 607 |  |  |                 sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 608 | 20 |  |                     'OK (%d %s, %d %s, %d %s, %d %s, %d %s)' . PHP_EOL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 609 |  |  |                     count($result->getBackups()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 610 | 20 |  |                     Util\Str::appendPluralS('backup', count($result->getBackups())), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 611 |  |  |                     $this->numChecks, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 612 |  |  |                     Util\Str::appendPluralS('check', $this->numChecks), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 613 | 20 |  |                     $this->numCrypts, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 614 | 20 |  |                     Util\Str::appendPluralS('crypt', $this->numCrypts), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 615 |  |  |                     $this->numSyncs, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 616 |  |  |                     Util\Str::appendPluralS('sync', $this->numSyncs), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 617 |  |  |                     $this->numCleanups, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 618 |  |  |                     Util\Str::appendPluralS('cleanup', $this->numCleanups) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 619 |  |  |                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 620 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 621 |  |  |         } elseif ($result->backupOkButSkipsOrFails()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 622 |  |  |             $this->writeWithColor( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 623 |  |  |                 'fg-yellow', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 624 |  |  |                 sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 625 |  |  |                     "WARNING, skipped|failed Crypts, Syncs or Cleanups!" . PHP_EOL . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 626 |  |  |                     'Backups: %d, Crypts: %d|%d, Syncs: %d|%d, Cleanups: %d|%d ' . PHP_EOL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 627 |  |  |                     count($result->getBackups()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 628 |  |  |                     $result->cryptsSkippedCount(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 629 |  |  |                     $result->cryptsFailedCount(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 630 |  |  |                     $result->syncsSkippedCount(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 631 |  |  |                     $result->syncsFailedCount(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 632 |  |  |                     $result->cleanupsSkippedCount(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 633 |  |  |                     $result->cleanupsFailedCount() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 634 |  |  |                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 635 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 636 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 637 |  |  |             $this->writeWithColor( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 638 |  |  |                 'fg-red', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 639 |  |  |                 sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 640 |  |  |                     "FAILURE!" . PHP_EOL . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 641 |  |  |                     'Backups: %d, ' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 642 |  |  |                     . 'failed Checks: %d, ' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 643 |  |  |                     . 'failed Crypts: %d, ' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 644 |  |  |                     . 'failed Syncs: %d, ' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 645 |  |  |                     . 'failed Cleanups: %d.' . PHP_EOL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 646 |  |  |                     count($result->getBackups()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 647 |  |  |                     $result->checksFailedCount(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 648 |  |  |                     $result->cryptsFailedCount(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 649 |  |  |                     $result->syncsFailedCount(), | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 650 |  |  |                     $result->cleanupsFailedCount() | 
            
                                                                        
                                                                
            
                                    
            
            
                | 651 |  |  |                 ) | 
            
                                                                        
                                                                
            
                                    
            
            
                | 652 |  |  |             ); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 653 |  |  |         } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 654 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 655 |  |  | } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 656 |  |  |  | 
            
                        
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.