Skip to content

Commit 4eca0c0

Browse files
committed
MAGETWO-69964: PHPCS cannot parse correctly syntax of PHP 7.x return types
1 parent 5a90e5c commit 4eca0c0

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\App\TemplateTypesInterface;
1111
use Magento\Framework\Phrase;
1212
use Magento\Setup\Module\I18n\Locale;
13+
use Magento\Theme\Block\Html\Footer;
1314

1415
/**
1516
* @magentoAppIsolation enabled
@@ -56,12 +57,12 @@ public function testViewDirective()
5657
*/
5758
public function testBlockDirective()
5859
{
59-
$class = 'Magento\\\\Theme\\\\Block\\\\Html\\\\Footer';
60-
$data = ["{{block class='$class' name='test.block' template='Magento_Theme::html/footer.phtml'}}",
61-
'block',
62-
" class='$class' name='test.block' template='Magento_Theme::html/footer.phtml'",
63-
64-
];
60+
$class = Footer::class;
61+
$data = [
62+
"{{block class='$class' name='test.block' template='Magento_Theme::html/footer.phtml'}}",
63+
'block',
64+
" class='$class' name='test.block' template='Magento_Theme::html/footer.phtml'",
65+
];
6566
$html = $this->model->blockDirective($data);
6667
$this->assertContains('<div class="footer-container">', $html);
6768
}

dev/tests/static/framework/Magento/Sniffs/LiteralNamespaces/LiteralNamespacesSniff.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public function process(File $sourceFile, $stackPtr)
4747
}
4848

4949
$content = trim($tokens[$stackPtr]['content'], "\"'");
50+
// replace double slashes from class name for avoiding problems with class autoload
51+
if (strpos($content, '\\') !== false) {
52+
$content = preg_replace('|\\\{2,}|', '\\', $content);
53+
}
54+
5055
if (preg_match($this->literalNamespacePattern, $content) === 1 && $this->classExists($content)) {
5156
$sourceFile->addError(
5257
"Use ::class notation instead.",

lib/internal/Magento/Framework/ObjectManager/Code/Generator/Repository.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
1010
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
11+
use Magento\Framework\Api\SearchCriteriaInterface;
12+
use Magento\Framework\Exception\NoSuchEntityException;
13+
use Magento\Framework\Exception\InputException;
1114
use Zend\Code\Reflection\MethodReflection;
1215
use Zend\Code\Reflection\ParameterReflection;
1316

@@ -21,13 +24,6 @@ class Repository extends \Magento\Framework\Code\Generator\EntityAbstract
2124
*/
2225
const ENTITY_TYPE = 'repository';
2326

24-
/**
25-
* No Such Entity Exception
26-
*/
27-
const NO_SUCH_ENTITY_EXCEPTION = '\\Magento\Framework\Exception\NoSuchEntityException';
28-
const INPUT_EXCEPTION = '\\Magento\Framework\Exception\InputException';
29-
const SEARCH_CRITERIA = '\\Magento\Framework\Api\SearchCriteriaInterface';
30-
3127
/**
3228
* The namespace of repository interface
3329
* @var string
@@ -227,13 +223,13 @@ protected function _getGetMethod()
227223
/** @var ParameterReflection $parameterReflection */
228224
$parameterReflection = $methodReflection->getParameters()[0];
229225
$body = "if (!\$id) {\n"
230-
. " throw new " . self::INPUT_EXCEPTION . "('ID required');\n"
226+
. " throw new " . InputException::class . "('ID required');\n"
231227
. "}\n"
232228
. "if (!isset(\$this->registry[\$id])) {\n"
233229
. " \$entity = \$this->" . $this->_getSourcePersistorPropertyName()
234230
. "->loadEntity(\$id);\n"
235231
. " if (!\$entity->getId()) {\n"
236-
. " throw new " . self::NO_SUCH_ENTITY_EXCEPTION . "('Requested entity doesn\\'t exist');\n"
232+
. " throw new " . NoSuchEntityException::class . "('Requested entity doesn\\'t exist');\n"
237233
. " }\n"
238234
. " \$this->registry[\$id] = \$entity;\n"
239235
. "}\n"
@@ -261,11 +257,11 @@ protected function _getGetMethod()
261257
],
262258
[
263259
'name' => 'throws',
264-
'description' => self::INPUT_EXCEPTION,
260+
'description' => InputException::class,
265261
],
266262
[
267263
'name' => 'throws',
268-
'description' => self::NO_SUCH_ENTITY_EXCEPTION,
264+
'description' => NoSuchEntityException::class,
269265
],
270266
],
271267
]
@@ -514,7 +510,7 @@ protected function _getGetListMethod()
514510
'parameters' => [
515511
[
516512
'name' => 'searchCriteria',
517-
'type' => self::SEARCH_CRITERIA,
513+
'type' => SearchCriteriaInterface::class,
518514
],
519515
],
520516
'body' => $body,
@@ -523,7 +519,7 @@ protected function _getGetListMethod()
523519
'tags' => [
524520
[
525521
'name' => 'param',
526-
'description' => self::SEARCH_CRITERIA . ' $searchCriteria',
522+
'description' => SearchCriteriaInterface::class . ' $searchCriteria',
527523
],
528524
[
529525
'name' => 'return',

0 commit comments

Comments
 (0)