Skip to content

Commit

Permalink
Apply the final wave of rector code migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
usox committed Nov 2, 2023
1 parent 20619b3 commit a7ca99d
Show file tree
Hide file tree
Showing 48 changed files with 110 additions and 276 deletions.
13 changes: 10 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="./tests/config/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
cacheDirectory=".phpunit.cache">
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"
>
<coverage/>
<php>
<ini name="display_errors" value="1"/>
Expand All @@ -16,7 +23,7 @@
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
<directory>src/</directory>
</include>
</source>
</phpunit>
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -26,6 +27,7 @@
$rectorConfig->skip([
StringClassNameToClassConstantRector::class,
JsonThrowOnErrorRector::class,
FirstClassCallableRector::class,
]);

// define sets of rules
Expand Down
2 changes: 1 addition & 1 deletion src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 3 additions & 7 deletions src/Dom/Attr.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,18 @@ 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
* @param string $namespace_uri full namespace URI or empty string
* @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)
{
}

Expand Down
19 changes: 5 additions & 14 deletions src/Dom/Defs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, TalNamespace>
*/
private $namespaces_by_uri = [];
private array $namespaces_by_uri = [];

/**
* @var array<string, string>
*/
private $prefix_to_uri = [
private array $prefix_to_uri = [
'xml' => Builtin::NS_XML,
'xmlns' => Builtin::NS_XMLNS,
];
Expand All @@ -65,7 +62,7 @@ class Defs
*
* @var array<string>
*/
private static $XHTML_EMPTY_TAGS = [
private static array $XHTML_EMPTY_TAGS = [
'area',
'base',
'basefont',
Expand Down Expand Up @@ -93,7 +90,7 @@ class Defs
*
* @var array<string>
*/
private static $XHTML_BOOLEAN_ATTRIBUTES = [
private static array $XHTML_BOOLEAN_ATTRIBUTES = [
'autoplay',
'async',
'autofocus',
Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand Down
2 changes: 0 additions & 2 deletions src/Dom/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
12 changes: 3 additions & 9 deletions src/Dom/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
5 changes: 1 addition & 4 deletions src/Dom/PHPTALDocumentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ class PHPTALDocumentBuilder extends DocumentBuilder
*/
private $xmlns;

/**
* @var string
*/
private $encoding;
private ?string $encoding = null;

private ?Element $documentElement = null;

Expand Down
14 changes: 4 additions & 10 deletions src/Dom/SaxXmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<string>';
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/Exception/TemplateException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/UnknownModifierException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ExceptionHandler
/**
* ExceptionHandler constructor.
*/
public function __construct(private string $encoding)
public function __construct(private readonly string $encoding)
{
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/FileSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class FileSource implements SourceInterface
{
private string $path;
private readonly string $path;

/**
* @throws Exception\IOException
Expand Down
2 changes: 1 addition & 1 deletion src/FileSourceResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FileSourceResolver implements SourceResolverInterface
* FileSourceResolver constructor.
* @param array<string> $repositories
*/
public function __construct(private array $repositories)
public function __construct(private readonly array $repositories)
{
}

Expand Down
2 changes: 0 additions & 2 deletions src/FilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
13 changes: 3 additions & 10 deletions src/GetTextTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,11 @@ class GetTextTranslator implements TranslationServiceInterface
/**
* @var array<string, string>
*/
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.
Expand Down Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit a7ca99d

Please sign in to comment.