Skip to content

Commit 6d67e82

Browse files
committed
Change folder structure
1 parent 13e5071 commit 6d67e82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+197
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.idea
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

ruleset.xml renamed to Magento1/ruleset.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
2-
<ruleset name="Ecg">
3-
<description>ECG Coding Standard</description>
2+
<ruleset name="Magento1">
3+
<description>Magento 1 Coding Standard</description>
44

55
<rule ref="Generic.Classes.DuplicateClassName"/>
66
<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
class Magento2_Sniffs_Plugins_PluginSniff implements PHP_CodeSniffer_Sniff
4+
{
5+
6+
const PARAMS_QTY = 2;
7+
8+
const P_BEFORE = 'before';
9+
const P_AROUND = 'around';
10+
const P_AFTER = 'after';
11+
12+
protected $prefixes = array(
13+
self::P_BEFORE,
14+
self::P_AROUND,
15+
self::P_AFTER
16+
);
17+
18+
protected $exclude = array();
19+
20+
21+
public function register()
22+
{
23+
return array(
24+
T_FUNCTION
25+
);
26+
}
27+
28+
29+
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
30+
{
31+
$functionName = $phpcsFile->getDeclarationName($stackPtr);
32+
33+
$plugin = $this->startsWith($functionName, $this->prefixes, $this->exclude);
34+
if ($plugin) {
35+
$paramsQty = count($phpcsFile->getMethodParameters($stackPtr));
36+
if ($paramsQty < self::PARAMS_QTY) {
37+
$phpcsFile->addWarning('Plugin '.$functionName.' function should have at least two parameters.', $stackPtr);
38+
}
39+
40+
if ($plugin == self::P_BEFORE) {
41+
return;
42+
}
43+
44+
$tokens = $phpcsFile->getTokens();
45+
46+
$hasReturn = false;
47+
foreach ($tokens as $currToken) {
48+
if ($currToken['code'] == T_RETURN && isset($currToken['conditions'][$stackPtr])) {
49+
$hasReturn = true;
50+
break;
51+
}
52+
}
53+
54+
if (!$hasReturn) {
55+
$phpcsFile->addError('Plugin '.$functionName.' function must return value.', $stackPtr);
56+
}
57+
}
58+
}
59+
60+
61+
protected function startsWith($haystack, array $needle, array $excludeFunctions = array())
62+
{
63+
if (in_array($haystack, $excludeFunctions)) {
64+
return false;
65+
}
66+
$haystackLength = strlen($haystack);
67+
foreach ($needle as $currPref) {
68+
$length = strlen($currPref);
69+
if ($haystackLength != $length && substr($haystack, 0, $length) === $currPref) {
70+
return $currPref;
71+
}
72+
}
73+
return false;
74+
}
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
class Magento2_Sniffs_Templates_ThisInTemplateSniff implements PHP_CodeSniffer_Sniff
4+
{
5+
6+
protected $message = 'Usage of $this in template files is deprecated.';
7+
8+
protected $allowedMethods = array(
9+
'helper',
10+
);
11+
12+
public function register()
13+
{
14+
return array(
15+
T_VARIABLE
16+
);
17+
}
18+
19+
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
20+
{
21+
$tokens = $phpcsFile->getTokens();
22+
if ($tokens[$stackPtr]['content'] == '$this') {
23+
$endOfStatementPtr = $phpcsFile->findEndOfStatement($stackPtr);
24+
$functionPtr = $phpcsFile->findNext(T_STRING, $stackPtr, $endOfStatementPtr);
25+
if ($functionPtr) {
26+
if (!in_array($tokens[$functionPtr]['content'], $this->allowedMethods)) {
27+
$phpcsFile->addWarning($this->message, $stackPtr);
28+
}
29+
} else {
30+
$phpcsFile->addWarning($this->message, $stackPtr);
31+
}
32+
}
33+
}
34+
}
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
namespace foo\bar;
3+
4+
class TestPlugin
5+
{
6+
7+
public function before()
8+
{
9+
return '';
10+
}
11+
12+
13+
public function beforeSetName($subject, $name)
14+
{
15+
return array('(' . $name . ')');
16+
}
17+
18+
19+
public function afterGetName($subject, $result)
20+
{
21+
if (true) {
22+
return 'hfwfwef';
23+
}
24+
return '|' . $result . '|';
25+
}
26+
27+
28+
public function aroundSave($subject, \Closure $proceed)
29+
{
30+
$this->doSmthBeforeProductIsSaved();
31+
$returnValue = $proceed();
32+
if ($returnValue) {
33+
$this->postProductToFacebook();
34+
}
35+
return $returnValue;
36+
}
37+
}
38+
39+
$class = new TestPlugin();
40+
echo $class->go();

Magento2/ruleset.xml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Magento2">
3+
<description>Magento 2 Coding Standard</description>
4+
5+
<rule ref="Generic.Classes.DuplicateClassName"/>
6+
<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
7+
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
8+
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>
9+
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
10+
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
11+
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
12+
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
13+
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
14+
<rule ref="Generic.Commenting.Fixme"/>
15+
<rule ref="Generic.Commenting.Todo"/>
16+
<rule ref="Generic.Files.ByteOrderMark"/>
17+
<rule ref="Generic.Files.OneClassPerFile"/>
18+
<rule ref="Generic.Files.OneInterfacePerFile"/>
19+
<rule ref="Generic.Functions.CallTimePassByReference"/>
20+
<rule ref="Generic.Metrics.CyclomaticComplexity"/>
21+
<rule ref="Generic.Metrics.NestingLevel"/>
22+
<rule ref="Generic.PHP.CharacterBeforePHPOpeningTag">
23+
<exclude-pattern>*.phtml</exclude-pattern>
24+
</rule>
25+
<rule ref="Generic.PHP.DeprecatedFunctions"/>
26+
<rule ref="Generic.PHP.NoSilencedErrors"/>
27+
<rule ref="Generic.PHP.Syntax"/>
28+
29+
<rule ref="Squiz.Functions.GlobalFunction"/>
30+
<rule ref="Squiz.Operators.IncrementDecrementUsage"/>
31+
<rule ref="Squiz.PHP.DiscouragedFunctions"/>
32+
<rule ref="Squiz.PHP.Eval"/>
33+
<rule ref="Squiz.PHP.GlobalKeyword"/>
34+
<rule ref="Squiz.PHP.NonExecutableCode"/>
35+
<rule ref="Squiz.Scope.MethodScope"/>
36+
<rule ref="Squiz.Scope.MemberVarScope"/>
37+
38+
<rule ref="Zend.Files.ClosingTag">
39+
<exclude-pattern>*.phtml</exclude-pattern>
40+
</rule>
41+
42+
<rule ref="Magento2.M2.ThisInTemplate">
43+
<exclude-pattern>*.php</exclude-pattern>
44+
</rule>
45+
</ruleset>

composer.json

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"role": "Maintainer"
1111
}
1212
],
13-
"target-dir": "Ecg",
1413
"require": {
1514
"php": ">=5.4.0"
1615
}

0 commit comments

Comments
 (0)