Skip to content

Fix phpcs issues #344

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

Merged
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ jobs:
run: vendor/bin/phpunit

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

- name: Run framework suite
run: vendor/bin/phpcs --standard=Magento2Framework Magento2/Helpers Magento2/Sniffs Magento2Framework/Sniffs
run: vendor/bin/phpcs --standard=Magento2Framework Magento2/Helpers Magento2/Sniffs Magento2/Rector Magento2Framework/Sniffs
js:
runs-on: ubuntu-latest
name: Javascript tests
Expand Down
13 changes: 6 additions & 7 deletions Magento2/Rector/Src/AddArrayAccessInterfaceReturnTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\Exception\PoorDocumentationException;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class AddArrayAccessInterfaceReturnTypes extends AbstractRector
class AddArrayAccessInterfaceReturnTypes extends AbstractRector
{
/**
* @return array<class-string<Node>>
* @inheritDoc
*/
public function getNodeTypes(): array
{
return [Class_::class];
}

/**
* @param Class_ $node
* @inheritDoc
*/
public function refactor(Node $node): ?Node
{
Expand All @@ -52,13 +51,13 @@ public function refactor(Node $node): ?Node
}

/**
* @return RuleDefinition
* @throws PoorDocumentationException
* @inheritDoc
*/
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Add return types specified by ArrayAccess interface', [
'Add return types specified by ArrayAccess interface',
[
new CodeSample(
'public function offsetSet($offset, $value)',
'public function offsetSet($offset, $value): void'
Expand Down
13 changes: 6 additions & 7 deletions Magento2/Rector/Src/ReplaceMbStrposNullLimit.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\LNumber;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\Exception\PoorDocumentationException;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class ReplaceMbStrposNullLimit extends AbstractRector
class ReplaceMbStrposNullLimit extends AbstractRector
{
/**
* @return array<class-string<Node>>
* @inheritDoc
*/
public function getNodeTypes(): array
{
return [FuncCall::class];
}

/**
* @param FuncCall $node
* @inheritDoc
*/
public function refactor(Node $node): ?Node
{
Expand All @@ -43,13 +42,13 @@ public function refactor(Node $node): ?Node
}

/**
* @return RuleDefinition
* @throws PoorDocumentationException
* @inheritDoc
*/
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Change mb_strpos offset from null to 0', [
'Change mb_strpos offset from null to 0',
[
new CodeSample(
'mb_strpos("pattern", "subject", null, "encoding");',
'mb_strpos("pattern", "subject", 0, "encoding");'
Expand Down
13 changes: 6 additions & 7 deletions Magento2/Rector/Src/ReplaceNewDateTimeNull.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\Exception\PoorDocumentationException;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class ReplaceNewDateTimeNull extends AbstractRector
class ReplaceNewDateTimeNull extends AbstractRector
{
/**
* @return array<class-string<Node>>
* @inheritDoc
*/
public function getNodeTypes(): array
{
return [New_::class];
}

/**
* @param New_ $node
* @inheritDoc
*/
public function refactor(Node $node): ?Node
{
Expand All @@ -43,13 +42,13 @@ public function refactor(Node $node): ?Node
}

/**
* @return RuleDefinition
* @throws PoorDocumentationException
* @inheritDoc
*/
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Change DateTime datetime input from null to "now"', [
'Change DateTime datetime input from null to "now"',
[
new CodeSample(
'new DateTime(null, new DateTimeZone("GMT"));',
'new DateTime("now", new DateTimeZone("GMT"));'
Expand Down
13 changes: 6 additions & 7 deletions Magento2/Rector/Src/ReplacePregSplitNullLimit.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\LNumber;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\Exception\PoorDocumentationException;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class ReplacePregSplitNullLimit extends AbstractRector
class ReplacePregSplitNullLimit extends AbstractRector
{
/**
* @return array<class-string<Node>>
* @inheritDoc
*/
public function getNodeTypes(): array
{
return [FuncCall::class];
}

/**
* @param FuncCall $node
* @inheritDoc
*/
public function refactor(Node $node): ?Node
{
Expand All @@ -43,13 +42,13 @@ public function refactor(Node $node): ?Node
}

/**
* @return RuleDefinition
* @throws PoorDocumentationException
* @inheritDoc
*/
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Change preg_split limit from null to -1', [
'Change preg_split limit from null to -1',
[
new CodeSample(
'preg_split("pattern", "subject", null, 0);',
'preg_split("pattern", "subject", -1, 0);'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

final class AddArrayAccessInterfaceReturnTypesTest extends AbstractRectorTestCase
class AddArrayAccessInterfaceReturnTypesTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

final class ReplaceMbStrposNullLimitTest extends AbstractRectorTestCase
class ReplaceMbStrposNullLimitTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
Expand All @@ -29,6 +29,9 @@ public function provideData(): Iterator
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

/**
* @return string
*/
public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

final class ReplaceNewDateTimeNullTest extends AbstractRectorTestCase
class ReplaceNewDateTimeNullTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

final class ReplacePregSplitNullLimitTest extends AbstractRectorTestCase
class ReplacePregSplitNullLimitTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
Expand Down
5 changes: 4 additions & 1 deletion Magento2/Tests/Eslint/AbstractEslintTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@
abstract class AbstractEslintTestCase extends TestCase
{
/**
* Assert that file contains a specific error.
*
* @param string $testFile
* @param array $expectedMessages
*/
protected function assertFileContainsError(string $testFile, array $expectedMessages): void
{
// phpcs:disable
exec(
'npm run eslint -- Magento2/Tests/Eslint/' . $testFile,
$output
);

foreach ($expectedMessages as $message) {
$this->assertStringContainsString($message, implode(' ',$output));
$this->assertStringContainsString($message, implode(' ', $output));
}
}
}
2 changes: 1 addition & 1 deletion Magento2/Tests/Eslint/ClickEventShorthandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public function testExecute(): void
['Instead of .blur(fn) use .on("blur", fn). Instead of .blur() use .trigger("blur")']
);
}
}
}
2 changes: 1 addition & 1 deletion Magento2/Tests/Eslint/DelegateUndelegateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public function testExecute(): void
['jQuery $.delegate and $.undelegate are deprecated, use $.on and $.off instead']
);
}
}
}
2 changes: 1 addition & 1 deletion Magento2/Tests/Eslint/EventShorthandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public function testExecute(): void
['jQuery.load() was removed, use .on("load", fn) instead']
);
}
}
}
2 changes: 1 addition & 1 deletion Magento2/Tests/Eslint/SizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public function testExecute(): void
['jQuery.size() removed, use jQuery.length']
);
}
}
}
2 changes: 1 addition & 1 deletion Magento2/Tests/Eslint/TrimTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public function testExecute(): void
['jQuery.trim is deprecated; use String.prototype.trim']
);
}
}
}
3 changes: 3 additions & 0 deletions Magento2/Tests/Legacy/InstallUpgradeUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

class InstallUpgradeUnitTest extends AbstractSniffUnitTest
{
/**
* @var string[]
*/
private $wrongFileNames = [
'data-install-.inc',
'data-upgrade-.inc',
Expand Down
3 changes: 1 addition & 2 deletions Magento2/Tests/Legacy/PhtmlTemplateUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public function getWarningList($testFile = '')
39 => 1
];
}
if ($testFile === 'PhtmlTemplateUnitTest.3.phtml')
{
if ($testFile === 'PhtmlTemplateUnitTest.3.phtml') {
return [
9 => 1,
20 => 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Tests\Legacy\_files\RestrictedCodeUnitTest\Magento\Framework\Model\ResourceModel;

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* This is NOT actually a test, but a file that must be ignored by RestrictedCodeSniff
Expand All @@ -15,20 +15,23 @@
*/
class IteratorDummyFile extends AbstractSniffUnitTest
{
protected function shouldSkipTest()
protected function shouldSkipTest(): bool
{
return true;
}

protected function getErrorList() {
protected function getErrorList(): array
{
return [];
}

protected function getWarningList() {
protected function getWarningList(): array
{
return [];
}

private function withProtectedClass() {
private function withProtectedClass(): Zend_Db_Expr
{
return new \Zend_Db_Expr();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public function dataForbiddenAbstractPrivateMethods()
];
}


/**
* Verify that the sniff throws an error for abstract private methods in traits for PHP 7.4
* and doesn't for PHP 8.0.
Expand Down Expand Up @@ -91,7 +90,6 @@ public function dataNewTraitAbstractPrivateMethods()
];
}


/**
* Verify the sniff does not throw false positives for valid code.
*
Expand Down Expand Up @@ -128,7 +126,6 @@ public function dataNoFalsePositives()
return $cases;
}


/**
* Verify no notices are thrown at all.
*
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Tests/PHPCompatibility/BaseSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BaseSniffTest extends TestCase
*
* @var string
*/
const STANDARD_NAME = 'Magento2';
private const STANDARD_NAME = 'Magento2';

/**
* The PHP_CodeSniffer object used for testing.
Expand Down
Loading