Skip to content

Combined #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 132 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
56e2de8
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 6, 2021
c9703a6
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 6, 2021
5a83385
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 9, 2021
5b40712
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 9, 2021
4fe226e
Merge branch 'develop' of github.com:magento/magento-coding-standard …
svera Sep 15, 2021
9d542d9
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 16, 2021
2c5c076
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 16, 2021
3636e9d
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 16, 2021
0293560
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 16, 2021
b91d0d4
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 16, 2021
717c998
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 16, 2021
5810c6e
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 16, 2021
0bc42a6
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 16, 2021
19bb57b
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 16, 2021
48a5816
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 16, 2021
b10df58
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 17, 2021
64fa0cc
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 17, 2021
5aa5721
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 17, 2021
389d7ca
Update Magento2/Sniffs/Legacy/ClassReferencesInConfigurationFilesSnif…
svera Sep 20, 2021
c480100
Update Magento2/Sniffs/Legacy/ClassReferencesInConfigurationFilesSnif…
svera Sep 20, 2021
c0ead7c
Update Magento2/Sniffs/Legacy/ClassReferencesInConfigurationFilesSnif…
svera Sep 20, 2021
7b38922
Update Magento2/Sniffs/Legacy/ClassReferencesInConfigurationFilesSnif…
svera Sep 20, 2021
9a69638
Update Magento2/ruleset.xml
svera Sep 20, 2021
936c28c
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 20, 2021
fbe2c1c
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 21, 2021
34169b2
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Sep 21, 2021
95f699c
AC-1314: Fix copyright sniff
eliseacornejo Sep 27, 2021
2c54b32
AC-1314: Fix copyright sniff
eliseacornejo Sep 28, 2021
1ba56bb
AC-670: Create phpcs static check for LayoutTest
svera Sep 29, 2021
cc12906
AC-670: Create phpcs static check for LayoutTest
svera Sep 30, 2021
5d04411
AC-670: Create phpcs static check for LayoutTest
svera Sep 30, 2021
f16142d
AC-670: Create phpcs static check for LayoutTest
svera Sep 30, 2021
f7f1a0d
AC-670: Create phpcs static check for LayoutTest
svera Sep 30, 2021
98cf893
AC-670: Create phpcs static check for LayoutTest
svera Sep 30, 2021
4929b1a
AC-670: Create phpcs static check for LayoutTest
svera Sep 30, 2021
4bb6fcb
Merge branch 'develop' of github.com:magento/magento-coding-standard …
svera Oct 1, 2021
a7a82f9
AC-681: Create phpcs static check for PhtmlTemplateTest
eliseacornejo Oct 5, 2021
a56e5bb
Merge branch 'develop' of github.com:magento/magento-coding-standard …
eliseacornejo Oct 5, 2021
a5dff74
AC-681: Create phpcs static check for PhtmlTemplateTest
eliseacornejo Oct 5, 2021
203e8af
AC-681: Create phpcs static check for PhtmlTemplateTest
eliseacornejo Oct 5, 2021
a43949d
AC-681: Create phpcs static check for PhtmlTemplateTest
eliseacornejo Oct 5, 2021
70a747c
AC-681: Create phpcs static check for PhtmlTemplateTest
eliseacornejo Oct 5, 2021
43b69ef
Merge pull request #93 from magento-commerce/imported-eliseacornejo-m…
eliseacornejo Oct 6, 2021
1b9f386
AC-1167: Update DiscouragedFunctionSniff with FilesystemDriverInterfa…
loginesta Oct 6, 2021
bf64205
AC-683: Create phpcs static check for TableTest
svera Oct 6, 2021
eb3ad47
AC-683: Create phpcs static check for TableTest
svera Oct 6, 2021
a1c933a
AC-683: Create phpcs static check for TableTest
svera Oct 6, 2021
1452ed3
AC-683: Create phpcs static check for TableTest
svera Oct 6, 2021
fbd5b1d
Merge pull request #94 from magento-commerce/imported-loginesta-magen…
loginesta Oct 6, 2021
ceeba56
AC-683: Create phpcs static check for TableTest
svera Oct 6, 2021
b8d2c96
Merge pull request #95 from magento-commerce/imported-svera-magento-c…
svera Oct 6, 2021
eda77b3
AC-676: Create phpcs static check for ObsoleteConnectionTest
eliseacornejo Oct 7, 2021
4b8687b
Merge branch 'develop' of github.com:magento/magento-coding-standard …
eliseacornejo Oct 7, 2021
5a34fd1
AC-676: Create phpcs static check for ObsoleteConnectionTest
eliseacornejo Oct 7, 2021
0bea0bc
AC-676: Create phpcs static check for ObsoleteConnectionTest
eliseacornejo Oct 7, 2021
5f08bf5
AC-678: Create phpcs sniff for ObsoleteResponseTest
eliseacornejo Oct 11, 2021
2270b33
Merge branch 'develop' of github.com:magento/magento-coding-standard …
eliseacornejo Oct 11, 2021
53380c7
AC-1314: Fix copyright sniff
eliseacornejo Oct 11, 2021
9416fc8
AC-1314: Fix copyright sniff
eliseacornejo Oct 13, 2021
9286ff9
AC-678: Create phpcs sniff for ObsoleteResponseTest
eliseacornejo Oct 13, 2021
01ff1bd
Merge branch 'develop' of github.com:magento/magento-coding-standard …
svera Oct 13, 2021
ec36aef
AC-676: Create phpcs static check for ObsoleteConnectionTest
eliseacornejo Oct 13, 2021
e59ca3f
AC-670: Create phpcs static check for LayoutTest
svera Oct 13, 2021
c30669f
AC-670: Create phpcs static check for LayoutTest
svera Oct 13, 2021
6558e29
Merge branch 'develop' of github.com:magento/magento-coding-standard …
svera Oct 13, 2021
36776b8
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Oct 13, 2021
a78b21d
Update Magento2/Sniffs/Legacy/LayoutSniff.php
svera Oct 13, 2021
39267ba
Update Magento2/Sniffs/Legacy/ClassReferencesInConfigurationFilesSnif…
svera Oct 13, 2021
34c66bd
Merge pull request #96 from magento-commerce/imported-eliseacornejo-m…
eliseacornejo Oct 13, 2021
3c477b1
Merge pull request #97 from magento-commerce/imported-svera-magento-c…
svera Oct 13, 2021
c420516
Merge branch 'develop' of github.com:magento/magento-coding-standard …
eliseacornejo Oct 13, 2021
8402f7d
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Oct 13, 2021
1338211
Merge branch 'AC-663_phpcs-ClassesTest' of github.com:svera/magento-c…
svera Oct 13, 2021
ee4c7d6
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Oct 13, 2021
47072f0
Merge pull request #98 from magento-commerce/imported-eliseacornejo-m…
eliseacornejo Oct 14, 2021
7fdd6b4
AC-672: Create phpcs static check for LicenseTest
eliseacornejo Oct 14, 2021
001076c
Merge branch 'develop' of github.com:magento/magento-coding-standard …
eliseacornejo Oct 14, 2021
e3cdba0
AC-672: Create phpcs static check for LicenseTest
eliseacornejo Oct 14, 2021
c22fd18
AC-672: Create phpcs static check for LicenseTest
eliseacornejo Oct 14, 2021
0d1ae00
AC-672: Create phpcs static check for LicenseTest
eliseacornejo Oct 14, 2021
08ed34b
Update Magento2/Sniffs/Legacy/ClassReferencesInConfigurationFilesSnif…
svera Oct 14, 2021
c9ca788
AC-663: Create phpcs static check for ClassesTest::testPhpCode
svera Oct 14, 2021
3b0e492
Merge pull request #99 from magento-commerce/imported-svera-magento-c…
svera Oct 14, 2021
d5c7119
Merge branch 'develop' of github.com:magento/magento-coding-standard …
eliseacornejo Oct 14, 2021
6691ae8
AC-672: Create phpcs static check for LicenseTest
eliseacornejo Oct 14, 2021
c38ca66
AC-206: Create UCT phpcs ruleset for customizations only
svera Oct 14, 2021
90983fb
AC-206: Create UCT phpcs ruleset for customizations only
svera Oct 14, 2021
ef49c1b
AC-672: Create phpcs static check for LicenseTest
eliseacornejo Oct 14, 2021
fd79554
Merge pull request #100 from magento-commerce/imported-eliseacornejo-…
eliseacornejo Oct 14, 2021
f895fbf
Merge branch 'develop' of github.com:magento-commerce/magento-coding-…
sivaschenko Oct 19, 2021
30a34f2
AC-206: Updated and renamed the extesnions-ruleset.xml
sivaschenko Oct 19, 2021
655960e
AC-206: Added Magento only ruleset
sivaschenko Oct 19, 2021
c0d26b8
AC-206: Moved License sniff to magento-only-ruleset
sivaschenko Oct 19, 2021
c7250a2
AC-206: Corrected rules names in magento-only-ruleset
sivaschenko Oct 19, 2021
97dab81
Merge branch 'AC-1314' of github.com:eliseacornejo/magento-coding-sta…
sivaschenko Oct 19, 2021
2c874c5
Merge pull request #101 from magento-commerce/AC-1314
sivaschenko Oct 19, 2021
47a6486
Merge branch 'develop' of github.com:magento-commerce/magento-coding-…
sivaschenko Oct 19, 2021
88d9f59
AC-206: Extracted Fframework only sniffs to a separate namespace
sivaschenko Oct 19, 2021
dd1e3f6
AC-206: Optimized eslint test command
sivaschenko Oct 19, 2021
6451e34
Merge pull request #103 from magento-commerce/AC-206
sivaschenko Oct 20, 2021
1bd89ac
AC-1549: Create codes for each type of returned error / warning
svera Oct 26, 2021
c147628
AC-1549: Fixed static tests
svera Oct 26, 2021
94a395a
AC-1549: Added more codes and cleaned up unused messages
svera Oct 26, 2021
f76f48f
Update Magento2/Sniffs/Legacy/InstallUpgradeSniff.php
svera Oct 26, 2021
3953207
Update Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php
svera Oct 26, 2021
28ce4ef
Update Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php
svera Oct 26, 2021
d7c4374
Update Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php
svera Oct 26, 2021
ee515c3
Update Magento2/Sniffs/Legacy/_files/restricted_classes.php
svera Oct 26, 2021
2391b0d
AC-1549: Made suggestions
svera Oct 26, 2021
852a479
AC-1549: Made suggestions
svera Oct 26, 2021
3d3dc9e
AC-1549: Made suggestions
svera Oct 26, 2021
8f6ddba
Merge pull request #316 from svera/AC-1549_single-error-codes
svera Oct 26, 2021
fe32712
magento/magento-coding-standard#315: Fixed undefined index in Magento…
sivaschenko Oct 27, 2021
b5eab5a
magento/magento-coding-standard#317: Updated phpdocs duplicating prop…
sivaschenko Oct 27, 2021
409fd33
Merge pull request #104 from magento-commerce/imported-sivaschenko-ma…
sivaschenko Oct 27, 2021
9ffb1a5
Extracted js tests to a separate build
sivaschenko Oct 27, 2021
67a798c
Merge branch 'develop' of github.com:magento/magento-coding-standard …
sivaschenko Oct 27, 2021
2c9a24a
Merge pull request #105 from magento-commerce/update-from-public
sivaschenko Oct 27, 2021
c4e2eca
magento/magento-coding-standard#314: Fixed AutogeneratedClassNotInCon…
sivaschenko Oct 28, 2021
de99e8b
magento/magento-coding-standard#319: Corrected regex
sivaschenko Oct 28, 2021
d903f9c
magento/magento-coding-standard#319: Corrected message
sivaschenko Oct 28, 2021
a30edcb
Merge pull request #106 from magento-commerce/github-actions-update
sivaschenko Oct 28, 2021
4b42f01
Run polyjuice to get eslintrc-jscs from original jscsrc
loginesta Oct 28, 2021
3c9c359
Tune space-before-function-paren
loginesta Oct 28, 2021
d78440c
Tune valid-jsdoc
loginesta Oct 28, 2021
112b8e0
Use eslint rule to disable/enable curly instead of jscs
loginesta Oct 28, 2021
040d156
Remove JSCS references on repo
loginesta Oct 28, 2021
36715df
Update CI file
loginesta Oct 28, 2021
6f94d87
AC-1314: Added copyright verification for graphqls files
sivaschenko Oct 29, 2021
b54b703
Merge branch 'copyright-graphql' of github.com:sivaschenko/magento-co…
sivaschenko Oct 29, 2021
bbf536f
Merge branch 'autogenerated-class-not-in-constructor' of github.com:s…
sivaschenko Oct 29, 2021
8c47117
Merge branch 'AC-1509' of github.com:loginesta/magento-coding-standar…
sivaschenko Oct 29, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ on:
branches: [ master, develop ]

jobs:
build:

php:
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -41,10 +40,6 @@ jobs:

- name: Install dependencies
run: npm install
- name: Run ESLint
run: npm run eslint -- eslint/rules Magento2 --ignore-pattern 'Magento2/Tests/Eslint/*Test.js'
- name: Run JSCS
run: npm run jscs eslint/rules Magento2

- name: Validate composer
run: composer validate
Expand All @@ -59,4 +54,24 @@ jobs:
run: vendor/bin/phpunit

- name: Run code style suite
run: vendor/bin/phpcs --standard=Magento2 Magento2/Helpers/ Magento2/Sniffs
run: vendor/bin/phpcs --standard=Magento2 Magento2/Helpers Magento2/Sniffs Magento2Framework/Sniffs

- name: Run framework suite
run: vendor/bin/phpcs --standard=Magento2Framework Magento2/Helpers Magento2/Sniffs Magento2Framework/Sniffs
js:
runs-on: ubuntu-latest
name: Javascript tests

steps:
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '16'

- uses: actions/checkout@v2

- name: Install dependencies
run: npm install

- name: Run ESLint
run: npm run eslint -- eslint/rules
155 changes: 94 additions & 61 deletions Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento2\Sniffs\Commenting;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\AbstractVariableSniff;
use PHP_CodeSniffer\Util\Tokens;
use Magento2\Helpers\Commenting\PHPDocFormattingValidator;

/**
* Class ClassPropertyPHPDocFormattingSniff
*/
class ClassPropertyPHPDocFormattingSniff extends AbstractVariableSniff
{

/**
* @var array
*/
private $ignoreTokens = [
private const TOKENS_ALLOWED_BETWEEN_PHPDOC_AND_PROPERTY_NAME = [
T_PUBLIC,
T_PRIVATE,
T_PROTECTED,
T_VAR,
T_STATIC,
T_WHITESPACE,
T_NS_SEPARATOR,
T_STRING,
T_COMMENT
];

/**
Expand All @@ -38,15 +41,9 @@ class ClassPropertyPHPDocFormattingSniff extends AbstractVariableSniff
*/
public function __construct()
{
$scopes = Tokens::$ooScopeTokens;
$this->PHPDocFormattingValidator = new PHPDocFormattingValidator();
$listen = [
T_VARIABLE,
T_DOUBLE_QUOTED_STRING,
T_HEREDOC,
];

parent::__construct($scopes, $listen, true);
parent::__construct();
}

/**
Expand All @@ -56,111 +53,147 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

$commentEnd = $phpcsFile->findPrevious($this->ignoreTokens, ($stackPtr - 1), null, true);
$commentEnd = $phpcsFile->findPrevious(
self::TOKENS_ALLOWED_BETWEEN_PHPDOC_AND_PROPERTY_NAME,
$stackPtr - 1,
null,
true
);

if ($commentEnd !== false && $tokens[$commentEnd]['code'] === T_STRING) {
$commentEnd = $phpcsFile->findPrevious($this->ignoreTokens, ($commentEnd - 1), null, true);
} elseif ($commentEnd === false
|| ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG
&& $tokens[$commentEnd]['code'] !== T_COMMENT)
) {
if ($commentEnd === false || $tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG) {
$phpcsFile->addWarning('Missing PHP DocBlock for class property.', $stackPtr, 'Missing');
return;
}

$commentStart = $tokens[$commentEnd]['comment_opener'];
$foundVar = null;
$varAnnotationPosition = null;
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
if ($tokens[$tag]['content'] === '@var') {
if ($foundVar !== null) {
$error = 'Only one @var tag is allowed for class property declaration.';
$phpcsFile->addWarning($error, $tag, 'DuplicateVar');
if ($varAnnotationPosition !== null) {
$phpcsFile->addWarning(
'Only one @var tag is allowed for class property declaration.',
$tag,
'DuplicateVar'
);
} else {
$foundVar = $tag;
$varAnnotationPosition = $tag;
}
}
}

if ($foundVar === null) {
$error = 'Class properties must have type declaration using @var tag.';
$phpcsFile->addWarning($error, $stackPtr, 'MissingVar');
if ($varAnnotationPosition === null) {
$phpcsFile->addWarning(
'Class properties must have type declaration using @var tag.',
$stackPtr,
'MissingVar'
);
return;
}

$string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $foundVar, $commentEnd);
if ($string === false || $tokens[$string]['line'] !== $tokens[$foundVar]['line']) {
$error = 'Content missing for @var tag in class property declaration.';
$phpcsFile->addWarning($error, $foundVar, 'EmptyVar');
$string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $varAnnotationPosition, $commentEnd);
if ($string === false || $tokens[$string]['line'] !== $tokens[$varAnnotationPosition]['line']) {
$phpcsFile->addWarning(
'Content missing for @var tag in class property declaration.',
$varAnnotationPosition,
'EmptyVar'
);
return;
}

// Check if class has already have meaningful description after @var tag
$isShortDescriptionAfterVar = $phpcsFile->findNext(
$shortDescriptionAfterVarPosition = $phpcsFile->findNext(
T_DOC_COMMENT_STRING,
$foundVar + 4,
$varAnnotationPosition + 4,
$commentEnd,
false,
null,
false
);

if ($this->PHPDocFormattingValidator->providesMeaning(
$isShortDescriptionAfterVar,
$shortDescriptionAfterVarPosition,
$commentStart,
$tokens
) !== true) {
preg_match(
'`^((?:\|?(?:array\([^\)]*\)|[\\\\\[\]]+))*)( .*)?`i',
$tokens[($foundVar + 2)]['content'],
$tokens[($varAnnotationPosition + 2)]['content'],
$varParts
);
if ($varParts[1]) {
return;
}
$error = 'Short description must be before @var tag.';
$phpcsFile->addWarning($error, $isShortDescriptionAfterVar, 'ShortDescriptionAfterVar');
return;
$phpcsFile->addWarning(
'Short description must be before @var tag.',
$shortDescriptionAfterVarPosition,
'ShortDescriptionAfterVar'
);
}

// Check if class has already have meaningful description before @var tag
$isShortDescriptionPreviousVar = $phpcsFile->findPrevious(
$this->processPropertyShortDescription($phpcsFile, $stackPtr, $varAnnotationPosition, $commentStart);
}

/**
* Check if class has already have meaningful description before var tag
*
* @param File $phpcsFile
* @param int $propertyNamePosition
* @param int $varAnnotationPosition
* @param int $commentStart
*/
private function processPropertyShortDescription(
File $phpcsFile,
int $propertyNamePosition,
int $varAnnotationPosition,
int $commentStart
): void {
$propertyShortDescriptionPosition = $phpcsFile->findPrevious(
T_DOC_COMMENT_STRING,
$foundVar,
$varAnnotationPosition,
$commentStart,
false,
null,
false
);

if ($isShortDescriptionPreviousVar === false) {
if ($propertyShortDescriptionPosition === false) {
return;
}

$propertyNamePosition = $phpcsFile->findNext(
T_VARIABLE,
$foundVar,
null,
false,
null,
false
);
if ($propertyNamePosition === false) {
return;
};
$tokens = $phpcsFile->getTokens();
$propertyName = trim($tokens[$propertyNamePosition]['content'], '$');
$shortDescription = strtolower($tokens[$isShortDescriptionPreviousVar]['content']);
$shortDescription = strtolower($tokens[$propertyShortDescriptionPosition]['content']);

if ($shortDescription === strtolower($propertyName)) {
$error = 'Short description duplicates class property name.';
$phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar');
return;
if ($this->isDuplicate($propertyName, $shortDescription)) {
$phpcsFile->addWarning(
'Short description duplicates class property name.',
$propertyShortDescriptionPosition,
'AlreadyHaveMeaningfulNameVar'
);
}
}

$propertyNameParts = array_filter(preg_split('/(?=[A-Z])/', $propertyName));
/**
* Does short description duplicate the property name
*
* @param string $propertyName
* @param string $shortDescription
* @return bool
*/
private function isDuplicate(string $propertyName, string $shortDescription): bool
{
return $this->clean($propertyName) === $this->clean($shortDescription);
}

if ($shortDescription === strtolower(implode(' ', $propertyNameParts))) {
$error = 'Short description duplicates class property name.';
$phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar');
}
/**
* Return only A-Za-z characters converted to lowercase from the string
*
* @param string $string
* @return string
*/
private function clean(string $string): string
{
return strtolower(preg_replace('/[^A-Za-z]/', '', $string));
}

/**
Expand Down
9 changes: 9 additions & 0 deletions Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,14 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
'^strval$' => '(string) construction',
'^htmlspecialchars$' => '\Magento\Framework\Escaper->escapeHtml',
'^getimagesize$' => 'getimagesizefromstring',
'^file_exists$' => 'Magento\Framework\Filesystem\DriverInterface::isExists()',
'^file_get_contents$' => 'Magento\Framework\Filesystem\DriverInterface::fileGetContents()',
'^file_put_contents$' => 'Magento\Framework\Filesystem\DriverInterface::filePutContents()',
'^fgetcsv$' => 'Magento\Framework\Filesystem\DriverInterface::fileGetCsv()',
'^fputcsv$' => 'Magento\Framework\Filesystem\DriverInterface::filePutCsv()',
'^ftell$' => 'Magento\Framework\Filesystem\DriverInterface::fileTell()',
'^fseek$' => 'Magento\Framework\Filesystem\DriverInterface::fileSeek()',
'^feof$' => 'Magento\Framework\Filesystem\DriverInterface::endOfFile()',
'^flock$' => 'Magento\Framework\Filesystem\DriverInterface::fileLock()',
];
}
12 changes: 4 additions & 8 deletions Magento2/Sniffs/Legacy/AbstractBlockSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ class AbstractBlockSniff implements Sniff
private const CHILD_HTML_METHOD = 'getChildHtml';
private const CHILD_CHILD_HTML_METHOD = 'getChildChildHtml';

/**
* Error violation code.
*
* @var string
*/
protected $errorCode = 'FoundCountOfParametersIncorrect';
private const ERROR_CODE_THIRD_PARAMETER = 'ThirdParameterNotNeeded';
private const ERROR_CODE_FOURTH_PARAMETER = 'FourthParameterNotNeeded';

/**
* @inheritdoc
Expand Down Expand Up @@ -52,14 +48,14 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->addError(
'3rd parameter is not needed anymore for getChildHtml()',
$stackPtr,
$this->errorCode
self::ERROR_CODE_THIRD_PARAMETER
);
}
if ($content === self::CHILD_CHILD_HTML_METHOD && $paramsCount >= 4) {
$phpcsFile->addError(
'4th parameter is not needed anymore for getChildChildHtml()',
$stackPtr,
$this->errorCode
self::ERROR_CODE_FOURTH_PARAMETER
);
}
}
Expand Down
Loading