-
Notifications
You must be signed in to change notification settings - Fork 160
Fix magento/magento-coding-standard#214 with class not found #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
magento-devops-reposync-svc
merged 1 commit into
magento:develop
from
edspc:tokenizer_parameter_not_found
Aug 20, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,128 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento2\Helpers\Tokenizer; | ||
|
||
/** | ||
* Template constructions tokenizer | ||
*/ | ||
abstract class AbstractTokenizer | ||
{ | ||
/** | ||
* Current index in string | ||
* | ||
* @var int | ||
*/ | ||
protected $_currentIndex; | ||
|
||
/** | ||
* String for tokenize | ||
* | ||
* @var string | ||
*/ | ||
protected $_string; | ||
|
||
/** | ||
* Move current index to next char. | ||
* | ||
* If index out of bounds returns false | ||
* | ||
* @return boolean | ||
*/ | ||
public function next() | ||
{ | ||
if ($this->_currentIndex + 1 >= strlen($this->_string)) { | ||
return false; | ||
} | ||
|
||
$this->_currentIndex++; | ||
return true; | ||
} | ||
|
||
/** | ||
* Move current index to previous char. | ||
* | ||
* If index out of bounds returns false | ||
* | ||
* @return boolean | ||
*/ | ||
public function prev() | ||
{ | ||
if ($this->_currentIndex - 1 < 0) { | ||
return false; | ||
} | ||
|
||
$this->_currentIndex--; | ||
return true; | ||
} | ||
|
||
/** | ||
* Move current index backwards. | ||
* | ||
* If index out of bounds returns false | ||
* | ||
* @param int $distance number of characters to backtrack | ||
* @return bool | ||
*/ | ||
public function back($distance) | ||
{ | ||
if ($this->_currentIndex - $distance < 0) { | ||
return false; | ||
} | ||
|
||
$this->_currentIndex -= $distance; | ||
return true; | ||
} | ||
|
||
/** | ||
* Return current char | ||
* | ||
* @return string | ||
*/ | ||
public function char() | ||
{ | ||
return $this->_string[$this->_currentIndex]; | ||
} | ||
|
||
/** | ||
* Set string for tokenize | ||
* | ||
* @param string $value | ||
* @return void | ||
*/ | ||
public function setString($value) | ||
{ | ||
//phpcs:ignore Magento2.Functions.DiscouragedFunction | ||
$this->_string = rawurldecode($value); | ||
$this->reset(); | ||
} | ||
|
||
/** | ||
* Move char index to begin of string | ||
* | ||
* @return void | ||
*/ | ||
public function reset() | ||
{ | ||
$this->_currentIndex = 0; | ||
} | ||
|
||
/** | ||
* Return true if current char is white-space | ||
* | ||
* @return boolean | ||
*/ | ||
public function isWhiteSpace() | ||
{ | ||
return $this->_string === '' ?: trim($this->char()) !== $this->char(); | ||
} | ||
|
||
/** | ||
* Tokenize string | ||
* | ||
* @return array | ||
*/ | ||
abstract public function tokenize(); | ||
} |
This file contains hidden or 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,76 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento2\Helpers\Tokenizer; | ||
|
||
/** | ||
* Template constructions parameters tokenizer | ||
*/ | ||
class Parameter extends AbstractTokenizer | ||
{ | ||
/** | ||
* Tokenize string and return getted parameters | ||
* | ||
* @return array | ||
*/ | ||
public function tokenize() | ||
{ | ||
$parameters = []; | ||
$parameterName = ''; | ||
do { | ||
if ($this->isWhiteSpace()) { | ||
continue; | ||
} | ||
|
||
if ($this->char() !== '=') { | ||
$parameterName .= $this->char(); | ||
} else { | ||
$parameters[$parameterName] = $this->getValue(); | ||
$parameterName = ''; | ||
} | ||
} while ($this->next()); | ||
return $parameters; | ||
} | ||
|
||
/** | ||
* Get string value in parameters through tokenize | ||
* | ||
* @return string | ||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||
*/ | ||
public function getValue() | ||
{ | ||
$this->next(); | ||
$value = ''; | ||
if ($this->isWhiteSpace()) { | ||
return $value; | ||
} | ||
$quoteStart = $this->char() == "'" || $this->char() == '"'; | ||
|
||
if ($quoteStart) { | ||
$breakSymbol = $this->char(); | ||
} else { | ||
$breakSymbol = false; | ||
$value .= $this->char(); | ||
} | ||
|
||
while ($this->next()) { | ||
if (!$breakSymbol && $this->isWhiteSpace()) { | ||
break; | ||
} elseif ($breakSymbol && $this->char() == $breakSymbol) { | ||
break; | ||
} elseif ($this->char() == '\\') { | ||
$this->next(); | ||
if ($this->char() != '\\') { | ||
$value .= '\\'; | ||
} | ||
$value .= $this->char(); | ||
} else { | ||
$value .= $this->char(); | ||
} | ||
} | ||
return $value; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally added this line for the pipeline.