Skip to content

Commit 747688b

Browse files
committed
refactor: Use of New Nullable Syntax
1 parent 5108943 commit 747688b

File tree

12 files changed

+26
-26
lines changed

12 files changed

+26
-26
lines changed

tests/webfiori/test/ui/HTMLNodeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function testAddChild05() {
194194
$node = new HTMLNode();
195195
$subNode = new HTMLNode('a');
196196
$subNode->text('Link');
197-
$liObj = new ListItem();
197+
$liObj = new ListItem(null);
198198
$liObj->text('List Item Obj');
199199
$node->ul([
200200
'Simple Text',
@@ -525,7 +525,7 @@ public function testChaining03() {
525525
'Hello', 'World'
526526
])->ol([
527527
'Good', 'Girl', new Label('Test With Node'),
528-
new ListItem()
528+
new ListItem(null)
529529
]);
530530
$node->getChild(0)
531531
->anchor(new HTMLNode('img', [

webfiori/ui/CodeSnippet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class CodeSnippet extends HTMLNode {
7272
*
7373
* @since 1.0
7474
*/
75-
public function __construct(string $title = 'Code Snippet',string $code = null) {
75+
public function __construct(string $title = 'Code Snippet', ?string $code = '') {
7676
parent::__construct();
7777
$this->originalCode = '';
7878
$this->codeStrNode = HTMLNode::createTextNode('');

webfiori/ui/HTMLDoc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class HTMLDoc {
8383
*/
8484
public function __construct() {
8585
$this->body = new HTMLNode('body');
86-
$this->body->setAttribute('itemscope');
86+
$this->body->setAttribute('itemscope', null);
8787
$this->body->setAttribute('itemtype', 'http://schema.org/WebPage');
8888
$this->headNode = new HeadNode();
8989
$this->htmlNode = new HTMLNode('html');
@@ -362,7 +362,7 @@ public function setHeadNode(HeadNode $node) {
362362
*
363363
* @since 1.0
364364
*/
365-
public function setLanguage(string $lang = null) : bool {
365+
public function setLanguage(?string $lang = '') : bool {
366366
if ($lang === null) {
367367
$this->getDocumentRoot()->removeAttribute('lang');
368368

webfiori/ui/HTMLList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function addListItem($listItemBody, bool $escHtmlEntities = true) : HTMLL
105105
if ($listItemBody instanceof ListItem) {
106106
$this->addChild($listItemBody);
107107
} else {
108-
$li = new ListItem();
108+
$li = new ListItem(null);
109109

110110
if ($listItemBody instanceof HTMLNode) {
111111
$li->addChild($listItemBody);

webfiori/ui/HTMLNode.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public function addTextNode(string $text, bool $escHtmlEntities = true) {
411411
*
412412
*
413413
*/
414-
public function anchor($body = null, array $attributes = []) : HTMLNode {
414+
public function anchor(string|HTMLNode $body, array $attributes = []) : HTMLNode {
415415
$href = null;
416416

417417
$href = $attributes['href'] ?? '';
@@ -576,7 +576,7 @@ public function build(array $arrOfChildren) {
576576
* method is called on.
577577
*
578578
*/
579-
public function cell($cellBody = null, string $cellType = 'td', array $attributes = []) : HTMLNode {
579+
public function cell(string|HTMLNode $cellBody = '', string $cellType = 'td', array $attributes = []) : HTMLNode {
580580
if ($this->getNodeName() == 'tr') {
581581
$cell = new TableCell($cellType, $cellBody);
582582
$cell->setAttributes($attributes);
@@ -1519,7 +1519,7 @@ public function label($body, array $attributes = []) : HTMLNode {
15191519
*/
15201520
public function li($itemBody, array $attributes = []) : HTMLNode {
15211521
if ($this->getNodeName() == 'ul' || $this->getNodeName() == 'ol') {
1522-
$item = new ListItem();
1522+
$item = new ListItem(null);
15231523

15241524
if ($itemBody instanceof HTMLNode) {
15251525
$item->addChild($itemBody);
@@ -1645,7 +1645,7 @@ public function open() : string {
16451645
*
16461646
*
16471647
*/
1648-
public function paragraph($body = null, array $attributes = [], bool $escEntities = true) : HTMLNode {
1648+
public function paragraph(string|HTMLNode $body = '', array $attributes = [], bool $escEntities = true) : HTMLNode {
16491649
$paragraph = new Paragraph();
16501650

16511651
if ($body instanceof HTMLNode) {
@@ -1826,7 +1826,7 @@ public function section($title, int $headingLvl = 1, array $attributes = []) : H
18261826
* method is called on.
18271827
*
18281828
*/
1829-
public function setAttribute(string $name, $val = null) : HTMLNode {
1829+
public function setAttribute(string $name, mixed $val = null) : HTMLNode {
18301830
$trimmedName = trim($name);
18311831
$attrValType = gettype($val);
18321832
$trimmedVal = null;
@@ -1855,7 +1855,7 @@ public function setAttribute(string $name, $val = null) : HTMLNode {
18551855
} else if ($val === null) {
18561856
$this->attributes[$trimmedName] = null;
18571857
} else if ($attrValType == 'string') {
1858-
$this->attributes[$trimmedName] = $trimmedVal;
1858+
$this->attributes[$trimmedName] = $trimmedVal;
18591859
} else if (in_array($attrValType, ['double', 'integer'])) {
18601860
$this->attributes[$trimmedName] = $val;
18611861
} else if ($attrValType == 'boolean') {
@@ -2390,7 +2390,7 @@ private function closeAsCode(array $FO) : string {
23902390
* @param LinkedList $chNodes
23912391
* @return null|HTMLNode Description
23922392
*/
2393-
private function getChildByIDHelper(string $val,LinkedList $chNodes = null) {
2393+
private function getChildByIDHelper(string $val, ?LinkedList $chNodes) {
23942394
$chCount = $chNodes !== null ? $chNodes->size() : 0;
23952395

23962396
for ($x = 0 ; $x < $chCount ; $x++) {
@@ -2671,7 +2671,7 @@ private function reduceTab() {
26712671
}
26722672
private function removeChHelper($node) {
26732673
if ($node instanceof HTMLNode) {
2674-
$node->setParentHelper();
2674+
$node->setParentHelper(null);
26752675

26762676
return $node;
26772677
}
@@ -2684,7 +2684,7 @@ private function removeChHelper($node) {
26842684
*
26852685
*
26862686
*/
2687-
private function setParentHelper(HTMLNode $node = null) {
2687+
private function setParentHelper(?HTMLNode $node) {
26882688
$this->parentNode = $node;
26892689
}
26902690
/**

webfiori/ui/HTMLTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function addColumn(array $data = []) {
8686
* stripped off. If the array has fewer elements than number of columns, the
8787
* method will add empty cells for remaining places.
8888
*/
89-
public function addRow($arrOrRowObj) {
89+
public function addRow(TableRow|array $arrOrRowObj) {
9090
if ($arrOrRowObj instanceof TableRow) {
9191
$this->addChild($arrOrRowObj);
9292
} else if (gettype($arrOrRowObj) == 'array') {

webfiori/ui/HeadNode.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ public function hasMeta(string $name) : bool {
888888
*
889889
* @since 1.0
890890
*/
891-
public function setBase(string $url = null) : HeadNode {
891+
public function setBase(?string $url = '') : HeadNode {
892892
if ($url === null && $this->hasChild($this->baseNode)) {
893893
$this->removeChild($this->baseNode);
894894
$this->baseNode->removeAttribute('href');
@@ -922,7 +922,7 @@ public function setBase(string $url = null) : HeadNode {
922922
*
923923
* @since 1.0
924924
*/
925-
public function setCanonical(string $link = null) : HeadNode {
925+
public function setCanonical(?string $link = '') : HeadNode {
926926
if ($link === null && $this->hasChild($this->canonical)) {
927927
$this->removeChild($this->canonical);
928928
$this->canonical->removeAttribute('href');
@@ -965,7 +965,7 @@ public function setCanonical(string $link = null) : HeadNode {
965965
*
966966
* @since 1.1.4
967967
*/
968-
public function setCharSet(string $charset = null) : HeadNode {
968+
public function setCharSet(?string $charset = '') : HeadNode {
969969
if ($charset === null && $this->hasChild($this->metaCharset)) {
970970
$this->removeChild($this->metaCharset);
971971
$this->metaCharset->removeAttribute('charset');
@@ -1004,7 +1004,7 @@ public function setCharSet(string $charset = null) : HeadNode {
10041004
*
10051005
* @since 1.0
10061006
*/
1007-
public function setPageTitle(string $title = null) : HeadNode {
1007+
public function setPageTitle(string|null $title = null) : HeadNode {
10081008
if ($title === null && $this->hasChild($this->titleNode)) {
10091009
$this->removeChild($this->titleNode);
10101010
$this->titleNode->children()->get(0)->setText('');

webfiori/ui/Input.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,8 @@ public function setNodeName(string $name) : bool {
422422
* @return Input The method will return the instance at which the method
423423
* is called on.
424424
*/
425-
public function setPlaceholder(string $text = null): Input {
426-
if ($text !== null) {
425+
public function setPlaceholder(?string $text = ''): Input {
426+
if ($text !== null && strlen($text) != 0) {
427427
$iType = $this->getType();
428428

429429
if ($iType == 'password' ||

webfiori/ui/JsCode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function addCode(string $jsCode) {
5454
*
5555
* @since 1.0
5656
*/
57-
public function setAttribute(string $name, $val = null) : HTMLNode {
57+
public function setAttribute(string $name, mixed $val = '') : HTMLNode {
5858
if ($name != 'type') {
5959
return parent::setAttribute($name, $val);
6060
}

webfiori/ui/ListItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ListItem extends HTMLNode {
2828
*
2929
* @since 1.0
3030
*/
31-
public function __construct($listItemBody = null) {
31+
public function __construct(null|string|HTMLNode $listItemBody = '') {
3232
parent::__construct('li');
3333
$this->addChild($listItemBody);
3434
}

0 commit comments

Comments
 (0)