Skip to content

Commit

Permalink
Apply the PHPUnitSetList::PHPUNIT_CODE_QUALITY set of rules
Browse files Browse the repository at this point in the history
  • Loading branch information
lisachenko committed Feb 19, 2024
1 parent 6e30ac6 commit c676882
Show file tree
Hide file tree
Showing 33 changed files with 122 additions and 103 deletions.
3 changes: 2 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
// DeclareStrictTypesRector::class,
])
->withSets([
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
]);
1 change: 1 addition & 0 deletions src/Lexer/AbstractLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* SimpleLexer and StatefulLexer extend this class.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Lexer\AbstractLexerTest
*/
abstract class AbstractLexer implements Lexer
{
Expand Down
1 change: 1 addition & 0 deletions src/Lexer/Recognizer/RegexRecognizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* regular expression.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Lexer\Recognizer\RegexRecognizerTest
*/
class RegexRecognizer implements Recognizer
{
Expand Down
1 change: 1 addition & 0 deletions src/Lexer/Recognizer/SimpleRecognizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* strpos match.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Lexer\Recognizer\SimpleRecognizerTest
*/
class SimpleRecognizer implements Recognizer
{
Expand Down
1 change: 1 addition & 0 deletions src/Lexer/RegexLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Jonathan Wage <[email protected]>
* @author Roman Borschel <[email protected]>
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Lexer\RegexLexerTest
*/
abstract class RegexLexer implements Lexer
{
Expand Down
1 change: 1 addition & 0 deletions src/Lexer/SimpleLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* without keeping track of state.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Lexer\SimpleLexerTest
*/
class SimpleLexer extends AbstractLexer
{
Expand Down
1 change: 1 addition & 0 deletions src/Lexer/StatefulLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* but internally keeps notion of current lexer state.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Lexer\StatefulLexerTest
*/
class StatefulLexer extends AbstractLexer
{
Expand Down
1 change: 1 addition & 0 deletions src/Lexer/TokenStream/ArrayTokenStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* A simple array based implementation of a token stream.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Lexer\TokenStream\ArrayTokenStreamTest
*/
class ArrayTokenStream implements TokenStream
{
Expand Down
1 change: 1 addition & 0 deletions src/Parser/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Represents a context-free grammar.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Parser\GrammarTest
*/
class Grammar
{
Expand Down
1 change: 1 addition & 0 deletions src/Parser/LALR1/Analysis/Analyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* the result.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Parser\LALR1\Analysis\AnalyzerTest
*/
class Analyzer
{
Expand Down
1 change: 1 addition & 0 deletions src/Parser/LALR1/Analysis/Automaton.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* grammar productions.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Parser\LALR1\Analysis\AutomatonTest
*/
class Automaton
{
Expand Down
1 change: 1 addition & 0 deletions src/Parser/LALR1/Analysis/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* can be reduced.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Parser\LALR1\Analysis\ItemTest
*/
class Item
{
Expand Down
1 change: 1 addition & 0 deletions src/Parser/LALR1/Analysis/KernelSet/KernelSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* of states by their kernel items.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Parser\LALR1\Analysis\KernelSet\KernelSetTest
*/
class KernelSet
{
Expand Down
1 change: 1 addition & 0 deletions src/Parser/LALR1/Analysis/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* A state in a handle-finding FSA.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Parser\LALR1\Analysis\StateTest
*/
class State
{
Expand Down
1 change: 1 addition & 0 deletions src/Parser/LALR1/Dumper/AutomatonDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* format used by Graphviz.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Parser\LALR1\Dumper\AutomatonDumperTest
*/
class AutomatonDumper
{
Expand Down
1 change: 1 addition & 0 deletions src/Parser/LALR1/Dumper/DebugTableDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* parser.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Parser\LALR1\Dumper\DebugTableDumperTest
*/
class DebugTableDumper implements TableDumper
{
Expand Down
1 change: 1 addition & 0 deletions src/Parser/LALR1/Dumper/ProductionTableDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* without any comments.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Parser\LALR1\Dumper\ProductionTableDumperTest
*/
class ProductionTableDumper implements TableDumper
{
Expand Down
1 change: 1 addition & 0 deletions src/Parser/LALR1/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* A LR parser.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Parser\LALR1\ParserTest
*/
class Parser implements P\Parser
{
Expand Down
1 change: 1 addition & 0 deletions src/Parser/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Represents a rule in a context-free grammar.
*
* @author Jakub Lédl <[email protected]>
* @see \Dissect\Parser\RuleTest
*/
class Rule
{
Expand Down
26 changes: 13 additions & 13 deletions tests/Lexer/AbstractLexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ public function lexShouldDelegateToExtractTokenUpdatingTheLineAndOffsetAccording
{
$stream = $this->lexer->lex("ab\nc");

$this->assertEquals('a', $stream->getCurrentToken()->getValue());
$this->assertEquals(1, $stream->getCurrentToken()->getLine());
$this->assertSame('a', $stream->getCurrentToken()->getValue());
$this->assertSame(1, $stream->getCurrentToken()->getLine());
$stream->next();

$this->assertEquals('b', $stream->getCurrentToken()->getValue());
$this->assertEquals(1, $stream->getCurrentToken()->getLine());
$this->assertSame('b', $stream->getCurrentToken()->getValue());
$this->assertSame(1, $stream->getCurrentToken()->getLine());
$stream->next();

$this->assertEquals("\n", $stream->getCurrentToken()->getValue());
$this->assertEquals(1, $stream->getCurrentToken()->getLine());
$this->assertSame("\n", $stream->getCurrentToken()->getValue());
$this->assertSame(1, $stream->getCurrentToken()->getLine());
$stream->next();

$this->assertEquals('c', $stream->getCurrentToken()->getValue());
$this->assertEquals(2, $stream->getCurrentToken()->getLine());
$this->assertSame('c', $stream->getCurrentToken()->getValue());
$this->assertSame(2, $stream->getCurrentToken()->getLine());
}

#[\PHPUnit\Framework\Attributes\Test]
Expand All @@ -44,8 +44,8 @@ public function lexShouldAppendAnEofTokenAutomatically(): void
$stream = $this->lexer->lex("abc");
$stream->seek(3);

$this->assertEquals(Parser::EOF_TOKEN_TYPE, $stream->getCurrentToken()->getType());
$this->assertEquals(1, $stream->getCurrentToken()->getLine());
$this->assertSame(Parser::EOF_TOKEN_TYPE, $stream->getCurrentToken()->getType());
$this->assertSame(1, $stream->getCurrentToken()->getLine());
}

#[\PHPUnit\Framework\Attributes\Test]
Expand All @@ -55,21 +55,21 @@ public function lexShouldThrowAnExceptionOnAnUnrecognizableToken(): void
$this->lexer->lex("abcd");
$this->fail('Expected a RecognitionException.');
} catch (RecognitionException $e) {
$this->assertEquals(1, $e->getSourceLine());
$this->assertSame(1, $e->getSourceLine());
}
}

#[\PHPUnit\Framework\Attributes\Test]
public function lexShouldNormalizeLineEndingsBeforeLexing(): void
{
$stream = $this->lexer->lex("a\r\nb");
$this->assertEquals("\n", $stream->get(1)->getValue());
$this->assertSame("\n", $stream->get(1)->getValue());
}

#[\PHPUnit\Framework\Attributes\Test]
public function lexShouldSkipTokensIfToldToDoSo(): void
{
$stream = $this->lexer->lex('aeb');
$this->assertNotEquals('e', $stream->get(1)->getType());
$this->assertNotSame('e', $stream->get(1)->getType());
}
}
2 changes: 1 addition & 1 deletion tests/Lexer/Recognizer/RegexRecognizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function recognizerShouldMatchAndPassTheValueByReference(): void

$this->assertTrue($result);
$this->assertNotNull($value);
$this->assertEquals('lorem', $value);
$this->assertSame('lorem', $value);
}

#[\PHPUnit\Framework\Attributes\Test]
Expand Down
2 changes: 1 addition & 1 deletion tests/Lexer/Recognizer/SimpleRecognizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function recognizerShouldMatchAndPassTheValueByReference(): void

$this->assertTrue($result);
$this->assertNotNull($value);
$this->assertEquals('class', $value);
$this->assertSame('class', $value);
}

#[\PHPUnit\Framework\Attributes\Test]
Expand Down
10 changes: 5 additions & 5 deletions tests/Lexer/RegexLexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ public function itShouldCallGetTypeToRetrieveTokenType(): void
$stream = $this->lexer->lex('5 + 6');

$this->assertCount(4, $stream);
$this->assertEquals('INT', $stream->get(0)->getType());
$this->assertEquals('+', $stream->get(1)->getType());
$this->assertEquals(Parser::EOF_TOKEN_TYPE, $stream->get(3)->getType());
$this->assertSame('INT', $stream->get(0)->getType());
$this->assertSame('+', $stream->get(1)->getType());
$this->assertSame(Parser::EOF_TOKEN_TYPE, $stream->get(3)->getType());
}

#[\PHPUnit\Framework\Attributes\Test]
public function itShouldTrackLineNumbers(): void
{
$stream = $this->lexer->lex("5\n+\n\n5");

$this->assertEquals(2, $stream->get(1)->getLine());
$this->assertEquals(4, $stream->get(2)->getLine());
$this->assertSame(2, $stream->get(1)->getLine());
$this->assertSame(4, $stream->get(2)->getLine());
}
}
14 changes: 7 additions & 7 deletions tests/Lexer/SimpleLexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public function simpleLexerShouldWalkThroughTheRecognizers(): void
{
$stream = $this->lexer->lex('a (b) c');

$this->assertEquals(6, $stream->count()); // with EOF
$this->assertEquals('(', $stream->get(1)->getType());
$this->assertEquals(1, $stream->get(3)->getLine());
$this->assertEquals('C', $stream->get(4)->getType());
$this->assertSame(6, $stream->count()); // with EOF
$this->assertSame('(', $stream->get(1)->getType());
$this->assertSame(1, $stream->get(3)->getLine());
$this->assertSame('C', $stream->get(4)->getType());
}

#[\PHPUnit\Framework\Attributes\Test]
Expand All @@ -42,7 +42,7 @@ public function simpleLexerShouldSkipSpecifiedTokens(): void
$stream = $this->lexer->lex('a (b) c');

foreach ($stream as $token) {
$this->assertNotEquals('WS', $token->getType());
$this->assertNotSame('WS', $token->getType());
}
}

Expand All @@ -54,7 +54,7 @@ public function simpleLexerShouldReturnTheBestMatch(): void

$stream = $this->lexer->lex('class classloremipsum');

$this->assertEquals('CLASS', $stream->getCurrentToken()->getType());
$this->assertEquals('WORD', $stream->lookAhead(1)->getType());
$this->assertSame('CLASS', $stream->getCurrentToken()->getType());
$this->assertSame('WORD', $stream->lookAhead(1)->getType());
}
}
8 changes: 4 additions & 4 deletions tests/Lexer/StatefulLexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function theStateMechanismShouldCorrectlyPushAndPopStatesFromTheStack():
$stream = $this->lexer->lex('foo bar "long \\" string" baz quux');

$this->assertCount(8, $stream);
$this->assertEquals('STRING_CONTENTS', $stream->get(3)->getType());
$this->assertEquals('long \\" string', $stream->get(3)->getValue());
$this->assertEquals('quux', $stream->get(6)->getValue());
$this->assertSame('STRING_CONTENTS', $stream->get(3)->getType());
$this->assertSame('long \\" string', $stream->get(3)->getValue());
$this->assertSame('quux', $stream->get(6)->getValue());
}

#[\PHPUnit\Framework\Attributes\Test]
Expand All @@ -70,6 +70,6 @@ public function defaultActionShouldBeNop(): void
$this->lexer->start('root');

$stream = $this->lexer->lex('foo bar');
$this->assertEquals(3, $stream->count());
$this->assertSame(3, $stream->count());
}
}
16 changes: 8 additions & 8 deletions tests/Lexer/TokenStream/ArrayTokenStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function setUp(): void
#[\PHPUnit\Framework\Attributes\Test]
public function theCursorShouldBeOnFirstTokenByDefault(): void
{
$this->assertEquals('6', $this->stream->getCurrentToken()->getValue());
$this->assertSame('6', $this->stream->getCurrentToken()->getValue());
}

#[\PHPUnit\Framework\Attributes\Test]
Expand All @@ -35,13 +35,13 @@ public function getPositionShouldReturnCurrentPosition(): void
$this->stream->seek(2);
$this->stream->next();

$this->assertEquals(3, $this->stream->getPosition());
$this->assertSame(3, $this->stream->getPosition());
}

#[\PHPUnit\Framework\Attributes\Test]
public function lookAheadShouldReturnTheCorrectToken(): void
{
$this->assertEquals('5', $this->stream->lookAhead(2)->getValue());
$this->assertSame('5', $this->stream->lookAhead(2)->getValue());
}

#[\PHPUnit\Framework\Attributes\Test]
Expand All @@ -54,7 +54,7 @@ public function lookAheadShouldThrowAnExceptionWhenInvalid(): void
#[\PHPUnit\Framework\Attributes\Test]
public function getShouldReturnATokenByAbsolutePosition(): void
{
$this->assertEquals('3', $this->stream->get(4)->getValue());
$this->assertSame('3', $this->stream->get(4)->getValue());
}

#[\PHPUnit\Framework\Attributes\Test]
Expand All @@ -68,7 +68,7 @@ public function getShouldThrowAnExceptionWhenInvalid(): void
public function moveShouldMoveTheCursorByToAnAbsolutePosition(): void
{
$this->stream->move(2);
$this->assertEquals('5', $this->stream->getCurrentToken()->getValue());
$this->assertSame('5', $this->stream->getCurrentToken()->getValue());
}

#[\PHPUnit\Framework\Attributes\Test]
Expand All @@ -82,7 +82,7 @@ public function moveShouldThrowAnExceptionWhenInvalid(): void
public function seekShouldMoveTheCursorByRelativeOffset(): void
{
$this->stream->seek(4);
$this->assertEquals('3', $this->stream->getCurrentToken()->getValue());
$this->assertSame('3', $this->stream->getCurrentToken()->getValue());
}

#[\PHPUnit\Framework\Attributes\Test]
Expand All @@ -96,10 +96,10 @@ public function seekShouldThrowAnExceptionWhenInvalid(): void
public function nextShouldMoveTheCursorOneTokenAhead(): void
{
$this->stream->next();
$this->assertEquals('PLUS', $this->stream->getCurrentToken()->getType());
$this->assertSame('PLUS', $this->stream->getCurrentToken()->getType());

$this->stream->next();
$this->assertEquals('5', $this->stream->getCurrentToken()->getValue());
$this->assertSame('5', $this->stream->getCurrentToken()->getValue());
}

#[\PHPUnit\Framework\Attributes\Test]
Expand Down
Loading

0 comments on commit c676882

Please sign in to comment.