| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @copyright 2017 Vladimir Jimenez | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | namespace allejo\stakx\Manager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use allejo\stakx\Object\JailObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use allejo\stakx\Object\PageView; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class MenuManager extends BaseManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** @var PageView */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     private $siteMenu; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 | 8 |  |     public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 | 8 |  |         parent::__construct(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 8 |  |         $this->siteMenu = array(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 8 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * An array representing the website's menu structure with children and grandchildren made from static PageViews | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @return JailObject[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 8 |  |     public function getSiteMenu () | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 8 |  |         $jailedMenu = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 8 |  |         foreach ($this->siteMenu as $key => $value) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             // If it's an array, it means the parent is hidden from the site menu therefore its children should be too | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 7 |  |             if (is_array($this->siteMenu[$key])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 7 |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 1 |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 7 |  |             $jailedMenu[$key] = $value->createJail(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 8 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 8 |  |         return $jailedMenu; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @param PageView[] $pageViews | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 51 | 8 |  |     public function buildFromPageViews ($pageViews) | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 53 | 8 |  |         foreach ($pageViews as &$pageView) | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |         { | 
            
                                                                        
                            
            
                                    
            
            
                | 55 | 8 |  |             $this->addToSiteMenu($pageView); | 
            
                                                                        
                            
            
                                    
            
            
                | 56 | 8 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 57 | 8 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @param PageView $pageView | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 8 |  |     public function addToSiteMenu (&$pageView) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 8 |  |         $frontMatter = $pageView->getFrontMatter(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 8 |  |         if (isset($frontMatter['menu']) && !$frontMatter['menu']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 8 |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 1 |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 8 |  |         $url = trim($pageView->getPermalink(), '/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         // @TODO in the next breaking release, remove this check and allow the homepage to be indexed as '.' | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 8 |  |         if (empty($url)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 8 |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 1 |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 7 |  |         $root = &$this->siteMenu; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 7 |  |         $dirs = explode('/', $url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 7 |  |         while (count($dirs) > 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 7 |  |             $name = array_shift($dirs); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 7 |  |             $name = (!empty($name)) ? $name : '.'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 7 |  |             if (!is_null($name) && count($dirs) == 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 7 |  |             { | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 89 | 7 | View Code Duplication |                 if (isset($root[$name]) && is_array($root[$name])) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 7 |  |                 { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 1 |  |                     $children = &$pageView->getChildren(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 1 |  |                     $children = $root[$name]['children']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 1 |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 7 |  |                 $root[$name] = &$pageView; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 7 |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 4 |  |                 if (!isset($root[$name])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 4 |  |                 { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 2 |  |                     $root[$name]['children'] = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 2 |  |                     $root = &$root[$name]['children']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 2 |  |                 } | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 104 | 4 | View Code Duplication |                 else if (isset($root[$name]) && is_array($root[$name])) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 4 |  |                 { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 2 |  |                     $root = &$root[$name]['children']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 2 |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                 else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                 { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 2 |  |                     $root = &$root[$name]->getChildren(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 7 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 7 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 115 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |  | 
            
                        
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..