Skip to content

Commit ac3e355

Browse files
author
Hayder Sharhan
committed
MAGETWO-43752: Static test ArgumentsTest does not check all cases
- Removed phpmd suppression of cyclomatic complexity warning. - Fixed cyclomatic complexity. - Fixed another occurrence in the code with an extra % sign. MAGETWO-43752: Static test ArgumentsTest does not check all cases - Code style fix. - Language files update text. MAGETWO-43752: Static test ArgumentsTest does not check all cases - Changed regex of ArgumentsTest to allow things like 100%. To do this one must use numbered placeholders not named ones. MAGETWO-43752: Static test ArgumentsTest does not check all cases - updated comment
1 parent d1ba66a commit ac3e355

File tree

9 files changed

+53
-34
lines changed

9 files changed

+53
-34
lines changed

app/code/Magento/Reports/i18n/de_DE.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Statistics,Statistik
170170
"Most Viewed Products Report","Most Viewed Products Report"
171171
"Show By","Show By"
172172
"Select Date","Select Date"
173-
"Customers that have wish list: %1%","Customers that have wish list: %1%"
173+
"Customers that have wish list: %1","Customers that have wish list: %1"
174174
"Number of wish lists: %1","Number of wish lists: %1"
175175
"Number of items bought from a wish list: %1","Number of items bought from a wish list: %1"
176176
"Number of times wish lists have been shared (emailed): %1","Number of times wish lists have been shared (emailed): %1"

app/code/Magento/Reports/i18n/en_US.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Statistics,Statistics
170170
"Most Viewed Products Report","Most Viewed Products Report"
171171
"Show By","Show By"
172172
"Select Date","Select Date"
173-
"Customers that have wish list: %1%","Customers that have wish list: %1%"
173+
"Customers that have wish list: %1","Customers that have wish list: %1"
174174
"Number of wish lists: %1","Number of wish lists: %1"
175175
"Number of items bought from a wish list: %1","Number of items bought from a wish list: %1"
176176
"Number of times wish lists have been shared (emailed): %1","Number of times wish lists have been shared (emailed): %1"

app/code/Magento/Reports/i18n/es_ES.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Statistics,Estadísticas
170170
"Most Viewed Products Report","Most Viewed Products Report"
171171
"Show By","Show By"
172172
"Select Date","Select Date"
173-
"Customers that have wish list: %1%","Customers that have wish list: %1%"
173+
"Customers that have wish list: %1","Customers that have wish list: %1"
174174
"Number of wish lists: %1","Number of wish lists: %1"
175175
"Number of items bought from a wish list: %1","Number of items bought from a wish list: %1"
176176
"Number of times wish lists have been shared (emailed): %1","Number of times wish lists have been shared (emailed): %1"

app/code/Magento/Reports/i18n/fr_FR.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Statistics,Statistiques
170170
"Most Viewed Products Report","Most Viewed Products Report"
171171
"Show By","Show By"
172172
"Select Date","Select Date"
173-
"Customers that have wish list: %1%","Customers that have wish list: %1%"
173+
"Customers that have wish list: %1","Customers that have wish list: %1"
174174
"Number of wish lists: %1","Number of wish lists: %1"
175175
"Number of items bought from a wish list: %1","Number of items bought from a wish list: %1"
176176
"Number of times wish lists have been shared (emailed): %1","Number of times wish lists have been shared (emailed): %1"

app/code/Magento/Reports/i18n/nl_NL.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Statistics,Statistieken
170170
"Most Viewed Products Report","Most Viewed Products Report"
171171
"Show By","Show By"
172172
"Select Date","Select Date"
173-
"Customers that have wish list: %1%","Customers that have wish list: %1%"
173+
"Customers that have wish list: %1","Customers that have wish list: %1"
174174
"Number of wish lists: %1","Number of wish lists: %1"
175175
"Number of items bought from a wish list: %1","Number of items bought from a wish list: %1"
176176
"Number of times wish lists have been shared (emailed): %1","Number of times wish lists have been shared (emailed): %1"

app/code/Magento/Reports/i18n/pt_BR.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Statistics,Estatísticas
170170
"Most Viewed Products Report","Most Viewed Products Report"
171171
"Show By","Show By"
172172
"Select Date","Select Date"
173-
"Customers that have wish list: %1%","Customers that have wish list: %1%"
173+
"Customers that have wish list: %1","Customers that have wish list: %1"
174174
"Number of wish lists: %1","Number of wish lists: %1"
175175
"Number of items bought from a wish list: %1","Number of items bought from a wish list: %1"
176176
"Number of times wish lists have been shared (emailed): %1","Number of times wish lists have been shared (emailed): %1"

app/code/Magento/Reports/i18n/zh_Hans_CN.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Statistics,状态
170170
"Most Viewed Products Report","Most Viewed Products Report"
171171
"Show By","Show By"
172172
"Select Date","Select Date"
173-
"Customers that have wish list: %1%","Customers that have wish list: %1%"
173+
"Customers that have wish list: %1","Customers that have wish list: %1"
174174
"Number of wish lists: %1","Number of wish lists: %1"
175175
"Number of items bought from a wish list: %1","Number of items bought from a wish list: %1"
176176
"Number of times wish lists have been shared (emailed): %1","Number of times wish lists have been shared (emailed): %1"

app/code/Magento/Reports/view/adminhtml/templates/report/wishlist.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<div class="switcher f-left" style="margin: 10px 10px 10px 0px; padding:15px;">
1212
<?php
13-
/* @escapeNotVerified */ echo __('Customers that have Wish List: %1%', $block->getCustomerWithWishlist())
13+
/* @escapeNotVerified */ echo __('Customers that have Wish List: %1', $block->getCustomerWithWishlist())
1414
?>
1515
</div>
1616

dev/tests/static/testsuite/Magento/Test/Integrity/Phrase/ArgumentsTest.php

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
/**
1313
* Scan source code for detects invocations of __() function or Phrase object, analyzes placeholders with arguments
1414
* and see if they not equal
15-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
1615
*/
1716
class ArgumentsTest extends \Magento\Test\Integrity\Phrase\AbstractTestCase
1817
{
@@ -42,7 +41,6 @@ protected function setUp()
4241
// the file below is the only file where strings are translated without corresponding arguments
4342
$componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Translation')
4443
. '/Model/Js/DataProvider.php',
45-
$componentRegistrar->getPath(ComponentRegistrar::MODULE, '')
4644
];
4745
}
4846

@@ -55,31 +53,10 @@ public function testArguments()
5553
continue;
5654
}
5755
$this->_phraseCollector->parse($file);
58-
foreach ($this->_phraseCollector->getPhrases() as $phrase) {
59-
if (empty(trim($phrase['phrase'], "'\"\t\n\r\0\x0B"))) {
60-
$missedPhraseErrors[] = $this->_createMissedPhraseError($phrase);
61-
}
62-
if (preg_match_all('/%(\w+)/', $phrase['phrase'], $matches) || $phrase['arguments']) {
63-
$placeholderCount = count(array_unique($matches[1]));
64-
65-
if ($placeholderCount != $phrase['arguments']) {
66-
// Check for zend placeholders %placehoder% and sprintf placeholder %s
67-
if (preg_match_all('/(%(s)|(\w+)%)/', $phrase['phrase'], $placeHlders, PREG_OFFSET_CAPTURE)) {
68-
69-
foreach ($placeHlders[0] as $ph) {
70-
// Check if char after placeholder is not a digit or letter
71-
$charAfterPh = $phrase['phrase'][$ph[1] + strlen($ph[0])];
72-
if (!preg_match('/[A-Za-z0-9]/', $charAfterPh)) {
73-
$placeholderCount--;
74-
}
75-
}
76-
}
7756

78-
if ($placeholderCount != $phrase['arguments']) {
79-
$incorrectNumberOfArgumentsErrors[] = $this->_createPhraseError($phrase);
80-
}
81-
}
82-
}
57+
foreach ($this->_phraseCollector->getPhrases() as $phrase) {
58+
$this->checkEmptyPhrases($phrase, $missedPhraseErrors);
59+
$this->checkArgumentMismatch($phrase, $incorrectNumberOfArgumentsErrors);
8360
}
8461
}
8562
$this->assertEmpty(
@@ -99,4 +76,46 @@ public function testArguments()
9976
)
10077
);
10178
}
79+
80+
/**
81+
* Will check if phrase is empty
82+
*
83+
* @param $phrase
84+
* @param $missedPhraseErrors
85+
*/
86+
private function checkEmptyPhrases($phrase, &$missedPhraseErrors)
87+
{
88+
if (empty(trim($phrase['phrase'], "'\"\t\n\r\0\x0B"))) {
89+
$missedPhraseErrors[] = $this->_createMissedPhraseError($phrase);
90+
}
91+
}
92+
93+
/**
94+
* Will check if the number of arguments does not match the number of placeholders
95+
*
96+
* @param $phrase
97+
* @param $incorrectNumberOfArgumentsErrors
98+
*/
99+
private function checkArgumentMismatch($phrase, &$incorrectNumberOfArgumentsErrors)
100+
{
101+
if (preg_match_all('/%(\w+)/', $phrase['phrase'], $matches) || $phrase['arguments']) {
102+
$placeholderCount = count(array_unique($matches[1]));
103+
104+
// Check for zend placeholders %placeholder% and sprintf placeholder %s
105+
if (preg_match_all('/%((s)|([A-Za-z]+)%)/', $phrase['phrase'], $placeHolders, PREG_OFFSET_CAPTURE)) {
106+
107+
foreach ($placeHolders[0] as $ph) {
108+
// Check if char after placeholder is not a digit or letter
109+
$charAfterPh = $phrase['phrase'][$ph[1] + strlen($ph[0])];
110+
if (!preg_match('/[A-Za-z0-9]/', $charAfterPh)) {
111+
$placeholderCount--;
112+
}
113+
}
114+
}
115+
116+
if ($placeholderCount != $phrase['arguments']) {
117+
$incorrectNumberOfArgumentsErrors[] = $this->_createPhraseError($phrase);
118+
}
119+
}
120+
}
102121
}

0 commit comments

Comments
 (0)