Conditions | 11 |
Paths | 8 |
Total Lines | 154 |
Code Lines | 84 |
Lines | 0 |
Ratio | 0 % |
Changes | 12 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
73 | public function updateFormWithQuicklinks($form) |
||
74 | { |
||
75 | $shortcuts = $this->getLinksFromImplementor(); |
||
76 | $html = ''; |
||
77 | if (count($shortcuts)) { |
||
78 | $html = '<div class="grid-wrapper">'; |
||
79 | |||
80 | usort( |
||
81 | $shortcuts, |
||
82 | function ($a, $b) { |
||
83 | ($a['SortOrder'] ?? 0) <=> ($b['SortOrder'] ?? 0); |
||
84 | } |
||
85 | ); |
||
86 | |||
87 | foreach ($shortcuts as $groupCode => $groupDetails) { |
||
88 | $colour = ''; |
||
89 | if (!empty($groupDetails['Colour'])) { |
||
90 | $colour = 'style="background-color: ' . $groupDetails['Colour'] . '"'; |
||
91 | } |
||
92 | $icon = ''; |
||
93 | if (!empty($groupDetails['IconClass'])) { |
||
94 | $icon = '<i class="' . $groupDetails['IconClass'] . '"></i> '; |
||
95 | } |
||
96 | $html .= ' |
||
97 | <div class="grid-cell" ' . $colour . '> |
||
98 | <div class="header"> |
||
99 | <h1>' . $icon . '' . ($groupDetails['Title'] ?? $groupCode) . '</h1> |
||
100 | </div> |
||
101 | <div class="entries">'; |
||
102 | $items = $groupDetails['Items'] ?? []; |
||
103 | if (!empty($entry['Link']) && class_exists($entry['Link'])) { |
||
104 | $obj = Injector::inst()->get($entry['Link']); |
||
105 | if ($obj instanceof DataObject) { |
||
106 | $entry['Link'] = DataObject::get_one($entry['Link'])->CMSEditLink(); |
||
107 | } else { |
||
108 | $entry['Link'] = $obj->Link(); |
||
109 | } |
||
110 | } |
||
111 | foreach ($items as $entry) { |
||
112 | $html .= $this->makeShortCut( |
||
113 | $entry['Title'], |
||
114 | $entry['Link'], |
||
115 | $entry['OnClick'] ?? '', |
||
116 | $entry['Script'] ?? '', |
||
117 | $entry['Style'] ?? '', |
||
118 | $entry['IconClass'] ?? '', |
||
119 | $entry['Target'] ?? '', |
||
120 | )->Field(); |
||
121 | } |
||
122 | $html .= '</div></div>'; |
||
123 | } |
||
124 | } |
||
125 | $kc = (array) $this->Config()->get('colour_options'); |
||
126 | if(empty($kc)) { |
||
127 | $kc = $this->Config()->get('default_colour_options'); |
||
128 | } |
||
129 | $kcCount = count($kc); |
||
130 | $colours = ''; |
||
131 | foreach ($kc as $key => $colour) { |
||
132 | $colours .= ' .grid-wrapper .grid-cell:nth-child(' . $kcCount . 'n+' . ($key + 1) . ') div.header {background-color: ' . $colour . '; color: '.$this->getFontColor($colour).'!important;}'; |
||
133 | } |
||
134 | $html .= '</div>'; |
||
135 | $html .= <<<JS |
||
136 | <script> |
||
137 | // Function to add the input box and set up the filtering behavior |
||
138 | function setupInputAndFilter() { |
||
139 | // Locate the target span element |
||
140 | const targetSpan = document.querySelector('.cms-content-header-info'); |
||
141 | |||
142 | // Create the input box |
||
143 | const inputBox = document.createElement('input'); |
||
144 | inputBox.type = 'text'; |
||
145 | inputBox.placeholder = 'Type to filter...'; |
||
146 | |||
147 | // Append the input box to the target span |
||
148 | targetSpan.appendChild(inputBox); |
||
149 | |||
150 | // Function to filter grid cells based on input |
||
151 | function filterGridCells() { |
||
152 | const inputValue = inputBox.value.toLowerCase(); |
||
153 | const gridCells = document.querySelectorAll('div.grid-cell'); |
||
154 | |||
155 | gridCells.forEach(cell => { |
||
156 | // Check if the text in the cell includes the input value |
||
157 | if (inputValue === '' || cell.textContent.toLowerCase().includes(inputValue)) { |
||
158 | cell.style.display = ''; // Show the cell |
||
159 | } else { |
||
160 | cell.style.display = 'none'; // Hide the cell |
||
161 | } |
||
162 | }); |
||
163 | } |
||
164 | |||
165 | // Add event listener to the input box to filter as the user types |
||
166 | inputBox.addEventListener('input', filterGridCells); |
||
167 | } |
||
168 | window.setTimeout(setupInputAndFilter, 500); |
||
169 | </script> |
||
170 | |||
171 | JS; |
||
172 | |||
173 | $html .= '<style> |
||
174 | |||
175 | .grid-wrapper { |
||
176 | display: grid; |
||
177 | grid-template-columns: repeat( auto-fit, minmax(300px, 1fr) );; |
||
178 | grid-gap: 20px; |
||
179 | } |
||
180 | |||
181 | .grid-wrapper .grid-cell { |
||
182 | max-width: 500px; |
||
183 | font-size: 150%; |
||
184 | border-radius: 1rem; |
||
185 | border: 1px solid #004e7f55; |
||
186 | display: flex; |
||
187 | flex-direction: column; |
||
188 | overflow: hidden; |
||
189 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); |
||
190 | transition: all 0.3s ease; |
||
191 | opacity: 0.8; |
||
192 | &:hover { |
||
193 | transform: scale(1.05); |
||
194 | box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); |
||
195 | opacity: 1; |
||
196 | } |
||
197 | } |
||
198 | .grid-wrapper .grid-cell > div { |
||
199 | padding: 20px; |
||
200 | padding-bottom: 0; |
||
201 | } |
||
202 | .grid-wrapper .grid-cell > div.header { |
||
203 | padding-bottom: 0; |
||
204 | border-bottom: 1px solid #004e7f55; |
||
205 | } |
||
206 | .grid-wrapper .grid-cell > div.header h1 { |
||
207 | font-weight: 700; |
||
208 | font-size: 1.3rem!important; |
||
209 | } |
||
210 | .grid-wrapper .grid-cell > div.entries { |
||
211 | background-color: #fff; |
||
212 | height: 100%; |
||
213 | } |
||
214 | ' . $colours . ' |
||
215 | .grid-wrapper .grid-cell div.entries *, |
||
216 | .grid-wrapper .grid-cell div.entries a:link, |
||
217 | .grid-wrapper .grid-cell div.entries a:visited { |
||
218 | color: #222; |
||
219 | } |
||
220 | .grid-wrapper .grid-cell div.entries a:link:hover, |
||
221 | .grid-wrapper .grid-cell div.entries a:visited:hover { |
||
222 | color: #0071c4; |
||
223 | text-decoration: none; |
||
224 | } |
||
225 | </style>'; |
||
226 | $form->Fields()->push(LiteralField::create('ShortCuts', $html)); |
||
227 | } |
||
326 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths