Skip to content

Commit

Permalink
Merge pull request #83 from magento/pre-release
Browse files Browse the repository at this point in the history
Pre 2.0.0 release improvements and fixes
  • Loading branch information
lenaorobei authored Apr 17, 2019
2 parents f2de49f + 38b7757 commit e2ed8ce
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
26 changes: 26 additions & 0 deletions Magento2/Sniffs/Performance/ForeachArrayMergeSniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Rule: array_merge(...) is used in a loop and is a resources greedy construction

## Reason
Merging arrays in a loop is slow and causes high CPU usage.

## How to Fix
Typical example when `array_merge` is being used in the loop:
``` php
$options = [];
foreach ($configurationSources as $source) {
// code here
$options = array_merge($options, $source->getOptions());
}
```

In order to reduce execution time `array_merge` can be called only once:
``` php
$options = [[]];
foreach ($configurationSources as $source) {
// code here
$options[] = $source->getOptions();
}

// PHP 5.6+
$options = array_merge(...$options);
```
18 changes: 18 additions & 0 deletions Magento2/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
<rule ref="Magento2.Classes.DiscouragedDependencies">
<severity>10</severity>
<type>error</type>
<exclude-pattern>*/_files/*</exclude-pattern>
<exclude-pattern>*/Fixtures/*</exclude-pattern>
<exclude-pattern>*/Test/*</exclude-pattern>
<exclude-pattern>*Test.php</exclude-pattern>
</rule>
<rule ref="Magento2.Legacy.MageEntity">
<severity>10</severity>
Expand All @@ -57,17 +60,23 @@
<severity>10</severity>
<type>error</type>
<exclude-pattern>*/_files/*</exclude-pattern>
<exclude-pattern>*/Fixtures/*</exclude-pattern>
<exclude-pattern>*/lib/*</exclude-pattern>
<exclude-pattern>*/Test/*</exclude-pattern>
<exclude-pattern>*Test.php</exclude-pattern>
</rule>
<rule ref="Magento2.Security.LanguageConstruct">
<severity>10</severity>
<type>error</type>
</rule>
<rule ref="Magento2.Security.LanguageConstruct.DirectOutput">
<exclude-pattern>*.phtml</exclude-pattern>
</rule>
<rule ref="Magento2.Security.Superglobal.SuperglobalUsageError">
<severity>10</severity>
<type>error</type>
<exclude-pattern>*/_files/*</exclude-pattern>
<exclude-pattern>*/Fixtures/*</exclude-pattern>
<exclude-pattern>*/lib/*</exclude-pattern>
<exclude-pattern>*/Test/*</exclude-pattern>
<exclude-pattern>*Test.php</exclude-pattern>
Expand Down Expand Up @@ -103,6 +112,7 @@
<severity>9</severity>
<type>warning</type>
<exclude-pattern>*/_files/*</exclude-pattern>
<exclude-pattern>*/Fixtures/*</exclude-pattern>
<exclude-pattern>*/lib/*</exclude-pattern>
<exclude-pattern>*/Test/*</exclude-pattern>
<exclude-pattern>*Test.php</exclude-pattern>
Expand All @@ -116,6 +126,7 @@
<severity>9</severity>
<type>warning</type>
<exclude-pattern>*/_files/*</exclude-pattern>
<exclude-pattern>*/Fixtures/*</exclude-pattern>
<exclude-pattern>*/lib/*</exclude-pattern>
<exclude-pattern>*/Test/*</exclude-pattern>
<exclude-pattern>*Test.php</exclude-pattern>
Expand All @@ -134,6 +145,7 @@
<severity>8</severity>
<type>warning</type>
<exclude-pattern>*/_files/*</exclude-pattern>
<exclude-pattern>*/Fixtures/*</exclude-pattern>
<exclude-pattern>*/Test/*</exclude-pattern>
<exclude-pattern>*Test.php</exclude-pattern>
</rule>
Expand All @@ -145,6 +157,7 @@
<severity>8</severity>
<type>warning</type>
<exclude-pattern>*/_files/*</exclude-pattern>
<exclude-pattern>*/Fixtures/*</exclude-pattern>
<exclude-pattern>*/lib/*</exclude-pattern>
<exclude-pattern>*/Test/*</exclude-pattern>
<exclude-pattern>*Test.php</exclude-pattern>
Expand All @@ -153,6 +166,7 @@
<severity>8</severity>
<type>warning</type>
<exclude-pattern>*/_files/*</exclude-pattern>
<exclude-pattern>*/Fixtures/*</exclude-pattern>
<exclude-pattern>*/lib/*</exclude-pattern>
<exclude-pattern>*/Setup/*</exclude-pattern>
<exclude-pattern>*/Test/*</exclude-pattern>
Expand Down Expand Up @@ -224,6 +238,7 @@
<severity>7</severity>
<type>warning</type>
<exclude-pattern>*/_files/*</exclude-pattern>
<exclude-pattern>*/Fixtures/*</exclude-pattern>
<exclude-pattern>*/Test/*</exclude-pattern>
<exclude-pattern>*Test.php</exclude-pattern>
</rule>
Expand Down Expand Up @@ -251,6 +266,7 @@
<severity>7</severity>
<type>warning</type>
<exclude-pattern>*/_files/*</exclude-pattern>
<exclude-pattern>*/Fixtures/*</exclude-pattern>
<exclude-pattern>*/Test/*</exclude-pattern>
<exclude-pattern>*Test.php</exclude-pattern>
</rule>
Expand All @@ -266,6 +282,7 @@
<severity>7</severity>
<type>warning</type>
<exclude-pattern>*/_files/*</exclude-pattern>
<exclude-pattern>*/Fixtures/*</exclude-pattern>
<exclude-pattern>*/Test/*</exclude-pattern>
<exclude-pattern>*Test.php</exclude-pattern>
</rule>
Expand Down Expand Up @@ -329,6 +346,7 @@
<severity>6</severity>
<type>warning</type>
<exclude-pattern>*/_files/*</exclude-pattern>
<exclude-pattern>*/Fixtures/*</exclude-pattern>
<exclude-pattern>*/Test/*</exclude-pattern>
<exclude-pattern>*Test.php</exclude-pattern>
</rule>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"AFL-3.0"
],
"type": "phpcodesniffer-standard",
"version": "1.0.2",
"version": "2.0.0",
"require": {
"php": ">=5.6.0",
"squizlabs/php_codesniffer": "^3.4"
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e2ed8ce

Please sign in to comment.