-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce
AttributeAnalysis
(#7909)
Co-authored-by: Greg Korba <greg@codito.dev> The concept implemented in this PR was proposed and discussed here: #7395 (comment) #7395 (comment) #7395 (comment)
- Loading branch information
Showing
4 changed files
with
517 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* Dariusz Rumiński <dariusz.ruminski@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace PhpCsFixer\Tokenizer\Analyzer\Analysis; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @phpstan-type _AttributeItems list<array{start: int, end: int, name: string}> | ||
*/ | ||
final class AttributeAnalysis | ||
{ | ||
private int $startIndex; | ||
private int $endIndex; | ||
private int $openingBracketIndex; | ||
private int $closingBracketIndex; | ||
|
||
/** | ||
* @var _AttributeItems | ||
*/ | ||
private array $attributes; | ||
|
||
/** | ||
* @param _AttributeItems $attributes | ||
*/ | ||
public function __construct(int $startIndex, int $endIndex, int $openingBracketIndex, int $closingBracketIndex, array $attributes) | ||
{ | ||
$this->startIndex = $startIndex; | ||
$this->endIndex = $endIndex; | ||
$this->openingBracketIndex = $openingBracketIndex; | ||
$this->closingBracketIndex = $closingBracketIndex; | ||
$this->attributes = $attributes; | ||
} | ||
|
||
public function getStartIndex(): int | ||
{ | ||
return $this->startIndex; | ||
} | ||
|
||
public function getEndIndex(): int | ||
{ | ||
return $this->endIndex; | ||
} | ||
|
||
public function getOpeningBracketIndex(): int | ||
{ | ||
return $this->openingBracketIndex; | ||
} | ||
|
||
public function getClosingBracketIndex(): int | ||
{ | ||
return $this->closingBracketIndex; | ||
} | ||
|
||
/** | ||
* @return _AttributeItems | ||
*/ | ||
public function getAttributes(): array | ||
{ | ||
return $this->attributes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
tests/Tokenizer/Analyzer/Analysis/AttributeAnalysisTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* Dariusz Rumiński <dariusz.ruminski@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace PhpCsFixer\Tests\Tokenizer\Analyzer\Analysis; | ||
|
||
use PhpCsFixer\Tests\TestCase; | ||
use PhpCsFixer\Tokenizer\Analyzer\Analysis\AttributeAnalysis; | ||
|
||
/** | ||
* @covers \PhpCsFixer\Tokenizer\Analyzer\Analysis\AttributeAnalysis | ||
* | ||
* @internal | ||
*/ | ||
final class AttributeAnalysisTest extends TestCase | ||
{ | ||
public function testAttribute(): void | ||
{ | ||
$attributes = [ | ||
['start' => 3, 'end' => 12, 'name' => 'AB\\Baz'], | ||
['start' => 14, 'end' => 32, 'name' => '\\A\\B\\Qux'], | ||
]; | ||
$analysis = new AttributeAnalysis(2, 34, 3, 34, $attributes); | ||
|
||
self::assertSame(2, $analysis->getStartIndex()); | ||
self::assertSame(34, $analysis->getEndIndex()); | ||
self::assertSame(3, $analysis->getOpeningBracketIndex()); | ||
self::assertSame(34, $analysis->getClosingBracketIndex()); | ||
self::assertSame($attributes, $analysis->getAttributes()); | ||
} | ||
} |
Oops, something went wrong.