Updated Rector to commit 084ac39f29

084ac39f29 Add option to configure followLinks of finder (#1703)
This commit is contained in:
Tomas Votruba 2022-01-24 22:07:08 +00:00
parent f61a2947b9
commit 65d013939f
26 changed files with 162 additions and 78 deletions

View File

@ -23,6 +23,9 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class DowngradeUnnecessarilyParenthesizedExpressionRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @var array<class-string<Expr>>
*/
private const PARENTHESIZABLE_NODES = [\PhpParser\Node\Expr\ArrayDimFetch::class, \PhpParser\Node\Expr\PropertyFetch::class, \PhpParser\Node\Expr\MethodCall::class, \PhpParser\Node\Expr\StaticPropertyFetch::class, \PhpParser\Node\Expr\StaticCall::class, \PhpParser\Node\Expr\FuncCall::class];
/**
* @readonly
@ -72,7 +75,7 @@ CODE_SAMPLE
return null;
}
$leftSubNode = $this->getLeftSubNode($node);
if ($leftSubNode === null) {
if (!$leftSubNode instanceof \PhpParser\Node) {
return null;
}
if (!$this->wrappedInParenthesesAnalyzer->isParenthesized($this->file, $leftSubNode)) {

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '85719ff0e72bae77930c8b3149dbb029e8e0b99b';
public const PACKAGE_VERSION = '084ac39f29204e2763433d07422a081c39c6399b';
/**
* @var string
*/
public const RELEASE_DATE = '2022-01-24 09:31:03';
public const RELEASE_DATE = '2022-01-24 23:00:10';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20220124\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

View File

@ -170,4 +170,8 @@ final class Option
* @var string
*/
public const PARALLEL_SYSTEM_ERROR_COUNT_LIMIT = 'parallel-system-error-count-limit';
/**
* @var string
*/
public const FOLLOW_SYMLINKS = 'follow-symlinks';
}

View File

@ -4,9 +4,11 @@ declare (strict_types=1);
namespace Rector\Core\FileSystem;
use Rector\Caching\UnchangedFilesFilter;
use Rector\Core\Configuration\Option;
use Rector\Core\Util\StringUtils;
use RectorPrefix20220124\Symfony\Component\Finder\Finder;
use RectorPrefix20220124\Symfony\Component\Finder\SplFileInfo;
use RectorPrefix20220124\Symplify\PackageBuilder\Parameter\ParameterProvider;
use RectorPrefix20220124\Symplify\Skipper\SkipCriteriaResolver\SkippedPathsResolver;
use RectorPrefix20220124\Symplify\SmartFileSystem\FileSystemFilter;
use RectorPrefix20220124\Symplify\SmartFileSystem\Finder\FinderSanitizer;
@ -51,13 +53,19 @@ final class FilesFinder
* @var \Rector\Caching\UnchangedFilesFilter
*/
private $unchangedFilesFilter;
public function __construct(\Rector\Core\FileSystem\FilesystemTweaker $filesystemTweaker, \RectorPrefix20220124\Symplify\SmartFileSystem\Finder\FinderSanitizer $finderSanitizer, \RectorPrefix20220124\Symplify\SmartFileSystem\FileSystemFilter $fileSystemFilter, \RectorPrefix20220124\Symplify\Skipper\SkipCriteriaResolver\SkippedPathsResolver $skippedPathsResolver, \Rector\Caching\UnchangedFilesFilter $unchangedFilesFilter)
/**
* @readonly
* @var \Symplify\PackageBuilder\Parameter\ParameterProvider
*/
private $parameterProvider;
public function __construct(\Rector\Core\FileSystem\FilesystemTweaker $filesystemTweaker, \RectorPrefix20220124\Symplify\SmartFileSystem\Finder\FinderSanitizer $finderSanitizer, \RectorPrefix20220124\Symplify\SmartFileSystem\FileSystemFilter $fileSystemFilter, \RectorPrefix20220124\Symplify\Skipper\SkipCriteriaResolver\SkippedPathsResolver $skippedPathsResolver, \Rector\Caching\UnchangedFilesFilter $unchangedFilesFilter, \RectorPrefix20220124\Symplify\PackageBuilder\Parameter\ParameterProvider $parameterProvider)
{
$this->filesystemTweaker = $filesystemTweaker;
$this->finderSanitizer = $finderSanitizer;
$this->fileSystemFilter = $fileSystemFilter;
$this->skippedPathsResolver = $skippedPathsResolver;
$this->unchangedFilesFilter = $unchangedFilesFilter;
$this->parameterProvider = $parameterProvider;
}
/**
* @param string[] $source
@ -86,7 +94,10 @@ final class FilesFinder
if ($directories === []) {
return [];
}
$finder = \RectorPrefix20220124\Symfony\Component\Finder\Finder::create()->followLinks()->files()->size('> 0')->in($directories)->sortByName();
$finder = \RectorPrefix20220124\Symfony\Component\Finder\Finder::create()->files()->size('> 0')->in($directories)->sortByName();
if ($this->hasFollowLinks()) {
$finder->followLinks();
}
if ($suffixes !== []) {
$suffixesPattern = $this->normalizeSuffixesToPattern($suffixes);
$finder->name($suffixesPattern);
@ -148,4 +159,11 @@ final class FilesFinder
}
return $path;
}
private function hasFollowLinks() : bool
{
if (!$this->parameterProvider->hasParameter(\Rector\Core\Configuration\Option::FOLLOW_SYMLINKS)) {
return \true;
}
return $this->parameterProvider->provideBoolParameter(\Rector\Core\Configuration\Option::FOLLOW_SYMLINKS);
}
}

View File

@ -41,6 +41,10 @@ final class PropertyManipulator
* @var string[]
*/
private const ALLOWED_NOT_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES = ['Doctrine\\ORM\\Mapping\\Entity', 'Doctrine\\ORM\\Mapping\\Table'];
/**
* @var string[]
*/
private const ALLOWED_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES = ['Doctrine\\ORM\\Mapping\\Id', 'Doctrine\\ORM\\Mapping\\Column', 'Doctrine\\ORM\\Mapping\\OneToMany', 'Doctrine\\ORM\\Mapping\\ManyToMany', 'Doctrine\\ORM\\Mapping\\ManyToOne', 'Doctrine\\ORM\\Mapping\\OneToOne', 'JMS\\Serializer\\Annotation\\Type'];
/**
* @readonly
* @var \Rector\Core\NodeManipulator\AssignManipulator
@ -110,8 +114,10 @@ final class PropertyManipulator
public function isPropertyUsedInReadContext($propertyOrPromotedParam) : bool
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($propertyOrPromotedParam);
// @todo attributes too
if ($phpDocInfo->hasByAnnotationClasses(['Doctrine\\ORM\\Mapping\\Id', 'Doctrine\\ORM\\Mapping\\Column', 'Doctrine\\ORM\\Mapping\\OneToMany', 'Doctrine\\ORM\\Mapping\\ManyToMany', 'Doctrine\\ORM\\Mapping\\ManyToOne', 'Doctrine\\ORM\\Mapping\\OneToOne', 'JMS\\Serializer\\Annotation\\Type'])) {
if ($phpDocInfo->hasByAnnotationClasses(self::ALLOWED_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES)) {
return \true;
}
if ($this->phpAttributeAnalyzer->hasPhpAttributes($propertyOrPromotedParam, self::ALLOWED_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES)) {
return \true;
}
$privatePropertyFetches = $this->propertyFetchFinder->findPrivatePropertyFetches($propertyOrPromotedParam);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit81dc169b4b341e97db2f44e6a4b90173::getLoader();
return ComposerAutoloaderIniteadda737f525a83114904b680e1f28e1::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit81dc169b4b341e97db2f44e6a4b90173
class ComposerAutoloaderIniteadda737f525a83114904b680e1f28e1
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit81dc169b4b341e97db2f44e6a4b90173
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit81dc169b4b341e97db2f44e6a4b90173', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderIniteadda737f525a83114904b680e1f28e1', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit81dc169b4b341e97db2f44e6a4b90173', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderIniteadda737f525a83114904b680e1f28e1', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit81dc169b4b341e97db2f44e6a4b90173::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticIniteadda737f525a83114904b680e1f28e1::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,12 +42,12 @@ class ComposerAutoloaderInit81dc169b4b341e97db2f44e6a4b90173
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit81dc169b4b341e97db2f44e6a4b90173::$files;
$includeFiles = Composer\Autoload\ComposerStaticIniteadda737f525a83114904b680e1f28e1::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire81dc169b4b341e97db2f44e6a4b90173($fileIdentifier, $file);
composerRequireeadda737f525a83114904b680e1f28e1($fileIdentifier, $file);
}
return $loader;
@ -59,7 +59,7 @@ class ComposerAutoloaderInit81dc169b4b341e97db2f44e6a4b90173
* @param string $file
* @return void
*/
function composerRequire81dc169b4b341e97db2f44e6a4b90173($fileIdentifier, $file)
function composerRequireeadda737f525a83114904b680e1f28e1($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit81dc169b4b341e97db2f44e6a4b90173
class ComposerStaticIniteadda737f525a83114904b680e1f28e1
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -3874,9 +3874,9 @@ class ComposerStaticInit81dc169b4b341e97db2f44e6a4b90173
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit81dc169b4b341e97db2f44e6a4b90173::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit81dc169b4b341e97db2f44e6a4b90173::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit81dc169b4b341e97db2f44e6a4b90173::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticIniteadda737f525a83114904b680e1f28e1::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticIniteadda737f525a83114904b680e1f28e1::$prefixDirsPsr4;
$loader->classMap = ComposerStaticIniteadda737f525a83114904b680e1f28e1::$classMap;
}, null, ClassLoader::class);
}

View File

@ -813,17 +813,17 @@
},
{
"name": "nette\/utils",
"version": "v3.2.6",
"version_normalized": "3.2.6.0",
"version": "v3.2.7",
"version_normalized": "3.2.7.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/nette\/utils.git",
"reference": "2f261e55bd6a12057442045bf2c249806abc1d02"
"reference": "0af4e3de4df9f1543534beab255ccf459e7a2c99"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/nette\/utils\/zipball\/2f261e55bd6a12057442045bf2c249806abc1d02",
"reference": "2f261e55bd6a12057442045bf2c249806abc1d02",
"url": "https:\/\/api.github.com\/repos\/nette\/utils\/zipball\/0af4e3de4df9f1543534beab255ccf459e7a2c99",
"reference": "0af4e3de4df9f1543534beab255ccf459e7a2c99",
"shasum": ""
},
"require": {
@ -846,7 +846,7 @@
"ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()",
"ext-xml": "to use Strings::length() etc. when mbstring is not available"
},
"time": "2021-11-24T15:47:23+00:00",
"time": "2022-01-24T11:29:14+00:00",
"type": "library",
"extra": {
"branch-alias": {
@ -895,7 +895,7 @@
],
"support": {
"issues": "https:\/\/github.com\/nette\/utils\/issues",
"source": "https:\/\/github.com\/nette\/utils\/tree\/v3.2.6"
"source": "https:\/\/github.com\/nette\/utils\/tree\/v3.2.7"
},
"install-path": "..\/nette\/utils"
},

File diff suppressed because one or more lines are too long

14
vendor/nette/utils/ncs.php vendored Normal file
View File

@ -0,0 +1,14 @@
<?php
/**
* Rules for Nette Coding Standard
* https://github.com/nette/coding-standard
*/
declare (strict_types=1);
namespace RectorPrefix20220124;
return [
// use function in Arrays.php, Callback.php, Html.php, Strings.php
'single_import_per_statement' => \false,
'ordered_imports' => \false,
];

13
vendor/nette/utils/ncs.xml vendored Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<ruleset name="Custom" namespace="Nette">
<rule ref="$presets/php72.xml"/>
<!-- bug in SlevomatCodingStandard -->
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator">
<severity>0</severity>
</rule>
<!-- bug in FunctionSpacingSniff -->
<exclude-pattern>./tests/Utils/Reflection.getDeclaringMethod.alias.phpt</exclude-pattern>
<exclude-pattern>./tests/Utils/Reflection.getDeclaringMethod.insteadof.phpt</exclude-pattern>
</ruleset>

View File

@ -45,14 +45,14 @@ class CachingIterator extends \CachingIterator implements \Countable
/**
* Is the current element the first one?
*/
public function isFirst(int $gridWidth = null) : bool
public function isFirst(?int $gridWidth = null) : bool
{
return $this->counter === 1 || $gridWidth && $this->counter !== 0 && ($this->counter - 1) % $gridWidth === 0;
}
/**
* Is the current element the last one?
*/
public function isLast(int $gridWidth = null) : bool
public function isLast(?int $gridWidth = null) : bool
{
return !$this->hasNext() || $gridWidth && $this->counter % $gridWidth === 0;
}

View File

@ -56,7 +56,13 @@ trait SmartObject
if (!($prop & 0b1)) {
throw new \RectorPrefix20220124\Nette\MemberAccessException("Cannot read a write-only property {$class}::\${$name}.");
}
$m = ($prop & 0b10 ? 'get' : 'is') . $name;
$m = ($prop & 0b10 ? 'get' : 'is') . \ucfirst($name);
if ($prop & 0b10000) {
$trace = \debug_backtrace(0, 1)[0];
// suppose this method is called from __call()
$loc = isset($trace['file'], $trace['line']) ? " in {$trace['file']} on line {$trace['line']}" : '';
\trigger_error("Property {$class}::\${$name} is deprecated, use {$class}::{$m}() method{$loc}.", \E_USER_DEPRECATED);
}
if ($prop & 0b100) {
// return by reference
return $this->{$m}();
@ -84,7 +90,14 @@ trait SmartObject
if (!($prop & 0b1000)) {
throw new \RectorPrefix20220124\Nette\MemberAccessException("Cannot write to a read-only property {$class}::\${$name}.");
}
$this->{'set' . $name}($value);
$m = 'set' . \ucfirst($name);
if ($prop & 0b10000) {
$trace = \debug_backtrace(0, 1)[0];
// suppose this method is called from __call()
$loc = isset($trace['file'], $trace['line']) ? " in {$trace['file']} on line {$trace['line']}" : '';
\trigger_error("Property {$class}::\${$name} is deprecated, use {$class}::{$m}() method{$loc}.", \E_USER_DEPRECATED);
}
$this->{$m}($value);
} else {
\RectorPrefix20220124\Nette\Utils\ObjectHelpers::strictSet($class, $name);
}

View File

@ -190,7 +190,7 @@ class Arrays
*/
public static function isList($value) : bool
{
return \is_array($value) && (!$value || \array_keys($value) === \range(0, \count($value) - 1));
return \is_array($value) && (\PHP_VERSION_ID < 80100 ? !$value || \array_keys($value) === \range(0, \count($value) - 1) : array_is_list($value));
}
/**
* Reformats table to associative tree. Path looks like 'field|field[]field->field=field'.

View File

@ -19,7 +19,7 @@ final class Callback
* @param string|object|callable $callable class, object, callable
* @deprecated use Closure::fromCallable()
*/
public static function closure($callable, string $method = null) : \Closure
public static function closure($callable, ?string $method = null) : \Closure
{
\trigger_error(__METHOD__ . '() is deprecated, use Closure::fromCallable().', \E_USER_DEPRECATED);
try {

View File

@ -7,6 +7,7 @@
declare (strict_types=1);
namespace RectorPrefix20220124\Nette\Utils;
use RectorPrefix20220124\Nette;
class Helpers
{
/**
@ -54,7 +55,7 @@ class Helpers
public static function clamp($value, $min, $max)
{
if ($min > $max) {
throw new \InvalidArgumentException("Minimum ({$min}) is not less than maximum ({$max}).");
throw new \RectorPrefix20220124\Nette\InvalidArgumentException("Minimum ({$min}) is not less than maximum ({$max}).");
}
return \min(\max($value, $min), $max);
}

View File

@ -247,7 +247,7 @@ class Html implements \ArrayAccess, \Countable, \IteratorAggregate, \RectorPrefi
* @param array|string $attrs element's attributes or plain text content
* @return static
*/
public static function el(string $name = null, $attrs = null)
public static function el(?string $name = null, $attrs = null)
{
$el = new static();
$parts = \explode(' ', (string) $name, 2);
@ -303,7 +303,7 @@ class Html implements \ArrayAccess, \Countable, \IteratorAggregate, \RectorPrefi
* Changes element's name.
* @return static
*/
public final function setName(string $name, bool $isEmpty = null)
public final function setName(string $name, ?bool $isEmpty = null)
{
$this->name = $name;
$this->isEmpty = $isEmpty ?? isset(static::$emptyElements[$name]);
@ -453,7 +453,7 @@ class Html implements \ArrayAccess, \Countable, \IteratorAggregate, \RectorPrefi
* Special setter for element's attribute.
* @return static
*/
public final function href(string $path, array $query = null)
public final function href(string $path, ?array $query = null)
{
if ($query) {
$query = \http_build_query($query, '', '&');
@ -632,7 +632,7 @@ class Html implements \ArrayAccess, \Countable, \IteratorAggregate, \RectorPrefi
/**
* Renders element's start tag, content and end tag.
*/
public final function render(int $indent = null) : string
public final function render(?int $indent = null) : string
{
$s = $this->startTag();
if (!$this->isEmpty) {

View File

@ -9,7 +9,7 @@ namespace RectorPrefix20220124\Nette\Utils;
use RectorPrefix20220124\Nette;
/**
* Basic manipulation with images. Supported types are JPEG, PNG, GIF, WEBP and BMP.
* Basic manipulation with images. Supported types are JPEG, PNG, GIF, WEBP, AVIF and BMP.
*
* <code>
* $image = Image::fromFile('nette.jpg');
@ -104,9 +104,9 @@ class Image
/** {@link resize()} fills given area exactly */
public const EXACT = 0b1000;
/** image types */
public const JPEG = \IMAGETYPE_JPEG, PNG = \IMAGETYPE_PNG, GIF = \IMAGETYPE_GIF, WEBP = \IMAGETYPE_WEBP, BMP = \IMAGETYPE_BMP;
public const JPEG = \IMAGETYPE_JPEG, PNG = \IMAGETYPE_PNG, GIF = \IMAGETYPE_GIF, WEBP = \IMAGETYPE_WEBP, AVIF = 19, BMP = \IMAGETYPE_BMP;
public const EMPTY_GIF = "GIF89a\1\0\1\0\0\0\0\0\0\0\0\0\4\1\0\0\0\0,\0\0\0\0\1\0\1\0\0\2\2D\1\0;";
private const FORMATS = [self::JPEG => 'jpeg', self::PNG => 'png', self::GIF => 'gif', self::WEBP => 'webp', self::BMP => 'bmp'];
private const FORMATS = [self::JPEG => 'jpeg', self::PNG => 'png', self::GIF => 'gif', self::WEBP => 'webp', self::AVIF => 'avif', self::BMP => 'bmp'];
/** @var resource|\GdImage */
private $image;
/**
@ -122,7 +122,7 @@ class Image
* @throws UnknownImageFileException if file not found or file type is not known
* @return static
*/
public static function fromFile(string $file, int &$type = null)
public static function fromFile(string $file, ?int &$type = null)
{
if (!\extension_loaded('gd')) {
throw new \RectorPrefix20220124\Nette\NotSupportedException('PHP extension GD is not loaded.');
@ -131,10 +131,7 @@ class Image
if (!$type) {
throw new \RectorPrefix20220124\Nette\Utils\UnknownImageFileException(\is_file($file) ? "Unknown type of file '{$file}'." : "File '{$file}' not found.");
}
$method = 'imagecreatefrom' . self::FORMATS[$type];
return new static(\RectorPrefix20220124\Nette\Utils\Callback::invokeSafe($method, [$file], function (string $message) : void {
throw new \RectorPrefix20220124\Nette\Utils\ImageException($message);
}));
return self::invokeSafe('imagecreatefrom' . self::FORMATS[$type], $file, "Unable to open file '{$file}'.", __METHOD__);
}
/**
* Reads an image from a string and returns its type in $type.
@ -142,7 +139,7 @@ class Image
* @throws Nette\NotSupportedException if gd extension is not loaded
* @throws ImageException
*/
public static function fromString(string $s, int &$type = null)
public static function fromString(string $s, ?int &$type = null)
{
if (!\extension_loaded('gd')) {
throw new \RectorPrefix20220124\Nette\NotSupportedException('PHP extension GD is not loaded.');
@ -151,16 +148,27 @@ class Image
if (!$type) {
throw new \RectorPrefix20220124\Nette\Utils\UnknownImageFileException('Unknown type of image.');
}
return new static(\RectorPrefix20220124\Nette\Utils\Callback::invokeSafe('imagecreatefromstring', [$s], function (string $message) : void {
throw new \RectorPrefix20220124\Nette\Utils\ImageException($message);
}));
return self::invokeSafe('imagecreatefromstring', $s, 'Unable to open image from string.', __METHOD__);
}
private static function invokeSafe(string $func, string $arg, string $message, string $callee) : self
{
$errors = [];
$res = \RectorPrefix20220124\Nette\Utils\Callback::invokeSafe($func, [$arg], function (string $message) use(&$errors) : void {
$errors[] = $message;
});
if (!$res) {
throw new \RectorPrefix20220124\Nette\Utils\ImageException($message . ' Errors: ' . \implode(', ', $errors));
} elseif ($errors) {
\trigger_error($callee . '(): ' . \implode(', ', $errors), \E_USER_WARNING);
}
return new static($res);
}
/**
* Creates a new true color image of the given dimensions. The default color is black.
* @return static
* @throws Nette\NotSupportedException if gd extension is not loaded
*/
public static function fromBlank(int $width, int $height, array $color = null)
public static function fromBlank(int $width, int $height, ?array $color = null)
{
if (!\extension_loaded('gd')) {
throw new \RectorPrefix20220124\Nette\NotSupportedException('PHP extension GD is not loaded.');
@ -451,10 +459,10 @@ class Image
return $this;
}
/**
* Saves image to the file. Quality is in the range 0..100 for JPEG (default 85) and WEBP (default 80) and 0..9 for PNG (default 9).
* Saves image to the file. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
* @throws ImageException
*/
public function save(string $file, int $quality = null, int $type = null) : void
public function save(string $file, ?int $quality = null, ?int $type = null) : void
{
if ($type === null) {
$extensions = \array_flip(self::FORMATS) + ['jpg' => self::JPEG];
@ -467,9 +475,9 @@ class Image
$this->output($type, $quality, $file);
}
/**
* Outputs image to string. Quality is in the range 0..100 for JPEG (default 85) and WEBP (default 80) and 0..9 for PNG (default 9).
* Outputs image to string. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
*/
public function toString(int $type = self::JPEG, int $quality = null) : string
public function toString(int $type = self::JPEG, ?int $quality = null) : string
{
return \RectorPrefix20220124\Nette\Utils\Helpers::capture(function () use($type, $quality) {
$this->output($type, $quality);
@ -491,10 +499,10 @@ class Image
}
}
/**
* Outputs image to browser. Quality is in the range 0..100 for JPEG (default 85) and WEBP (default 80) and 0..9 for PNG (default 9).
* Outputs image to browser. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
* @throws ImageException
*/
public function send(int $type = self::JPEG, int $quality = null) : void
public function send(int $type = self::JPEG, ?int $quality = null) : void
{
\header('Content-Type: ' . self::typeToMimeType($type));
$this->output($type, $quality);
@ -503,7 +511,7 @@ class Image
* Outputs image to browser or file.
* @throws ImageException
*/
private function output(int $type, ?int $quality, string $file = null) : void
private function output(int $type, ?int $quality, ?string $file = null) : void
{
switch ($type) {
case self::JPEG:
@ -525,6 +533,11 @@ class Image
$success = @\imagewebp($this->image, $file, $quality);
// @ is escalated to exception
break;
case self::AVIF:
$quality = $quality === null ? 30 : \max(0, \min(100, $quality));
$success = @imageavif($this->image, $file, $quality);
// @ is escalated to exception
break;
case self::BMP:
$success = @\imagebmp($this->image, $file);
// @ is escalated to exception

View File

@ -14,9 +14,9 @@ use RectorPrefix20220124\Nette;
final class Json
{
use Nette\StaticClass;
public const FORCE_ARRAY = 0b1;
public const PRETTY = 0b10;
public const ESCAPE_UNICODE = 0b100;
public const FORCE_ARRAY = \JSON_OBJECT_AS_ARRAY;
public const PRETTY = \JSON_PRETTY_PRINT;
public const ESCAPE_UNICODE = 1 << 19;
/**
* Converts value to JSON format. The flag can be Json::PRETTY, which formats JSON for easier reading and clarity,
* and Json::ESCAPE_UNICODE for ASCII output.
@ -25,7 +25,7 @@ final class Json
*/
public static function encode($value, int $flags = 0) : string
{
$flags = ($flags & self::ESCAPE_UNICODE ? 0 : \JSON_UNESCAPED_UNICODE) | \JSON_UNESCAPED_SLASHES | ($flags & self::PRETTY ? \JSON_PRETTY_PRINT : 0) | (\defined('JSON_PRESERVE_ZERO_FRACTION') ? \JSON_PRESERVE_ZERO_FRACTION : 0);
$flags = ($flags & self::ESCAPE_UNICODE ? 0 : \JSON_UNESCAPED_UNICODE) | \JSON_UNESCAPED_SLASHES | $flags & ~self::ESCAPE_UNICODE | (\defined('JSON_PRESERVE_ZERO_FRACTION') ? \JSON_PRESERVE_ZERO_FRACTION : 0);
// since PHP 5.6.6 & PECL JSON-C 1.3.7
$json = \json_encode($value, $flags);
if ($error = \json_last_error()) {
@ -40,8 +40,7 @@ final class Json
*/
public static function decode(string $json, int $flags = 0)
{
$forceArray = (bool) ($flags & self::FORCE_ARRAY);
$value = \json_decode($json, $forceArray, 512, \JSON_BIGINT_AS_STRING);
$value = \json_decode($json, null, 512, $flags | \JSON_BIGINT_AS_STRING);
if ($error = \json_last_error()) {
throw new \RectorPrefix20220124\Nette\Utils\JsonException(\json_last_error_msg(), $error);
}

View File

@ -100,14 +100,14 @@ final class ObjectHelpers
return $props;
}
$rc = new \ReflectionClass($class);
\preg_match_all('~^ [ \\t*]* @property(|-read|-write) [ \\t]+ [^\\s$]+ [ \\t]+ \\$ (\\w+) ()~mx', (string) $rc->getDocComment(), $matches, \PREG_SET_ORDER);
\preg_match_all('~^ [ \\t*]* @property(|-read|-write|-deprecated) [ \\t]+ [^\\s$]+ [ \\t]+ \\$ (\\w+) ()~mx', (string) $rc->getDocComment(), $matches, \PREG_SET_ORDER);
$props = [];
foreach ($matches as [, $type, $name]) {
$uname = \ucfirst($name);
$write = $type !== '-read' && $rc->hasMethod($nm = 'set' . $uname) && ($rm = $rc->getMethod($nm))->name === $nm && !$rm->isPrivate() && !$rm->isStatic();
$read = $type !== '-write' && ($rc->hasMethod($nm = 'get' . $uname) || $rc->hasMethod($nm = 'is' . $uname)) && ($rm = $rc->getMethod($nm))->name === $nm && !$rm->isPrivate() && !$rm->isStatic();
if ($read || $write) {
$props[$name] = $read << 0 | ($nm[0] === 'g') << 1 | $rm->returnsReference() << 2 | $write << 3;
$props[$name] = $read << 0 | ($nm[0] === 'g') << 1 | $rm->returnsReference() << 2 | $write << 3 | ($type === '-deprecated') << 4;
}
}
foreach ($rc->getTraits() as $trait) {

View File

@ -146,7 +146,7 @@ class Paginator
* Sets the total number of items.
* @return static
*/
public function setItemCount(int $itemCount = null)
public function setItemCount(?int $itemCount = null)
{
$this->itemCount = $itemCount === null ? null : \max(0, $itemCount);
return $this;

View File

@ -236,7 +236,7 @@ final class Reflection
/**
* Parses PHP code to [class => [alias => class, ...]]
*/
private static function parseUseStatements(string $code, string $forClass = null) : array
private static function parseUseStatements(string $code, ?string $forClass = null) : array
{
try {
$tokens = \token_get_all($code, \TOKEN_PARSE);

View File

@ -69,7 +69,7 @@ class Strings
* Returns a part of UTF-8 string specified by starting position and length. If start is negative,
* the returned string will start at the start'th character from the end of string.
*/
public static function substring(string $s, int $start, int $length = null) : string
public static function substring(string $s, int $start, ?int $length = null) : string
{
if (\function_exists('mb_substr')) {
return \mb_substr($s, $start, $length, 'UTF-8');
@ -175,7 +175,7 @@ class Strings
* Modifies the UTF-8 string to the form used in the URL, ie removes diacritics and replaces all characters
* except letters of the English alphabet and numbers with a hyphens.
*/
public static function webalize(string $s, string $charlist = null, bool $lower = \true) : string
public static function webalize(string $s, ?string $charlist = null, bool $lower = \true) : string
{
$s = self::toAscii($s);
if ($lower) {
@ -254,7 +254,7 @@ class Strings
* if it is negative, the corresponding number of characters from the end of the strings is compared,
* otherwise the appropriate number of characters from the beginning is compared.
*/
public static function compare(string $left, string $right, int $length = null) : bool
public static function compare(string $left, string $right, ?int $length = null) : bool
{
if (\class_exists('Normalizer', \false)) {
$left = \Normalizer::normalize($left, \Normalizer::FORM_D);

View File

@ -86,7 +86,7 @@ class Validators
* @param int|string $key
* @throws AssertionException
*/
public static function assertField(array $array, $key, string $expected = null, string $label = "item '%' in array") : void
public static function assertField(array $array, $key, ?string $expected = null, string $label = "item '%' in array") : void
{
if (!\array_key_exists($key, $array)) {
throw new \RectorPrefix20220124\Nette\Utils\AssertionException('Missing ' . \str_replace('%', $key, $label) . '.');
@ -181,7 +181,7 @@ class Validators
*/
public static function isNumeric($value) : bool
{
return \is_float($value) || \is_int($value) || \is_string($value) && \preg_match('#^[+-]?[0-9]*[.]?[0-9]+$#D', $value);
return \is_float($value) || \is_int($value) || \is_string($value) && \preg_match('#^[+-]?([0-9]++\\.?[0-9]*|\\.[0-9]+)$#D', $value);
}
/**
* Checks if the value is a syntactically correct callback.

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20220124\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit81dc169b4b341e97db2f44e6a4b90173', false) && !interface_exists('ComposerAutoloaderInit81dc169b4b341e97db2f44e6a4b90173', false) && !trait_exists('ComposerAutoloaderInit81dc169b4b341e97db2f44e6a4b90173', false)) {
spl_autoload_call('RectorPrefix20220124\ComposerAutoloaderInit81dc169b4b341e97db2f44e6a4b90173');
if (!class_exists('ComposerAutoloaderIniteadda737f525a83114904b680e1f28e1', false) && !interface_exists('ComposerAutoloaderIniteadda737f525a83114904b680e1f28e1', false) && !trait_exists('ComposerAutoloaderIniteadda737f525a83114904b680e1f28e1', false)) {
spl_autoload_call('RectorPrefix20220124\ComposerAutoloaderIniteadda737f525a83114904b680e1f28e1');
}
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
spl_autoload_call('RectorPrefix20220124\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -71,9 +71,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220124\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire81dc169b4b341e97db2f44e6a4b90173')) {
function composerRequire81dc169b4b341e97db2f44e6a4b90173() {
return \RectorPrefix20220124\composerRequire81dc169b4b341e97db2f44e6a4b90173(...func_get_args());
if (!function_exists('composerRequireeadda737f525a83114904b680e1f28e1')) {
function composerRequireeadda737f525a83114904b680e1f28e1() {
return \RectorPrefix20220124\composerRequireeadda737f525a83114904b680e1f28e1(...func_get_args());
}
}
if (!function_exists('scanPath')) {