Skip to content

Commit

Permalink
Updated Rector to commit d246d27a9442cc08a419e899e07c2c19a680eb80
Browse files Browse the repository at this point in the history
rectorphp/rector-src@d246d27 [CodeQuality] Skip multiple lines on JoinStringConcatRector (#6404)
  • Loading branch information
TomasVotruba committed Oct 30, 2024
1 parent 6aa0ede commit 9798fd4
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 10 deletions.
1 change: 1 addition & 0 deletions vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,7 @@
'Rector\\PHPUnit\\CodeQuality\\Rector\\ClassMethod\\DataProviderArrayItemsNewLinedRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/ClassMethod/DataProviderArrayItemsNewLinedRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\ClassMethod\\RemoveEmptyTestMethodRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/ClassMethod/RemoveEmptyTestMethodRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\ClassMethod\\ReplaceTestAnnotationWithPrefixedFunctionRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/ClassMethod/ReplaceTestAnnotationWithPrefixedFunctionRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\ClassMethod\\ReplaceTestFunctionPrefixWithAttributeRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\Class_\\AddCoversClassAttributeRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/Class_/AddCoversClassAttributeRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\Class_\\AddParentSetupCallOnSetupRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/Class_/AddParentSetupCallOnSetupRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\Class_\\AddSeeTestAnnotationRector' => $vendorDir . '/rector/rector-phpunit/rules/CodeQuality/Rector/Class_/AddSeeTestAnnotationRector.php',
Expand Down
1 change: 1 addition & 0 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,7 @@ class ComposerStaticInit4d4c37b878ce01a3ff505ba7def6aac7
'Rector\\PHPUnit\\CodeQuality\\Rector\\ClassMethod\\DataProviderArrayItemsNewLinedRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/ClassMethod/DataProviderArrayItemsNewLinedRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\ClassMethod\\RemoveEmptyTestMethodRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/ClassMethod/RemoveEmptyTestMethodRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\ClassMethod\\ReplaceTestAnnotationWithPrefixedFunctionRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/ClassMethod/ReplaceTestAnnotationWithPrefixedFunctionRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\ClassMethod\\ReplaceTestFunctionPrefixWithAttributeRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\Class_\\AddCoversClassAttributeRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/Class_/AddCoversClassAttributeRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\Class_\\AddParentSetupCallOnSetupRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/Class_/AddParentSetupCallOnSetupRector.php',
'Rector\\PHPUnit\\CodeQuality\\Rector\\Class_\\AddSeeTestAnnotationRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/CodeQuality/Rector/Class_/AddSeeTestAnnotationRector.php',
Expand Down
16 changes: 8 additions & 8 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@
},
{
"name": "illuminate\/container",
"version": "v11.29.0",
"version_normalized": "11.29.0.0",
"version": "v11.30.0",
"version_normalized": "11.30.0.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/illuminate\/container.git",
Expand Down Expand Up @@ -569,8 +569,8 @@
},
{
"name": "illuminate\/contracts",
"version": "v11.29.0",
"version_normalized": "11.29.0.0",
"version": "v11.30.0",
"version_normalized": "11.30.0.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/illuminate\/contracts.git",
Expand Down Expand Up @@ -1811,12 +1811,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "4d6a2824c66bb265d1c0b769a5fb8bb2a6ddd278"
"reference": "8026eca60bd8398e59d7adf7b13f98d9d57a387f"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/4d6a2824c66bb265d1c0b769a5fb8bb2a6ddd278",
"reference": "4d6a2824c66bb265d1c0b769a5fb8bb2a6ddd278",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/8026eca60bd8398e59d7adf7b13f98d9d57a387f",
"reference": "8026eca60bd8398e59d7adf7b13f98d9d57a387f",
"shasum": ""
},
"require": {
Expand All @@ -1840,7 +1840,7 @@
"tomasvotruba\/class-leak": "^0.2",
"tracy\/tracy": "^2.10"
},
"time": "2024-10-25T23:57:17+00:00",
"time": "2024-10-30T16:55:08+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/installed.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/rector/extension-installer/src/GeneratedConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
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 e75008c'), '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 d9cef57'), '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 4d6a282'), '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 799b454'));
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 e75008c'), '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 d9cef57'), '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 8026eca'), '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 799b454'));
private function __construct()
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

declare (strict_types=1);
namespace Rector\PHPUnit\CodeQuality\Rector\ClassMethod;

use PhpParser\Node;
use PhpParser\Node\AttributeGroup;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector\ReplaceTestAnnotationWithPrefixedFunctionRectorTest
*/
final class ReplaceTestFunctionPrefixWithAttributeRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer
*/
private $testsNodeAnalyzer;
/**
* @readonly
* @var \Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory
*/
private $phpAttributeGroupFactory;
/**
* @readonly
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
*/
private $phpAttributeAnalyzer;
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer, PhpAttributeGroupFactory $phpAttributeGroupFactory, PhpAttributeAnalyzer $phpAttributeAnalyzer)
{
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
$this->phpAttributeGroupFactory = $phpAttributeGroupFactory;
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Replace @test with prefixed function', [new CodeSample(<<<'CODE_SAMPLE'
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function testOnePlusOneShouldBeTwo()
{
$this->assertSame(2, 1+1);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeTest extends \PHPUnit\Framework\TestCase
{
#[Test]
public function onePlusOneShouldBeTwo()
{
$this->assertSame(2, 1+1);
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ClassMethod::class];
}
/**
* @param ClassMethod $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
return null;
}
if (\strncmp($node->name->toString(), 'test', \strlen('test')) !== 0) {
return null;
}
if ($this->phpAttributeAnalyzer->hasPhpAttributes($node, ['PHPUnit\\Framework\\Attributes\\Test'])) {
return null;
}
if ($node->name->toString() !== 'test' && $node->name->toString() !== 'test_') {
if (\strncmp($node->name->toString(), 'test_', \strlen('test_')) === 0) {
$node->name->name = \lcfirst(\substr($node->name->name, 5));
} elseif (\strncmp($node->name->toString(), 'test', \strlen('test')) === 0) {
$node->name->name = \lcfirst(\substr($node->name->name, 4));
}
}
$coversAttributeGroup = $this->createAttributeGroup();
$node->attrGroups = \array_merge($node->attrGroups, [$coversAttributeGroup]);
return $node;
}
private function createAttributeGroup() : AttributeGroup
{
$attributeClass = 'PHPUnit\\Framework\\Attributes\\Test';
return $this->phpAttributeGroupFactory->createFromClassWithItems($attributeClass, []);
}
}

0 comments on commit 9798fd4

Please sign in to comment.