Updates and fixes from phan/phpstan runs
This commit is contained in:
@@ -483,7 +483,8 @@ final class CoreLibsTemplateHtmlBuilderElementTest extends TestCase
|
|||||||
// if we set invalid tag
|
// if we set invalid tag
|
||||||
$el = new Element('div');
|
$el = new Element('div');
|
||||||
$this->expectException(HtmlBuilderExcpetion::class);
|
$this->expectException(HtmlBuilderExcpetion::class);
|
||||||
$this->expectExceptionMessage("Invalid or empty tag");
|
$this->expectExceptionMessageMatches("/^Invalid or empty tag: /");
|
||||||
|
$this->expectExceptionMessage("Invalid or empty tag: 123123");
|
||||||
$el->setTag('123123');
|
$el->setTag('123123');
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
Error::hasError(),
|
Error::hasError(),
|
||||||
|
|||||||
@@ -117,7 +117,9 @@ try {
|
|||||||
$el_er = new Element('');
|
$el_er = new Element('');
|
||||||
} catch (HtmlBuilderExcpetion $e) {
|
} catch (HtmlBuilderExcpetion $e) {
|
||||||
print "E: " . $e->getMessage() . " | " . $e->getTraceAsString() . "<br>";
|
print "E: " . $e->getMessage() . " | " . $e->getTraceAsString() . "<br>";
|
||||||
print "E: " . $e->getPrevious()->getMessage() . " | " . $e->getPrevious()->getTraceAsString() . "<br>";
|
if ($e->getPrevious() !== null) {
|
||||||
|
print "E: " . $e->getPrevious()->getMessage() . " | " . $e->getPrevious()->getTraceAsString() . "<br>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print "Errors: <pre>" . print_r(Error::getMessages(), true) . "</pre>";
|
print "Errors: <pre>" . print_r(Error::getMessages(), true) . "</pre>";
|
||||||
print "Warning: " . Support::printToString(Error::hasWarning()) . "<br>";
|
print "Warning: " . Support::printToString(Error::hasWarning()) . "<br>";
|
||||||
@@ -127,7 +129,9 @@ try {
|
|||||||
$el_er = new Element('123123');
|
$el_er = new Element('123123');
|
||||||
} catch (HtmlBuilderExcpetion $e) {
|
} catch (HtmlBuilderExcpetion $e) {
|
||||||
print "E: " . $e->getMessage() . " | " . $e->getTraceAsString() . "<br>";
|
print "E: " . $e->getMessage() . " | " . $e->getTraceAsString() . "<br>";
|
||||||
print "E: " . $e->getPrevious()->getMessage() . " | " . $e->getPrevious()->getTraceAsString() . "<br>";
|
if ($e->getPrevious() !== null) {
|
||||||
|
print "E: " . $e->getPrevious()->getMessage() . " | " . $e->getPrevious()->getTraceAsString() . "<br>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print "Errors: <pre>" . print_r(Error::getMessages(), true) . "</pre>";
|
print "Errors: <pre>" . print_r(Error::getMessages(), true) . "</pre>";
|
||||||
print "Warning: " . Support::printToString(Error::hasWarning()) . "<br>";
|
print "Warning: " . Support::printToString(Error::hasWarning()) . "<br>";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?php
|
<?php // phpcs:disable Generic.Files.LineLength
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AUTOR: Clemens Schwaighofer
|
* AUTOR: Clemens Schwaighofer
|
||||||
@@ -26,6 +26,7 @@ class Block
|
|||||||
* @param string $content
|
* @param string $content
|
||||||
* @param array<string> $css,
|
* @param array<string> $css,
|
||||||
* @param array<string,string> $options
|
* @param array<string,string> $options
|
||||||
|
* @return array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}
|
||||||
* @throws HtmlBuilderExcpetion
|
* @throws HtmlBuilderExcpetion
|
||||||
*/
|
*/
|
||||||
public static function cel(
|
public static function cel(
|
||||||
@@ -58,10 +59,10 @@ class Block
|
|||||||
* Search element tree for id and add
|
* Search element tree for id and add
|
||||||
* if id is empty add at current
|
* if id is empty add at current
|
||||||
*
|
*
|
||||||
* @param array<mixed> $base
|
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $base
|
||||||
* @param array<mixed> $attach
|
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $attach
|
||||||
* @param string $id
|
* @param string $id
|
||||||
* @return array<mixed>
|
* @return array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}
|
||||||
*/
|
*/
|
||||||
public static function ael(
|
public static function ael(
|
||||||
array $base,
|
array $base,
|
||||||
@@ -87,9 +88,9 @@ class Block
|
|||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @param array<mixed> $base
|
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $base
|
||||||
* @param array<mixed> ...$attach
|
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} ...$attach
|
||||||
* @return array<mixed>
|
* @return array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}
|
||||||
*/
|
*/
|
||||||
public static function aelx(
|
public static function aelx(
|
||||||
array $base,
|
array $base,
|
||||||
@@ -102,9 +103,9 @@ class Block
|
|||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @param array<mixed> $element
|
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $element
|
||||||
* @param array<mixed> $sub
|
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $sub
|
||||||
* @return array<mixed>
|
* @return array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}
|
||||||
*/
|
*/
|
||||||
public static function addSub(array $element, array ...$sub): array
|
public static function addSub(array $element, array ...$sub): array
|
||||||
{
|
{
|
||||||
@@ -118,10 +119,10 @@ class Block
|
|||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @param array<mixed> $element
|
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $element
|
||||||
* @return array<mixed>
|
* @return array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}
|
||||||
*/
|
*/
|
||||||
public static function resetSub(array $elment): array
|
public static function resetSub(array $element): array
|
||||||
{
|
{
|
||||||
$element['sub'] = [];
|
$element['sub'] = [];
|
||||||
return $element;
|
return $element;
|
||||||
@@ -132,9 +133,9 @@ class Block
|
|||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @param array<mixed> $element
|
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $element
|
||||||
* @param string ...$css
|
* @param string ...$css
|
||||||
* @return array<mixed>
|
* @return array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}
|
||||||
*/
|
*/
|
||||||
public static function acssel(array $element, string ...$css): array
|
public static function acssel(array $element, string ...$css): array
|
||||||
{
|
{
|
||||||
@@ -145,8 +146,9 @@ class Block
|
|||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
|
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $element
|
||||||
* @param string ...$css
|
* @param string ...$css
|
||||||
* @return array<mixed>
|
* @return array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}
|
||||||
*/
|
*/
|
||||||
public static function rcssel(array $element, string ...$css): array
|
public static function rcssel(array $element, string ...$css): array
|
||||||
{
|
{
|
||||||
@@ -159,10 +161,10 @@ class Block
|
|||||||
* scssel (switch) is not supported
|
* scssel (switch) is not supported
|
||||||
* use rcssel -> acssel
|
* use rcssel -> acssel
|
||||||
*
|
*
|
||||||
* @param array $element
|
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $element
|
||||||
* @param array $rcss
|
* @param array<string> $rcss
|
||||||
* @param array $acss
|
* @param array<string> $acss
|
||||||
* @return array
|
* @return array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}
|
||||||
*/
|
*/
|
||||||
public static function scssel(array $element, array $rcss, array $acss): array
|
public static function scssel(array $element, array $rcss, array $acss): array
|
||||||
{
|
{
|
||||||
@@ -176,7 +178,7 @@ class Block
|
|||||||
* Undocumented function
|
* Undocumented function
|
||||||
* alias phfo
|
* alias phfo
|
||||||
*
|
*
|
||||||
* @param array<mixed> $tree
|
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $tree
|
||||||
* @param bool $add_nl [default=false]
|
* @param bool $add_nl [default=false]
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -232,14 +234,15 @@ class Block
|
|||||||
* Undocumented function
|
* Undocumented function
|
||||||
* alias phfa
|
* alias phfa
|
||||||
*
|
*
|
||||||
* @param array<mixed> $list
|
* @param array<array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}> $list
|
||||||
|
* @param bool $add_nl [default=false]
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function buildHtmlFromList(array $list): string
|
public static function buildHtmlFromList(array $list, bool $add_nl = false): string
|
||||||
{
|
{
|
||||||
$output = '';
|
$output = '';
|
||||||
foreach ($list as $el) {
|
foreach ($list as $el) {
|
||||||
$output .= self::buildHtml($el);
|
$output .= self::buildHtml($el, $add_nl);
|
||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
@@ -248,7 +251,7 @@ class Block
|
|||||||
* Undocumented function
|
* Undocumented function
|
||||||
* wrapper for buildHtmlFromList
|
* wrapper for buildHtmlFromList
|
||||||
*
|
*
|
||||||
* @param array<Element> $list array of Elements to build string from
|
* @param array<array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}> $list array of Elements to build string from
|
||||||
* @param bool $add_nl [default=false] Optional output string line break
|
* @param bool $add_nl [default=false] Optional output string line break
|
||||||
* @return string build html as string
|
* @return string build html as string
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class Element
|
|||||||
'invalid or empty tag',
|
'invalid or empty tag',
|
||||||
['tag' => $tag]
|
['tag' => $tag]
|
||||||
);
|
);
|
||||||
throw new HtmlBuilderExcpetion('Invalid or empty tag');
|
throw new HtmlBuilderExcpetion('Invalid or empty tag: ' . $tag);
|
||||||
}
|
}
|
||||||
$this->tag = $tag;
|
$this->tag = $tag;
|
||||||
}
|
}
|
||||||
@@ -297,7 +297,9 @@ class Element
|
|||||||
}
|
}
|
||||||
// only on first level
|
// only on first level
|
||||||
foreach ($this->sub as $pos => $el) {
|
foreach ($this->sub as $pos => $el) {
|
||||||
if ($el['id'] === $id) {
|
if (
|
||||||
|
$el->getId() === $id
|
||||||
|
) {
|
||||||
unset($this->sub[$pos]);
|
unset($this->sub[$pos]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -525,10 +527,10 @@ class Element
|
|||||||
* not recommended to be used, rather use "Element->buildHtml()"
|
* not recommended to be used, rather use "Element->buildHtml()"
|
||||||
* wrapper for buildHtml
|
* wrapper for buildHtml
|
||||||
*
|
*
|
||||||
* @param Element $element Element tree to build
|
* @param ?Element $tree Element tree to build
|
||||||
* if not set returns empty string
|
* if not set returns empty string
|
||||||
* @param bool $add_nl [default=false] Optional output string line break
|
* @param bool $add_nl [default=false] Optional output string line break
|
||||||
* @return string build html as string
|
* @return string build html as string
|
||||||
* @deprecated Do not use, use Element->buildHtml() instead
|
* @deprecated Do not use, use Element->buildHtml() instead
|
||||||
*/
|
*/
|
||||||
public static function printHtmlFromObject(Element $tree = null, bool $add_nl = false): string
|
public static function printHtmlFromObject(Element $tree = null, bool $add_nl = false): string
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace CoreLibs\Template\HtmlBuilder\General;
|
|||||||
|
|
||||||
class Error
|
class Error
|
||||||
{
|
{
|
||||||
/** @var array{level:string,id:string,message:string,context:array<mixed>} */
|
/** @var array<array{level:string,id:string,message:string,context:array<mixed>}> */
|
||||||
private static array $messages = [];
|
private static array $messages = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,7 +22,7 @@ class Error
|
|||||||
* @param string $level
|
* @param string $level
|
||||||
* @param string $id
|
* @param string $id
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array<mixed> $context
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function writeContent(
|
private static function writeContent(
|
||||||
@@ -98,7 +98,7 @@ class Error
|
|||||||
return array_filter(
|
return array_filter(
|
||||||
self::$messages,
|
self::$messages,
|
||||||
function ($var) use ($level) {
|
function ($var) use ($level) {
|
||||||
return ($var['level'] ?? '') == $level ? true : false;
|
return $var['level'] == $level ? true : false;
|
||||||
}
|
}
|
||||||
) === [] ? false : true;
|
) === [] ? false : true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace CoreLibs\Template\HtmlBuilder\General;
|
|||||||
|
|
||||||
class Settings
|
class Settings
|
||||||
{
|
{
|
||||||
/** @var array>string> list of html elements that can have the name tag */
|
/** @var array<string> list of html elements that can have the name tag */
|
||||||
public const NAME_ELEMENTS = [
|
public const NAME_ELEMENTS = [
|
||||||
'button',
|
'button',
|
||||||
'fieldset',
|
'fieldset',
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class StringReplace
|
|||||||
* index must be non empty (but has no fixed format)
|
* index must be non empty (but has no fixed format)
|
||||||
* if same index is tried twice it will set an error and skip
|
* if same index is tried twice it will set an error and skip
|
||||||
*
|
*
|
||||||
* @param array<string,string> ...$element Elements to load
|
* @param array{0:string,1:string} ...$element Elements to load
|
||||||
* @return void
|
* @return void
|
||||||
* @throws HtmlBuilderExcpetion
|
* @throws HtmlBuilderExcpetion
|
||||||
*/
|
*/
|
||||||
@@ -138,32 +138,27 @@ class StringReplace
|
|||||||
*
|
*
|
||||||
* @param string $index index of set element
|
* @param string $index index of set element
|
||||||
* @param array<string,string> $replace array of text to search (key) and replace (value) for
|
* @param array<string,string> $replace array of text to search (key) and replace (value) for
|
||||||
* @return string|false
|
* @return string
|
||||||
|
* @throws HtmlBuilderExcpetion
|
||||||
*/
|
*/
|
||||||
public static function buildElement(
|
public static function buildElement(
|
||||||
string $index,
|
string $index,
|
||||||
array $replace,
|
array $replace,
|
||||||
string $replace_index = ''
|
string $replace_index = ''
|
||||||
): string|bool {
|
): string {
|
||||||
if (self::getElement($index) === false) {
|
try {
|
||||||
return false;
|
self::getElement($index);
|
||||||
|
} catch (HtmlBuilderExcpetion $e) {
|
||||||
|
throw new HtmlBuilderExcpetion('Cannot fetch element with index: ' . $index, 0, $e);
|
||||||
}
|
}
|
||||||
if ($replace_index) {
|
if ($replace_index) {
|
||||||
self::setReplaceBlock(
|
self::setReplaceBlock(
|
||||||
$replace_index,
|
$replace_index,
|
||||||
self::replaceData(
|
self::replaceData(self::$elements[$index], $replace)
|
||||||
self::$elements[$index],
|
|
||||||
array_keys($replace),
|
|
||||||
array_values($replace)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
return self::getReplaceBlock($replace_index);
|
return self::getReplaceBlock($replace_index);
|
||||||
} else {
|
} else {
|
||||||
return self::replaceData(
|
return self::replaceData(self::$elements[$index], $replace);
|
||||||
self::$elements[$index],
|
|
||||||
array_keys($replace),
|
|
||||||
array_values($replace)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,9 +175,9 @@ class StringReplace
|
|||||||
*/
|
*/
|
||||||
public static function replaceData(string $data, array $replace): string
|
public static function replaceData(string $data, array $replace): string
|
||||||
{
|
{
|
||||||
$replace = array_keys($replace);
|
$to_replace = array_keys($replace);
|
||||||
// all replace data must have {} around
|
// all replace data must have {} around
|
||||||
array_walk($replace, function (&$entry) {
|
array_walk($to_replace, function (&$entry) {
|
||||||
if (!str_starts_with($entry, '{')) {
|
if (!str_starts_with($entry, '{')) {
|
||||||
$entry = '{' . $entry;
|
$entry = '{' . $entry;
|
||||||
}
|
}
|
||||||
@@ -192,7 +187,7 @@ class StringReplace
|
|||||||
// do some validation?
|
// do some validation?
|
||||||
});
|
});
|
||||||
// replace content
|
// replace content
|
||||||
return str_replace($replace, array_values($replace), $data);
|
return str_replace($to_replace, array_values($replace), $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user