Skip to content

Commit

Permalink
Updated Rector to commit 58c8f170182d3350e21a3b141bb3971651943e63
Browse files Browse the repository at this point in the history
rectorphp/rector-src@58c8f17 [CodingStyle] Add DataProviderArrayItemsNewlinedRector (#3271)
  • Loading branch information
TomasVotruba committed Jan 10, 2023
1 parent 70d56f8 commit b771e1c
Show file tree
Hide file tree
Showing 18 changed files with 175 additions and 44 deletions.
4 changes: 2 additions & 2 deletions packages/ChangesReporting/Output/ConsoleOutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ private function reportRemovedFilesAndNodes(ProcessResult $processResult) : void
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
{
Expand Down
5 changes: 5 additions & 0 deletions packages/NodeTypeResolver/Node/AttributeKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
12 changes: 1 addition & 11 deletions rules/Naming/Naming/PropertyNaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,6 @@ public function fqnToVariableName($objectType) : string
// 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) {
Expand Down Expand Up @@ -234,7 +224,7 @@ private function normalizeShortClassName(string $shortClassName) : string
$shortClassName = \strtolower($shortClassName);
}
// remove "_"
$shortClassName = Strings::replace($shortClassName, '#_#', '');
$shortClassName = Strings::replace($shortClassName, '#_#');
return $this->normalizeUpperCase($shortClassName);
}
private function resolveClassNameFromType(Type $type) : ?string
Expand Down
2 changes: 1 addition & 1 deletion rules/PSR4/FileInfoAnalyzer/FileInfoDeletionAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public function isClassLikeAndFileInfoMatch(File $file, ClassLike $classLike) :
}
private function clearNameFromTestingPrefix(string $name) : string
{
return Strings::replace($name, self::TESTING_PREFIX_REGEX, '');
return Strings::replace($name, self::TESTING_PREFIX_REGEX);
}
}
2 changes: 1 addition & 1 deletion rules/Php55/RegexMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function resolveModifiers(string $modifiersCandidate) : string
}
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
Expand Down
8 changes: 2 additions & 6 deletions rules/Php73/Rector/String_/SensitiveHereNowDocRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,11 +57,11 @@ public function refactor(Node $node) : ?Node
}
// 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;
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
9 changes: 7 additions & 2 deletions src/PhpParser/Printer/BetterStandardPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected function pArray(array $nodes, array $origNodes, int &$pos, int $indent
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:
Expand Down Expand Up @@ -262,6 +262,11 @@ protected function pExpr_Array(Array_ $array) : string
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);
}
/**
Expand Down Expand Up @@ -310,7 +315,7 @@ protected function pStmt_ClassMethod(ClassMethod $classMethod) : string
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
{
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit94cdc26f3ced1adb2ace61719468a5ec::getLoader();
return ComposerAutoloaderInit58c70eaf531a8b46e8c985851030093e::getLoader();
1 change: 1 addition & 0 deletions vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@
'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',
Expand Down
10 changes: 5 additions & 5 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit94cdc26f3ced1adb2ace61719468a5ec
class ComposerAutoloaderInit58c70eaf531a8b46e8c985851030093e
{
private static $loader;

Expand All @@ -22,17 +22,17 @@ public static function getLoader()
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;
Expand Down
9 changes: 5 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit94cdc26f3ced1adb2ace61719468a5ec
class ComposerStaticInit58c70eaf531a8b46e8c985851030093e
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 6 additions & 5 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand All @@ -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"
},
Expand Down
Loading

0 comments on commit b771e1c

Please sign in to comment.