Skip to content

Commit 0370887

Browse files
authored
Merge pull request #22 from magento-commerce/imported-magento-magento-coding-standard-222
[Imported] Version 7 master update
2 parents efc9084 + 9eda380 commit 0370887

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+5556
-425
lines changed

.github/workflows/php.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master, develop ]
6+
pull_request:
7+
branches: [ master, develop ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
php-version:
17+
- "7.3"
18+
- "7.4"
19+
- "8.0"
20+
dependencies:
21+
- "lowest"
22+
- "highest"
23+
experimental:
24+
- false
25+
name: Tests with PHP ${{ matrix.php-version }} and ${{ matrix.dependencies }} dependencies
26+
27+
steps:
28+
- uses: actions/checkout@v2
29+
30+
- name: Setup PHP
31+
uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: ${{ matrix.php-version }}
34+
env:
35+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Validate composer
38+
run: composer validate
39+
40+
- name: Composer install
41+
uses: "ramsey/composer-install@v1"
42+
with:
43+
dependency-versions: "${{ matrix.dependencies }}"
44+
composer-options: "${{ matrix.composer-options }}"
45+
46+
- name: Run unit tests suite
47+
run: vendor/bin/phpunit
48+
49+
- name: Run code style suite
50+
run: vendor/bin/phpcs --standard=Magento2 Magento2/Helpers/ Magento2/Sniffs

.travis.yml

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2\Helpers\Tokenizer;
7+
8+
/**
9+
* Template constructions tokenizer
10+
*/
11+
abstract class AbstractTokenizer
12+
{
13+
/**
14+
* Current index in string
15+
*
16+
* @var int
17+
*/
18+
protected $_currentIndex;
19+
20+
/**
21+
* String for tokenize
22+
*
23+
* @var string
24+
*/
25+
protected $_string;
26+
27+
/**
28+
* Move current index to next char.
29+
*
30+
* If index out of bounds returns false
31+
*
32+
* @return boolean
33+
*/
34+
public function next()
35+
{
36+
if ($this->_currentIndex + 1 >= strlen($this->_string)) {
37+
return false;
38+
}
39+
40+
$this->_currentIndex++;
41+
return true;
42+
}
43+
44+
/**
45+
* Move current index to previous char.
46+
*
47+
* If index out of bounds returns false
48+
*
49+
* @return boolean
50+
*/
51+
public function prev()
52+
{
53+
if ($this->_currentIndex - 1 < 0) {
54+
return false;
55+
}
56+
57+
$this->_currentIndex--;
58+
return true;
59+
}
60+
61+
/**
62+
* Move current index backwards.
63+
*
64+
* If index out of bounds returns false
65+
*
66+
* @param int $distance number of characters to backtrack
67+
* @return bool
68+
*/
69+
public function back($distance)
70+
{
71+
if ($this->_currentIndex - $distance < 0) {
72+
return false;
73+
}
74+
75+
$this->_currentIndex -= $distance;
76+
return true;
77+
}
78+
79+
/**
80+
* Return current char
81+
*
82+
* @return string
83+
*/
84+
public function char()
85+
{
86+
return $this->_string[$this->_currentIndex];
87+
}
88+
89+
/**
90+
* Set string for tokenize
91+
*
92+
* @param string $value
93+
* @return void
94+
*/
95+
public function setString($value)
96+
{
97+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
98+
$this->_string = rawurldecode($value);
99+
$this->reset();
100+
}
101+
102+
/**
103+
* Move char index to begin of string
104+
*
105+
* @return void
106+
*/
107+
public function reset()
108+
{
109+
$this->_currentIndex = 0;
110+
}
111+
112+
/**
113+
* Return true if current char is white-space
114+
*
115+
* @return boolean
116+
*/
117+
public function isWhiteSpace()
118+
{
119+
return $this->_string === '' ?: trim($this->char()) !== $this->char();
120+
}
121+
122+
/**
123+
* Tokenize string
124+
*
125+
* @return array
126+
*/
127+
abstract public function tokenize();
128+
}
+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2\Helpers\Tokenizer;
7+
8+
/**
9+
* Template constructions parameters tokenizer
10+
*/
11+
class Parameter extends AbstractTokenizer
12+
{
13+
/**
14+
* Tokenize string and return getted parameters
15+
*
16+
* @return array
17+
*/
18+
public function tokenize()
19+
{
20+
$parameters = [];
21+
$parameterName = '';
22+
do {
23+
if ($this->isWhiteSpace()) {
24+
continue;
25+
}
26+
27+
if ($this->char() !== '=') {
28+
$parameterName .= $this->char();
29+
} else {
30+
$parameters[$parameterName] = $this->getValue();
31+
$parameterName = '';
32+
}
33+
} while ($this->next());
34+
return $parameters;
35+
}
36+
37+
/**
38+
* Get string value in parameters through tokenize
39+
*
40+
* @return string
41+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
42+
*/
43+
public function getValue()
44+
{
45+
$this->next();
46+
$value = '';
47+
if ($this->isWhiteSpace()) {
48+
return $value;
49+
}
50+
$quoteStart = $this->char() == "'" || $this->char() == '"';
51+
52+
if ($quoteStart) {
53+
$breakSymbol = $this->char();
54+
} else {
55+
$breakSymbol = false;
56+
$value .= $this->char();
57+
}
58+
59+
while ($this->next()) {
60+
if (!$breakSymbol && $this->isWhiteSpace()) {
61+
break;
62+
} elseif ($breakSymbol && $this->char() == $breakSymbol) {
63+
break;
64+
} elseif ($this->char() == '\\') {
65+
$this->next();
66+
if ($this->char() != '\\') {
67+
$value .= '\\';
68+
}
69+
$value .= $this->char();
70+
} else {
71+
$value .= $this->char();
72+
}
73+
}
74+
return $value;
75+
}
76+
}

0 commit comments

Comments
 (0)