We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Total Complexity | 41 |
Total Lines | 230 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Complex classes like TableOfContentsController 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.
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 TableOfContentsController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class TableOfContentsController extends AbstractController |
||
28 | { |
||
29 | /** |
||
30 | * This holds the active entries according to the currently selected page |
||
31 | * |
||
32 | * @var array |
||
33 | * @access protected |
||
34 | */ |
||
35 | protected $activeEntries = []; |
||
36 | |||
37 | /** |
||
38 | * This builds an array for one menu entry |
||
39 | * |
||
40 | * @access protected |
||
41 | * |
||
42 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
43 | * @param bool $recursive : Whether to include the child entries |
||
44 | * |
||
45 | * @return array HMENU array for menu entry |
||
46 | */ |
||
47 | protected function getMenuEntry(array $entry, $recursive = false) |
||
48 | { |
||
49 | $entry = $this->resolveMenuEntry($entry); |
||
50 | |||
51 | $entryArray = []; |
||
52 | // Set "title", "volume", "type" and "pagination" from $entry array. |
||
53 | $entryArray['title'] = !empty($entry['label']) ? $entry['label'] : $entry['orderlabel']; |
||
54 | $entryArray['volume'] = $entry['volume']; |
||
55 | $entryArray['orderlabel'] = $entry['orderlabel']; |
||
56 | $entryArray['type'] = Helper::translate($entry['type'], 'tx_dlf_structures', $this->settings['storagePid']); |
||
57 | $entryArray['pagination'] = htmlspecialchars($entry['pagination']); |
||
58 | $entryArray['_OVERRIDE_HREF'] = ''; |
||
59 | $entryArray['doNotLinkIt'] = 1; |
||
60 | $entryArray['ITEM_STATE'] = 'NO'; |
||
61 | // Build menu links based on the $entry['points'] array. |
||
62 | if ( |
||
63 | !empty($entry['points']) |
||
64 | && MathUtility::canBeInterpretedAsInteger($entry['points']) |
||
65 | ) { |
||
66 | $entryArray['page'] = $entry['points']; |
||
67 | |||
68 | $entryArray['doNotLinkIt'] = 0; |
||
69 | if ($this->settings['basketButton']) { |
||
70 | $entryArray['basketButton'] = [ |
||
71 | 'logId' => $entry['id'], |
||
72 | 'startpage' => $entry['points'] |
||
73 | ]; |
||
74 | } |
||
75 | } elseif ( |
||
76 | !empty($entry['points']) |
||
77 | && is_string($entry['points']) |
||
78 | ) { |
||
79 | $entryArray['id'] = $entry['points']; |
||
80 | $entryArray['page'] = 1; |
||
81 | $entryArray['doNotLinkIt'] = 0; |
||
82 | if ($this->settings['basketButton']) { |
||
83 | $entryArray['basketButton'] = [ |
||
84 | 'logId' => $entry['id'], |
||
85 | 'startpage' => $entry['points'] |
||
86 | ]; |
||
87 | } |
||
88 | } elseif (!empty($entry['targetUid'])) { |
||
89 | $entryArray['id'] = $entry['targetUid']; |
||
90 | $entryArray['page'] = 1; |
||
91 | $entryArray['doNotLinkIt'] = 0; |
||
92 | if ($this->settings['basketButton']) { |
||
93 | $entryArray['basketButton'] = [ |
||
94 | 'logId' => $entry['id'], |
||
95 | 'startpage' => $entry['targetUid'] |
||
96 | ]; |
||
97 | } |
||
98 | } |
||
99 | // Set "ITEM_STATE" to "CUR" if this entry points to current page. |
||
100 | if (in_array($entry['id'], $this->activeEntries)) { |
||
101 | $entryArray['ITEM_STATE'] = 'CUR'; |
||
102 | } |
||
103 | // Build sub-menu if available and called recursively. |
||
104 | if ( |
||
105 | $recursive === true |
||
106 | && !empty($entry['children']) |
||
107 | ) { |
||
108 | // Build sub-menu only if one of the following conditions apply: |
||
109 | // 1. Current menu node is in rootline |
||
110 | // 2. Current menu node points to another file |
||
111 | // 3. Current menu node has no corresponding images |
||
112 | if ( |
||
113 | $entryArray['ITEM_STATE'] == 'CUR' |
||
114 | || is_string($entry['points']) |
||
115 | || empty($this->document->getDoc()->smLinks['l2p'][$entry['id']]) |
||
116 | ) { |
||
117 | $entryArray['_SUB_MENU'] = []; |
||
118 | foreach ($entry['children'] as $child) { |
||
119 | // Set "ITEM_STATE" to "ACT" if this entry points to current page and has sub-entries pointing to the same page. |
||
120 | if (in_array($child['id'], $this->activeEntries)) { |
||
121 | $entryArray['ITEM_STATE'] = 'ACT'; |
||
122 | } |
||
123 | $entryArray['_SUB_MENU'][] = $this->getMenuEntry($child, true); |
||
124 | } |
||
125 | } |
||
126 | // Append "IFSUB" to "ITEM_STATE" if this entry has sub-entries. |
||
127 | $entryArray['ITEM_STATE'] = ($entryArray['ITEM_STATE'] == 'NO' ? 'IFSUB' : $entryArray['ITEM_STATE'] . 'IFSUB'); |
||
128 | } |
||
129 | return $entryArray; |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * If $entry references an external METS file (as mptr), |
||
134 | * try to resolve its database UID and return an updated $entry. |
||
135 | * |
||
136 | * This is so that when linking from a child document back to its parent, |
||
137 | * that link is via UID, so that subsequently the parent's TOC is built from database. |
||
138 | * |
||
139 | * @param array $entry |
||
140 | * @return array |
||
141 | */ |
||
142 | protected function resolveMenuEntry($entry) |
||
143 | { |
||
144 | // If the menu entry points to the parent document, |
||
145 | // resolve to the parent UID set on indexation. |
||
146 | $doc = $this->document->getDoc(); |
||
147 | if ( |
||
148 | $doc instanceof MetsDocument |
||
149 | && $entry['points'] === $doc->parentHref |
||
150 | && !empty($this->document->getPartof()) |
||
151 | ) { |
||
152 | unset($entry['points']); |
||
153 | $entry['targetUid'] = $this->document->getPartof(); |
||
154 | } |
||
155 | |||
156 | return $entry; |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * The main method of the plugin |
||
161 | * |
||
162 | * @return void |
||
163 | */ |
||
164 | public function mainAction() |
||
165 | { |
||
166 | $this->view->assign('toc', $this->makeMenuArray()); |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * This builds a menu array for HMENU |
||
171 | * |
||
172 | * @access public |
||
173 | * @return array HMENU array |
||
174 | */ |
||
175 | public function makeMenuArray() |
||
257 | } |
||
258 | } |
||
259 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.