| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace jumper423\decaptcha\services; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Class RuCaptchaGrid. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class RuCaptchaClick extends RuCaptchaInstruction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     public function init() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |         parent::init(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         unset( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |             $this->paramsNames[static::ACTION_FIELD_PHRASE], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |             $this->paramsNames[static::ACTION_FIELD_PINGBACK], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |             $this->paramsNames[static::ACTION_FIELD_REGSENSE], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |             $this->paramsNames[static::ACTION_FIELD_NUMERIC], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |             $this->paramsNames[static::ACTION_FIELD_CALC], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |             $this->paramsNames[static::ACTION_FIELD_MIN_LEN], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |             $this->paramsNames[static::ACTION_FIELD_MAX_LEN], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |             $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_PHRASE], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_PINGBACK], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_REGSENSE], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |             $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_NUMERIC], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_CALC], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_MIN_LEN], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_MAX_LEN] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $this->paramsNames[static::ACTION_FIELD_COORDINATE] = 'coordinatescaptcha'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_INSTRUCTIONS][static::PARAM_SLUG_REQUIRE] = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_COORDINATE] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             static::PARAM_SLUG_DEFAULT => 1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             static::PARAM_SLUG_TYPE    => static::PARAM_FIELD_TYPE_INTEGER, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             static::PARAM_SLUG_NOTWIKI    => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |     public function getCode() | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |         $code = parent::getCode(); | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |         $code = explode(':', $code)[1]; | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |         $code = explode(';', $code); | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |         $result = []; | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |         foreach ($code as $row) { | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |             $rowCoord = explode(',', $row); | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |             foreach ($rowCoord as &$rowCoordOne) { | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |                 $rowCoordOne = substr($rowCoordOne, 2); | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |             } | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |             $result[] = $rowCoord; | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |         return $result; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 60 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |  | 
            
                        
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.