Skip to content

Commit 5dc14fb

Browse files
Merge pull request #38 from VincentLanglet/fix
🐛 Fix to handle utf8
2 parents eb41919 + aad2f8e commit 5dc14fb

File tree

7 files changed

+1261
-12
lines changed

7 files changed

+1261
-12
lines changed

SymfonyCustom/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function processMultiLineArray(File $phpcsFile, $stackPtr, $arrayStart, $
284284
if (false === $indent) {
285285
$currentIndent = 0;
286286
} else {
287-
$currentIndent = strlen($tokens[$indent]['content']);
287+
$currentIndent = mb_strlen($tokens[$indent]['content']);
288288
}
289289

290290
// Check the closing bracket is on a new line.
@@ -462,7 +462,7 @@ public function processMultiLineArray(File $phpcsFile, $stackPtr, $arrayStart, $
462462
);
463463
}
464464

465-
$indexLength = strlen($currentEntry['index_content']);
465+
$indexLength = mb_strlen($currentEntry['index_content']);
466466
if ($maxLength < $indexLength) {
467467
$maxLength = $indexLength;
468468
}
@@ -652,9 +652,9 @@ public function processMultiLineArray(File $phpcsFile, $stackPtr, $arrayStart, $
652652
}
653653

654654
if ($tokens[$index['arrow']]['column'] !== $arrowStart) {
655-
$expected = ($arrowStart - (strlen($index['index_content']) + $tokens[$index['index']]['column']));
655+
$expected = ($arrowStart - (mb_strlen($index['index_content']) + $tokens[$index['index']]['column']));
656656
$found = $tokens[$index['arrow']]['column']
657-
- (strlen($index['index_content']) + $tokens[$index['index']]['column']);
657+
- (mb_strlen($index['index_content']) + $tokens[$index['index']]['column']);
658658

659659
if ($found < 0) {
660660
$found = 'newline';

SymfonyCustom/Tests/Arrays/ArrayDeclarationUnitTest.inc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,32 @@ class TestClass
6969
),
7070
'short_name' => 'big'
7171
);
72+
73+
$utf8 = array(
74+
'/[áàâãªäå]/u' => 'a',
75+
'/[ÁÀÂÃÄÅ]/u' => 'A',
76+
'/[ÍÌÎÏ]/u' => 'I',
77+
'/[íìîï]/u' => 'i',
78+
'/[éèêë]/u' => 'e',
79+
'/[ÉÈÊË]/u' => 'E',
80+
'/[óòôõºöø]/u' => 'o',
81+
'/[ÓÒÔÕÖØ]/u' => 'O',
82+
'/ÿ/' => 'y',
83+
'/Ÿ/' => 'Y',
84+
'/æ/' => 'ae',
85+
'/Æ/' => 'AE',
86+
'/œ/' => 'oe',
87+
'/Œ/' => 'OE',
88+
'/[úùûü]/u' => 'u',
89+
'/[ÚÙÛÜ]/u' => 'U',
90+
'/ç/' => 'c',
91+
'/Ç/' => 'C',
92+
'/ñ/' => 'n',
93+
'/Ñ/' => 'N',
94+
'/–/' => '-',
95+
'/[’‘‹›‚]/u' => ' ',
96+
'/[“”«»„]/u' => ' ',
97+
'/ +/' => ' ',
98+
);
7299
}
73100
}

SymfonyCustom/Tests/Arrays/ArrayDeclarationUnitTest.inc.fixed

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,32 @@ class TestClass
6969
),
7070
'short_name' => 'big',
7171
);
72+
73+
$utf8 = array(
74+
'/[áàâãªäå]/u' => 'a',
75+
'/[ÁÀÂÃÄÅ]/u' => 'A',
76+
'/[ÍÌÎÏ]/u' => 'I',
77+
'/[íìîï]/u' => 'i',
78+
'/[éèêë]/u' => 'e',
79+
'/[ÉÈÊË]/u' => 'E',
80+
'/[óòôõºöø]/u' => 'o',
81+
'/[ÓÒÔÕÖØ]/u' => 'O',
82+
'/ÿ/' => 'y',
83+
'/Ÿ/' => 'Y',
84+
'/æ/' => 'ae',
85+
'/Æ/' => 'AE',
86+
'/œ/' => 'oe',
87+
'/Œ/' => 'OE',
88+
'/[úùûü]/u' => 'u',
89+
'/[ÚÙÛÜ]/u' => 'U',
90+
'/ç/' => 'c',
91+
'/Ç/' => 'C',
92+
'/ñ/' => 'n',
93+
'/Ñ/' => 'N',
94+
'/–/' => '-',
95+
'/[’‘‹›‚]/u' => ' ',
96+
'/[“”«»„]/u' => ' ',
97+
'/ +/' => ' ',
98+
);
7299
}
73100
}

build.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
composer.url = http://getcomposer.org/composer.phar
33
composer.path = ${basedir}/composer.phar
44

5+
# Php Unit
6+
phpunit.bin = ${basedir}/vendor/bin/phpunit
7+
58
# PHP Code Sniffer
69
## Paths
710
phpcs.bin = ${basedir}/vendor/bin/phpcs

build.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
<target name="test" depends="vendor,lint,phpunit,phpcs"/>
88

99
<target name="vendor" depends="composer" description="Load composer repositories">
10-
<exec executable="composer" failonerror="true">
11-
<arg value="install"/>
10+
<exec executable="/bin/bash" failonerror="true">
11+
<arg value="-c" />
12+
<arg value="php composer.phar install"/>
1213
</exec>
1314
</target>
1415

@@ -27,7 +28,7 @@
2728
</target>
2829

2930
<target name="phpunit" depends="symlink-cs" description="Run unit tests with PHPUnit">
30-
<exec executable="phpunit" failonerror="true" >
31+
<exec executable="${phpunit.bin}" failonerror="true" >
3132
<arg value="--verbose"/>
3233
<arg value="--group=SymfonyCustom"/>
3334
<arg value="${phpcs.dir}/tests/AllTests.php"/>

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@
1717
],
1818
"require": {
1919
"squizlabs/php_codesniffer": "3.0.*"
20+
},
21+
"require-dev": {
22+
"phpunit/phpunit": "~4.0"
2023
}
2124
}

0 commit comments

Comments
 (0)