Skip to content

Commit 0207f9d

Browse files
authored
Merge branch 'develop' into AC-677
2 parents a91d371 + b2111fa commit 0207f9d

File tree

11 files changed

+147
-7
lines changed

11 files changed

+147
-7
lines changed

Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
5757
$tokens = $phpcsFile->getTokens();
5858

5959
$commentEnd = $phpcsFile->findPrevious($this->ignoreTokens, ($stackPtr - 1), null, true);
60-
if ($commentEnd === false
60+
61+
if ($commentEnd !== false && $tokens[$commentEnd]['code'] === T_STRING) {
62+
$commentEnd = $phpcsFile->findPrevious($this->ignoreTokens, ($commentEnd - 1), null, true);
63+
} elseif ($commentEnd === false
6164
|| ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG
6265
&& $tokens[$commentEnd]['code'] !== T_COMMENT)
6366
) {
6467
$phpcsFile->addWarning('Missing PHP DocBlock for class property.', $stackPtr, 'Missing');
6568
return;
6669
}
70+
6771
$commentStart = $tokens[$commentEnd]['comment_opener'];
6872
$foundVar = null;
6973
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {

Magento2/Sniffs/Legacy/InstallUpgradeSniff.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ public function process(File $phpcsFile, $stackPtr)
6464
}
6565
}
6666

67-
if (preg_match('/(sql|data)/', $fileInfo->getPath()) === 1) {
67+
$folders = array_filter(explode('/', $fileInfo->getPath()));
68+
$folderName = array_pop($folders);
69+
70+
if ($folderName === 'data' || $folderName === 'sql') {
6871
$phpcsFile->addError(
6972
$fileInfo->getFilename()." is in an invalid directory ".$fileInfo->getPath().":\n"
7073
. "- Create a data patch within module's Setup/Patch/Data folder for data upgrades.\n"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2\Sniffs\Legacy;
7+
8+
use DOMDocument;
9+
use PHP_CodeSniffer\Files\File;
10+
use PHP_CodeSniffer\Sniffs\Sniff;
11+
12+
/**
13+
* Test to find obsolete acl declaration
14+
*/
15+
class ObsoleteAclSniff implements Sniff
16+
{
17+
private const WARNING_OBSOLETE_ACL_STRUCTURE = 'ObsoleteAclStructure';
18+
19+
/**
20+
* @inheritdoc
21+
*/
22+
public function register(): array
23+
{
24+
return [
25+
T_INLINE_HTML
26+
];
27+
}
28+
29+
/**
30+
* @inheritDoc
31+
*/
32+
public function process(File $phpcsFile, $stackPtr)
33+
{
34+
if ($stackPtr > 0) {
35+
return;
36+
}
37+
38+
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
39+
$foundElements = $xml->xpath('/config/acl/*[boolean(./children) or boolean(./title)]');
40+
foreach ($foundElements as $element) {
41+
$phpcsFile->addWarning(
42+
'Obsolete acl structure detected in line ' . dom_import_simplexml($element)->getLineNo(),
43+
dom_import_simplexml($element)->getLineNo() - 1,
44+
self::WARNING_OBSOLETE_ACL_STRUCTURE
45+
);
46+
}
47+
}
48+
49+
/**
50+
* Format the incoming XML to avoid tags split into several lines.
51+
*
52+
* @param File $phpcsFile
53+
* @return false|string
54+
*/
55+
private function getFormattedXML(File $phpcsFile)
56+
{
57+
$doc = new DomDocument('1.0');
58+
$doc->formatOutput = true;
59+
$doc->loadXML($phpcsFile->getTokensAsString(0, 999999));
60+
return $doc->saveXML();
61+
}
62+
}

Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,9 @@ class correctlyFormattedClassMemberDocBlock
120120
* @var test
121121
*/
122122
protected $test;
123+
124+
/**
125+
* @var string
126+
*/
127+
protected string $test;
123128
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2\Tests\Legacy;
7+
8+
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
9+
10+
class ObsoleteAclUnitTest extends AbstractSniffUnitTest
11+
{
12+
/**
13+
* @inheritdoc
14+
*/
15+
public function getErrorList(): array
16+
{
17+
return [];
18+
}
19+
20+
/**
21+
* @inheritdoc
22+
*/
23+
public function getWarningList(): array
24+
{
25+
return [
26+
15 => 1,
27+
20 => 1,
28+
23 => 1
29+
];
30+
}
31+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
9+
<children>
10+
<title value="foo"/>
11+
</children>
12+
<title value="bar"/>
13+
<children default_policy="deny"/>
14+
<acl>
15+
<children>
16+
<title value="foo"/>
17+
</children>
18+
<children default_policy="deny"/>
19+
<title value="bar"/>
20+
<title>
21+
<children default_policy="deny"/>
22+
</title>
23+
<children>
24+
<title
25+
value="foo"/>
26+
</children>
27+
</acl>
28+
</config>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

Magento2/ruleset.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@
117117
<severity>10</severity>
118118
<type>error</type>
119119
</rule>
120-
<rule ref="Magento2.Legacy.EmailTemplate.FoundObsoleteEmailDirective">
121-
<include-pattern>view/email/*.html</include-pattern>
122-
<include-pattern>view/*/email/*.html</include-pattern>
120+
<rule ref="Magento2.Legacy.EmailTemplate">
123121
<severity>10</severity>
124122
<type>error</type>
125123
</rule>
@@ -285,6 +283,13 @@
285283
<severity>8</severity>
286284
<type>warning</type>
287285
</rule>
286+
<rule ref="Magento2.Legacy.ObsoleteAcl">
287+
<include-pattern>etc/config.xml</include-pattern>
288+
<include-pattern>etc/config.*.xml</include-pattern>
289+
<include-pattern>etc/*/config.xml</include-pattern>
290+
<severity>8</severity>
291+
<type>warning</type>
292+
</rule>
288293
<rule ref="Magento2.Legacy.ObsoleteMenu">
289294
<include-pattern>etc/config.xml</include-pattern>
290295
<include-pattern>etc/config.*.xml</include-pattern>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"AFL-3.0"
77
],
88
"type": "phpcodesniffer-standard",
9-
"version": "11",
9+
"version": "12",
1010
"require": {
1111
"php": ">=7.3",
1212
"squizlabs/php_codesniffer": "^3.6",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)