forked from WalterWoshid/php-dissect
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from goaop/feature/maintenance-of-library
Maintenance work on library
- Loading branch information
Showing
75 changed files
with
664 additions
and
774 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
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
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
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector; | ||
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; | ||
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; | ||
use Rector\Php71\Rector\ClassConst\PublicConstantVisibilityRector; | ||
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; | ||
use Rector\PHPUnit\Set\PHPUnitSetList; | ||
use Rector\TypeDeclaration\Rector\Class_\AddTestsVoidReturnTypeWhereNoReturnRector; | ||
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector; | ||
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector; | ||
|
||
return RectorConfig::configure() | ||
->withPaths([ | ||
__DIR__ . '/src', | ||
__DIR__ . '/tests', | ||
]) | ||
// uncomment to reach your current PHP version | ||
// ->withPhpSets() | ||
->withRules([ | ||
// Dead-code | ||
RemoveUselessParamTagRector::class, | ||
RemoveUselessReturnTagRector::class, | ||
RemoveUselessVarTagRector::class, | ||
PublicConstantVisibilityRector::class, | ||
ClosureToArrowFunctionRector::class, | ||
AddVoidReturnTypeWhereNoReturnRector::class, | ||
AddTestsVoidReturnTypeWhereNoReturnRector::class, | ||
// DeclareStrictTypesRector::class, | ||
]) | ||
->withSets([ | ||
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES, | ||
PHPUnitSetList::PHPUNIT_CODE_QUALITY, | ||
]); |
2 changes: 2 additions & 0 deletions
2
src/Dissect/Console/Application.php → src/Console/Application.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
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
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dissect\Lexer; | ||
|
||
use Dissect\Lexer\Exception\RecognitionException; | ||
use Dissect\Lexer\TokenStream\ArrayTokenStream; | ||
use Dissect\Lexer\TokenStream\TokenStream; | ||
use Dissect\Parser\Parser; | ||
use Dissect\Util\Util; | ||
|
||
|
@@ -13,18 +16,14 @@ | |
* SimpleLexer and StatefulLexer extend this class. | ||
* | ||
* @author Jakub Lédl <[email protected]> | ||
* @see \Dissect\Lexer\AbstractLexerTest | ||
*/ | ||
abstract class AbstractLexer implements Lexer | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private int $line = 1; | ||
|
||
/** | ||
* Returns the current line. | ||
* | ||
* @return int The current line. | ||
*/ | ||
protected function getCurrentLine(): int | ||
{ | ||
|
@@ -36,24 +35,18 @@ protected function getCurrentLine(): int | |
* Returns the token on success or null on failure. | ||
* | ||
* @param string $string The string to extract the token from. | ||
* | ||
* @return Token|null The extracted token or null. | ||
*/ | ||
abstract protected function extractToken(string $string): ?Token; | ||
|
||
/** | ||
* Should given token be skipped? | ||
* | ||
* @param Token $token The token to evaluate. | ||
* | ||
* @return boolean Whether to skip the token. | ||
*/ | ||
abstract protected function shouldSkipToken(Token $token): bool; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function lex(string $string): TokenStream\TokenStream|ArrayTokenStream | ||
public function lex(string $string): TokenStream | ||
{ | ||
// normalize line endings | ||
$string = strtr($string, ["\r\n" => "\n", "\r" => "\n"]); | ||
|
@@ -92,6 +85,6 @@ public function lex(string $string): TokenStream\TokenStream|ArrayTokenStream | |
|
||
$tokens[] = new CommonToken(Parser::EOF_TOKEN_TYPE, '', $this->line); | ||
|
||
return new ArrayTokenStream($tokens); | ||
return new ArrayTokenStream(...$tokens); | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
.../Lexer/Exception/RecognitionException.php → src/Lexer/Exception/RecognitionException.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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dissect\Lexer\Exception; | ||
|
||
use RuntimeException; | ||
|
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
2 changes: 2 additions & 0 deletions
2
src/Dissect/Lexer/Recognizer/Recognizer.php → src/Lexer/Recognizer/Recognizer.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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dissect\Lexer\Recognizer; | ||
|
||
/** | ||
|
3 changes: 3 additions & 0 deletions
3
...sect/Lexer/Recognizer/RegexRecognizer.php → src/Lexer/Recognizer/RegexRecognizer.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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dissect\Lexer\Recognizer; | ||
|
||
/** | ||
* The RegexRecognizer matches a string using a | ||
* regular expression. | ||
* | ||
* @author Jakub Lédl <[email protected]> | ||
* @see \Dissect\Lexer\Recognizer\RegexRecognizerTest | ||
*/ | ||
class RegexRecognizer implements Recognizer | ||
{ | ||
|
3 changes: 3 additions & 0 deletions
3
...ect/Lexer/Recognizer/SimpleRecognizer.php → src/Lexer/Recognizer/SimpleRecognizer.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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dissect\Lexer\Recognizer; | ||
|
||
/** | ||
* SimpleRecognizer matches a string by a simple | ||
* strpos match. | ||
* | ||
* @author Jakub Lédl <[email protected]> | ||
* @see \Dissect\Lexer\Recognizer\SimpleRecognizerTest | ||
*/ | ||
class SimpleRecognizer implements Recognizer | ||
{ | ||
|
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dissect\Lexer; | ||
|
||
use Dissect\Lexer\TokenStream\ArrayTokenStream; | ||
|
@@ -13,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 | ||
{ | ||
|
@@ -52,29 +55,21 @@ public function lex(string $string): TokenStream | |
|
||
$tokens[] = new CommonToken(Parser::EOF_TOKEN_TYPE, '', $line); | ||
|
||
return new ArrayTokenStream($tokens); | ||
return new ArrayTokenStream(...$tokens); | ||
} | ||
|
||
/** | ||
* The patterns corresponding to tokens. | ||
* | ||
* @return array | ||
*/ | ||
abstract protected function getCatchablePatterns(): array; | ||
|
||
/** | ||
* The patterns corresponding to tokens to be skipped. | ||
* | ||
* @return array | ||
*/ | ||
abstract protected function getNonCatchablePatterns(): array; | ||
|
||
/** | ||
* Retrieves the token type. | ||
* | ||
* @param string $value | ||
* | ||
* @return string $type | ||
*/ | ||
abstract protected function getType(string &$value): string; | ||
} |
Oops, something went wrong.