| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** @formatter:off | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * ****************************************************************** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Created by   Marko Kungla on Jun 25, 2016 - 8:48:28 AM | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Contact      [email protected] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @copyright   2016 Marko Kungla - https://github.com/mkungla | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license     The MIT License (MIT) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @category       AframeVR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @package        aframe-php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * Lang         PHP (php version >= 7) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * Encoding     UTF-8 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * File         ShaderAbstract.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * Code format  PSR-2 and 12 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @link        https://github.com/mkungla/aframe-php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @issues      https://github.com/mkungla/aframe-php/issues | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * ******************************************************************** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * Contributors: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @author Marko Kungla <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * ******************************************************************** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * Comments: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @formatter:on */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | namespace AframeVR\Core\Helpers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | abstract class ShaderAbstract | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * Get default class vars | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 7 |  |     protected function getShaderClassDefaultVars() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 7 |  |         return get_class_vars(get_class($this)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * removeDefaultDOMAttributes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 7 |  |     public function removeDefaultDOMAttributes() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 7 |  |         $defaults = $this->getShaderClassDefaultVars(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 7 |  |         $vars = get_object_vars($this); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 7 |  |         foreach ($vars as $name => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 7 |  |             $this->removeDOMAttributes($name, $value, $defaults); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 7 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 54 | 5 |  |     public function getAttributes() | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 56 | 5 |  |         $this->removeDefaultDOMAttributes(); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 | 5 |  |         return get_object_vars($this); | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 7 |  |     private function removeDOMAttributes($name, $value, $defaults) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 7 |  |         if ($name === 'shader') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 7 |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 7 |  |         if (empty($value) || $value === $defaults[$name]) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 7 |  |             unset($this->$name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 7 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 69 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |  | 
            
                        
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.