File tree 3 files changed +143
-0
lines changed 3 files changed +143
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types = 1 );
7
+
8
+ namespace Magento2 \Sniffs \Legacy ;
9
+
10
+ use PHP_CodeSniffer \Files \File ;
11
+ use PHP_CodeSniffer \Sniffs \Sniff ;
12
+
13
+ class ObsoleteConnectionSniff implements Sniff
14
+ {
15
+ private const ERROR_CODE_METHOD = 'FoundObsoleteMethod ' ;
16
+
17
+ /**
18
+ * @var string[]
19
+ */
20
+ private $ obsoleteMethods = [
21
+ '_getReadConnection ' ,
22
+ '_getWriteConnection ' ,
23
+ '_getReadAdapter ' ,
24
+ '_getWriteAdapter ' ,
25
+ 'getReadConnection ' ,
26
+ 'getWriteConnection ' ,
27
+ 'getReadAdapter ' ,
28
+ 'getWriteAdapter ' ,
29
+ ];
30
+
31
+ /**
32
+ * @inheritdoc
33
+ */
34
+ public function register ()
35
+ {
36
+ return [
37
+ T_OBJECT_OPERATOR ,
38
+ T_FUNCTION
39
+ ];
40
+ }
41
+
42
+ /**
43
+ * @inheritdoc
44
+ */
45
+ public function process (File $ phpcsFile , $ stackPtr )
46
+ {
47
+ $ this ->validateObsoleteMethod ($ phpcsFile , $ stackPtr );
48
+ }
49
+
50
+ /**
51
+ * Check if obsolete methods are used
52
+ *
53
+ * @param $phpcsFile
54
+ * @param $stackPtr
55
+ */
56
+ private function validateObsoleteMethod ($ phpcsFile , $ stackPtr )
57
+ {
58
+ $ tokens = $ phpcsFile ->getTokens ();
59
+ $ stringPos = $ phpcsFile ->findNext (T_STRING , $ stackPtr + 1 );
60
+
61
+ foreach ($ this ->obsoleteMethods as $ method ) {
62
+ if ($ tokens [$ stringPos ]['content ' ] === $ method ) {
63
+ $ phpcsFile ->addWarning (
64
+ sprintf ("Contains obsolete method: %s. " , $ method ),
65
+ $ stackPtr ,
66
+ self ::ERROR_CODE_METHOD
67
+ );
68
+ }
69
+ }
70
+ }
71
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+
7
+ $ this ->_getReadConnection ();
8
+
9
+ $ connection = new Connection ();
10
+ return $ connection ->_getWriteConnection ();
11
+
12
+ $ this ->getMethod (
13
+ function ($ param ){
14
+ $ param ->_getWriteAdapter ();
15
+ }
16
+ );
17
+
18
+ $ writeAdapter = $ this ->getWriteAdapter ();
19
+
20
+ protected function getConnection ()
21
+ {
22
+ return $ this ->_resource ->getReadConnection ($ this ->connection );
23
+ }
24
+
25
+ return $ this ->_getReadAdapter ();
26
+
27
+ $ this ->getReadAdapterMyMehtod ();
28
+
29
+ private function getReadAdapter ()
30
+ {
31
+
32
+ }
33
+
34
+ $ getWriteAdapter = new WriteAdapter ();
35
+
36
+ $ getWriteAdapter = $ this ->getWriteAdapter ();
Original file line number Diff line number Diff line change
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 ObsoleteConnectionUnitTest extends AbstractSniffUnitTest
11
+ {
12
+ /**
13
+ * @inheritdoc
14
+ */
15
+ public function getErrorList ()
16
+ {
17
+ return [];
18
+ }
19
+
20
+ /**
21
+ * @inheritdoc
22
+ */
23
+ public function getWarningList ()
24
+ {
25
+ return [
26
+ 3 => 1 ,
27
+ 6 => 1 ,
28
+ 10 => 1 ,
29
+ 14 => 1 ,
30
+ 18 => 1 ,
31
+ 21 => 1 ,
32
+ 25 => 1 ,
33
+ 32 => 1
34
+ ];
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments