| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace TonicHealthCheck\Check; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * Class AbstractCheck. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  | abstract class AbstractCheck implements CheckInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |      * @var null|string | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     protected $checkNode = self::CHECK_NODE_DEFAULT; | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      * @var ResultInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     protected $lastCheckResult = null; | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |      * AbstractCheck constructor. | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |      * @param null $checkNode | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 7 |  |     public function __construct($checkNode = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 7 |  |         if (null !== $checkNode) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 7 |  |             $this->setCheckNode($checkNode); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 7 |  |         } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 32 | 7 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 2 |  |     public function getCheckComponent() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 2 |  |         return static::COMPONENT; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 40 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 1 |  |     public function getCheckGroup() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 1 |  |         return static::GROUP; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * @return null|string | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 2 |  |     public function getCheckNode() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 2 |  |         return $this->checkNode; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 2 |  |     public function getCheckIdent() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 2 |  |         return static::CHECK; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |      * @return null|string | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 1 |  |     public function getIndent() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 1 |  |         return $this->getCheckNode().'.'.$this->getCheckGroup().'.'.$this->getCheckComponent().'.'.$this->getCheckIdent(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |      * @return null|string | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 1 |  |     public function getLabel() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 1 |  |         return sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 1 |  |             '%s "%s" %s', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 1 |  |             $this->getCheckComponent(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 1 |  |             $this->getCheckNode(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 1 |  |             $this->getCheckIdent() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 1 |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |      * @return ResultInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 1 |  |     public function getLastCheckResult() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 1 |  |         return $this->lastCheckResult; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 93 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |      * @return ResultInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 4 |  |     public function check() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 4 |  |             $this->performCheck(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 1 |  |             $checkResult = new Success(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 4 |  |         } catch (CheckException $exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 | 2 |  |             $checkResult = new Failure($exception->getCode(), $exception); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 3 |  |         } catch (Exception $exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 1 |  |             $errorUnexpected  = CheckUnexpectedException::catchUnexpectedError(__CLASS__, __METHOD__, $exception); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 1 |  |             $checkResult = new Failure($errorUnexpected->getCode(), $errorUnexpected); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 4 |  |         $this->setLastCheckResult($checkResult); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 4 |  |         return $checkResult; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 113 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |      * @param string $checkNode | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 | 7 |  |     protected function setCheckNode($checkNode) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 7 |  |         $this->checkNode = $checkNode; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 121 | 7 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |      * @param ResultInterface $lastCheckResult | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 4 |  |     protected function setLastCheckResult(ResultInterface $lastCheckResult) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 | 4 |  |         $this->lastCheckResult = $lastCheckResult; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 129 | 4 |  |     } | 
            
                                                        
            
                                    
            
            
                | 130 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 131 |  |  |  |