| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace app\controllers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | class Examples extends \erdiko\controllers\Web | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |     use \erdiko\theme\traits\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 8 |  | View Code Duplication |     public function get($request, $response, $args) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |         $view = 'examples/list.html'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |         // Get erdiko config, this gets application.json and loads the theme specified | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |         $themeData = \erdiko\theme\Config::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         // $themeData['args'] = $args; // optional | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         $themeData['page'] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |             'title' => "Erdiko Web Example", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |             'hello' => "world" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         return $this->container->theme->render($response, $view, $themeData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 23 |  | View Code Duplication |     public function getJohn($request, $response, $args) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $view = 'pages/example.html'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         // Get erdiko config, this gets application.json and loads the theme specified | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $themeData = \erdiko\theme\Config::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $themeData['args'] = $args; // optional | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $themeData['page'] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             'title' => "Erdiko Web Example" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         return $this->container->theme->render($response, $view, $themeData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 37 |  | View Code Duplication |     public function getMarkup($request, $response, $args) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $view = 'examples/markup.html'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         // Get erdiko config, this gets application.json and loads the theme specified | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $themeData = \erdiko\theme\Config::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $themeData['args'] = $args; // optional | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $themeData['page'] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             'title' => "Markup Example" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         return $this->container->theme->render($response, $view, $themeData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 51 |  | View Code Duplication |     public function getCarousel($request, $response, $args) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $view = 'examples/carousel.html'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         // Get erdiko config, this gets application.json and loads the theme specified | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $themeData = \erdiko\theme\Config::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $themeData['page'] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             'title' => "Fullpage Example", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             'description' => "This is the description of the page." | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         return $this->container->theme->render($response, $view, $themeData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |     public function getTheme($request, $response, $args) | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         // $view = 'examples/theme.html'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |         $theme = new \erdiko\theme\Engine; | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |         $theme->title = "Theme Engine Example"; | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |         $theme->description = "This page is rendered using the theme engine.   | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |             \\erdiko\\theme\\Engine"; | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |         return $this->render($response, null, $theme); | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     public function getFlash($request, $response, $args) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $view = 'bootstrap.html'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         // Add some flash messages | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $this->container->flash->addMessage('success', 'This is a success message'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $this->container->flash->addMessage('info', 'This is an info message'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $this->container->flash->addMessage('warning', 'This is a warning message'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $this->container->flash->addMessage('danger', 'This is a danger (error) message');  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         // Get erdiko config, this gets application.json and loads the theme specified | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $themeData = \erdiko\theme\Config::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $themeData['args'] = $args; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $themeData['page'] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             'title' => "Flash Message Example" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         return $this->container->theme->render($response, $view, $themeData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     public function getGrid($request, $response, $args) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $this->container->logger->debug("/controller"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         $view = 'examples/grid.html'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         // Get erdiko config, this gets application.json and loads the theme specified | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $themeData = \erdiko\theme\Config::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         // $this->container->logger->debug("config: ".print_r($config, true)); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         // Generate data for grid | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $item = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             'url' => "#", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             'image' => "/images/grid-item.png", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |             'name' => "Item" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $items = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         $max = (int)$args['param']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $this->container->logger->debug("param: ".$max); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 115 |  | View Code Duplication |         for($i = 0; $i < $max; $i++) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             $item['name'] = "Item $i"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             $items[] = $item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         $themeData['page'] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             'title' => "Grid Example", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             'items' => $items | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         return $this->container->theme->render($response, $view, $themeData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 128 |  | View Code Duplication |     public function getFullpage($request, $response, $args) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         $view = 'fullpage.html'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         // Get erdiko config, this gets application.json and loads the theme specified | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         $themeData = \erdiko\theme\Config::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         $themeData['page'] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |             'title' => "Fullpage Example", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |             'description' => "This is the description of the page." | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         return $this->container->theme->render($response, $view, $themeData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     public function getException($request, $response, $args) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         $view = 'fullpage.html'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         throw new \Exception("This is an exception"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         // Get erdiko config, this gets application.json and loads the theme specified | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         $themeData = \erdiko\theme\Config::get(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         $themeData['page'] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |             'title' => "Fullpage Example", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |             'description' => "This is the description of the page." | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         return $this->container->theme->render($response, $view, $themeData); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 156 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 157 |  |  | } | 
            
                        
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.