| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace BootPress\Theme; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use BootPress\Page\Component as Page; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use BootPress\Bootstrap\Component as Bootstrap; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Symfony\Component\Yaml\Yaml; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Smarty; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class Component | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     public $bp; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     private $page; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     private $vars; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     private $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     private $folder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * Theme folder getter. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @param string $name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @return null|string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 1 |  |     public function __get($name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         switch ($name) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 1 |  |             case 'folder': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 1 |  |                 return $this->$name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 break; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 3 |  |     public function __construct($folder = 'themes') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 3 |  |         $this->folder = Page::html()->dir($folder); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 3 |  |         if (!is_dir($this->folder)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 1 |  |             mkdir($this->folder, 0755, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 1 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 3 |  |         $file = $this->folder.'config.yml'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 3 |  |         $this->config = (is_file($file)) ? (array) Yaml::parse(file_get_contents($file)) : array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 3 |  |         if (!isset($this->config['default']) || !isset($this->config['bootstrap'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 3 |  |             $this->config = array_merge(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 3 |  |                 'default' => '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 3 |  |                 'bootstrap' => '3.3.6', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 3 |  |             ), $this->config); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 3 |  |             file_put_contents($file, Yaml::dump($this->config, 3)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 3 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 3 |  |         $this->vars = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 3 |  |         $this->page = new PageClone(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 3 |  |         $this->bp = Bootstrap::version($this->config['bootstrap']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 3 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 1 |  |     public function layout($html) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 1 |  |         $page = Page::html(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 1 |  |         $theme = $page->theme; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 1 |  |         if ($theme === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 1 |  |             return $html; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 1 |  |         } elseif (is_callable($theme)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 1 |  |             return $theme($html, $this->config); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 1 |  |         } elseif (is_file($theme)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 1 |  |             return $page->load($theme, array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 1 |  |                 'content' => $html, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 1 |  |                 'config' => $this->config, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 1 |  |             )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 1 |  |         } elseif (!$index = $this->getTemplate('index.tpl')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 1 |  |             return $html; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $vars = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 1 |  |             'content' => $html, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 1 |  |             'config' => $this->config | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 1 |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 1 |  |         if ($index['dir'] != $this->folder) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 1 |  |             $theme = substr($index['dir'], mb_strlen($this->folder)); // with trailing slash | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 1 |  |             $parent = strstr($theme, '/', true); // good thing we had that trailing slash | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 1 |  |             $path = substr($index['dir'], mb_strlen($page->dir())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 1 |  |             $page->url('set', 'theme', $page->url['base'].'page/'.$path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 1 |  |             $config = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 1 |  |             $previous = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 1 |  |             foreach (explode('/', substr($theme, 0, -1)) as $folder) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 1 |  |                 $previous .= $folder . '/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 1 |  |                 $file = $this->folder . $previous . 'config.yml'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 1 |  |                 if (is_file($file)) { // any child values will override the parents | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 1 |  |                     $config = array_merge($config, (array) Yaml::parse(file_get_contents($file))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 1 |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 1 |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 1 |  |             $vars['config'] += $config; // The original config values override them all | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 1 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 1 |  |         return $this->fetchSmarty($index['file'], $vars); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 25 |  |     public function globalVars($name, $value = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 25 |  |         $vars = (is_array($name)) ? $name : array($name => $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 25 |  |         foreach ($vars as $name => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 25 |  |             if (is_array($value) && isset($this->vars[$name]) && is_array($this->vars[$name])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 24 |  |                 $this->vars[$name] = array_merge($this->vars[$name], $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 24 |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 2 |  |                 $this->vars[$name] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 25 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 | 25 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 25 |  |     public function addPageMethod($name, $function) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 25 |  |         if (!is_callable($function, false, $method)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 1 |  |             throw new \LogicException("'{$method}' cannot be called"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 25 |  |         $this->page->additional[$name] = $function; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 25 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 114 | 25 |  |     public function fetchSmarty($file, array $vars = array(), $testing = false) | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 116 | 25 |  |         static $smarty = null; | 
            
                                                                        
                            
            
                                    
            
            
                | 117 | 25 |  |         if (is_null($smarty)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 118 | 1 |  |             $functions = array('var_dump', 'preg_replace', 'number_format', 'implode', 'explode', 'array_keys', 'array_values', 'array_flip', 'array_reverse', 'array_shift', 'array_unshift', 'array_pop', 'array_push', 'array_combine', 'array_merge'); | 
            
                                                                        
                            
            
                                    
            
            
                | 119 | 1 |  |             $smarty = new Smarty(); | 
            
                                                                        
                            
            
                                    
            
            
                | 120 | 1 |  |             $smarty->addPluginsDir($this->folder.'smarty/plugins/'); | 
            
                                                                        
                            
            
                                    
            
            
                | 121 | 1 |  |             $smarty->setCompileDir($this->folder.'smarty/templates_c/'); | 
            
                                                                        
                            
            
                                    
            
            
                | 122 | 1 |  |             $smarty->setConfigDir($this->folder.'smarty/configs/'); | 
            
                                                                        
                            
            
                                    
            
            
                | 123 | 1 |  |             $smarty->setCacheDir($this->folder.'smarty/cache/'); | 
            
                                                                        
                            
            
                                    
            
            
                | 124 | 1 |  |             $smarty->error_reporting = false; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 125 | 1 |  |             $security = new \Smarty_Security($smarty); | 
            
                                                                        
                            
            
                                    
            
            
                | 126 | 1 |  |             $security->php_functions = array_merge(array('isset', 'empty', 'count', 'in_array', 'is_array', 'date', 'time', 'nl2br'), $functions); // Smarty defaults (except date) | 
            
                                                                        
                            
            
                                    
            
            
                | 127 | 1 |  |             $security->allow_super_globals = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 128 | 1 |  |             $security->allow_constants = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 129 | 1 |  |             $smarty->enableSecurity($security); | 
            
                                                                        
                            
            
                                    
            
            
                | 130 | 1 |  |             $smarty->assign('bp', new BPClone($this->bp)); | 
            
                                                                        
                            
            
                                    
            
            
                | 131 | 1 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 132 | 25 |  |         $default = null; | 
            
                                                                        
                            
            
                                    
            
            
                | 133 | 25 |  |         if (is_array($file)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 134 | 21 |  |             if (isset($file['default']) && is_dir($file['default'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 135 | 21 |  |                 $default = rtrim($file['default'], '/').'/'; | 
            
                                                                        
                            
            
                                    
            
            
                | 136 | 21 |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 137 | 21 |  |             if (isset($file['vars']) && is_array($file['vars'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 138 | 21 |  |                 $vars = $file['vars']; | 
            
                                                                        
                            
            
                                    
            
            
                | 139 | 21 |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 140 | 21 |  |             $file = (isset($file['file']) && is_string($file['file'])) ? $file['file'] : ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 141 | 21 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 142 | 25 |  |         $page = Page::html(); | 
            
                                                                        
                            
            
                                    
            
            
                | 143 | 25 |  |         if (is_file($file) && strpos($file, $page->dir['page']) === 0) { | 
            
                                                                        
                            
            
                                    
            
            
                | 144 | 11 |  |             if (strpos($file, $this->folder) === 0) { | 
            
                                                                        
                            
            
                                    
            
            
                | 145 | 1 |  |                 $dir = $this->folder; | 
            
                                                                        
                            
            
                                    
            
            
                | 146 | 1 |  |                 $file = substr($file, strlen($this->folder)); | 
            
                                                                        
                            
            
                                    
            
            
                | 147 | 1 |  |             } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 148 | 10 |  |                 $dir = dirname($file).'/'; | 
            
                                                                        
                            
            
                                    
            
            
                | 149 | 10 |  |                 $file = basename($file); | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 151 | 11 |  |             $page->url('set', 'folder', 'page/'.substr($dir, strlen($page->dir['page']), -1)); | 
            
                                                                        
                            
            
                                    
            
            
                | 152 | 25 |  |         } elseif ($template = $this->getTemplate($file, $default)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 153 | 21 |  |             $dir = $this->folder; | 
            
                                                                        
                            
            
                                    
            
            
                | 154 | 21 |  |             $file = substr($template['file'], strlen($this->folder)); | 
            
                                                                        
                            
            
                                    
            
            
                | 155 | 21 |  |             $page->url('set', 'folder', 'page/'.$template['folder']); | 
            
                                                                        
                            
            
                                    
            
            
                | 156 | 21 |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 157 | 1 |  |             return '<p>The "'.$file.'" file does not exist.</p>'; | 
            
                                                                        
                            
            
                                    
            
            
                | 158 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 159 | 25 |  |         $vars = array_merge($vars, $this->vars); | 
            
                                                                        
                            
            
                                    
            
            
                | 160 | 25 |  |         unset($vars['bp']); | 
            
                                                                        
                            
            
                                    
            
            
                | 161 | 25 |  |         $vars['page'] = $this->page; | 
            
                                                                        
                            
            
                                    
            
            
                | 162 | 25 |  |         $smarty->assign($vars); | 
            
                                                                        
                            
            
                                    
            
            
                | 163 | 25 |  |         $smarty->setTemplateDir($dir); | 
            
                                                                        
                            
            
                                    
            
            
                | 164 |  |  |         try { | 
            
                                                                        
                            
            
                                    
            
            
                | 165 | 25 |  |             $html = $smarty->fetch($file); | 
            
                                                                        
                            
            
                                    
            
            
                | 166 | 24 |  |             if (!empty($vars)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 167 | 24 |  |                 $smarty->clearAssign(array_keys($vars)); | 
            
                                                                        
                            
            
                                    
            
            
                | 168 | 24 |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 169 | 25 |  |         } catch (\Exception $e) { | 
            
                                                                        
                            
            
                                    
            
            
                | 170 | 2 |  |             $dir = str_replace('/', DIRECTORY_SEPARATOR, $this->folder); | 
            
                                                                        
                            
            
                                    
            
            
                | 171 | 2 |  |             $page = str_replace('/', DIRECTORY_SEPARATOR, $page->dir['page']); | 
            
                                                                        
                            
            
                                    
            
            
                | 172 | 2 |  |             $error = str_replace(array($dir, $page, '\\'), array('', '', '/'), $e->getMessage()); | 
            
                                                                        
                            
            
                                    
            
            
                | 173 | 2 |  |             if ($testing) { | 
            
                                                                        
                            
            
                                    
            
            
                | 174 | 1 |  |                 return htmlspecialchars_decode($error); | 
            
                                                                        
                            
            
                                    
            
            
                | 175 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 176 | 2 |  |             $html = '<p>'.$error.'</p>'; | 
            
                                                                        
                            
            
                                    
            
            
                | 177 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 179 | 25 |  |         return ($testing) ? true : $html; | 
            
                                                                        
                            
            
                                    
            
            
                | 180 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |      * Gets a template $file following a given pecking order.  If a ``$page->theme`` has been set and the folder exists, it looks there first.  If not and a default theme folder (that exists) has been established in the config file, then we will look for one there.  Otherwise we look in the root theme folder where the config file is. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |      * @param string $file    The file name you are looking for eg. 'index.tpl' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |      * @param string $default A file path to a default template if no other is available.  This will be saved (only once) in the root theme folder alongside the config file. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |      * @return array Same as is returned from the ``$page->folder()`` method. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 | 22 |  |     public function getTemplate($file, $default = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 | 22 |  |         if (empty($file)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 | 1 |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 | 22 |  |         $page = Page::html(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 | 22 |  |         if (!is_null($default) && !is_file($this->folder.$file) && is_file($default.$file)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 | 7 |  |             copy($default.$file, $this->folder.$file); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 | 7 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 | 22 |  |         if (!empty($page->theme) && is_string($page->theme) && is_dir($this->folder.$page->theme)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 | 2 |  |             $dir = $this->folder.$page->theme; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 | 22 |  |         } elseif (!empty($this->config['default']) && is_dir($this->folder.$this->config['default'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 | 1 |  |             $dir = $this->folder.$this->config['default']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 | 1 |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 | 21 |  |             $dir = $this->folder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 | 22 |  |         $path = substr($dir, strlen($this->folder)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 | 22 |  |         return $page->folder($this->folder, $path, $file); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 210 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 211 |  |  |  | 
            
                        
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.