Updated Rector to commit 67238d841a46b5fecc9ef204ffef4ba773e82cb9

67238d841a [docs] add note about new find-rule page (#6224)
This commit is contained in:
Tomas Votruba 2024-08-08 13:54:22 +00:00
parent cbfdee3c34
commit efcd77aa17
29 changed files with 299 additions and 161 deletions

View File

@ -72,7 +72,7 @@ vendor/bin/rector process src
## Documentation
* Find [full documentation here](https://getrector.com/documentation/).
* [Explore Rector Rules](/docs/rector_rules_overview.md)
* [Explore Rector Rules](https://getrector.com/find-rule)
<br>

View File

@ -1,5 +1,9 @@
# 382 Rules Overview
**This overview is deprecated and replaced by more advanced web search. There you can search and filter by nodes, copy-paste configs for configurable rules and more.**
Use https://getrector.com/find-rule instead!
<br>
## Categories

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '59585ae75aafa8c5e2666b047a84f13ab35fb59f';
public const PACKAGE_VERSION = '67238d841a46b5fecc9ef204ffef4ba773e82cb9';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-08-07 08:05:18';
public const RELEASE_DATE = '2024-08-08 13:51:11';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit4bcaef4da4b0314c67dae59e30837b25::getLoader();
return ComposerAutoloaderInit969cf4fb8686733ba64d08544d342ca0::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit4bcaef4da4b0314c67dae59e30837b25
class ComposerAutoloaderInit969cf4fb8686733ba64d08544d342ca0
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit4bcaef4da4b0314c67dae59e30837b25
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit4bcaef4da4b0314c67dae59e30837b25', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit969cf4fb8686733ba64d08544d342ca0', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit4bcaef4da4b0314c67dae59e30837b25', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit969cf4fb8686733ba64d08544d342ca0', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit4bcaef4da4b0314c67dae59e30837b25::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit969cf4fb8686733ba64d08544d342ca0::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit4bcaef4da4b0314c67dae59e30837b25::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit969cf4fb8686733ba64d08544d342ca0::$files;
$requireFile = \Closure::bind(static function ($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 ComposerStaticInit4bcaef4da4b0314c67dae59e30837b25
class ComposerStaticInit969cf4fb8686733ba64d08544d342ca0
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2797,9 +2797,9 @@ class ComposerStaticInit4bcaef4da4b0314c67dae59e30837b25
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit4bcaef4da4b0314c67dae59e30837b25::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit4bcaef4da4b0314c67dae59e30837b25::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit4bcaef4da4b0314c67dae59e30837b25::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit969cf4fb8686733ba64d08544d342ca0::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit969cf4fb8686733ba64d08544d342ca0::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit969cf4fb8686733ba64d08544d342ca0::$classMap;
}, null, ClassLoader::class);
}

View File

@ -620,21 +620,21 @@
},
{
"name": "nette\/utils",
"version": "v4.0.4",
"version_normalized": "4.0.4.0",
"version": "v4.0.5",
"version_normalized": "4.0.5.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/nette\/utils.git",
"reference": "d3ad0aa3b9f934602cb3e3902ebccf10be34d218"
"reference": "736c567e257dbe0fcf6ce81b4d6dbe05c6899f96"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/nette\/utils\/zipball\/d3ad0aa3b9f934602cb3e3902ebccf10be34d218",
"reference": "d3ad0aa3b9f934602cb3e3902ebccf10be34d218",
"url": "https:\/\/api.github.com\/repos\/nette\/utils\/zipball\/736c567e257dbe0fcf6ce81b4d6dbe05c6899f96",
"reference": "736c567e257dbe0fcf6ce81b4d6dbe05c6899f96",
"shasum": ""
},
"require": {
"php": ">=8.0 <8.4"
"php": "8.0 - 8.4"
},
"conflict": {
"nette\/finder": "<3",
@ -654,7 +654,7 @@
"ext-mbstring": "to use Strings::lower() etc...",
"ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()"
},
"time": "2024-01-17T16:50:36+00:00",
"time": "2024-08-07T15:39:19+00:00",
"type": "library",
"extra": {
"branch-alias": {
@ -703,7 +703,7 @@
],
"support": {
"issues": "https:\/\/github.com\/nette\/utils\/issues",
"source": "https:\/\/github.com\/nette\/utils\/tree\/v4.0.4"
"source": "https:\/\/github.com\/nette\/utils\/tree\/v4.0.5"
},
"install-path": "..\/nette\/utils"
},
@ -1688,12 +1688,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
"reference": "3ba7adbca3491a977b81147d93eb78084ed8e454"
"reference": "11ac7b9060990b62f972a42330cceab294ee097e"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/3ba7adbca3491a977b81147d93eb78084ed8e454",
"reference": "3ba7adbca3491a977b81147d93eb78084ed8e454",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/11ac7b9060990b62f972a42330cceab294ee097e",
"reference": "11ac7b9060990b62f972a42330cceab294ee097e",
"shasum": ""
},
"require": {
@ -1712,13 +1712,13 @@
"symplify\/easy-coding-standard": "^12.3",
"symplify\/phpstan-extensions": "^11.4",
"symplify\/phpstan-rules": "^13.0",
"symplify\/rule-doc-generator": "^12.2",
"symplify\/rule-doc-generator": "^12.2.5",
"symplify\/vendor-patches": "^11.3",
"tomasvotruba\/class-leak": "^0.2.15",
"tomasvotruba\/unused-public": "^0.3",
"tracy\/tracy": "^2.10"
},
"time": "2024-07-25T15:38:30+00:00",
"time": "2024-08-08T13:34:44+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -1810,12 +1810,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "acfcef8cfbceefee966253ef5f1b2ec57bc10e22"
"reference": "2bacfc618ca1987deab1e70f87720805a171a1a8"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/acfcef8cfbceefee966253ef5f1b2ec57bc10e22",
"reference": "acfcef8cfbceefee966253ef5f1b2ec57bc10e22",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/2bacfc618ca1987deab1e70f87720805a171a1a8",
"reference": "2bacfc618ca1987deab1e70f87720805a171a1a8",
"shasum": ""
},
"require": {
@ -1834,12 +1834,12 @@
"symplify\/easy-coding-standard": "^12.3",
"symplify\/phpstan-extensions": "^11.2",
"symplify\/phpstan-rules": "^13.0",
"symplify\/rule-doc-generator": "^12.0",
"symplify\/rule-doc-generator": "^12.2.5",
"symplify\/vendor-patches": "^11.2",
"tomasvotruba\/class-leak": "^0.2",
"tracy\/tracy": "^2.10"
},
"time": "2024-07-31T14:43:42+00:00",
"time": "2024-08-08T13:39:23+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -1875,12 +1875,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "01e3fe74284092db2c4b6cec28a0ae723d419f31"
"reference": "ece927272de55206ad2832bb7fe3993c814fae01"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/01e3fe74284092db2c4b6cec28a0ae723d419f31",
"reference": "01e3fe74284092db2c4b6cec28a0ae723d419f31",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/ece927272de55206ad2832bb7fe3993c814fae01",
"reference": "ece927272de55206ad2832bb7fe3993c814fae01",
"shasum": ""
},
"require": {
@ -1904,13 +1904,13 @@
"symplify\/easy-coding-standard": "^12.3",
"symplify\/phpstan-extensions": "^11.4",
"symplify\/phpstan-rules": "^13.0",
"symplify\/rule-doc-generator": "^12.2.2",
"symplify\/rule-doc-generator": "^12.2.5",
"symplify\/vendor-patches": "^11.3",
"tomasvotruba\/class-leak": "^0.2",
"tomasvotruba\/unused-public": "^0.3.10",
"tracy\/tracy": "^2.10"
},
"time": "2024-08-05T15:01:30+00:00",
"time": "2024-08-08T13:37:21+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -34,7 +34,7 @@
}
],
"require": {
"php": ">=8.0 <8.4"
"php": "8.0 - 8.4"
},
"require-dev": {
"nette\/tester": "^2.5",

View File

@ -1,5 +1,4 @@
Nette Utility Classes
=====================
[![Nette Utils](https://github.com/nette/utils/assets/194960/c33fdb74-0652-4cad-ac6e-c1ce0d29e32a)](https://doc.nette.org/en/utils)
[![Downloads this Month](https://img.shields.io/packagist/dm/nette/utils.svg)](https://packagist.org/packages/nette/utils)
[![Tests](https://github.com/nette/utils/workflows/Tests/badge.svg?branch=master)](https://github.com/nette/utils/actions)
@ -11,25 +10,27 @@ Nette Utility Classes
Introduction
------------
In package nette/utils you will find a set of [useful classes](https://doc.nette.org/utils) for everyday use:
In package nette/utils you will find a set of useful classes for everyday use:
- [Arrays](https://doc.nette.org/utils/arrays) - manipulate arrays
- [Callback](https://doc.nette.org/utils/callback) - PHP callbacks
- [Date and Time](https://doc.nette.org/utils/datetime) - modify times and dates
- [Filesystem](https://doc.nette.org/utils/filesystem) - copying, renaming, …
- [Finder](https://doc.nette.org/utils/finder) - finds files and directories
- [Helper Functions](https://doc.nette.org/utils/helpers)
- [HTML elements](https://doc.nette.org/utils/html-elements) - generate HTML
- [Images](https://doc.nette.org/utils/images) - crop, resize, rotate images
- [JSON](https://doc.nette.org/utils/json) - encoding and decoding
- [Generating Random Strings](https://doc.nette.org/utils/random)
- [Paginator](https://doc.nette.org/utils/paginator) - pagination math
- [PHP Reflection](https://doc.nette.org/utils/reflection)
- [Strings](https://doc.nette.org/utils/strings) - useful text functions
- [SmartObject](https://doc.nette.org/utils/smartobject) - PHP object enhancements
- [Validation](https://doc.nette.org/utils/validators) - validate inputs
- [Type](https://doc.nette.org/utils/type) - PHP data type
✅ [Arrays](https://doc.nette.org/utils/arrays)<br>
✅ [Callback](https://doc.nette.org/utils/callback) - PHP callbacks<br>
✅ [Filesystem](https://doc.nette.org/utils/filesystem) - copying, renaming, …<br>
✅ [Finder](https://doc.nette.org/utils/finder) - finds files and directories<br>
✅ [Floats](https://doc.nette.org/utils/floats) - floating point numbers<br>
✅ [Helper Functions](https://doc.nette.org/utils/helpers)<br>
✅ [HTML elements](https://doc.nette.org/utils/html-elements) - generate HTML<br>
✅ [Images](https://doc.nette.org/utils/images) - crop, resize, rotate images<br>
✅ [Iterables](https://doc.nette.org/utils/iterables) <br>
✅ [JSON](https://doc.nette.org/utils/json) - encoding and decoding<br>
✅ [Generating Random Strings](https://doc.nette.org/utils/random)<br>
✅ [Paginator](https://doc.nette.org/utils/paginator) - pagination math<br>
✅ [PHP Reflection](https://doc.nette.org/utils/reflection)<br>
✅ [Strings](https://doc.nette.org/utils/strings) - useful text functions<br>
✅ [SmartObject](https://doc.nette.org/utils/smartobject) - PHP object enhancements<br>
✅ [Type](https://doc.nette.org/utils/type) - PHP data type<br>
✅ [Validation](https://doc.nette.org/utils/validators) - validate inputs<br>
 <!---->
Installation
------------
@ -40,11 +41,9 @@ The recommended way to install is via Composer:
composer require nette/utils
```
- Nette Utils 4.0 is compatible with PHP 8.0 to 8.3
- Nette Utils 3.2 is compatible with PHP 7.2 to 8.3
- Nette Utils 3.1 is compatible with PHP 7.1 to 8.0
- Nette Utils 3.0 is compatible with PHP 7.1 to 8.0
- Nette Utils 2.5 is compatible with PHP 5.6 to 8.0
Nette Utils 4.0 is compatible with PHP 8.0 to 8.4.
 <!---->
[Support Me](https://github.com/sponsors/dg)
--------------------------------------------

View File

@ -27,22 +27,13 @@ class CachingIterator extends \CachingIterator implements \Countable
* @var int
*/
private $counter = 0;
public function __construct($iterator)
/**
* @param iterable|\stdClass $iterable
*/
public function __construct($iterable)
{
if (\is_array($iterator) || $iterator instanceof \stdClass) {
$iterator = new \ArrayIterator($iterator);
} elseif ($iterator instanceof \IteratorAggregate) {
do {
$iterator = $iterator->getIterator();
} while ($iterator instanceof \IteratorAggregate);
\assert($iterator instanceof \Iterator);
} elseif ($iterator instanceof \Iterator) {
} elseif ($iterator instanceof \Traversable) {
$iterator = new \IteratorIterator($iterator);
} else {
throw new Nette\InvalidArgumentException(\sprintf('Invalid argument passed to %s; array or Traversable expected, %s given.', self::class, \get_debug_type($iterator)));
}
parent::__construct($iterator, 0);
$iterable = $iterable instanceof \stdClass ? new \ArrayIterator($iterable) : Nette\Utils\Iterables::toIterator($iterable);
parent::__construct($iterable, 0);
}
/**
* Is the current element the first one?

View File

@ -8,7 +8,7 @@ declare (strict_types=1);
namespace RectorPrefix202408\Nette\Iterators;
/**
* Applies the callback to the elements of the inner iterator.
* @deprecated use Nette\Utils\Iterables::map()
*/
class Mapper extends \IteratorIterator
{

View File

@ -103,10 +103,11 @@ class Arrays
}
/**
* Returns the first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
* The $predicate has the signature `function (mixed $value, int|string $key, array $array): bool`.
* @template T
* @param array<T> $array
* @return ?T
* @template K of int|string
* @template V
* @param array<K, V> $array
* @param ?callable(V, K, array<K, V>): bool $predicate
* @return ?V
*/
public static function first(array $array, ?callable $predicate = null, ?callable $else = null)
{
@ -115,10 +116,11 @@ class Arrays
}
/**
* Returns the last item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
* The $predicate has the signature `function (mixed $value, int|string $key, array $array): bool`.
* @template T
* @param array<T> $array
* @return ?T
* @template K of int|string
* @template V
* @param array<K, V> $array
* @param ?callable(V, K, array<K, V>): bool $predicate
* @return ?V
*/
public static function last(array $array, ?callable $predicate = null, ?callable $else = null)
{
@ -127,8 +129,11 @@ class Arrays
}
/**
* Returns the key of first item (matching the specified predicate if given) or null if there is no such item.
* The $predicate has the signature `function (mixed $value, int|string $key, array $array): bool`.
* @return int|string|null
* @template K of int|string
* @template V
* @param array<K, V> $array
* @param ?callable(V, K, array<K, V>): bool $predicate
* @return ?K
*/
public static function firstKey(array $array, ?callable $predicate = null)
{
@ -145,8 +150,11 @@ class Arrays
}
/**
* Returns the key of last item (matching the specified predicate if given) or null if there is no such item.
* The $predicate has the signature `function (mixed $value, int|string $key, array $array): bool`.
* @return int|string|null
* @template K of int|string
* @template V
* @param array<K, V> $array
* @param ?callable(V, K, array<K, V>): bool $predicate
* @return ?K
*/
public static function lastKey(array $array, ?callable $predicate = null)
{
@ -328,12 +336,11 @@ class Arrays
}
}
/**
* Tests whether at least one element in the array passes the test implemented by the provided function,
* which has the signature `function ($value, $key, array $array): bool`.
* @template K
* Tests whether at least one element in the array passes the test implemented by the provided function.
* @template K of int|string
* @template V
* @param iterable<K, V> $array
* @param callable(V, K, ($array is array ? array<K, V> : iterable<K, V>)): bool $predicate
* @param array<K, V> $array
* @param callable(V, K, array<K, V>): bool $predicate
*/
public static function some(iterable $array, callable $predicate) : bool
{
@ -345,12 +352,11 @@ class Arrays
return \false;
}
/**
* Tests whether all elements in the array pass the test implemented by the provided function,
* which has the signature `function ($value, $key, array $array): bool`.
* @template K
* Tests whether all elements in the array pass the test implemented by the provided function.
* @template K of int|string
* @template V
* @param iterable<K, V> $array
* @param callable(V, K, ($array is array ? array<K, V> : iterable<K, V>)): bool $predicate
* @param array<K, V> $array
* @param callable(V, K, array<K, V>): bool $predicate
*/
public static function every(iterable $array, callable $predicate) : bool
{
@ -363,11 +369,10 @@ class Arrays
}
/**
* Returns a new array containing all key-value pairs matching the given $predicate.
* The callback has the signature `function (mixed $value, int|string $key, array $array): bool`.
* @template K of array-key
* @template K of int|string
* @template V
* @param array<K, V> $array
* @param callable(V, K, array<K, V>): bool $predicate
* @param array<K, V> $array
* @param callable(V, K, array<K, V>): bool $predicate
* @return array<K, V>
*/
public static function filter(array $array, callable $predicate) : array
@ -382,12 +387,11 @@ class Arrays
}
/**
* Returns an array containing the original keys and results of applying the given transform function to each element.
* The function has signature `function ($value, $key, array $array): mixed`.
* @template K of array-key
* @template K of int|string
* @template V
* @template R
* @param iterable<K, V> $array
* @param callable(V, K, ($array is array ? array<K, V> : iterable<K, V>)): R $transformer
* @param array<K, V> $array
* @param callable(V, K, array<K, V>): R $transformer
* @return array<K, R>
*/
public static function map(iterable $array, callable $transformer) : array
@ -398,6 +402,28 @@ class Arrays
}
return $res;
}
/**
* Returns an array containing new keys and values generated by applying the given transform function to each element.
* If the function returns null, the element is skipped.
* @template K of int|string
* @template V
* @template ResK of int|string
* @template ResV
* @param array<K, V> $array
* @param callable(V, K, array<K, V>): ?array{ResK, ResV} $transformer
* @return array<ResK, ResV>
*/
public static function mapWithKeys(array $array, callable $transformer) : array
{
$res = [];
foreach ($array as $k => $v) {
$pair = $transformer($v, $k, $array);
if ($pair) {
$res[$pair[0]] = $pair[1];
}
}
return $res;
}
/**
* Invokes all callbacks and returns array of results.
* @param callable[] $callbacks

View File

@ -77,7 +77,7 @@ final class Callback
$callable = self::unwrap($callable);
}
if (is_string($callable) && \strpos($callable, '::') !== \false) {
return new ReflectionMethod($callable);
return new ReflectionMethod(...\explode('::', $callable, 2));
} elseif (is_array($callable)) {
return new ReflectionMethod($callable[0], $callable[1]);
} elseif (is_object($callable) && !$callable instanceof \Closure) {

View File

@ -133,9 +133,7 @@ class Image
*/
public static function fromFile(string $file, ?int &$type = null)
{
if (!\extension_loaded('gd')) {
throw new Nette\NotSupportedException('PHP extension GD is not loaded.');
}
self::ensureExtension();
$type = self::detectTypeFromFile($file);
if (!$type) {
throw new UnknownImageFileException(\is_file($file) ? "Unknown type of file '{$file}'." : "File '{$file}' not found.");
@ -150,9 +148,7 @@ class Image
*/
public static function fromString(string $s, ?int &$type = null)
{
if (!\extension_loaded('gd')) {
throw new Nette\NotSupportedException('PHP extension GD is not loaded.');
}
self::ensureExtension();
$type = self::detectTypeFromString($s);
if (!$type) {
throw new UnknownImageFileException('Unknown type of image.');
@ -185,9 +181,7 @@ class Image
*/
public static function fromBlank(int $width, int $height, $color = null)
{
if (!\extension_loaded('gd')) {
throw new Nette\NotSupportedException('PHP extension GD is not loaded.');
}
self::ensureExtension();
if ($width < 1 || $height < 1) {
throw new Nette\InvalidArgumentException('Image width and height must be greater than zero.');
}
@ -257,6 +251,7 @@ class Image
*/
public static function isTypeSupported(int $type) : bool
{
self::ensureExtension();
switch ($type) {
case ImageType::JPEG:
return \IMG_JPG;
@ -277,6 +272,7 @@ class Image
/** @return ImageType[] */
public static function getSupportedTypes() : array
{
self::ensureExtension();
$flag = \imagetypes();
return \array_filter([
$flag & \IMG_GIF ? ImageType::GIF : null,
@ -526,6 +522,7 @@ class Image
*/
public static function calculateTextBox(string $text, string $fontFile, float $size, float $angle = 0, array $options = []) : array
{
self::ensureExtension();
$box = \imagettfbbox($size, $angle, $fontFile, $text, $options);
return ['left' => $minX = \min([$box[0], $box[2], $box[4], $box[6]]), 'top' => $minY = \min([$box[1], $box[3], $box[5], $box[7]]), 'width' => \max([$box[0], $box[2], $box[4], $box[6]]) - $minX + 1, 'height' => \max([$box[1], $box[3], $box[5], $box[7]]) - $minY + 1];
}
@ -684,4 +681,10 @@ class Image
$color = $color instanceof ImageColor ? $color->toRGBA() : \array_values($color);
return \imagecolorallocatealpha($this->image, ...$color) ?: \imagecolorresolvealpha($this->image, ...$color);
}
private static function ensureExtension() : void
{
if (!\extension_loaded('gd')) {
throw new Nette\NotSupportedException('PHP extension GD is not loaded.');
}
}
}

View File

@ -42,10 +42,11 @@ final class Iterables
}
/**
* Returns the first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
* The $predicate has the signature `function (mixed $value, mixed $key, iterable $iterable): bool`.
* @template T
* @param iterable<T> $iterable
* @return ?T
* @template K
* @template V
* @param iterable<K, V> $iterable
* @param ?callable(V, K, iterable<K, V>): bool $predicate
* @return ?V
*/
public static function first(iterable $iterable, ?callable $predicate = null, ?callable $else = null)
{
@ -58,10 +59,11 @@ final class Iterables
}
/**
* Returns the key of first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
* The $predicate has the signature `function (mixed $value, mixed $key, iterable $iterable): bool`.
* @template T
* @param iterable<T, mixed> $iterable
* @return ?T
* @template K
* @template V
* @param iterable<K, V> $iterable
* @param ?callable(V, K, iterable<K, V>): bool $predicate
* @return ?K
*/
public static function firstKey(iterable $iterable, ?callable $predicate = null, ?callable $else = null)
{
@ -73,11 +75,10 @@ final class Iterables
return $else ? $else() : null;
}
/**
* Tests whether at least one element in the iterator passes the test implemented by the
* provided callback with signature `function (mixed $value, mixed $key, iterable $iterable): bool`.
* Tests whether at least one element in the iterator passes the test implemented by the provided function.
* @template K
* @template V
* @param iterable<K, V> $iterable
* @param iterable<K, V> $iterable
* @param callable(V, K, iterable<K, V>): bool $predicate
*/
public static function some(iterable $iterable, callable $predicate) : bool
@ -90,11 +91,10 @@ final class Iterables
return \false;
}
/**
* Tests whether all elements in the iterator pass the test implemented by the provided function,
* which has the signature `function (mixed $value, mixed $key, iterable $iterable): bool`.
* Tests whether all elements in the iterator pass the test implemented by the provided function.
* @template K
* @template V
* @param iterable<K, V> $iterable
* @param iterable<K, V> $iterable
* @param callable(V, K, iterable<K, V>): bool $predicate
*/
public static function every(iterable $iterable, callable $predicate) : bool
@ -108,11 +108,10 @@ final class Iterables
}
/**
* Iterator that filters elements according to a given $predicate. Maintains original keys.
* The callback has the signature `function (mixed $value, mixed $key, iterable $iterable): bool`.
* @template K
* @template V
* @param iterable<K, V> $iterable
* @param callable(V, K, iterable<K, V>): bool $predicate
* @param iterable<K, V> $iterable
* @param callable(V, K, iterable<K, V>): bool $predicate
* @return \Generator<K, V>
*/
public static function filter(iterable $iterable, callable $predicate) : \Generator
@ -125,12 +124,11 @@ final class Iterables
}
/**
* Iterator that transforms values by calling $transformer. Maintains original keys.
* The callback has the signature `function (mixed $value, mixed $key, iterable $iterable): bool`.
* @template K
* @template V
* @template R
* @param iterable<K, V> $iterable
* @param callable(V, K, iterable<K, V>): R $transformer
* @param iterable<K, V> $iterable
* @param callable(V, K, iterable<K, V>): R $transformer
* @return \Generator<K, R>
*/
public static function map(iterable $iterable, callable $transformer) : \Generator
@ -139,4 +137,89 @@ final class Iterables
(yield $k => $transformer($v, $k, $iterable));
}
}
/**
* Iterator that transforms keys and values by calling $transformer. If it returns null, the element is skipped.
* @template K
* @template V
* @template ResV
* @template ResK
* @param iterable<K, V> $iterable
* @param callable(V, K, iterable<K, V>): ?array{ResV, ResK} $transformer
* @return \Generator<ResV, ResK>
*/
public static function mapWithKeys(iterable $iterable, callable $transformer) : \Generator
{
foreach ($iterable as $k => $v) {
$pair = $transformer($v, $k, $iterable);
if ($pair) {
(yield $pair[0] => $pair[1]);
}
}
}
/**
* Wraps around iterator and caches its keys and values during iteration.
* This allows the data to be re-iterated multiple times.
* @template K
* @template V
* @param iterable<K, V> $iterable
* @return \IteratorAggregate<K, V>
*/
public static function memoize(iterable $iterable) : iterable
{
return new class(self::toIterator($iterable)) implements \IteratorAggregate
{
/**
* @var \Iterator
*/
private $iterator;
/**
* @var mixed[]
*/
private $cache = [];
public function __construct(\Iterator $iterator, array $cache = [])
{
$this->iterator = $iterator;
$this->cache = $cache;
}
public function getIterator() : \Generator
{
if (!$this->cache) {
$this->iterator->rewind();
}
$i = 0;
while (\true) {
if (isset($this->cache[$i])) {
[$k, $v] = $this->cache[$i];
} elseif ($this->iterator->valid()) {
$k = $this->iterator->key();
$v = $this->iterator->current();
$this->iterator->next();
$this->cache[$i] = [$k, $v];
} else {
break;
}
(yield $k => $v);
$i++;
}
}
};
}
/**
* Creates an iterator from anything that is iterable.
* @template K
* @template V
* @param iterable<K, V> $iterable
* @return \Iterator<K, V>
*/
public static function toIterator(iterable $iterable) : \Iterator
{
switch (\true) {
case $iterable instanceof \Iterator:
return $iterable;
case $iterable instanceof \IteratorAggregate:
return self::toIterator($iterable->getIterator());
case \is_array($iterable):
return new \ArrayIterator($iterable);
}
}
}

View File

@ -75,7 +75,7 @@ final class Reflection
return $method;
}
$hash = [$method->getFileName(), $method->getStartLine(), $method->getEndLine()];
if (($alias = $decl->getTraitAliases()[$method->name] ?? null) && ($m = new \ReflectionMethod($alias)) && $hash === [$m->getFileName(), $m->getStartLine(), $m->getEndLine()]) {
if (($alias = $decl->getTraitAliases()[$method->name] ?? null) && ($m = new \ReflectionMethod(...\explode('::', $alias, 2))) && $hash === [$m->getFileName(), $m->getStartLine(), $m->getEndLine()]) {
return self::getMethodDeclaringMethod($m);
}
foreach ($decl->getTraits() as $trait) {
@ -91,7 +91,7 @@ final class Reflection
public static function areCommentsAvailable() : bool
{
static $res;
return $res ?? ($res = (bool) (new \ReflectionMethod(__METHOD__))->getDocComment());
return $res ?? ($res = (bool) (new \ReflectionMethod(self::class, __FUNCTION__))->getDocComment());
}
public static function toString(\Reflector $ref) : string
{
@ -100,7 +100,7 @@ final class Reflection
} elseif ($ref instanceof \ReflectionMethod) {
return $ref->getDeclaringClass()->name . '::' . $ref->name . '()';
} elseif ($ref instanceof \ReflectionFunction) {
return $ref->name . '()';
return \PHP_VERSION_ID >= 80200 && $ref->isAnonymous() ? '{closure}()' : $ref->name . '()';
} elseif ($ref instanceof \ReflectionProperty) {
return self::getPropertyDeclaringClass($ref)->name . '::$' . $ref->name;
} elseif ($ref instanceof \ReflectionParameter) {

View File

@ -486,6 +486,7 @@ class Strings
/**
* Searches the string for all occurrences matching the regular expression and
* returns an array of arrays containing the found expression and each subexpression.
* @return ($lazy is true ? \Generator<int, array> : array[])
* @param bool|int $captureOffset
*/
public static function matchAll(
@ -498,17 +499,35 @@ class Strings
int $offset = 0,
bool $unmatchedAsNull = \false,
bool $patternOrder = \false,
bool $utf8 = \false
) : array
bool $utf8 = \false,
bool $lazy = \false
)
{
$flags = \is_int($captureOffset) ? $captureOffset : ($captureOffset ? \PREG_OFFSET_CAPTURE : 0) | ($unmatchedAsNull ? \PREG_UNMATCHED_AS_NULL : 0) | ($patternOrder ? \PREG_PATTERN_ORDER : 0);
if ($utf8) {
$offset = strlen(self::substring($subject, 0, $offset));
$pattern .= 'u';
}
if ($lazy) {
$flags = \PREG_OFFSET_CAPTURE | ($unmatchedAsNull ? \PREG_UNMATCHED_AS_NULL : 0);
return (function () use($utf8, $captureOffset, $flags, $subject, $pattern, $offset) {
$counter = 0;
while ($offset <= strlen($subject) - ($counter ? 1 : 0) && self::pcre('preg_match', [$pattern, $subject, &$m, $flags, $offset])) {
$offset = $m[0][1] + \max(1, strlen($m[0][0]));
if (!$captureOffset) {
$m = \array_map(function ($item) {
return $item[0];
}, $m);
} elseif ($utf8) {
$m = self::bytesToChars($subject, [$m])[0];
}
(yield $counter++ => $m);
}
})();
}
if ($offset > strlen($subject)) {
return [];
}
$flags = \is_int($captureOffset) ? $captureOffset : ($captureOffset ? \PREG_OFFSET_CAPTURE : 0) | ($unmatchedAsNull ? \PREG_UNMATCHED_AS_NULL : 0) | ($patternOrder ? \PREG_PATTERN_ORDER : 0);
self::pcre('preg_match_all', [$pattern, $subject, &$m, $flags & \PREG_PATTERN_ORDER ? $flags : $flags | \PREG_SET_ORDER, $offset]);
return $utf8 && $captureOffset ? self::bytesToChars($subject, $m) : $m;
}

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 3ba7adb'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main c053b97'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main acfcef8'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 01e3fe7'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 11ac7b9'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main c053b97'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 2bacfc6'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main ece9272'));
private function __construct()
{
}

View File

@ -1,6 +1,6 @@
# Rector Rules for Doctrine
See available [Doctrine rules](/docs/rector_rules_overview.md)
See available [Doctrine rules](https://getrector.com/find-rule?query=doctrine+rules)
## Install

View File

@ -19,7 +19,7 @@
"symplify\/easy-coding-standard": "^12.3",
"symplify\/phpstan-extensions": "^11.4",
"symplify\/phpstan-rules": "^13.0",
"symplify\/rule-doc-generator": "^12.2",
"symplify\/rule-doc-generator": "^12.2.5",
"symplify\/vendor-patches": "^11.3",
"tomasvotruba\/class-leak": "^0.2.15",
"tomasvotruba\/unused-public": "^0.3",
@ -51,10 +51,7 @@
"phpstan": "vendor\/bin\/phpstan analyse --ansi --error-format symplify",
"rector": "vendor\/bin\/rector --ansi",
"check-cs": "vendor\/bin\/ecs check --ansi",
"fix-cs": "vendor\/bin\/ecs check --fix --ansi",
"docs": [
"vendor\/bin\/rule-doc-generator generate src rules --output-file docs\/rector_rules_overview.md --ansi"
]
"fix-cs": "vendor\/bin\/ecs check --fix --ansi"
},
"extra": {
"enable-patching": true

View File

@ -1,5 +1,11 @@
# 18 Rules Overview
**This overview is deprecated and replaced by more advanced web search. There you can search and filter by nodes, copy-paste configs for configurable rules and more.**
Use https://getrector.com/find-rule?query=doctrine+rules instead!
---
## AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector
Adds `@return` PHPDoc type to Collection property getter by *ToMany annotation/attribute

View File

@ -1,6 +1,6 @@
# Rector Rules for PHPUnit
See available [PHPUnit rules](/docs/rector_rules_overview.md)
See available [PHPUnit rules](https://getrector.com/find-rule?query=phpunit+rules)
## Install

View File

@ -13,7 +13,7 @@
"symplify\/phpstan-rules": "^13.0",
"symplify\/phpstan-extensions": "^11.2",
"symplify\/easy-coding-standard": "^12.3",
"symplify\/rule-doc-generator": "^12.0",
"symplify\/rule-doc-generator": "^12.2.5",
"phpstan\/extension-installer": "^1.4",
"phpstan\/phpstan-webmozart-assert": "^1.2",
"symplify\/vendor-patches": "^11.2",
@ -53,8 +53,7 @@
"check-cs": "vendor\/bin\/ecs check --ansi",
"class-leak": "vendor\/bin\/class-leak check config src rules --skip-suffix \"Rector\"",
"fix-cs": "vendor\/bin\/ecs check --fix --ansi",
"rector": "vendor\/bin\/rector process --ansi",
"docs": "vendor\/bin\/rule-doc-generator generate src rules --output-file docs\/rector_rules_overview.md --ansi"
"rector": "vendor\/bin\/rector process --ansi"
},
"extra": {
"enable-patching": true,

View File

@ -1,5 +1,11 @@
# 55 Rules Overview
**This overview is deprecated and replaced by more advanced web search. There you can search and filter by nodes, copy-paste configs for configurable rules and more.**
Use https://getrector.com/find-rule?query=phpunit+rules instead!
---
## AddCoversClassAttributeRector
Adds `#[CoversClass(...)]` attribute to test files guessing source class name.

View File

@ -1,6 +1,6 @@
# Rector Rules for Symfony
See available [Symfony rules](/docs/rector_rules_overview.md)
See available [Symfony rules](https://getrector.com/find-rule?query=symfony+rules)
## Install

View File

@ -24,7 +24,7 @@
"symplify\/easy-coding-standard": "^12.3",
"symplify\/phpstan-extensions": "^11.4",
"symplify\/phpstan-rules": "^13.0",
"symplify\/rule-doc-generator": "^12.2.2",
"symplify\/rule-doc-generator": "^12.2.5",
"symplify\/vendor-patches": "^11.3",
"tomasvotruba\/class-leak": "^0.2",
"tomasvotruba\/unused-public": "^0.3.10",
@ -52,8 +52,7 @@
"scripts": {
"phpstan": "vendor\/bin\/phpstan analyse --ansi --error-format symplify",
"check-cs": "vendor\/bin\/ecs check --ansi",
"fix-cs": "vendor\/bin\/ecs check --fix --ansi",
"docs": "vendor\/bin\/rule-doc-generator generate src rules --output-file docs\/rector_rules_overview.md --ansi"
"fix-cs": "vendor\/bin\/ecs check --fix --ansi"
},
"extra": {
"enable-patching": true

View File

@ -1,5 +1,11 @@
# 85 Rules Overview
**This overview is deprecated and replaced by more advanced web search. There you can search and filter by nodes, copy-paste configs for configurable rules and more.**
Use https://getrector.com/find-rule?query=symfony+rules instead!
---
## ActionSuffixRemoverRector
Removes Action suffixes from methods in Symfony Controllers

View File

@ -14,7 +14,7 @@ $loader = (static function () {
// Restore the backup and ensure the excluded files are properly marked as loaded
$GLOBALS['__composer_autoload_files'] = \array_merge(
$existingComposerAutoloadFiles,
\array_fill_keys(['0e6d7bf4a5811bfa5cf40c5ccd6fae6a', '5928a00fa978807cf85d90ec3f4b0147'], true)
\array_fill_keys(['5928a00fa978807cf85d90ec3f4b0147', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a'], true)
);
return $loader;
@ -30,7 +30,7 @@ if (!function_exists('humbug_phpscoper_expose_class')) {
}
}
humbug_phpscoper_expose_class('AutoloadIncluder', 'RectorPrefix202408\AutoloadIncluder');
humbug_phpscoper_expose_class('ComposerAutoloaderInit4bcaef4da4b0314c67dae59e30837b25', 'RectorPrefix202408\ComposerAutoloaderInit4bcaef4da4b0314c67dae59e30837b25');
humbug_phpscoper_expose_class('ComposerAutoloaderInit969cf4fb8686733ba64d08544d342ca0', 'RectorPrefix202408\ComposerAutoloaderInit969cf4fb8686733ba64d08544d342ca0');
humbug_phpscoper_expose_class('Product', 'RectorPrefix202408\Product');
// Function aliases. For more information see: