diff --git a/phpunit.xml b/phpunit.xml index aaef098e..7d29e7e3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,8 +1,15 @@ + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" + cacheDirectory=".phpunit.cache" + displayDetailsOnTestsThatTriggerDeprecations="true" + displayDetailsOnTestsThatTriggerWarnings="true" + displayDetailsOnSkippedTests="true" + displayDetailsOnIncompleteTests="true" + displayDetailsOnTestsThatTriggerErrors="true" + displayDetailsOnTestsThatTriggerNotices="true" +> @@ -16,7 +23,7 @@ - src/ + src/ diff --git a/rector.php b/rector.php index e7c21271..e61135b6 100644 --- a/rector.php +++ b/rector.php @@ -8,6 +8,7 @@ use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector; +use Rector\Php81\Rector\Array_\FirstClassCallableRector; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; @@ -26,6 +27,7 @@ $rectorConfig->skip([ StringClassNameToClassConstantRector::class, JsonThrowOnErrorRector::class, + FirstClassCallableRector::class, ]); // define sets of rules diff --git a/src/Context.php b/src/Context.php index 08ab3e11..da790811 100644 --- a/src/Context.php +++ b/src/Context.php @@ -401,7 +401,7 @@ private static function pathError(mixed $base, string $path, string $current, ?s * * @throws Exception\VariableNotFoundException */ - public static function path($base, string $path, bool $nothrow = null): mixed + public static function path(mixed $base, string $path, bool $nothrow = null): mixed { if ($base === null) { if ($nothrow) { diff --git a/src/Dom/Attr.php b/src/Dom/Attr.php index 11ff2d70..01fef5db 100644 --- a/src/Dom/Attr.php +++ b/src/Dom/Attr.php @@ -28,14 +28,10 @@ class Attr /** * attribute's value can be overriden with a variable - * @var string|null */ - private $phpVariable; + private ?string $phpVariable = null; - /** - * @var int - */ - private $replacedState = 0; + private int $replacedState = 0; /** * @param string $qualified_name attribute name with prefix @@ -43,7 +39,7 @@ class Attr * @param string $value_escaped value with HTML-escaping * @param string $encoding character encoding used by the value */ - public function __construct(private string $qualified_name, private string $namespace_uri, private ?string $value_escaped, private string $encoding) + public function __construct(private readonly string $qualified_name, private readonly string $namespace_uri, private ?string $value_escaped, private readonly string $encoding) { } diff --git a/src/Dom/Defs.php b/src/Dom/Defs.php index 461856c4..f94ba855 100644 --- a/src/Dom/Defs.php +++ b/src/Dom/Defs.php @@ -36,22 +36,19 @@ */ class Defs { - /** - * @var Defs|null - */ - private static $instance; + private static ?\PhpTal\Dom\Defs $instance = null; /** * list of \PhpTal\TalNamespace objects * * @var array */ - private $namespaces_by_uri = []; + private array $namespaces_by_uri = []; /** * @var array */ - private $prefix_to_uri = [ + private array $prefix_to_uri = [ 'xml' => Builtin::NS_XML, 'xmlns' => Builtin::NS_XMLNS, ]; @@ -65,7 +62,7 @@ class Defs * * @var array */ - private static $XHTML_EMPTY_TAGS = [ + private static array $XHTML_EMPTY_TAGS = [ 'area', 'base', 'basefont', @@ -93,7 +90,7 @@ class Defs * * @var array */ - private static $XHTML_BOOLEAN_ATTRIBUTES = [ + private static array $XHTML_BOOLEAN_ATTRIBUTES = [ 'autoplay', 'async', 'autofocus', @@ -215,9 +212,6 @@ public function isCDATAElementInHTML(string $namespace_uri, string $local_name): * * Examples of valid attributes: tal:content, metal:use-slot * Examples of invalid attributes: tal:unknown, metal:content - * - * @param string $namespace_uri - * @param string $local_name */ public function isValidAttributeNS(string $namespace_uri, string $local_name): bool { @@ -244,9 +238,6 @@ public function isHandledNamespace(string $namespace_uri): bool * declaration. * * Examples of handled xmlns: xmlns:tal, xmlns:metal - * - * @param string $qname - * @param string $value */ public function isHandledXmlNs(string $qname, string $value): bool { diff --git a/src/Dom/Element.php b/src/Dom/Element.php index bdef1045..e79e16ff 100644 --- a/src/Dom/Element.php +++ b/src/Dom/Element.php @@ -350,8 +350,6 @@ public function getAttributeNode(string $qname): ?Attr * If possible, use getAttributeNodeNS and setAttributeNS. * * NB: This method doesn't handle namespaces properly. - * - * @param string $qname */ public function getOrCreateAttributeNode(string $qname): Attr { diff --git a/src/Dom/Node.php b/src/Dom/Node.php index b32ae73d..59578b85 100644 --- a/src/Dom/Node.php +++ b/src/Dom/Node.php @@ -30,20 +30,14 @@ abstract class Node implements Stringable */ public $parentNode; - /** - * @var string - */ - private $source_file; + private ?string $source_file = null; - /** - * @var int - */ - private $source_line; + private ?int $source_line = null; /** * Node constructor. */ - public function __construct(private string $value_escaped, private string $encoding) + public function __construct(private string $value_escaped, private readonly string $encoding) { } diff --git a/src/Dom/PHPTALDocumentBuilder.php b/src/Dom/PHPTALDocumentBuilder.php index 5b7de96e..ac7d67f7 100644 --- a/src/Dom/PHPTALDocumentBuilder.php +++ b/src/Dom/PHPTALDocumentBuilder.php @@ -31,10 +31,7 @@ class PHPTALDocumentBuilder extends DocumentBuilder */ private $xmlns; - /** - * @var string - */ - private $encoding; + private ?string $encoding = null; private ?Element $documentElement = null; diff --git a/src/Dom/SaxXmlParser.php b/src/Dom/SaxXmlParser.php index e3a23e46..3da29290 100644 --- a/src/Dom/SaxXmlParser.php +++ b/src/Dom/SaxXmlParser.php @@ -80,21 +80,15 @@ class SaxXmlParser self::ST_ATTR_VALUE => 'unquoted attribute value', ]; - /** - * @var string - */ - private $file; + private string $file; - /** - * @var int - */ - private $line; + private ?int $line = null; /** * SaxXmlParser constructor. */ - public function __construct(private string $input_encoding) + public function __construct(private readonly string $input_encoding) { $this->file = ''; } @@ -422,7 +416,7 @@ private function checkEncoding(string $str): string if (strlen($str) > 200) { $chunks = preg_split('/(?>[\x09\x0A\x0D\x20-\x7F]+)/', $str, -1, PREG_SPLIT_NO_EMPTY); foreach ($chunks as $chunk) { - if (strlen((string) $chunk) < 200) { + if (strlen($chunk) < 200) { $this->checkEncoding($chunk); } } diff --git a/src/Exception/TemplateException.php b/src/Exception/TemplateException.php index e70eb6a3..136a4add 100644 --- a/src/Exception/TemplateException.php +++ b/src/Exception/TemplateException.php @@ -35,10 +35,7 @@ class TemplateException extends PhpTalException implements Stringable */ public $srcLine; - /** - * @var bool - */ - private $is_src_accurate; + private ?bool $is_src_accurate = null; /** * Construct the exception. Note: The message is NOT binary safe. diff --git a/src/Exception/UnknownModifierException.php b/src/Exception/UnknownModifierException.php index bc3c59a6..5da5d2fe 100644 --- a/src/Exception/UnknownModifierException.php +++ b/src/Exception/UnknownModifierException.php @@ -25,7 +25,7 @@ class UnknownModifierException extends TemplateException * UnknownModifierException constructor. * @param string $modifier_name */ - public function __construct(string $msg, private ?string $modifier_name = null) + public function __construct(string $msg, private readonly ?string $modifier_name = null) { parent::__construct($msg); } diff --git a/src/ExceptionHandler.php b/src/ExceptionHandler.php index c7003f9d..1f0f317d 100644 --- a/src/ExceptionHandler.php +++ b/src/ExceptionHandler.php @@ -23,7 +23,7 @@ class ExceptionHandler /** * ExceptionHandler constructor. */ - public function __construct(private string $encoding) + public function __construct(private readonly string $encoding) { } @@ -34,7 +34,6 @@ public function __construct(private string $encoding) * Doesn't change exception handler if non-default one is set. * * @param Throwable $e exception to re-throw and display - * @param string $encoding * * @throws TemplateException * @throws Throwable diff --git a/src/FileSource.php b/src/FileSource.php index 8470e446..da4857cd 100644 --- a/src/FileSource.php +++ b/src/FileSource.php @@ -23,7 +23,7 @@ */ class FileSource implements SourceInterface { - private string $path; + private readonly string $path; /** * @throws Exception\IOException diff --git a/src/FileSourceResolver.php b/src/FileSourceResolver.php index d4fc31a5..34db51a2 100644 --- a/src/FileSourceResolver.php +++ b/src/FileSourceResolver.php @@ -24,7 +24,7 @@ class FileSourceResolver implements SourceResolverInterface * FileSourceResolver constructor. * @param array $repositories */ - public function __construct(private array $repositories) + public function __construct(private readonly array $repositories) { } diff --git a/src/FilterInterface.php b/src/FilterInterface.php index b0a1098f..df40b54a 100644 --- a/src/FilterInterface.php +++ b/src/FilterInterface.php @@ -27,8 +27,6 @@ interface FilterInterface * * In postfilter template output is passed to this method, and final output goes to the browser. * TAL or PHP tags won't be executed. Postfilters should be fast. - * - * @param string $str */ public function filter(string $str): string; } diff --git a/src/GetTextTranslator.php b/src/GetTextTranslator.php index 10f2fd7b..a3439ce5 100644 --- a/src/GetTextTranslator.php +++ b/src/GetTextTranslator.php @@ -33,17 +33,11 @@ class GetTextTranslator implements TranslationServiceInterface /** * @var array */ - private $vars = []; + private array $vars = []; - /** - * @var string - */ - private $currentDomain; + private ?string $currentDomain = null; - /** - * @var string - */ - private $encoding = 'UTF-8'; + private string $encoding = 'UTF-8'; /** * GetTextTranslator constructor. @@ -118,7 +112,6 @@ private function trySettingLanguages(int $category, array $langs): ?string * * Encoding must be set before calling addDomain! * - * @param string $domain * @param string $path */ public function addDomain(string $domain, ?string $path = null): void diff --git a/src/Helper.php b/src/Helper.php index 407b5884..55f90d69 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -18,7 +18,7 @@ class Helper * @param mixed $var value to check * @access private */ - public static function phptal_isempty($var): bool + public static function phptal_isempty(mixed $var): bool { return in_array($var, [null, false, ''], true) || ((is_countable($var)) && count($var) === 0); @@ -30,7 +30,7 @@ public static function phptal_isempty($var): bool * @param mixed $var value to check * @access private */ - public static function phptal_true($var): bool + public static function phptal_true(mixed $var): bool { $var = static::phptal_unravel_closure($var); return $var && (!$var instanceof Countable || count($var)); @@ -41,10 +41,9 @@ public static function phptal_true($var): bool * * @access private * - * @param mixed $var * @param string $encoding */ - public static function phptal_escape($var, $encoding): string + public static function phptal_escape(mixed $var, $encoding): string { if (is_string($var)) { return htmlspecialchars($var, ENT_QUOTES, $encoding); @@ -56,10 +55,8 @@ public static function phptal_escape($var, $encoding): string * convert anything to string * * @access private - * - * @param mixed $var */ - public static function phptal_tostring($var): string + public static function phptal_tostring(mixed $var): string { if (is_string($var)) { return $var; @@ -93,10 +90,9 @@ public static function phptal_tostring($var): string * * This function has no effect on non-Closure expressions * - * @param mixed $var * @return mixed */ - public static function phptal_unravel_closure($var) + public static function phptal_unravel_closure(mixed $var) { while (is_object($var) && is_callable($var)) { $var = $var(); diff --git a/src/PHPTAL.php b/src/PHPTAL.php index db120d12..c5021db5 100644 --- a/src/PHPTAL.php +++ b/src/PHPTAL.php @@ -176,15 +176,10 @@ class PHPTAL implements PhpTalInterface /** * directory where code cache is - * - * @var string */ - private $phpCodeDestination; + private string $phpCodeDestination; - /** - * @var string - */ - private $phpCodeExtension = 'php'; + private string $phpCodeExtension = 'php'; /** * number of days @@ -195,10 +190,8 @@ class PHPTAL implements PhpTalInterface /** * 1/x - * - * @var int */ - private $cachePurgeFrequency = 30; + private int $cachePurgeFrequency = 30; /** * speeds up calls to external templates @@ -207,10 +200,7 @@ class PHPTAL implements PhpTalInterface */ private $externalMacroTemplatesCache = []; - /** - * @var int - */ - private $subpathRecursionLevel = 0; + private int $subpathRecursionLevel = 0; /** * @param string $path Template file path. @@ -620,12 +610,11 @@ public function getTrigger(string $id): ?TriggerInterface * Use it by setting properties on PHPTAL object. * * @param string $varname - * @param mixed $value * * @return void * @throws InvalidVariableNameException */ - public function __set($varname, $value) + public function __set($varname, mixed $value) { $this->context->set($varname, $value); } @@ -728,7 +717,6 @@ public function echoExecute(): void * * $this is caller's context (the file where execution had originally started) * - * @param string $path * @param PhpTalInterface $local_tpl is PHPTAL instance of the file in which macro is defined * (it will be different from $this if it's external macro call) * diff --git a/src/Php/Attribute.php b/src/Php/Attribute.php index c159dc08..6c66f524 100644 --- a/src/Php/Attribute.php +++ b/src/Php/Attribute.php @@ -82,8 +82,6 @@ public function __construct(Element $phpelement, string $expression) * ... * * $this->doEcho($code); - * - * @param string $expression */ protected function extractEchoType(string $expression): string { diff --git a/src/Php/Attribute/METAL/DefineSlot.php b/src/Php/Attribute/METAL/DefineSlot.php index 514558cd..6e132d69 100644 --- a/src/Php/Attribute/METAL/DefineSlot.php +++ b/src/Php/Attribute/METAL/DefineSlot.php @@ -55,10 +55,7 @@ */ class DefineSlot extends Attribute { - /** - * @var string - */ - private $tmp_var; + private ?string $tmp_var = null; /** * Called before element printing. diff --git a/src/Php/Attribute/METAL/FillSlot.php b/src/Php/Attribute/METAL/FillSlot.php index db50a5b3..0f24694a 100644 --- a/src/Php/Attribute/METAL/FillSlot.php +++ b/src/Php/Attribute/METAL/FillSlot.php @@ -62,15 +62,9 @@ class FillSlot extends Attribute { final public const CALLBACK_THRESHOLD = 10000; - /** - * @var int - */ - private static $uid = 0; + private static int $uid = 0; - /** - * @var string|null - */ - private $function_name; + private ?string $function_name = null; /** * Called before element printing. diff --git a/src/Php/Attribute/METAL/UseMacro.php b/src/Php/Attribute/METAL/UseMacro.php index 33570a63..552bdf98 100644 --- a/src/Php/Attribute/METAL/UseMacro.php +++ b/src/Php/Attribute/METAL/UseMacro.php @@ -122,8 +122,6 @@ public function after(CodeWriter $codewriter): void * we may define a member.html macro which use the design.html macro * for the general layout, fill the menu slot and let caller templates * fill the parent content slot without interfering. - * - * @param CodeWriter $codewriter */ private function pushSlots(CodeWriter $codewriter): void { diff --git a/src/Php/Attribute/PHPTAL/Cache.php b/src/Php/Attribute/PHPTAL/Cache.php index 657cf1e5..1dbfdd95 100644 --- a/src/Php/Attribute/PHPTAL/Cache.php +++ b/src/Php/Attribute/PHPTAL/Cache.php @@ -43,10 +43,7 @@ */ class Cache extends Attribute { - /** - * @var string - */ - private $cache_filename_var; + private ?string $cache_filename_var = null; /** * Called before element printing. diff --git a/src/Php/Attribute/PHPTAL/Debug.php b/src/Php/Attribute/PHPTAL/Debug.php index 5006b26f..5ab226b5 100644 --- a/src/Php/Attribute/PHPTAL/Debug.php +++ b/src/Php/Attribute/PHPTAL/Debug.php @@ -23,10 +23,7 @@ */ class Debug extends Attribute { - /** - * @var bool - */ - private $oldMode; + private ?bool $oldMode = null; /** * Called before element printing. diff --git a/src/Php/Attribute/PHPTAL/Id.php b/src/Php/Attribute/PHPTAL/Id.php index 0578c9d9..3eb5b6ac 100644 --- a/src/Php/Attribute/PHPTAL/Id.php +++ b/src/Php/Attribute/PHPTAL/Id.php @@ -24,10 +24,7 @@ */ class Id extends Attribute { - /** - * @var string - */ - private $var; + private ?string $var = null; /** * Called before element printing. diff --git a/src/Php/Attribute/PHPTAL/Tales.php b/src/Php/Attribute/PHPTAL/Tales.php index eb8714d9..7fb35e7a 100644 --- a/src/Php/Attribute/PHPTAL/Tales.php +++ b/src/Php/Attribute/PHPTAL/Tales.php @@ -24,10 +24,7 @@ */ class Tales extends Attribute { - /** - * @var string - */ - private $oldMode; + private ?string $oldMode = null; /** * Called before element printing. diff --git a/src/Php/Attribute/TAL/Attributes.php b/src/Php/Attribute/TAL/Attributes.php index 8b3a433c..3fd6898a 100644 --- a/src/Php/Attribute/TAL/Attributes.php +++ b/src/Php/Attribute/TAL/Attributes.php @@ -52,7 +52,7 @@ class Attributes extends Attribute implements TalesChainReaderInterface * * @var array */ - private $vars_to_recycle = []; + private array $vars_to_recycle = []; /** * value for default keyword diff --git a/src/Php/Attribute/TAL/Define.php b/src/Php/Attribute/TAL/Define.php index 8afa41ed..27d5769e 100644 --- a/src/Php/Attribute/TAL/Define.php +++ b/src/Php/Attribute/TAL/Define.php @@ -48,15 +48,9 @@ */ class Define extends Attribute implements TalesChainReaderInterface { - /** - * @var string - */ - private $tmp_content_var; + private ?string $tmp_content_var = null; - /** - * @var bool - */ - private $buffered = false; + private bool $buffered = false; /** * @var string @@ -68,16 +62,12 @@ class Define extends Attribute implements TalesChainReaderInterface */ private $defineVar; - /** - * @var bool - */ - private $pushedContext = false; + private bool $pushedContext = false; /** * Prevents generation of invalid PHP code when given invalid TALES - * @var bool */ - private $chainPartGenerated = false; + private bool $chainPartGenerated = false; /** * Called before element printing. diff --git a/src/Php/Attribute/TAL/OmitTag.php b/src/Php/Attribute/TAL/OmitTag.php index 678d8e4c..6e9f8bc8 100644 --- a/src/Php/Attribute/TAL/OmitTag.php +++ b/src/Php/Attribute/TAL/OmitTag.php @@ -54,10 +54,7 @@ */ class OmitTag extends Attribute { - /** - * @var string - */ - private $varname; + private ?string $varname = null; /** * Called before element printing. diff --git a/src/Php/Attribute/TAL/Repeat.php b/src/Php/Attribute/TAL/Repeat.php index 3ea0fb02..ff9bf035 100644 --- a/src/Php/Attribute/TAL/Repeat.php +++ b/src/Php/Attribute/TAL/Repeat.php @@ -76,10 +76,7 @@ */ class Repeat extends Attribute { - /** - * @var string - */ - private $var; + private ?string $var = null; /** * Called before element printing. diff --git a/src/Php/CodeWriter.php b/src/Php/CodeWriter.php index 7c49f63e..ee5968a2 100644 --- a/src/Php/CodeWriter.php +++ b/src/Php/CodeWriter.php @@ -34,21 +34,20 @@ class CodeWriter { /** * max id of variable to give as temp - * @var int */ - private $temp_var_counter = 0; + private int $temp_var_counter = 0; /** * stack with free'd variables * @var string[] */ - private $temp_recycling = []; + private array $temp_recycling = []; /** * keeps track of seen functions for function_exists * @var array */ - private $known_functions = []; + private array $known_functions = []; /** * @var string @@ -78,22 +77,13 @@ class CodeWriter /** * @var array */ - private $contexts = []; + private array $contexts = []; - /** - * @var string - */ - private $functionPrefix = ''; + private string $functionPrefix = ''; - /** - * @var string - */ - private $doctype = ''; + private string $doctype = ''; - /** - * @var string - */ - private $xmldeclaration = ''; + private string $xmldeclaration = ''; /** * CodeWriter constructor. diff --git a/src/Php/State.php b/src/Php/State.php index 95d6e468..9d84bda9 100644 --- a/src/Php/State.php +++ b/src/Php/State.php @@ -26,30 +26,18 @@ */ class State { - /** - * @var bool - */ - private $debug = false; + private bool $debug = false; - /** - * @var string - */ - private $tales_mode = 'tales'; + private string $tales_mode = 'tales'; - /** - * @var string - */ - private $encoding; + private readonly string $encoding; - /** - * @var int - */ - private $output_mode; + private readonly int $output_mode; /** * State constructor. */ - public function __construct(private PhpTalInterface $phptal) + public function __construct(private readonly PhpTalInterface $phptal) { $this->encoding = $phptal->getEncoding(); $this->output_mode = $phptal->getOutputMode(); @@ -169,7 +157,6 @@ private function compileTalesToPHPExpression($expression): string * * It's almost unused. * - * @param string $string * * @throws ParserException * @throws UnknownModifierException diff --git a/src/Php/TalesChainExecutor.php b/src/Php/TalesChainExecutor.php index 951ca483..4658d467 100644 --- a/src/Php/TalesChainExecutor.php +++ b/src/Php/TalesChainExecutor.php @@ -24,15 +24,9 @@ class TalesChainExecutor final public const CHAIN_BREAK = 1; final public const CHAIN_CONT = 2; - /** - * @var int - */ - private $state = 0; + private int $state = 0; - /** - * @var bool - */ - private $chainStarted = false; + private bool $chainStarted = false; /** * @param array $chain diff --git a/src/Php/TalesInternal.php b/src/Php/TalesInternal.php index fa27e5dc..e2cacd8b 100644 --- a/src/Php/TalesInternal.php +++ b/src/Php/TalesInternal.php @@ -59,15 +59,12 @@ class TalesInternal implements TalesInterface final public const DEFAULT_KEYWORD = 'new \PhpTal\DefaultKeyword'; final public const NOTHING_KEYWORD = 'new \PhpTal\NothingKeyword'; - /** - * @var bool - */ - private static $phpModifierAllowed = false; + private static bool $phpModifierAllowed = false; /** * @var array */ - private static $tokenBlacklist = [ + private static array $tokenBlacklist = [ T_CLASS_C, T_FUNC_C, T_METHOD_C, @@ -92,7 +89,7 @@ class TalesInternal implements TalesInterface /** * @var array */ - private static $functionWhitelist = []; + private static array $functionWhitelist = []; /** * @@ -129,8 +126,6 @@ public static function true(string $src): string * not: string:${foo} * not: foo/bar/booleancomparable * - * @param string $expression - * @param bool $nothrow * * @throws ParserException * @throws UnknownModifierException @@ -294,7 +289,6 @@ private static function checkExpressionPart(string $expression): int * string:hello, ${user/name} * string:you have $$130 in your bank account * - * @param string $expression * @param bool $nothrow * * @throws ParserException @@ -433,7 +427,6 @@ public static function parseString(string $expression, bool $nothrow, string $ta * * Transform the expression into a regular PHP expression. * - * @param string $src * * @throws ParserException * @throws PhpNotAllowedException @@ -456,7 +449,6 @@ public static function php(string $src): string * * Returns the code required to invoke Context::exists() on specified path. * - * @param string $src * * @throws ParserException * @throws UnknownModifierException @@ -476,7 +468,6 @@ public static function exists(string $src): string * * Returns the number as is. * - * @param string $src * * @throws ParserException */ diff --git a/src/Php/Transformer.php b/src/Php/Transformer.php index 1492ba78..e5b53b4a 100644 --- a/src/Php/Transformer.php +++ b/src/Php/Transformer.php @@ -52,7 +52,7 @@ class Transformer /** * @var array */ - private static $TranslationTable = [ + private static array $TranslationTable = [ 'not' => '!', 'ne' => '!=', 'and' => '&&', diff --git a/src/PhpTalInterface.php b/src/PhpTalInterface.php index 10ff6d1e..1238e26d 100644 --- a/src/PhpTalInterface.php +++ b/src/PhpTalInterface.php @@ -245,7 +245,6 @@ public function echoExecute(): void; * * $this is caller's context (the file where execution had originally started) * - * @param string $path * @param PhpTalInterface $local_tpl is PHPTAL instance of the file in which macro is defined * (it will be different from $this if it's external macro call) */ diff --git a/src/PreFilter/Compress.php b/src/PreFilter/Compress.php index f904a6a1..820dceab 100644 --- a/src/PreFilter/Compress.php +++ b/src/PreFilter/Compress.php @@ -32,23 +32,19 @@ class Compress extends Normalize /** * keeps track whether last element had trailing whitespace (or didn't need it). * If had_space==false, next element must keep leading space. - * - * @var bool */ - private $had_space = false; + private bool $had_space = false; /** * last text node before closing tag that may need trailing whitespace trimmed. * It's often last-child, but comments, multiple end tags make that trickier. - * - * @var Text|null */ - private $most_recent_text_node; + private ?Text $most_recent_text_node = null; /** * @var array */ - private static $no_interelement_space = [ + private static array $no_interelement_space = [ 'html', 'head', 'table', @@ -68,7 +64,7 @@ class Compress extends Normalize * * @var array */ - private static $breaks_line = [ + private static array $breaks_line = [ 'address', 'article', 'aside', @@ -122,7 +118,7 @@ class Compress extends Normalize * * @var array */ - private static $inline_blocks = [ + private static array $inline_blocks = [ 'select', 'input', 'button', @@ -138,7 +134,7 @@ class Compress extends Normalize * * @var array */ - private static $attributes_order = [ + private static array $attributes_order = [ 'href', 'src', 'class', diff --git a/src/PreFilter/StripComments.php b/src/PreFilter/StripComments.php index b5efe993..219379fd 100644 --- a/src/PreFilter/StripComments.php +++ b/src/PreFilter/StripComments.php @@ -29,7 +29,6 @@ class StripComments extends PreFilter * * Default implementation does nothing. Override it. * - * @param Element $root * * @throws PhpTalException * @see Element class for methods and fields available. diff --git a/src/RepeatController.php b/src/RepeatController.php index 3edb4176..96dc27d8 100644 --- a/src/RepeatController.php +++ b/src/RepeatController.php @@ -57,20 +57,11 @@ class RepeatController implements Iterator */ private $current; - /** - * @var bool - */ - private $valid; + private ?bool $valid = null; - /** - * @var bool - */ - private $validOnNext; + private ?bool $validOnNext = null; - /** - * @var bool - */ - private $uses_groups = false; + private bool $uses_groups = false; /** * @var Iterator @@ -92,10 +83,7 @@ class RepeatController implements Iterator */ private $length; - /** - * @var RepeatControllerGroups - */ - private $groups; + private ?RepeatControllerGroups $groups = null; /** * Construct a new RepeatController. @@ -104,7 +92,7 @@ class RepeatController implements Iterator * * @todo welcome to hell, I'll be your guide */ - public function __construct($source) + public function __construct(mixed $source) { if (is_string($source)) { $this->iterator = new ArrayIterator(str_split($source)); // FIXME: invalid for UTF-8 encoding, use preg_match_all('/./u') trick diff --git a/src/RepeatControllerGroups.php b/src/RepeatControllerGroups.php index 0e3ffc5a..2e25e22d 100644 --- a/src/RepeatControllerGroups.php +++ b/src/RepeatControllerGroups.php @@ -73,7 +73,7 @@ public function reset(): void * * @todo cleanup this abomination of type abuse */ - public function first($data) + public function first(mixed $data) { if (!is_array($data) && !is_object($data) && $data !== null) { if (!isset($this->cache['F'])) { @@ -108,7 +108,7 @@ public function first($data) * * @todo cleanup this abomination of type abuse */ - public function last($data) + public function last(mixed $data) { if (!is_array($data) && !is_object($data) && $data !== null) { if (!isset($this->cache['L'])) { diff --git a/src/StringSource.php b/src/StringSource.php index e439d109..843b4192 100644 --- a/src/StringSource.php +++ b/src/StringSource.php @@ -23,10 +23,10 @@ class StringSource implements SourceInterface { final public const NO_PATH_PREFIX = 'realpath = $realpath ?? self::NO_PATH_PREFIX . md5($data) . '>'; diff --git a/src/TalNamespace.php b/src/TalNamespace.php index b5c1f617..bd331e30 100644 --- a/src/TalNamespace.php +++ b/src/TalNamespace.php @@ -24,15 +24,9 @@ */ abstract class TalNamespace { - /** - * @var string - */ - private $prefix; + private readonly string $prefix; - /** - * @var string - */ - private $namespace_uri; + private readonly string $namespace_uri; /** * @var array @@ -90,13 +84,10 @@ public function getAttributes(): array return $this->attributes; } - /** - * @param mixed $expression - * - */ + abstract public function createAttributeHandler( TalNamespaceAttribute $att, Element $tag, - $expression + mixed $expression ): Attribute; } diff --git a/src/TalNamespace/Builtin.php b/src/TalNamespace/Builtin.php index e14d790d..6ab3bb0f 100644 --- a/src/TalNamespace/Builtin.php +++ b/src/TalNamespace/Builtin.php @@ -24,12 +24,12 @@ */ class Builtin extends TalNamespace { - public const NS_METAL = 'http://xml.zope.org/namespaces/metal'; - public const NS_TAL = 'http://xml.zope.org/namespaces/tal'; - public const NS_I18N = 'http://xml.zope.org/namespaces/i18n'; - public const NS_XML = 'http://www.w3.org/XML/1998/namespace'; - public const NS_XMLNS = 'http://www.w3.org/2000/xmlns/'; - public const NS_XHTML = 'http://www.w3.org/1999/xhtml'; + final public const NS_METAL = 'http://xml.zope.org/namespaces/metal'; + final public const NS_TAL = 'http://xml.zope.org/namespaces/tal'; + final public const NS_I18N = 'http://xml.zope.org/namespaces/i18n'; + final public const NS_XML = 'http://www.w3.org/XML/1998/namespace'; + final public const NS_XMLNS = 'http://www.w3.org/2000/xmlns/'; + final public const NS_XHTML = 'http://www.w3.org/1999/xhtml'; /** * @param mixed $expression diff --git a/src/TalNamespaceAttribute.php b/src/TalNamespaceAttribute.php index 80db9efa..a653a038 100644 --- a/src/TalNamespaceAttribute.php +++ b/src/TalNamespaceAttribute.php @@ -64,16 +64,13 @@ */ abstract class TalNamespaceAttribute { - /** - * @var TalNamespace - */ - private $namespace; + private ?TalNamespace $namespace = null; /** * @param string $local_name The attribute name * @param int $priority Attribute execution priority */ - public function __construct(private string $local_name, private int $priority) + public function __construct(private readonly string $local_name, private readonly int $priority) { } @@ -98,10 +95,9 @@ public function setNamespace(TalNamespace $ns): void } /** - * @param mixed $expression * @return Attribute */ - public function createAttributeHandler(Element $tag, $expression) + public function createAttributeHandler(Element $tag, mixed $expression) { return $this->namespace->createAttributeHandler($this, $tag, $expression); } diff --git a/src/TalesRegistry.php b/src/TalesRegistry.php index 3910d717..f92555b0 100644 --- a/src/TalesRegistry.php +++ b/src/TalesRegistry.php @@ -68,7 +68,6 @@ public static function unregisterPrefix(string $prefix): void * Expects either a function name or an array of class and method or a closure as callback. * A closure *must* return a string enclosed in double quotes. * - * @param string $prefix * @param string|callable-string|callable(?string, bool):mixed|array{0: callable-string, 1: string} $callback * @param bool $is_fallback if true, method will be used as last resort (if there's no phptal_tales_foo) * diff --git a/src/TalesRegistryInterface.php b/src/TalesRegistryInterface.php index 1657602f..0abb99f5 100644 --- a/src/TalesRegistryInterface.php +++ b/src/TalesRegistryInterface.php @@ -32,7 +32,6 @@ public static function isRegistered(string $prefix): bool; * Expects an either a function name or an array of class and method as * callback. * - * @param string $prefix * @param string|callable-string|callable(?string, bool):mixed|array{0: callable-string, 1: string} $callback * @param bool $is_fallback if true, method will be used as last resort (if there's no phptal_tales_foo) * diff --git a/src/TriggerInterface.php b/src/TriggerInterface.php index 9ab382c9..e94db08e 100644 --- a/src/TriggerInterface.php +++ b/src/TriggerInterface.php @@ -22,16 +22,12 @@ interface TriggerInterface public const PROCEED = 2; /** - * @param mixed $id - * * @return mixed */ - public function start($id, PhpTalInterface $tpl); + public function start(mixed $id, PhpTalInterface $tpl); /** - * @param mixed $id - * * @return mixed */ - public function end($id, PhpTalInterface $tpl); + public function end(mixed $id, PhpTalInterface $tpl); } diff --git a/tests/CompressTest.php b/tests/CompressTest.php index 8d3e8c83..16e91e22 100644 --- a/tests/CompressTest.php +++ b/tests/CompressTest.php @@ -133,7 +133,7 @@ public function testPreservesSpaceAroundImages(): void $this->assertStrips("
y
", "
y
"); } - public function testPreservesSpaceAroundButtons(): never + public function testPreservesSpaceAroundButtons(): void { $this->assertStrips("
", "
"); $this->assertStrips("
x
", "
x
");