Updated Rector to commit 58c8f170182d3350e21a3b141bb3971651943e63

58c8f17018 [CodingStyle] Add DataProviderArrayItemsNewlinedRector (#3271)
This commit is contained in:
Tomas Votruba 2023-01-10 11:07:38 +00:00
parent 70d56f8d24
commit b771e1ca1a
18 changed files with 175 additions and 44 deletions

View File

@ -120,8 +120,8 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
private function normalizePathsToRelativeWithLine(string $errorMessage) : string
{
$regex = '#' . \preg_quote(\getcwd(), '#') . '/#';
$errorMessage = Strings::replace($errorMessage, $regex, '');
return Strings::replace($errorMessage, self::ON_LINE_REGEX, ':');
$errorMessage = Strings::replace($errorMessage, $regex);
return Strings::replace($errorMessage, self::ON_LINE_REGEX);
}
private function reportRemovedNodes(ProcessResult $processResult) : void
{

View File

@ -157,4 +157,9 @@ final class AttributeKey
* @var string
*/
public const DOC_LABEL = 'docLabel';
/**
* Prints array in newlined fastion, one item per line
* @var string
*/
public const NEWLINED_ARRAY_PRINT = 'newlined_array_print';
}

View File

@ -0,0 +1,119 @@
<?php
declare (strict_types=1);
namespace Rector\CodingStyle\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\CodingStyle\Rector\ClassMethod\DataProviderArrayItemsNewlinedRector\DataProviderArrayItemsNewlinedRectorTest
*/
final class DataProviderArrayItemsNewlinedRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer
*/
private $testsNodeAnalyzer;
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer)
{
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change data provider in PHPUnit test case to newline per item', [new CodeSample(<<<'CODE_SAMPLE'
use PHPUnit\Framework\TestCase;
final class ImageBinaryTest extends TestCase
{
/**
* @dataProvider provideData()
*/
public function testGetBytesSize(string $content, int $number): void
{
// ...
}
public function provideData(): array
{
return [['content', 8], ['content123', 11]];
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use PHPUnit\Framework\TestCase;
final class ImageBinaryTest extends TestCase
{
/**
* @dataProvider provideData()
*/
public function testGetBytesSize(string $content, int $number): void
{
// ...
}
public function provideData(): array
{
return [
['content', 8],
['content123', 11]
];
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ClassMethod::class];
}
/**
* @param ClassMethod $node
*/
public function refactor(Node $node) : ?Node
{
if (!$node->isPublic()) {
return null;
}
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
return null;
}
// skip test methods
if ($this->isName($node, 'test*')) {
return null;
}
// find array in data provider - must contain a return node
/** @var Return_[] $returns */
$returns = $this->betterNodeFinder->findInstanceOf((array) $node->stmts, Return_::class);
$hasChanged = \false;
foreach ($returns as $return) {
if (!$return->expr instanceof Array_) {
continue;
}
$array = $return->expr;
if ($array->items === []) {
continue;
}
// ensure newlined printed
$array->setAttribute(AttributeKey::NEWLINED_ARRAY_PRINT, \true);
// invoke reprint
$array->setAttribute(AttributeKey::ORIGINAL_NODE, null);
$hasChanged = \true;
}
if ($hasChanged) {
return $node;
}
return null;
}
}

View File

@ -112,16 +112,6 @@ final class PropertyNaming
// prolong too short generic names with one namespace up
return $this->prolongIfTooShort($variableName, $className);
}
/**
* @api symfony
* @see https://stackoverflow.com/a/2792045/1348344
*/
public function underscoreToName(string $underscoreName) : string
{
$uppercaseWords = \ucwords($underscoreName, '_');
$pascalCaseName = \str_replace('_', '', $uppercaseWords);
return \lcfirst($pascalCaseName);
}
private function resolveShortClassName(string $className) : string
{
if (\strpos($className, '\\') !== \false) {
@ -234,7 +224,7 @@ final class PropertyNaming
$shortClassName = \strtolower($shortClassName);
}
// remove "_"
$shortClassName = Strings::replace($shortClassName, '#_#', '');
$shortClassName = Strings::replace($shortClassName, '#_#');
return $this->normalizeUpperCase($shortClassName);
}
private function resolveClassNameFromType(Type $type) : ?string

View File

@ -41,6 +41,6 @@ final class FileInfoDeletionAnalyzer
}
private function clearNameFromTestingPrefix(string $name) : string
{
return Strings::replace($name, self::TESTING_PREFIX_REGEX, '');
return Strings::replace($name, self::TESTING_PREFIX_REGEX);
}
}

View File

@ -89,7 +89,7 @@ final class RegexMatcher
}
private function createPatternWithoutE(string $pattern, string $delimiter, string $modifiers) : string
{
$modifiersWithoutE = Strings::replace($modifiers, '#e#', '');
$modifiersWithoutE = Strings::replace($modifiers, '#e#');
return Strings::before($pattern, $delimiter, -1) . $delimiter . $modifiersWithoutE;
}
private function matchConcat(Concat $concat) : ?Concat

View File

@ -21,10 +21,6 @@ final class SensitiveHereNowDocRector extends AbstractRector implements MinPhpVe
* @var string
*/
private const WRAP_SUFFIX = '_WRAP';
/**
* @var string
*/
private const ATTRIBUTE_DOC_LABEL = 'docLabel';
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::SENSITIVE_HERE_NOW_DOC;
@ -61,11 +57,11 @@ CODE_SAMPLE
}
// the doc label is not in the string → ok
/** @var string $docLabel */
$docLabel = $node->getAttribute(self::ATTRIBUTE_DOC_LABEL);
$docLabel = $node->getAttribute(AttributeKey::DOC_LABEL);
if (\strpos($node->value, $docLabel) === \false) {
return null;
}
$node->setAttribute(self::ATTRIBUTE_DOC_LABEL, $this->uniquateDocLabel($node->value, $docLabel));
$node->setAttribute(AttributeKey::DOC_LABEL, $this->uniquateDocLabel($node->value, $docLabel));
// invoke redraw
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
return $node;

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'e8dd953f10a7afc3610d5185c6b42216e6d9e050';
public const PACKAGE_VERSION = '58c8f170182d3350e21a3b141bb3971651943e63';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-01-09 12:13:11';
public const RELEASE_DATE = '2023-01-10 11:03:14';
/**
* @var int
*/

View File

@ -200,7 +200,7 @@ final class BetterStandardPrinter extends Standard implements NodePrinterInterfa
if (!$this->containsNop($nodes)) {
return $content;
}
return Strings::replace($content, self::EXTRA_SPACE_BEFORE_NOP_REGEX, '');
return Strings::replace($content, self::EXTRA_SPACE_BEFORE_NOP_REGEX);
}
/**
* Do not preslash all slashes (parent behavior), but only those:
@ -262,6 +262,11 @@ final class BetterStandardPrinter extends Standard implements NodePrinterInterfa
if (!$array->hasAttribute(AttributeKey::KIND)) {
$array->setAttribute(AttributeKey::KIND, Array_::KIND_SHORT);
}
if ($array->getAttribute(AttributeKey::NEWLINED_ARRAY_PRINT) === \true) {
$printedArray = '[';
$printedArray .= $this->pCommaSeparatedMultiline($array->items, \true);
return $printedArray . ($this->nl . ']');
}
return parent::pExpr_Array($array);
}
/**
@ -310,7 +315,7 @@ final class BetterStandardPrinter extends Standard implements NodePrinterInterfa
protected function pStmt_Declare(Declare_ $declare) : string
{
$declareString = parent::pStmt_Declare($declare);
return Strings::replace($declareString, '#\\s+#', '');
return Strings::replace($declareString, '#\\s+#');
}
protected function pExpr_Ternary(Ternary $ternary) : string
{

2
vendor/autoload.php vendored
View File

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

View File

@ -1284,6 +1284,7 @@ return array(
'Rector\\CodingStyle\\Rector\\ClassConst\\SplitGroupedClassConstantsRector' => $baseDir . '/rules/CodingStyle/Rector/ClassConst/SplitGroupedClassConstantsRector.php',
'Rector\\CodingStyle\\Rector\\ClassConst\\SplitGroupedConstantsAndPropertiesRector' => $baseDir . '/rules/CodingStyle/Rector/ClassConst/SplitGroupedConstantsAndPropertiesRector.php',
'Rector\\CodingStyle\\Rector\\ClassConst\\VarConstantCommentRector' => $baseDir . '/rules/CodingStyle/Rector/ClassConst/VarConstantCommentRector.php',
'Rector\\CodingStyle\\Rector\\ClassMethod\\DataProviderArrayItemsNewlinedRector' => $baseDir . '/rules/CodingStyle/Rector/ClassMethod/DataProviderArrayItemsNewlinedRector.php',
'Rector\\CodingStyle\\Rector\\ClassMethod\\FuncGetArgsToVariadicParamRector' => $baseDir . '/rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.php',
'Rector\\CodingStyle\\Rector\\ClassMethod\\MakeInheritedMethodVisibilitySameAsParentRector' => $baseDir . '/rules/CodingStyle/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector.php',
'Rector\\CodingStyle\\Rector\\ClassMethod\\NewlineBeforeNewAssignSetRector' => $baseDir . '/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit94cdc26f3ced1adb2ace61719468a5ec
class ComposerAutoloaderInit58c70eaf531a8b46e8c985851030093e
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit94cdc26f3ced1adb2ace61719468a5ec
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit94cdc26f3ced1adb2ace61719468a5ec', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit58c70eaf531a8b46e8c985851030093e', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit94cdc26f3ced1adb2ace61719468a5ec', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit58c70eaf531a8b46e8c985851030093e', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit94cdc26f3ced1adb2ace61719468a5ec::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit58c70eaf531a8b46e8c985851030093e::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit94cdc26f3ced1adb2ace61719468a5ec::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit58c70eaf531a8b46e8c985851030093e::$files;
$requireFile = 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 ComposerStaticInit94cdc26f3ced1adb2ace61719468a5ec
class ComposerStaticInit58c70eaf531a8b46e8c985851030093e
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1529,6 +1529,7 @@ class ComposerStaticInit94cdc26f3ced1adb2ace61719468a5ec
'Rector\\CodingStyle\\Rector\\ClassConst\\SplitGroupedClassConstantsRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassConst/SplitGroupedClassConstantsRector.php',
'Rector\\CodingStyle\\Rector\\ClassConst\\SplitGroupedConstantsAndPropertiesRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassConst/SplitGroupedConstantsAndPropertiesRector.php',
'Rector\\CodingStyle\\Rector\\ClassConst\\VarConstantCommentRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassConst/VarConstantCommentRector.php',
'Rector\\CodingStyle\\Rector\\ClassMethod\\DataProviderArrayItemsNewlinedRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassMethod/DataProviderArrayItemsNewlinedRector.php',
'Rector\\CodingStyle\\Rector\\ClassMethod\\FuncGetArgsToVariadicParamRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.php',
'Rector\\CodingStyle\\Rector\\ClassMethod\\MakeInheritedMethodVisibilitySameAsParentRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector.php',
'Rector\\CodingStyle\\Rector\\ClassMethod\\NewlineBeforeNewAssignSetRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php',
@ -3063,9 +3064,9 @@ class ComposerStaticInit94cdc26f3ced1adb2ace61719468a5ec
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit94cdc26f3ced1adb2ace61719468a5ec::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit94cdc26f3ced1adb2ace61719468a5ec::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit94cdc26f3ced1adb2ace61719468a5ec::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit58c70eaf531a8b46e8c985851030093e::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit58c70eaf531a8b46e8c985851030093e::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit58c70eaf531a8b46e8c985851030093e::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2122,12 +2122,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "46a2234f3463d662ea9756e0a1f25d61e146f331"
"reference": "3b132c15485836be4f16d9810a8390ce80ed553b"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/46a2234f3463d662ea9756e0a1f25d61e146f331",
"reference": "46a2234f3463d662ea9756e0a1f25d61e146f331",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/3b132c15485836be4f16d9810a8390ce80ed553b",
"reference": "3b132c15485836be4f16d9810a8390ce80ed553b",
"shasum": ""
},
"require": {
@ -2152,12 +2152,13 @@
"symfony\/security-http": "^6.1",
"symplify\/easy-ci": "^11.1",
"symplify\/easy-coding-standard": "^11.1",
"symplify\/monorepo-builder": "^11.1.30",
"symplify\/phpstan-extensions": "^11.1",
"symplify\/phpstan-rules": "^11.1",
"symplify\/rule-doc-generator": "^11.1",
"symplify\/vendor-patches": "^11.1"
},
"time": "2023-01-10T10:22:55+00:00",
"time": "2023-01-10T10:35:17+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -2184,7 +2185,7 @@
"description": "Rector upgrades rules for Symfony Framework",
"support": {
"issues": "https:\/\/github.com\/rectorphp\/rector-symfony\/issues",
"source": "https:\/\/github.com\/rectorphp\/rector-symfony\/tree\/main"
"source": "https:\/\/github.com\/rectorphp\/rector-symfony\/tree\/0.14.2"
},
"install-path": "..\/rector\/rector-symfony"
},

File diff suppressed because one or more lines are too long

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/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main f0c3c11'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6cf8d9d'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9ea5f62'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 97cab8d'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 46a2234'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main f0c3c11'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6cf8d9d'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9ea5f62'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 97cab8d'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3b132c1'));
private function __construct()
{
}

View File

@ -9,12 +9,12 @@
"symfony\/string": "^6.1"
},
"require-dev": {
"phpstan\/phpstan": "^1.9.2",
"phpstan\/extension-installer": "^1.2",
"phpstan\/phpstan": "^1.9.2",
"phpstan\/phpstan-webmozart-assert": "^1.2",
"phpunit\/phpunit": "^9.5",
"rector\/rector-debugging": "dev-main",
"rector\/phpstan-rules": "^0.6",
"rector\/rector-debugging": "dev-main",
"rector\/rector-generator": "^0.6",
"rector\/rector-src": "dev-main",
"symfony\/routing": "^6.1",
@ -22,6 +22,7 @@
"symfony\/security-http": "^6.1",
"symplify\/easy-ci": "^11.1",
"symplify\/easy-coding-standard": "^11.1",
"symplify\/monorepo-builder": "^11.1.30",
"symplify\/phpstan-extensions": "^11.1",
"symplify\/phpstan-rules": "^11.1",
"symplify\/rule-doc-generator": "^11.1",

View File

@ -0,0 +1,12 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202301;
use RectorPrefix202301\Symplify\MonorepoBuilder\Config\MBConfig;
use RectorPrefix202301\Symplify\MonorepoBuilder\Release\ReleaseWorker\PushTagReleaseWorker;
use RectorPrefix202301\Symplify\MonorepoBuilder\Release\ReleaseWorker\TagVersionReleaseWorker;
return static function (MBConfig $mbConfig) : void {
// @see https://github.com/symplify/monorepo-builder#6-release-flow
$mbConfig->workers([TagVersionReleaseWorker::class, PushTagReleaseWorker::class]);
};