Skip to content

Commit 7ae17fb

Browse files
authored
Fix some phpmd advisories (#2066)
1 parent caef0aa commit 7ae17fb

28 files changed

+55
-149
lines changed

demos/init-db.php

-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
->addMoreInfo('PDO error', $e->getMessage());
2323
}
2424

25-
// a very basic file that sets up Agile Data to be used in some demonstrations
26-
2725
trait ModelPreventModificationTrait
2826
{
2927
protected function isAllowDbModifications(): bool
@@ -369,9 +367,6 @@ protected function init(): void
369367
->addTitle();
370368
}
371369

372-
/**
373-
* Perform import from filesystem.
374-
*/
375370
public function importFromFilesystem(string $path, bool $isSub = null): void
376371
{
377372
if ($isSub === null) {

src/Accordion.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ public function jsBehavior($behavior, array $args, $when = false): JsExpressiona
134134
public function getSectionIdx(AccordionSection $section)
135135
{
136136
$idx = -1;
137-
foreach ($this->sections as $key => $accordion_section) {
138-
if ($accordion_section->name === $section->name) {
139-
$idx = $key;
137+
foreach ($this->sections as $k => $v) {
138+
if ($v->name === $section->name) {
139+
$idx = $k;
140140

141141
break;
142142
}

src/App.php

+11-19
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function __construct(array $defaults = [])
179179
}
180180
}
181181

182-
// Set our exception handler
182+
// set our exception handler
183183
if ($this->catchExceptions) {
184184
set_exception_handler(\Closure::fromCallable([$this, 'caughtException']));
185185
set_error_handler(static function (int $severity, string $msg, string $file, int $line): bool {
@@ -207,7 +207,7 @@ public function __construct(array $defaults = [])
207207
http_response_code(500);
208208
}
209209

210-
// Always run app on shutdown
210+
// always run app on shutdown
211211
if ($this->alwaysRun) {
212212
$this->setupAlwaysRun();
213213
}
@@ -289,9 +289,6 @@ public function callExit(): void
289289
exit;
290290
}
291291

292-
/**
293-
* Catch exception.
294-
*/
295292
public function caughtException(\Throwable $exception): void
296293
{
297294
if ($exception instanceof LateOutputError) {
@@ -415,22 +412,22 @@ public function terminate($output = ''): void
415412

416413
$this->outputResponseJson($output);
417414
} elseif (isset($_GET['__atk_tab']) && $type === 'text/html') {
418-
// ugly hack for TABS
419-
// because Fomantic-UI tab only deal with HTML and not JSON
420-
// we need to hack output to include app modal.
415+
// ugly hack for Tabs
416+
// because Fomantic-UI Tab only deal with HTML and not JSON
417+
// we need to hack output to include app modal
421418
$ids = [];
422-
$remove_function = '';
419+
$jsRemoveFunction = '';
423420
foreach ($this->getRenderedPortals() as $key => $modal) {
424421
// add modal rendering to output
425422
$ids[] = '#' . $key;
426423
$output['atkjs'] .= '; ' . $modal['js'];
427424
$output['html'] .= $modal['html'];
428425
}
429426
if (count($ids) > 0) {
430-
$remove_function = '$(\'.ui.dimmer.modals.page, .atk-side-panels\').find(\'' . implode(', ', $ids) . '\').remove();';
427+
$jsRemoveFunction = '$(\'.ui.dimmer.modals.page, .atk-side-panels\').find(\'' . implode(', ', $ids) . '\').remove();';
431428
}
432429

433-
$output = $this->getTag('script', [], '$(function () {' . $remove_function . $output['atkjs'] . '});')
430+
$output = $this->getTag('script', [], '$(function () {' . $jsRemoveFunction . $output['atkjs'] . '});')
434431
. $output['html'];
435432

436433
$this->outputResponseHtml($output);
@@ -699,9 +696,9 @@ public function url($page = [], $useRequestUrl = false, $extraRequestUrlArgs = [
699696

700697
$pagePath = '';
701698
if (is_string($page)) {
702-
$page_arr = explode('?', $page, 2);
703-
$pagePath = $page_arr[0];
704-
parse_str($page_arr[1] ?? '', $page);
699+
$pageExploded = explode('?', $page, 2);
700+
$pagePath = $pageExploded[0];
701+
parse_str($pageExploded[1] ?? '', $page);
705702
} else {
706703
if (isset($page[0])) {
707704
$pagePath = $page[0];
@@ -1103,9 +1100,6 @@ protected function emitResponse(): void
11031100
}
11041101
}
11051102

1106-
/**
1107-
* Output Response to the client.
1108-
*/
11091103
protected function outputResponse(string $data): void
11101104
{
11111105
foreach (ob_get_status(true) as $status) {
@@ -1170,8 +1164,6 @@ private function outputResponseHtml(string $data): void
11701164
}
11711165

11721166
/**
1173-
* Output JSON response to the client.
1174-
*
11751167
* @param string|array $data
11761168
*/
11771169
private function outputResponseJson($data): void

src/Callback.php

-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ public function isTriggered(): bool
102102
return isset($_GET[self::URL_QUERY_TRIGGER_PREFIX . $this->urlTrigger]);
103103
}
104104

105-
/**
106-
* Return callback triggered value.
107-
*/
108105
public function getTriggeredValue(): string
109106
{
110107
return $_GET[self::URL_QUERY_TRIGGER_PREFIX . $this->urlTrigger] ?? '';

src/CardDeck.php

-3
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ protected function addMenuBarSeach(): void
123123
$this->query = $this->stickyGet($this->search->queryArg);
124124
}
125125

126-
/**
127-
* Add Paginator view to card deck.
128-
*/
129126
protected function addPaginator(): void
130127
{
131128
$seg = View::addTo($this->container, ['ui' => 'basic segment'])->setStyle('text-align', 'center');

src/Form.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,9 @@ public function jsInput(string $name): JsExpressionable
390390
* 3. $f->type is converted into seed and evaluated
391391
* 4. lastly, falling back to Line, Dropdown (based on $reference and $enum)
392392
*
393-
* @param array<string, mixed> $ControlSeed
393+
* @param array<string, mixed> $controlSeed
394394
*/
395-
public function controlFactory(Field $field, $ControlSeed = []): Control
395+
public function controlFactory(Field $field, $controlSeed = []): Control
396396
{
397397
$this->model->assertIsEntity($field->getOwner());
398398

@@ -420,8 +420,8 @@ public function controlFactory(Field $field, $ControlSeed = []): Control
420420
$fallbackSeed['placeholder'] = $field->ui['placeholder'];
421421
}
422422

423-
$ControlSeed = Factory::mergeSeeds(
424-
$ControlSeed,
423+
$controlSeed = Factory::mergeSeeds(
424+
$controlSeed,
425425
$field->ui['form'] ?? null,
426426
$this->typeToControl[$field->type] ?? null,
427427
$fallbackSeed
@@ -433,7 +433,7 @@ public function controlFactory(Field $field, $ControlSeed = []): Control
433433
'shortName' => $field->shortName,
434434
];
435435

436-
return Factory::factory($ControlSeed, $defaults);
436+
return Factory::factory($controlSeed, $defaults);
437437
}
438438

439439
/**

src/Form/Control/Dropdown.php

-6
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,11 @@ protected function jsDropdown($when = false, $action = null): JsExpressionable
176176
return $this->js($when, $action, 'div.ui.dropdown:has(> #' . $this->name . '_input)');
177177
}
178178

179-
/**
180-
* Render JS for dropdown.
181-
*/
182179
protected function jsRenderDropdown(): JsExpressionable
183180
{
184181
return $this->jsDropdown(true)->dropdown($this->dropdownOptions);
185182
}
186183

187-
/**
188-
* Render values as HTML for Dropdown.
189-
*/
190184
protected function htmlRenderValue(): void
191185
{
192186
// add selection only if no value is required and Dropdown has no multiple selections enabled

src/Form/Control/Multiline.php

-10
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,6 @@ protected function init(): void
243243
});
244244
}
245245

246-
/**
247-
* Typecast each loaded value.
248-
*/
249246
protected function typeCastLoadValues(array $values): array
250247
{
251248
$dataRows = [];
@@ -552,9 +549,6 @@ protected function getLookupProps(Field $field): array
552549
return $props;
553550
}
554551

555-
/**
556-
* Lookup Props set based on field value.
557-
*/
558552
public function setLookupOptionValue(Field $field, string $value): void
559553
{
560554
$model = $field->getReference()->refModel($this->model);
@@ -573,7 +567,6 @@ public function setLookupOptionValue(Field $field, string $value): void
573567
}
574568

575569
/**
576-
* Return a component definition.
577570
* Component definition require at least a name and a props array.
578571
*/
579572
protected function getComponentDefinition(Field $field): array
@@ -602,9 +595,6 @@ protected function getComponentDefinition(Field $field): array
602595
return $definition;
603596
}
604597

605-
/**
606-
* Return array of possible items set for a select or lookup field.
607-
*/
608598
protected function getFieldItems(Field $field, ?int $limit = 10): array
609599
{
610600
$items = [];

src/Form/Control/UploadImage.php

-6
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ public function getThumbnail(): View
4242
return $this->thumbnail;
4343
}
4444

45-
/**
46-
* Set the thumbnail img src value.
47-
*/
4845
public function setThumbnailSrc(string $src): void
4946
{
5047
$this->thumbnail->setAttr(['src' => $src]);
@@ -53,9 +50,6 @@ public function setThumbnailSrc(string $src): void
5350
$this->addJsAction($js);
5451
}
5552

56-
/**
57-
* Clear the thumbnail src.
58-
*/
5953
public function clearThumbnail(): void
6054
{
6155
$js = $this->thumbnail->js();

src/Form/Layout.php

-7
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ protected function init(): void
5757
}
5858

5959
/**
60-
* Adds Button.
61-
*
6260
* @param Button|array $seed
6361
*
6462
* @return Button
@@ -69,8 +67,6 @@ public function addButton($seed)
6967
}
7068

7169
/**
72-
* Adds Header in form layout.
73-
*
7470
* @param string|array $label
7571
*
7672
* @return $this
@@ -127,9 +123,6 @@ public function addSubLayout($seed = [self::class], $addDivider = true)
127123
return $v;
128124
}
129125

130-
/**
131-
* Recursively renders this view.
132-
*/
133126
protected function recursiveRender(): void
134127
{
135128
$labeledControl = $this->inputTemplate->cloneRegion('LabeledControl');

src/Grid.php

-3
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,6 @@ public function addDragHandler()
609609
return $handler;
610610
}
611611

612-
/**
613-
* Will set model limit according to paginator value.
614-
*/
615612
private function setModelLimitFromPaginator(): void
616613
{
617614
$this->paginator->setTotal((int) ceil($this->model->executeCountQuery() / $this->ipp));

src/GridLayout.php

-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ protected function init(): void
5151
$this->buildTemplate();
5252
}
5353

54-
/**
55-
* Build and set view template.
56-
*/
5754
protected function buildTemplate(): void
5855
{
5956
$this->tWrap->del('rows');

src/JsCallback.php

-3
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ private function _getProperAction($response): JsExpressionable
160160
return $response;
161161
}
162162

163-
/**
164-
* Render View into modal.
165-
*/
166163
private function _jsRenderIntoModal(View $response): JsExpressionable
167164
{
168165
if ($response instanceof Modal) {

src/JsSse.php

-6
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ public function flush(): void
120120
flush();
121121
}
122122

123-
/**
124-
* Send Data.
125-
*/
126123
private function output(string $content): void
127124
{
128125
if ($this->echoFunction) {
@@ -138,9 +135,6 @@ private function output(string $content): void
138135
}, null, $app)();
139136
}
140137

141-
/**
142-
* Send a SSE data block.
143-
*/
144138
public function sendBlock(string $id, string $data, string $eventName = null): void
145139
{
146140
if (connection_aborted()) {

src/LoremIpsum.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ public function generateLorem(int $words)
7575
$lorem = '';
7676

7777
while ($words > 0) {
78-
$sentence_length = random_int(3, 10);
78+
$sentenceLength = random_int(3, 10);
7979

8080
$lorem .= ucfirst($dictionary[array_rand($dictionary)]);
81-
for ($i = 1; $i < $sentence_length; ++$i) {
81+
for ($i = 1; $i < $sentenceLength; ++$i) {
8282
$lorem .= ' ' . $dictionary[array_rand($dictionary)];
8383
}
8484

8585
$lorem .= $punctuation[array_rand($punctuation)];
86-
$words -= $sentence_length;
86+
$words -= $sentenceLength;
8787
}
8888

8989
return $lorem;

src/Paginator.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,22 @@ public function renderItem($t, $page = null): void
183183

184184
protected function renderView(): void
185185
{
186-
$t_item = $this->template->cloneRegion('Item');
187-
$t_first = $this->template->hasTag('FirstItem') ? $this->template->cloneRegion('FirstItem') : $t_item;
188-
$t_last = $this->template->hasTag('LastItem') ? $this->template->cloneRegion('LastItem') : $t_item;
189-
$t_spacer = $this->template->cloneRegion('Spacer');
186+
$tItem = $this->template->cloneRegion('Item');
187+
$tFirst = $this->template->hasTag('FirstItem') ? $this->template->cloneRegion('FirstItem') : $tItem;
188+
$tLast = $this->template->hasTag('LastItem') ? $this->template->cloneRegion('LastItem') : $tItem;
189+
$tSpacer = $this->template->cloneRegion('Spacer');
190190

191191
$this->template->del('rows');
192192

193193
foreach ($this->getPaginatorItems() as $item) {
194194
if ($item === '[') {
195-
$this->renderItem($t_first, 1);
195+
$this->renderItem($tFirst, 1);
196196
} elseif ($item === '...') {
197-
$this->renderItem($t_spacer);
197+
$this->renderItem($tSpacer);
198198
} elseif ($item === ']') {
199-
$this->renderItem($t_last, $this->total);
199+
$this->renderItem($tLast, $this->total);
200200
} else {
201-
$this->renderItem($t_item, $item);
201+
$this->renderItem($tItem, $item);
202202
}
203203
}
204204

0 commit comments

Comments
 (0)