Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ecs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,10 @@ parameters:
# intentional "assertEquals()"
- 'tests/PhpParser/Node/NodeFactoryTest.php'
- '*TypeResolverTest.php'

Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer:
# buggy with PHP heredoc
- 'packages/SOLID/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php'
- 'packages/Php/src/Rector/FuncCall/SensitiveDefineRector.php'
- 'packages/Php/src/Rector/Name/ReservedObjectRector.php'
- 'packages/Php/src/Rector/Assign/AssignArrayToStringRector.php'
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getDefinition(): RectorDefinition
{
return new RectorDefinition('', [
new CodeSample(
<<<'CODE_SAMPLE'
<<<'PHP'
final class SomeController
{
/**
Expand All @@ -70,17 +70,17 @@ public function default()
$products = $this->productRepository->fetchAll();
}
}
CODE_SAMPLE
PHP
,
<<<'CODE_SAMPLE'
<<<'PHP'
final class SomeController
{
public function default(ProductRepository $productRepository)
{
$products = $productRepository->fetchAll();
}
}
CODE_SAMPLE
PHP
),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Removes repository class from @Entity annotation', [
new CodeSample(
<<<'CODE_SAMPLE'
<<<'PHP'
use Doctrine\ORM\Mapping as ORM;

/**
Expand All @@ -39,9 +39,9 @@ public function getDefinition(): RectorDefinition
class Product
{
}
CODE_SAMPLE
PHP
,
<<<'CODE_SAMPLE'
<<<'PHP'
use Doctrine\ORM\Mapping as ORM;

/**
Expand All @@ -50,7 +50,7 @@ class Product
class Product
{
}
CODE_SAMPLE
PHP
),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(FileMover $fileMover, DocBlockManipulator $docBlockM
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Move entities to Entity namespace', [new CodeSample(
<<<'CODE_SAMPLE'
<<<'PHP'
// file: app/Controller/Product.php

namespace App\Controller;
Expand All @@ -54,9 +54,9 @@ public function getDefinition(): RectorDefinition
class Product
{
}
CODE_SAMPLE
PHP
,
<<<'CODE_SAMPLE'
<<<'PHP'
// file: app/Entity/Product.php

namespace App\Entity;
Expand All @@ -69,7 +69,7 @@ class Product
class Product
{
}
CODE_SAMPLE
PHP
)]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ public function __construct(FileMover $fileMover)
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Move interface to "Contract" namespace', [new CodeSample(
<<<'CODE_SAMPLE'
<<<'PHP'
// file: app/Exception/Rule.php

namespace App\Exception;

interface Rule
{
}
CODE_SAMPLE
PHP
,
<<<'CODE_SAMPLE'
<<<'PHP'
// file: app/Contract/Rule.php

namespace App\Contract;

interface Rule
{
}
CODE_SAMPLE
PHP
)]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@ public function refactor(SmartFileInfo $smartFileInfo): void
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Move classes by their suffix to their own group/directory', [new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
<<<'PHP'
// file: app/Entity/ProductRepository.php

namespace App/Entity;

class ProductRepository
{
}
CODE_SAMPLE
PHP
,
<<<'CODE_SAMPLE'
<<<'PHP'
// file: app/Repository/ProductRepository.php

namespace App/Repository;

class ProductRepository
{
}
CODE_SAMPLE
PHP
,
[
'$groupNamesBySuffix' => ['Repository'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,58 +37,36 @@ protected function getCurrentPhpNode(): Node
return $this->currentNodeProvider->getNode();
}

/**
* Skip all tokens for this annotation, so next annotation can work with tokens after this one
* Inspired at @see \PHPStan\PhpDocParser\Parser\PhpDocParser::parseText()
*/
protected function resolveAnnotationContent(TokenIterator $tokenIterator): string
{
$tokenIterator->pushSavePoint();

$singleLineContent = $tokenIterator->joinUntil(
Lexer::TOKEN_END,
Lexer::TOKEN_PHPDOC_EOL,
Lexer::TOKEN_CLOSE_PHPDOC
);

$tokenIterator->rollback();

if ($singleLineContent === '' || Strings::match($singleLineContent, '#^\((.*?)\)$#m')) {
$annotationContent = $singleLineContent;
$tokenIterator->joinUntil(Lexer::TOKEN_END, Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC);
} else { // multiline - content
// skip all tokens for this annotation, so next annotation can work with tokens after this one
$tokenIterator->pushSavePoint();

$annotationContent = $tokenIterator->joinUntil(Lexer::TOKEN_END, Lexer::TOKEN_CLOSE_PHPDOC);
if (! Strings::match($annotationContent, '#\)\s+$#m')) {
$tokenIterator->rollback();

/** inspired at @see \PHPStan\PhpDocParser\Parser\PhpDocParser::parseText() */
$annotationContent = '';
$unclosedOpenedBracketCount = 0;
while (true) {
if ($tokenIterator->currentTokenType() === Lexer::TOKEN_OPEN_PARENTHESES) {
++$unclosedOpenedBracketCount;
}

if ($tokenIterator->currentTokenType() === Lexer::TOKEN_CLOSE_PARENTHESES) {
--$unclosedOpenedBracketCount;
}
$annotationContent = '';
$unclosedOpenedBracketCount = 0;
while (true) {
if ($tokenIterator->currentTokenType() === Lexer::TOKEN_OPEN_PARENTHESES) {
++$unclosedOpenedBracketCount;
}

if ($unclosedOpenedBracketCount === 0 && $tokenIterator->currentTokenType() === Lexer::TOKEN_PHPDOC_EOL) {
break;
}
if ($tokenIterator->currentTokenType() === Lexer::TOKEN_CLOSE_PARENTHESES) {
--$unclosedOpenedBracketCount;
}

// remove new line "*"
if (Strings::contains($tokenIterator->currentTokenValue(), '*')) {
$tokenValueWithoutAsterisk = Strings::replace($tokenIterator->currentTokenValue(), '#\*#');
$annotationContent .= $tokenValueWithoutAsterisk;
} else {
$annotationContent .= $tokenIterator->currentTokenValue();
}
if ($unclosedOpenedBracketCount === 0 && $tokenIterator->currentTokenType() === Lexer::TOKEN_PHPDOC_EOL) {
break;
}

$tokenIterator->next();
}
// remove new line "*"
if (Strings::contains($tokenIterator->currentTokenValue(), '*')) {
$tokenValueWithoutAsterisk = Strings::replace($tokenIterator->currentTokenValue(), '#\*#');
$annotationContent .= $tokenValueWithoutAsterisk;
} else {
$tokenIterator->dropSavePoint();
$annotationContent .= $tokenIterator->currentTokenValue();
}

$tokenIterator->next();
}

return $this->cleanMultilineAnnotationContent($annotationContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public function parse(TokenIterator $tokenIterator): PhpDocNode
$children = [];
if (! $tokenIterator->isCurrentTokenType(Lexer::TOKEN_CLOSE_PHPDOC)) {
$children[] = $this->parseChildAndStoreItsPositions($tokenIterator);

while ($tokenIterator->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL) && ! $tokenIterator->isCurrentTokenType(
Lexer::TOKEN_CLOSE_PHPDOC
)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
* @ORM\Table(name="amenity_building", uniqueConstraints={
* @ORM\UniqueConstraint(name="building_id_amenity_id", columns={"building_id", "amenity_id"})
* })
* @ORM\Entity
* @ORM\DiscriminatorMap({
* "portfolio" = PortfolioBillingProfile::class,
* "user" = UserBillingProfile::class
* })
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
*/
final class SomeEntityClass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
* @ORM\Table(name="amenity_building", uniqueConstraints={@ORM\UniqueConstraint(name="building_id_amenity_id",
* columns={"building_id", "amenity_id"})}
* )
* @ORM\Entity
* @ORM\DiscriminatorMap({
* "portfolio" = PortfolioBillingProfile::class,
* "user" = UserBillingProfile::class
* })
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
*/
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
* @ORM\Table(name="amenity_building", uniqueConstraints={
* @ORM\UniqueConstraint(name="building_id_amenity_id", columns={"building_id", "amenity_id"})
* })
* @ORM\Entity
* @ORM\DiscriminatorMap({
* "portfolio" = PortfolioBillingProfile::class,
* "user" = UserBillingProfile::class
* })
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
*/
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ public function getDefinition(): RectorDefinition
'Changes combined set/get `value()` to specific `getValue()` or `setValue(x)`.',
[
new CodeSample(
<<<'CODE_SAMPLE'
<<<'PHP'
$object = new InstanceConfigTrait;

$config = $object->config();
$config = $object->config('key');

$object->config('key', 'value');
$object->config(['key' => 'value']);
CODE_SAMPLE
PHP
,
<<<'CODE_SAMPLE'
<<<'PHP'
$object = new InstanceConfigTrait;

$config = $object->getConfig();
$config = $object->getConfig('key');

$object->setConfig('key', 'value');
$object->setConfig(['key' => 'value']);
CODE_SAMPLE
PHP
),
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Changes $fixtues style from snake_case to CamelCase.', [
new CodeSample(
<<<'CODE_SAMPLE'
<<<'PHP'
class SomeTest
{
protected $fixtures = [
'app.posts',
'app.users',
'some_plugin.posts/special_posts',
];
CODE_SAMPLE
PHP
,
<<<'CODE_SAMPLE'
<<<'PHP'
class SomeTest
{
protected $fixtures = [
'app.Posts',
'app.Users',
'some_plugin.Posts/SpeectialPosts',
];
CODE_SAMPLE
PHP
),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Change OR, AND to ||, && with more common understanding', [
new CodeSample(
<<<'CODE_SAMPLE'
<<<'PHP'
if ($f = false or true) {
return $f;
}
CODE_SAMPLE
PHP
,
<<<'CODE_SAMPLE'
<<<'PHP'
if (($f = false) || true) {
return $f;
}
CODE_SAMPLE
PHP
),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Changes settype() to (type) where possible', [
new CodeSample(
<<<'CODE_SAMPLE'
<<<'PHP'
class SomeClass
{
public function run($foo)
Expand All @@ -55,9 +55,9 @@ public function run($foo)
return settype($foo, 'integer');
}
}
CODE_SAMPLE
PHP
,
<<<'CODE_SAMPLE'
<<<'PHP'
class SomeClass
{
public function run(array $items)
Expand All @@ -67,7 +67,7 @@ public function run(array $items)
return (int) $foo;
}
}
CODE_SAMPLE
PHP
),
]);
}
Expand Down
Loading