Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like AdministrationPage often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AdministrationPage, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class AdministrationPage extends HTMLPage |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * An array of `Alert` objects used to display page level |
||
| 19 | * messages to Symphony backend users one by one. Prior to Symphony 2.3 |
||
| 20 | * this variable only held a single `Alert` object. |
||
| 21 | * @var array |
||
| 22 | */ |
||
| 23 | public $Alert = array(); |
||
| 24 | |||
| 25 | /** |
||
| 26 | * As the name suggests, a `<div>` that holds the following `$Header`, |
||
| 27 | * `$Contents` and `$Footer`. |
||
| 28 | * @var XMLElement |
||
| 29 | */ |
||
| 30 | public $Wrapper = null; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * A `<div>` that contains the header of a Symphony backend page, which |
||
| 34 | * typically contains the Site title and the navigation. |
||
| 35 | * @var XMLElement |
||
| 36 | */ |
||
| 37 | public $Header = null; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * A `<div>` that contains the breadcrumbs, the page title and some contextual |
||
| 41 | * actions (e.g. "Create new"). |
||
| 42 | * @since Symphony 2.3 |
||
| 43 | * @var XMLElement |
||
| 44 | */ |
||
| 45 | public $Context = null; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * An object that stores the markup for the breadcrumbs and is only used |
||
| 49 | * internally. |
||
| 50 | * @since Symphony 2.3 |
||
| 51 | * @var XMLElement |
||
| 52 | */ |
||
| 53 | public $Breadcrumbs = null; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * An array of Drawer widgets for the current page |
||
| 57 | * @since Symphony 2.3 |
||
| 58 | * @var array |
||
| 59 | */ |
||
| 60 | public $Drawer = array(); |
||
| 61 | |||
| 62 | /** |
||
| 63 | * A `<div>` that contains the content of a Symphony backend page. |
||
| 64 | * @var XMLElement |
||
| 65 | */ |
||
| 66 | public $Contents = null; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * An associative array of the navigation where the key is the group |
||
| 70 | * index, and the value is an associative array of 'name', 'index' and |
||
| 71 | * 'children'. Name is the name of the this group, index is the same as |
||
| 72 | * the key and children is an associative array of navigation items containing |
||
| 73 | * the keys 'link', 'name' and 'visible'. In Symphony, all navigation items |
||
| 74 | * are contained within a group, and the group has no 'default' link, therefore |
||
| 75 | * it is up to the children to provide the link to pages. This link should be |
||
| 76 | * relative to the Symphony path, although it is possible to provide an |
||
| 77 | * absolute link by providing a key, 'relative' with the value false. |
||
| 78 | * @var array |
||
| 79 | */ |
||
| 80 | public $_navigation = array(); |
||
| 81 | |||
| 82 | /** |
||
| 83 | * An associative array describing this pages context. This |
||
| 84 | * can include the section handle, the current entry_id, the page |
||
| 85 | * name and any flags such as 'saved' or 'created'. This variable |
||
| 86 | * often provided in delegates so extensions can manipulate based |
||
| 87 | * off the current context or add new keys. |
||
| 88 | * @var array |
||
| 89 | */ |
||
| 90 | public $_context = null; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * The class attribute of the `<body>` element for this page. Defaults |
||
| 94 | * to an empty string |
||
| 95 | * @var string |
||
| 96 | */ |
||
| 97 | private $_body_class = ''; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Constructor calls the parent constructor to set up |
||
| 101 | * the basic HTML, Head and Body `XMLElement`'s. This function |
||
| 102 | * also sets the `XMLElement` element style to be HTML, instead of XML |
||
| 103 | */ |
||
| 104 | public function __construct() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Specifies the type of page that being created. This is used to |
||
| 113 | * trigger various styling hooks. If your page is mainly a form, |
||
| 114 | * pass 'form' as the parameter, if it's displaying a single entry, |
||
| 115 | * pass 'single'. If any other parameter is passed, the 'index' |
||
| 116 | * styling will be applied. |
||
| 117 | * |
||
| 118 | * @param string $type |
||
| 119 | * Accepts 'form' or 'single', any other `$type` will trigger 'index' |
||
| 120 | * styling. |
||
| 121 | */ |
||
| 122 | public function setPageType($type = 'form') |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Setter function to set the class attribute on the `<body>` element. |
||
| 129 | * This function will respect any previous classes that have been added |
||
| 130 | * to this `<body>` |
||
| 131 | * |
||
| 132 | * @param string $class |
||
| 133 | * The string of the classname, multiple classes can be specified by |
||
| 134 | * uses a space separator |
||
| 135 | */ |
||
| 136 | public function setBodyClass($class) |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Accessor for `$this->_context` which includes contextual information |
||
| 146 | * about the current page such as the class, file location or page root. |
||
| 147 | * This information varies depending on if the page is provided by an |
||
| 148 | * extension, is for the publish area, is the login page or any other page |
||
| 149 | * |
||
| 150 | * @since Symphony 2.3 |
||
| 151 | * @return array |
||
| 152 | */ |
||
| 153 | public function getContext() |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Given a `$message` and an optional `$type`, this function will |
||
| 160 | * add an Alert instance into this page's `$this->Alert` property. |
||
| 161 | * Since Symphony 2.3, there may be more than one `Alert` per page. |
||
| 162 | * Unless the Alert is an Error, it is required the `$message` be |
||
| 163 | * passed to this function. |
||
| 164 | * |
||
| 165 | * @param string $message |
||
| 166 | * The message to display to users |
||
| 167 | * @param string $type |
||
| 168 | * An Alert constant, being `Alert::NOTICE`, `Alert::ERROR` or |
||
| 169 | * `Alert::SUCCESS`. The differing types will show the error |
||
| 170 | * in a different style in the backend. If omitted, this defaults |
||
| 171 | * to `Alert::NOTICE`. |
||
| 172 | * @throws Exception |
||
| 173 | */ |
||
| 174 | public function pageAlert($message = null, $type = Alert::NOTICE) |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Appends the heading of this Symphony page to the Context element. |
||
| 191 | * Action buttons can be provided (e.g. "Create new") as second parameter. |
||
| 192 | * |
||
| 193 | * @since Symphony 2.3 |
||
| 194 | * @param string $value |
||
| 195 | * The heading text |
||
| 196 | * @param array|XMLElement|string $actions |
||
| 197 | * Some contextual actions to append to the heading, they can be provided as |
||
| 198 | * an array of XMLElements or strings. Traditionally Symphony uses this to append |
||
| 199 | * a "Create new" link to the Context div. |
||
| 200 | */ |
||
| 201 | public function appendSubheading($value, $actions = null) |
||
| 215 | |||
| 216 | /** |
||
| 217 | * This function allows a user to insert an Action button to the page. |
||
| 218 | * It accepts an `XMLElement` (which should be of the `Anchor` type), |
||
| 219 | * an optional parameter `$prepend`, which when `true` will add this |
||
| 220 | * action before any existing actions. |
||
| 221 | * |
||
| 222 | * @since Symphony 2.3 |
||
| 223 | * @see core.Widget#Anchor |
||
| 224 | * @param XMLElement $action |
||
| 225 | * An Anchor element to add to the top of the page. |
||
| 226 | * @param boolean $append |
||
| 227 | * If true, this will add the `$action` after existing actions, otherwise |
||
| 228 | * it will be added before existing actions. By default this is `true`, |
||
| 229 | * which will add the `$action` after current actions. |
||
| 230 | */ |
||
| 231 | public function insertAction(XMLElement $action, $append = true) |
||
| 232 | { |
||
| 233 | $actions = $this->Context->getChildrenByName('ul'); |
||
| 234 | |||
| 235 | // Actions haven't be added yet, create the element |
||
| 236 | if (empty($actions)) { |
||
| 237 | $ul = new XMLElement('ul', null, array('class' => 'actions')); |
||
| 238 | $this->Context->appendChild($ul); |
||
| 239 | } else { |
||
| 240 | $ul = current($actions); |
||
| 241 | $this->Context->replaceChildAt(1, $ul); |
||
| 242 | } |
||
| 243 | |||
| 244 | $li = new XMLElement('li', $action); |
||
| 245 | |||
| 246 | if ($append) { |
||
| 247 | $ul->prependChild($li); |
||
| 248 | } else { |
||
| 249 | $ul->appendChild($li); |
||
| 250 | } |
||
| 251 | } |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Allows developers to specify a list of nav items that build the |
||
| 255 | * path to the current page or, in jargon, "breadcrumbs". |
||
| 256 | * |
||
| 257 | * @since Symphony 2.3 |
||
| 258 | * @param array $values |
||
| 259 | * An array of `XMLElement`'s or strings that compose the path. If breadcrumbs |
||
| 260 | * already exist, any new item will be appended to the rightmost part of the |
||
| 261 | * path. |
||
| 262 | */ |
||
| 263 | public function insertBreadcrumbs(array $values) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Allows a Drawer element to added to the backend page in one of three |
||
| 290 | * positions, `horizontal`, `vertical-left` or `vertical-right`. The button |
||
| 291 | * to trigger the visibility of the drawer will be added after existing |
||
| 292 | * actions by default. |
||
| 293 | * |
||
| 294 | * @since Symphony 2.3 |
||
| 295 | * @see core.Widget#Drawer |
||
| 296 | * @param XMLElement $drawer |
||
| 297 | * An XMLElement representing the drawer, use `Widget::Drawer` to construct |
||
| 298 | * @param string $position |
||
| 299 | * Where `$position` can be `horizontal`, `vertical-left` or |
||
| 300 | * `vertical-right`. Defaults to `horizontal`. |
||
| 301 | * @param string $button |
||
| 302 | * If not passed, a button to open/close the drawer will not be added |
||
| 303 | * to the interface. Accepts 'prepend' or 'append' values, which will |
||
| 304 | * add the button before or after existing buttons. Defaults to `prepend`. |
||
| 305 | * If any other value is passed, no button will be added. |
||
| 306 | * @throws InvalidArgumentException |
||
| 307 | */ |
||
| 308 | public function insertDrawer(XMLElement $drawer, $position = 'horizontal', $button = 'append') |
||
| 327 | |||
| 328 | /** |
||
| 329 | * This function initialises a lot of the basic elements that make up a Symphony |
||
| 330 | * backend page such as the default stylesheets and scripts, the navigation and |
||
| 331 | * the footer. Any alerts are also appended by this function. `view()` is called to |
||
| 332 | * build the actual content of the page. The `InitialiseAdminPageHead` delegate |
||
| 333 | * allows extensions to add elements to the `<head>`. The `CanAccessPage` delegate |
||
| 334 | * allows extensions to restrict access to pages. |
||
| 335 | * |
||
| 336 | * @see view() |
||
| 337 | * @uses InitialiseAdminPageHead |
||
| 338 | * @uses CanAccessPage |
||
| 339 | * @param array $context |
||
| 340 | * An associative array describing this pages context. This |
||
| 341 | * can include the section handle, the current entry_id, the page |
||
| 342 | * name and any flags such as 'saved' or 'created'. This list is not exhaustive |
||
| 343 | * and extensions can add their own keys to the array. |
||
| 344 | * @throws InvalidArgumentException |
||
| 345 | * @throws SymphonyErrorPage |
||
| 346 | */ |
||
| 347 | public function build(array $context = array()) |
||
| 494 | |||
| 495 | /** |
||
| 496 | * Checks the current Symphony Author can access the current page. |
||
| 497 | * This check uses the `ASSETS . /xml/navigation.xml` file to determine |
||
| 498 | * if the current page (or the current page namespace) can be viewed |
||
| 499 | * by the currently logged in Author. |
||
| 500 | * |
||
| 501 | * @since Symphony 2.7.0 |
||
| 502 | * It fires a delegate, CanAccessPage, to allow extensions to restrict access |
||
| 503 | * to the current page |
||
| 504 | * |
||
| 505 | * @uses CanAccessPage |
||
| 506 | * |
||
| 507 | * @link http://github.com/symphonycms/symphony-2/blob/master/symphony/assets/xml/navigation.xml |
||
| 508 | * @return boolean |
||
| 509 | * true if the Author can access the current page, false otherwise |
||
| 510 | */ |
||
| 511 | public function canAccessPage() |
||
| 587 | |||
| 588 | /** |
||
| 589 | * Given the limit of the current navigation item or page, this function |
||
| 590 | * returns if the current Author can access that item or not. |
||
| 591 | * |
||
| 592 | * @since Symphony 2.5.1 |
||
| 593 | * @param string $item_limit |
||
| 594 | * @return boolean |
||
| 595 | */ |
||
| 596 | public function doesAuthorHaveAccess($item_limit = null) |
||
| 612 | |||
| 613 | /** |
||
| 614 | * Appends the `$this->Header`, `$this->Context` and `$this->Contents` |
||
| 615 | * to `$this->Wrapper` before adding the ID and class attributes for |
||
| 616 | * the `<body>` element. This function will also place any Drawer elements |
||
| 617 | * in their relevant positions in the page. After this has completed the |
||
| 618 | * parent `generate()` is called which will convert the `XMLElement`'s |
||
| 619 | * into strings ready for output. |
||
| 620 | * |
||
| 621 | * @see core.HTMLPage#generate() |
||
| 622 | * @param null $page |
||
| 623 | * @return string |
||
| 624 | */ |
||
| 625 | public function generate($page = null) |
||
| 664 | |||
| 665 | /** |
||
| 666 | * Uses this pages PHP classname as the `<body>` ID attribute. |
||
| 667 | * This function removes 'content' from the start of the classname |
||
| 668 | * and converts all uppercase letters to lowercase and prefixes them |
||
| 669 | * with a hyphen. |
||
| 670 | */ |
||
| 671 | private function __appendBodyId() |
||
| 692 | |||
| 693 | /** |
||
| 694 | * Given the context of the current page, which is an associative |
||
| 695 | * array, this function will append the values to the page's body as |
||
| 696 | * classes. If an context value is numeric it will be prepended by 'id-', |
||
| 697 | * otherwise all classes will be prefixed by the context key. |
||
| 698 | * |
||
| 699 | * @param array $context |
||
| 700 | */ |
||
| 701 | private function __appendBodyClass(array $context = array()) |
||
| 732 | |||
| 733 | /** |
||
| 734 | * Called to build the content for the page. This function immediately calls |
||
| 735 | * `__switchboard()` which acts a bit of a controller to show content based on |
||
| 736 | * off a type, such as 'view' or 'action'. `AdministrationPages` can override this |
||
| 737 | * function to just display content if they do not need the switchboard functionality |
||
| 738 | * |
||
| 739 | * @see __switchboard() |
||
| 740 | */ |
||
| 741 | public function view() |
||
| 745 | |||
| 746 | /** |
||
| 747 | * This function is called when `$_REQUEST` contains a key of 'action'. |
||
| 748 | * Any logic that needs to occur immediately for the action to complete |
||
| 749 | * should be contained within this function. By default this calls the |
||
| 750 | * `__switchboard` with the type set to 'action'. |
||
| 751 | * |
||
| 752 | * @see __switchboard() |
||
| 753 | */ |
||
| 754 | public function action() |
||
| 758 | |||
| 759 | /** |
||
| 760 | * The `__switchboard` function acts as a controller to display content |
||
| 761 | * based off the $type. By default, the `$type` is 'view' but it can be set |
||
| 762 | * also set to 'action'. The `$type` is prepended by __ and the context is |
||
| 763 | * append to the $type to create the name of the function that will provide |
||
| 764 | * that logic. For example, if the $type was action and the context of the |
||
| 765 | * current page was new, the resulting function to be called would be named |
||
| 766 | * `__actionNew()`. If an action function is not provided by the Page, this function |
||
| 767 | * returns nothing, however if a view function is not provided, a 404 page |
||
| 768 | * will be returned. |
||
| 769 | * |
||
| 770 | * @param string $type |
||
| 771 | * Either 'view' or 'action', by default this will be 'view' |
||
| 772 | * @throws SymphonyErrorPage |
||
| 773 | */ |
||
| 774 | public function __switchboard($type = 'view') |
||
| 795 | |||
| 796 | /** |
||
| 797 | * If `$this->Alert` is set, it will be added to this page. The |
||
| 798 | * `AppendPageAlert` delegate is fired to allow extensions to provide their |
||
| 799 | * their own Alert messages for this page. Since Symphony 2.3, there may be |
||
| 800 | * more than one `Alert` per page. Alerts are displayed in the order of |
||
| 801 | * severity, with Errors first, then Success alerts followed by Notices. |
||
| 802 | * |
||
| 803 | * @uses AppendPageAlert |
||
| 804 | */ |
||
| 805 | public function appendAlert() |
||
| 834 | |||
| 835 | // Errors first, success next, then notices. |
||
| 836 | public function sortAlerts($a, $b) |
||
| 851 | |||
| 852 | /** |
||
| 853 | * This function will append the Navigation to the AdministrationPage. |
||
| 854 | * It fires a delegate, NavigationPreRender, to allow extensions to manipulate |
||
| 855 | * the navigation. Extensions should not use this to add their own navigation, |
||
| 856 | * they should provide the navigation through their fetchNavigation function. |
||
| 857 | * Note with the Section navigation groups, if there is only one section in a group |
||
| 858 | * and that section is set to visible, the group will not appear in the navigation. |
||
| 859 | * |
||
| 860 | * @uses NavigationPreRender |
||
| 861 | * @see getNavigationArray() |
||
| 862 | * @see toolkit.Extension#fetchNavigation() |
||
| 863 | */ |
||
| 864 | public function appendNavigation() |
||
| 944 | |||
| 945 | /** |
||
| 946 | * Returns the `$_navigation` variable of this Page. If it is empty, |
||
| 947 | * it will be built by `__buildNavigation` |
||
| 948 | * |
||
| 949 | * When it calls `__buildNavigation`, it fires a delegate, NavigationPostBuild, |
||
| 950 | * to allow extensions to manipulate the navigation. |
||
| 951 | * |
||
| 952 | * @uses NavigationPostBuild |
||
| 953 | * @see __buildNavigation() |
||
| 954 | * @return array |
||
| 955 | */ |
||
| 956 | public function getNavigationArray() |
||
| 964 | |||
| 965 | /** |
||
| 966 | * This method fills the `$nav` array with value |
||
| 967 | * from the `ASSETS/xml/navigation.xml` file |
||
| 968 | * |
||
| 969 | * @link http://github.com/symphonycms/symphony-2/blob/master/symphony/assets/xml/navigation.xml |
||
| 970 | * |
||
| 971 | * @since Symphony 2.3.2 |
||
| 972 | * |
||
| 973 | * @param array $nav |
||
| 974 | * The navigation array that will receive nav nodes |
||
| 975 | */ |
||
| 976 | private function buildXmlNavigation(&$nav) |
||
| 1025 | |||
| 1026 | /** |
||
| 1027 | * This method fills the `$nav` array with value |
||
| 1028 | * from each Section |
||
| 1029 | * |
||
| 1030 | * @since Symphony 2.3.2 |
||
| 1031 | * |
||
| 1032 | * @param array $nav |
||
| 1033 | * The navigation array that will receive nav nodes |
||
| 1034 | */ |
||
| 1035 | private function buildSectionNavigation(&$nav) |
||
| 1106 | |||
| 1107 | /** |
||
| 1108 | * This method fills the `$nav` array with value |
||
| 1109 | * from each Extension's `fetchNavigation` method |
||
| 1110 | * |
||
| 1111 | * @since Symphony 2.3.2 |
||
| 1112 | * |
||
| 1113 | * @param array $nav |
||
| 1114 | * The navigation array that will receive nav nodes |
||
| 1115 | * @throws Exception |
||
| 1116 | * @throws SymphonyErrorPage |
||
| 1117 | */ |
||
| 1118 | private function buildExtensionsNavigation(&$nav) |
||
| 1177 | |||
| 1178 | /** |
||
| 1179 | * This function builds out a navigation menu item for parents. Parents display |
||
| 1180 | * in the top level navigation of the backend and may have children (dropdown menus) |
||
| 1181 | * |
||
| 1182 | * @since Symphony 2.5.1 |
||
| 1183 | * @param integer $index |
||
| 1184 | * @param array $item |
||
| 1185 | * @return array |
||
| 1186 | */ |
||
| 1187 | private static function createParentNavItem($index, $item) |
||
| 1199 | |||
| 1200 | /** |
||
| 1201 | * This function builds out a navigation menu item for children. Children |
||
| 1202 | * live under a parent navigation item and are shown on hover. |
||
| 1203 | * |
||
| 1204 | * @since Symphony 2.5.1 |
||
| 1205 | * @param array $item |
||
| 1206 | * @param string $extension_handle |
||
| 1207 | * @return array |
||
| 1208 | */ |
||
| 1209 | private static function createChildNavItem($item, $extension_handle) |
||
| 1227 | |||
| 1228 | /** |
||
| 1229 | * This function populates the `$_navigation` array with an associative array |
||
| 1230 | * of all the navigation groups and their links. Symphony only supports one |
||
| 1231 | * level of navigation, so children links cannot have children links. The default |
||
| 1232 | * Symphony navigation is found in the `ASSETS/xml/navigation.xml` folder. This is |
||
| 1233 | * loaded first, and then the Section navigation is built, followed by the Extension |
||
| 1234 | * navigation. Additionally, this function will set the active group of the navigation |
||
| 1235 | * by checking the current page against the array of links. |
||
| 1236 | * |
||
| 1237 | * It fires a delegate, NavigationPostBuild, to allow extensions to manipulate |
||
| 1238 | * the navigation. |
||
| 1239 | * |
||
| 1240 | * @uses NavigationPostBuild |
||
| 1241 | * @link https://github.com/symphonycms/symphony-2/blob/master/symphony/assets/xml/navigation.xml |
||
| 1242 | * @link https://github.com/symphonycms/symphony-2/blob/master/symphony/lib/toolkit/class.extension.php |
||
| 1243 | */ |
||
| 1244 | public function __buildNavigation() |
||
| 1285 | |||
| 1286 | /** |
||
| 1287 | * Given an associative array representing the navigation, and a group, |
||
| 1288 | * this function will attempt to return the index of the group in the navigation |
||
| 1289 | * array. If it is found, it will return the index, otherwise it will return false. |
||
| 1290 | * |
||
| 1291 | * @param array $nav |
||
| 1292 | * An associative array of the navigation where the key is the group |
||
| 1293 | * index, and the value is an associative array of 'name', 'index' and |
||
| 1294 | * 'children'. Name is the name of the this group, index is the same as |
||
| 1295 | * the key and children is an associative array of navigation items containing |
||
| 1296 | * the keys 'link', 'name' and 'visible'. The 'haystack'. |
||
| 1297 | * @param string $group |
||
| 1298 | * The group name to find, the 'needle'. |
||
| 1299 | * @return integer|boolean |
||
| 1300 | * If the group is found, the index will be returned, otherwise false. |
||
| 1301 | */ |
||
| 1302 | private static function __navigationFindGroupIndex(array $nav, $group) |
||
| 1312 | |||
| 1313 | /** |
||
| 1314 | * Given the navigation array, this function will loop over all the items |
||
| 1315 | * to determine which is the 'active' navigation group, or in other words, |
||
| 1316 | * what group best represents the current page `$this->Author` is viewing. |
||
| 1317 | * This is done by checking the current page's link against all the links |
||
| 1318 | * provided in the `$nav`, and then flagging the group of the found link |
||
| 1319 | * with an 'active' CSS class. The current page's link omits any flags or |
||
| 1320 | * URL parameters and just uses the root page URL. |
||
| 1321 | * |
||
| 1322 | * @param array $nav |
||
| 1323 | * An associative array of the navigation where the key is the group |
||
| 1324 | * index, and the value is an associative array of 'name', 'index' and |
||
| 1325 | * 'children'. Name is the name of the this group, index is the same as |
||
| 1326 | * the key and children is an associative array of navigation items containing |
||
| 1327 | * the keys 'link', 'name' and 'visible'. The 'haystack'. This parameter is passed |
||
| 1328 | * by reference to this function. |
||
| 1329 | * @param string $pageroot |
||
| 1330 | * The current page the Author is the viewing, minus any flags or URL |
||
| 1331 | * parameters such as a Symphony object ID. eg. Section ID, Entry ID. This |
||
| 1332 | * parameter is also be a regular expression, but this is highly unlikely. |
||
| 1333 | * @param boolean $pattern |
||
| 1334 | * If set to true, the `$pageroot` represents a regular expression which will |
||
| 1335 | * determine if the active navigation item |
||
| 1336 | * @return boolean |
||
| 1337 | * Returns true if an active link was found, false otherwise. If true, the |
||
| 1338 | * navigation group of the active link will be given the CSS class 'active' |
||
| 1339 | */ |
||
| 1340 | private static function __findActiveNavigationGroup(array &$nav, $pageroot, $pattern = false) |
||
| 1358 | |||
| 1359 | /** |
||
| 1360 | * Creates the Symphony footer for an Administration page. By default |
||
| 1361 | * this includes the installed Symphony version and the currently logged |
||
| 1362 | * in Author. A delegate is provided to allow extensions to manipulate the |
||
| 1363 | * footer HTML, which is an XMLElement of a `<ul>` element. |
||
| 1364 | * Since Symphony 2.3, it no longer uses the `AddElementToFooter` delegate. |
||
| 1365 | */ |
||
| 1366 | public function appendUserLinks() |
||
| 1385 | |||
| 1386 | /** |
||
| 1387 | * Adds a localized Alert message for failed timestamp validations. |
||
| 1388 | * It also adds meta information about the last author and timestamp. |
||
| 1389 | * |
||
| 1390 | * @since Symphony 2.7.0 |
||
| 1391 | * @param string $errorMessage |
||
| 1392 | * The error message to display. |
||
| 1393 | * @param Entry|Section $existingObject |
||
| 1394 | * The Entry or section object that failed validation. |
||
| 1395 | * @param string $action |
||
| 1396 | * The requested action. |
||
| 1397 | */ |
||
| 1398 | public function addTimestampValidationPageAlert($errorMessage, $existingObject, $action) |
||
| 1438 | } |
||
| 1439 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.