| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace FMUP\Cache\Driver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use FMUP\Cache\CacheInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use FMUP\Cache\Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | class Shm implements CacheInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     const SETTING_NAME = 'SETTING_NAME'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     const SETTING_SIZE = 'SETTING_SIZE'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     private $shmInstance = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     private $isAvailable = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     protected $settings = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * constructor of File | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * @param array $settings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     public function __construct($settings = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->setSettings($settings); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * Can define settings of the component | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @param array $settings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public function setSettings($settings = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->settings = $settings; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @param string $setting | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @param mixed $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     public function setSetting($setting, $value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $this->settings[$setting] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * Get a specific value of setting | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @param string $setting | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     public function getSetting($setting) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         return isset($this->settings[$setting]) ? $this->settings[$setting] : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * Internal method to secure a SHM name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @param string $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     private function secureName($name = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         return is_null($name) ? 1 : $this->stringToUniqueId($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * Convert string to a unique id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @param string $string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     private function stringToUniqueId($string) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         if (is_numeric($string)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             return (int)$string; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $length = strlen($string); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $return = 0; | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 83 |  | View Code Duplication |         for ($i = 0; $i < $length; $i++) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             $return += ord($string{$i}); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         return (int)$length . '1' . $return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * Get SHM resource | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * @return resource | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @throws Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     private function getShm() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         if (!$this->isAvailable()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             throw new Exception('SHM is not available'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         if (!$this->shmInstance) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             $memorySize = $this->getSetting(self::SETTING_SIZE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             $shmName = $this->secureName($this->getSetting(self::SETTING_NAME)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             $this->shmInstance = is_numeric($memorySize) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                 ? $this->shmAttach($shmName, (int)$memorySize) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                 : $this->shmAttach($shmName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         return $this->shmInstance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @return resource | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @codeCoverageIgnore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     protected function shmAttach() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         return call_user_func_array('shm_attach', func_get_args()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      * @codeCoverageIgnore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     protected function shmGetVar() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         return call_user_func_array('shm_get_var', func_get_args()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      * Retrieve stored value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * @param string $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      * @return mixed|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      * @throws Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 133 |  | View Code Duplication |     public function get($key) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         if (!$this->isAvailable()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |             throw new Exception('SHM is not available'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         $key = $this->secureName($key); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         return ($this->has($key)) ? $this->shmGetVar($this->getShm(), $key) : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |      * @codeCoverageIgnore | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 145 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |     protected function shmHasVar() | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |         return call_user_func_array('shm_has_var', func_get_args()); | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      * Check whether key exists in SHM | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      * @param string $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |      * @throws Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 157 |  | View Code Duplication |     public function has($key) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         if (!$this->isAvailable()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             throw new Exception('SHM is not available'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         $key = $this->secureName($key); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         return $this->shmHasVar($this->getShm(), $key); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      * Remove a stored key if exists | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      * @param string $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |      * @throws Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 172 |  | View Code Duplication |     public function remove($key) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |         if (!$this->isAvailable()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |             throw new Exception('SHM is not available'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         $key = $this->secureName($key); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         if ($this->has($key) && !$this->shmRemoveVar($this->getShm(), $key)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |             throw new Exception('Unable to delete key from cache Shm'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |      * @param resource $shmResource | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |      * @param string $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |      * @codeCoverageIgnore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |     protected function shmRemoveVar($shmResource, $key) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |         return shm_remove_var($shmResource, $key); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |      * Define a key in SHM | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |      * @param string $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |      * @param mixed $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |      * @throws Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 202 |  | View Code Duplication |     public function set($key, $value) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |         if (!$this->isAvailable()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |             throw new Exception('SHM is not available'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |         $key = $this->secureName($key); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         if (!$this->shmPutVar($this->getShm(), $key, $value)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |             throw new Exception('Unable to define key into cache Shm'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |      * @param resource $shmResource | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |      * @param string $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |      * @param mixed $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |      * @codeCoverageIgnore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |     protected function shmPutVar($shmResource, $key, $value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         return shm_put_var($shmResource, $key, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |      * Check whether apc is available | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |     public function isAvailable() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |         if (is_null($this->isAvailable)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |             $this->isAvailable = function_exists('shm_attach'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |         return $this->isAvailable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 237 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 238 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.