This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * This file is part of Lexer package. |
||
4 | * |
||
5 | * For the full copyright and license information, please view the LICENSE |
||
6 | * file that was distributed with this source code. |
||
7 | */ |
||
8 | declare(strict_types=1); |
||
9 | |||
10 | namespace Railt\Lexer\Driver; |
||
11 | |||
12 | use Parle\Lexer as Parle; |
||
13 | use Parle\LexerException; |
||
14 | use Parle\Token as InternalToken; |
||
15 | use Railt\Io\Readable; |
||
16 | use Railt\Lexer\Definition\TokenDefinition; |
||
17 | use Railt\Lexer\Exception\BadLexemeException; |
||
18 | use Railt\Lexer\LexerInterface; |
||
19 | use Railt\Lexer\Result\Eoi; |
||
20 | use Railt\Lexer\Result\Token; |
||
21 | use Railt\Lexer\Result\Unknown; |
||
22 | use Railt\Lexer\TokenInterface; |
||
23 | |||
24 | /** |
||
25 | * Class ParleStateless |
||
26 | */ |
||
27 | class ParleLexer extends SimpleLexer |
||
28 | { |
||
29 | /** |
||
30 | * @var array|string[] |
||
31 | */ |
||
32 | private $map = []; |
||
33 | |||
34 | /** |
||
35 | * @var int |
||
36 | */ |
||
37 | private $id = 1; |
||
38 | |||
39 | /** |
||
40 | * @var Parle |
||
41 | */ |
||
42 | private $lexer; |
||
43 | |||
44 | /** |
||
45 | * ParleStateless constructor. |
||
46 | * @param array $tokens |
||
47 | * @param array $skip |
||
48 | * @throws BadLexemeException |
||
49 | */ |
||
50 | public function __construct(array $tokens = [], array $skip = []) |
||
51 | { |
||
52 | \assert(\class_exists(Parle::class, false)); |
||
53 | |||
54 | $this->lexer = new Parle(); |
||
55 | $this->skipped = $skip; |
||
56 | |||
57 | foreach ($tokens as $name => $pcre) { |
||
58 | $this->add($name, $pcre); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param string $name |
||
64 | * @param string $pcre |
||
65 | * @return LexerInterface |
||
66 | * @throws BadLexemeException |
||
67 | */ |
||
68 | public function add(string $name, string $pcre): LexerInterface |
||
69 | { |
||
70 | try { |
||
71 | $this->lexer->push($pcre, $this->id); |
||
72 | |||
73 | $this->map[$this->id] = $name; |
||
74 | $this->tokens[$this->id] = $pcre; |
||
75 | } catch (LexerException $e) { |
||
0 ignored issues
–
show
|
|||
76 | $message = \preg_replace('/rule\h+id\h+\d+/iu', 'token ' . $name, $e->getMessage()); |
||
77 | |||
78 | throw new BadLexemeException($message); |
||
79 | } |
||
80 | |||
81 | ++$this->id; |
||
82 | |||
83 | return $this; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @param Readable $input |
||
88 | * @return \Traversable|TokenInterface[] |
||
89 | */ |
||
90 | protected function exec(Readable $input): \Traversable |
||
91 | { |
||
92 | $iterator = $this->getInnerIterator($input); |
||
93 | |||
94 | while ($iterator->valid()) { |
||
95 | /** @var InternalToken $current */ |
||
96 | $current = $iterator->current(); |
||
97 | |||
98 | /** @var TokenInterface $token */ |
||
99 | yield $current->id === InternalToken::UNKNOWN |
||
100 | ? $this->unknown($iterator) |
||
101 | : $this->token($iterator); |
||
102 | } |
||
103 | |||
104 | yield new Eoi($this->lexer->marker); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * @param Readable $input |
||
109 | * @return \Generator|\Traversable |
||
110 | */ |
||
111 | protected function getInnerIterator(Readable $input): \Traversable |
||
112 | { |
||
113 | $this->lexer->build(); |
||
114 | $this->lexer->consume($input->getContents()); |
||
115 | |||
116 | $this->lexer->advance(); |
||
117 | $token = $this->lexer->getToken(); |
||
118 | |||
119 | while ($token->id !== InternalToken::EOI) { |
||
120 | yield $token->id => $token; |
||
121 | |||
122 | $this->lexer->advance(); |
||
123 | $token = $this->lexer->getToken(); |
||
124 | } |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @param \Traversable|\Generator $iterator |
||
129 | * @return Unknown |
||
130 | */ |
||
131 | private function unknown(\Traversable $iterator): TokenInterface |
||
132 | { |
||
133 | /** @var InternalToken $current */ |
||
134 | $current = $iterator->current(); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Traversable as the method current() does only exist in the following implementations of said interface: APCUIterator , AppendIterator , ArrayIterator , CachingIterator , CallbackFilterIterator , DirectoryIterator , EmptyIterator , File_Iterator , FilesystemIterator , FilterIterator , Generator , GlobIterator , HttpMessage , HttpRequestPool , Imagick , ImagickPixelIterator , InfiniteIterator , Issue523 , IteratorIterator , LimitIterator , MongoCommandCursor , MongoCursor , MongoGridFSCursor , MultipleIterator , NoRewindIterator , PHPUnit\Framework\TestSuiteIterator , PHPUnit\Runner\Filter\ExcludeGroupFilterIterator , PHPUnit\Runner\Filter\GroupFilterIterator , PHPUnit\Runner\Filter\IncludeGroupFilterIterator , PHPUnit\Runner\Filter\NameFilterIterator , PHP_Token_Stream , ParentIterator , Phar , PharData , PharIo\Manifest\AuthorCollectionIterator , PharIo\Manifest\AuthorElementCollection , PharIo\Manifest\BundledComponentCollectionIterator , PharIo\Manifest\ComponentElementCollection , PharIo\Manifest\ElementCollection , PharIo\Manifest\ExtElementCollection , PharIo\Manifest\RequirementCollectionIterator , RecursiveArrayIterator , RecursiveCachingIterator , RecursiveCallbackFilterIterator , RecursiveDirectoryIterator , RecursiveFilterIterator , RecursiveIteratorIterator , RecursiveRegexIterator , RecursiveTreeIterator , RegexIterator , SQLiteResult , SebastianBergmann\CodeCoverage\Node\Iterator , SimpleXMLIterator , SplDoublyLinkedList , SplFileObject , SplFixedArray , SplHeap , SplMaxHeap , SplMinHeap , SplObjectStorage , SplPriorityQueue , SplQueue , SplStack , SplTempFileObject , TestIterator , TestIterator2 , TheSeer\Tokenizer\TokenCollection .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
135 | $offset = $this->lexer->marker; |
||
136 | $body = ''; |
||
137 | |||
138 | while ($current->id === InternalToken::UNKNOWN) { |
||
139 | $body .= $current->value; |
||
140 | $iterator->next(); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Traversable as the method next() does only exist in the following implementations of said interface: APCUIterator , AppendIterator , ArrayIterator , CachingIterator , CallbackFilterIterator , DirectoryIterator , EmptyIterator , File_Iterator , FilesystemIterator , FilterIterator , Generator , GlobIterator , HttpMessage , HttpRequestPool , Imagick , ImagickPixelIterator , InfiniteIterator , Issue523 , IteratorIterator , LimitIterator , MongoCommandCursor , MongoCursor , MongoGridFSCursor , MultipleIterator , NoRewindIterator , PHPUnit\Framework\TestSuiteIterator , PHPUnit\Runner\Filter\ExcludeGroupFilterIterator , PHPUnit\Runner\Filter\GroupFilterIterator , PHPUnit\Runner\Filter\IncludeGroupFilterIterator , PHPUnit\Runner\Filter\NameFilterIterator , PHP_Token_Stream , ParentIterator , Phar , PharData , PharIo\Manifest\AuthorCollectionIterator , PharIo\Manifest\AuthorElementCollection , PharIo\Manifest\BundledComponentCollectionIterator , PharIo\Manifest\ComponentElementCollection , PharIo\Manifest\ElementCollection , PharIo\Manifest\ExtElementCollection , PharIo\Manifest\RequirementCollectionIterator , RecursiveArrayIterator , RecursiveCachingIterator , RecursiveCallbackFilterIterator , RecursiveDirectoryIterator , RecursiveFilterIterator , RecursiveIteratorIterator , RecursiveRegexIterator , RecursiveTreeIterator , RegexIterator , SQLiteResult , SebastianBergmann\CodeCoverage\Node\Iterator , SimpleXMLIterator , SplDoublyLinkedList , SplFileObject , SplFixedArray , SplHeap , SplMaxHeap , SplMinHeap , SplObjectStorage , SplPriorityQueue , SplQueue , SplStack , SplTempFileObject , TestIterator , TestIterator2 , TheSeer\Tokenizer\TokenCollection .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
141 | $current = $iterator->current(); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Traversable as the method current() does only exist in the following implementations of said interface: APCUIterator , AppendIterator , ArrayIterator , CachingIterator , CallbackFilterIterator , DirectoryIterator , EmptyIterator , File_Iterator , FilesystemIterator , FilterIterator , Generator , GlobIterator , HttpMessage , HttpRequestPool , Imagick , ImagickPixelIterator , InfiniteIterator , Issue523 , IteratorIterator , LimitIterator , MongoCommandCursor , MongoCursor , MongoGridFSCursor , MultipleIterator , NoRewindIterator , PHPUnit\Framework\TestSuiteIterator , PHPUnit\Runner\Filter\ExcludeGroupFilterIterator , PHPUnit\Runner\Filter\GroupFilterIterator , PHPUnit\Runner\Filter\IncludeGroupFilterIterator , PHPUnit\Runner\Filter\NameFilterIterator , PHP_Token_Stream , ParentIterator , Phar , PharData , PharIo\Manifest\AuthorCollectionIterator , PharIo\Manifest\AuthorElementCollection , PharIo\Manifest\BundledComponentCollectionIterator , PharIo\Manifest\ComponentElementCollection , PharIo\Manifest\ElementCollection , PharIo\Manifest\ExtElementCollection , PharIo\Manifest\RequirementCollectionIterator , RecursiveArrayIterator , RecursiveCachingIterator , RecursiveCallbackFilterIterator , RecursiveDirectoryIterator , RecursiveFilterIterator , RecursiveIteratorIterator , RecursiveRegexIterator , RecursiveTreeIterator , RegexIterator , SQLiteResult , SebastianBergmann\CodeCoverage\Node\Iterator , SimpleXMLIterator , SplDoublyLinkedList , SplFileObject , SplFixedArray , SplHeap , SplMaxHeap , SplMinHeap , SplObjectStorage , SplPriorityQueue , SplQueue , SplStack , SplTempFileObject , TestIterator , TestIterator2 , TheSeer\Tokenizer\TokenCollection .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
142 | } |
||
143 | |||
144 | return new Unknown($body, $offset); |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * @param \Traversable|\Iterator $iterator |
||
149 | * @return Token |
||
150 | */ |
||
151 | private function token(\Traversable $iterator): TokenInterface |
||
152 | { |
||
153 | /** @var InternalToken $current */ |
||
154 | $current = $iterator->current(); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Traversable as the method current() does only exist in the following implementations of said interface: APCUIterator , AppendIterator , ArrayIterator , CachingIterator , CallbackFilterIterator , DirectoryIterator , EmptyIterator , File_Iterator , FilesystemIterator , FilterIterator , Generator , GlobIterator , HttpMessage , HttpRequestPool , Imagick , ImagickPixelIterator , InfiniteIterator , Issue523 , IteratorIterator , LimitIterator , MongoCommandCursor , MongoCursor , MongoGridFSCursor , MultipleIterator , NoRewindIterator , PHPUnit\Framework\TestSuiteIterator , PHPUnit\Runner\Filter\ExcludeGroupFilterIterator , PHPUnit\Runner\Filter\GroupFilterIterator , PHPUnit\Runner\Filter\IncludeGroupFilterIterator , PHPUnit\Runner\Filter\NameFilterIterator , PHP_Token_Stream , ParentIterator , Phar , PharData , PharIo\Manifest\AuthorCollectionIterator , PharIo\Manifest\AuthorElementCollection , PharIo\Manifest\BundledComponentCollectionIterator , PharIo\Manifest\ComponentElementCollection , PharIo\Manifest\ElementCollection , PharIo\Manifest\ExtElementCollection , PharIo\Manifest\RequirementCollectionIterator , RecursiveArrayIterator , RecursiveCachingIterator , RecursiveCallbackFilterIterator , RecursiveDirectoryIterator , RecursiveFilterIterator , RecursiveIteratorIterator , RecursiveRegexIterator , RecursiveTreeIterator , RegexIterator , SQLiteResult , SebastianBergmann\CodeCoverage\Node\Iterator , SimpleXMLIterator , SplDoublyLinkedList , SplFileObject , SplFixedArray , SplHeap , SplMaxHeap , SplMinHeap , SplObjectStorage , SplPriorityQueue , SplQueue , SplStack , SplTempFileObject , TestIterator , TestIterator2 , TheSeer\Tokenizer\TokenCollection .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
155 | |||
156 | $iterator->next(); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Traversable as the method next() does only exist in the following implementations of said interface: APCUIterator , AppendIterator , ArrayIterator , CachingIterator , CallbackFilterIterator , DirectoryIterator , EmptyIterator , File_Iterator , FilesystemIterator , FilterIterator , Generator , GlobIterator , HttpMessage , HttpRequestPool , Imagick , ImagickPixelIterator , InfiniteIterator , Issue523 , IteratorIterator , LimitIterator , MongoCommandCursor , MongoCursor , MongoGridFSCursor , MultipleIterator , NoRewindIterator , PHPUnit\Framework\TestSuiteIterator , PHPUnit\Runner\Filter\ExcludeGroupFilterIterator , PHPUnit\Runner\Filter\GroupFilterIterator , PHPUnit\Runner\Filter\IncludeGroupFilterIterator , PHPUnit\Runner\Filter\NameFilterIterator , PHP_Token_Stream , ParentIterator , Phar , PharData , PharIo\Manifest\AuthorCollectionIterator , PharIo\Manifest\AuthorElementCollection , PharIo\Manifest\BundledComponentCollectionIterator , PharIo\Manifest\ComponentElementCollection , PharIo\Manifest\ElementCollection , PharIo\Manifest\ExtElementCollection , PharIo\Manifest\RequirementCollectionIterator , RecursiveArrayIterator , RecursiveCachingIterator , RecursiveCallbackFilterIterator , RecursiveDirectoryIterator , RecursiveFilterIterator , RecursiveIteratorIterator , RecursiveRegexIterator , RecursiveTreeIterator , RegexIterator , SQLiteResult , SebastianBergmann\CodeCoverage\Node\Iterator , SimpleXMLIterator , SplDoublyLinkedList , SplFileObject , SplFixedArray , SplHeap , SplMaxHeap , SplMinHeap , SplObjectStorage , SplPriorityQueue , SplQueue , SplStack , SplTempFileObject , TestIterator , TestIterator2 , TheSeer\Tokenizer\TokenCollection .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
157 | |||
158 | return new Token($this->map[$current->id], $current->value, $this->lexer->marker); |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * @return iterable|TokenDefinition[] |
||
163 | */ |
||
164 | public function getTokenDefinitions(): iterable |
||
165 | { |
||
166 | View Code Duplication | foreach ($this->tokens as $id => $pcre) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
167 | $name = $this->map[$id]; |
||
168 | |||
169 | yield new TokenDefinition($name, $pcre, ! \in_array($name, $this->skipped, true)); |
||
170 | } |
||
171 | } |
||
172 | } |
||
173 |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.