@@ -80,25 +80,25 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
80
80
return ;
81
81
}
82
82
83
- if (T_OPEN_TAG === $ openTag ['code ' ]) {
84
- if (' <% ' === $ content ) {
85
- $ error = 'ASP style opening tag used; expected "<?php" but found "%s" ' ;
86
- $ closer = $ this ->findClosingTag ($ phpcsFile , $ tokens , $ stackPtr , '%> ' );
87
- $ error_id = 'ASPOpenTagFound ' ;
88
- } else if (false !== strpos ($ content , '<script ' )) {
89
- $ error = 'Script style opening tag used; expected "<?php" but found "%s" ' ;
90
- $ closer = $ this ->findClosingTag ($ phpcsFile , $ tokens , $ stackPtr , '</script> ' );
91
- $ error_id = 'ScriptOpenTagFound ' ;
83
+ if ($ openTag ['code ' ] === T_OPEN_TAG ) {
84
+ if ($ content === ' <% ' ) {
85
+ $ error = 'ASP style opening tag used; expected "<?php" but found "%s" ' ;
86
+ $ closer = $ this ->findClosingTag ($ phpcsFile , $ tokens , $ stackPtr , '%> ' );
87
+ $ errorCode = 'ASPOpenTagFound ' ;
88
+ } else if (strpos ($ content , '<script ' ) !== false ) {
89
+ $ error = 'Script style opening tag used; expected "<?php" but found "%s" ' ;
90
+ $ closer = $ this ->findClosingTag ($ phpcsFile , $ tokens , $ stackPtr , '</script> ' );
91
+ $ errorCode = 'ScriptOpenTagFound ' ;
92
92
}
93
93
94
- if (isset ($ error , $ closer , $ error_id ) === true ) {
94
+ if (isset ($ error , $ closer , $ errorCode ) === true ) {
95
95
$ data = array ($ content );
96
96
97
- if (false === $ closer ) {
98
- $ phpcsFile ->addError ($ error , $ stackPtr , $ error_id , $ data );
97
+ if ($ closer === false ) {
98
+ $ phpcsFile ->addError ($ error , $ stackPtr , $ errorCode , $ data );
99
99
} else {
100
- $ fix = $ phpcsFile ->addFixableError ($ error , $ stackPtr , $ error_id , $ data );
101
- if (true === $ fix ) {
100
+ $ fix = $ phpcsFile ->addFixableError ($ error , $ stackPtr , $ errorCode , $ data );
101
+ if ($ fix === true ) {
102
102
$ this ->addChangeset ($ phpcsFile , $ tokens , $ stackPtr , $ closer );
103
103
}
104
104
}
@@ -107,7 +107,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
107
107
return ;
108
108
}//end if
109
109
110
- if (T_OPEN_TAG_WITH_ECHO === $ openTag ['code ' ] && ' <%= ' === $ content ) {
110
+ if ($ openTag ['code ' ] === T_OPEN_TAG_WITH_ECHO && $ content === ' <%= ' ) {
111
111
$ error = 'ASP style opening tag used with echo; expected "<?php echo %s ..." but found "%s %s ..." ' ;
112
112
$ nextVar = $ phpcsFile ->findNext (T_WHITESPACE , ($ stackPtr + 1 ), null , true );
113
113
$ snippet = $ this ->getSnippet ($ tokens [$ nextVar ]['content ' ]);
@@ -119,37 +119,39 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
119
119
120
120
$ closer = $ this ->findClosingTag ($ phpcsFile , $ tokens , $ stackPtr , '%> ' );
121
121
122
- if (false === $ closer ) {
122
+ if ($ closer === false ) {
123
123
$ phpcsFile ->addError ($ error , $ stackPtr , 'ASPShortOpenTagFound ' , $ data );
124
124
} else {
125
125
$ fix = $ phpcsFile ->addFixableError ($ error , $ stackPtr , 'ASPShortOpenTagFound ' , $ data );
126
- if (true === $ fix ) {
126
+ if ($ fix === true ) {
127
127
$ this ->addChangeset ($ phpcsFile , $ tokens , $ stackPtr , $ closer , true );
128
128
}
129
129
}
130
130
131
131
return ;
132
132
}//end if
133
133
134
- // Account for incorrect script open tags. The "(?:<s)?" in the regex is to work-around a bug in PHP 5.2.
135
- if (T_INLINE_HTML === $ openTag ['code ' ] && 1 === preg_match ('`((?:<s)?cript (?:[^>]+)?language=[ \'"]?php[ \'"]?(?:[^>]+)?>)`i ' , $ content , $ match )) {
134
+ // Account for incorrect script open tags.
135
+ // The "(?:<s)?" in the regex is to work-around a bug in PHP 5.2.
136
+ if ($ openTag ['code ' ] === T_INLINE_HTML
137
+ && preg_match ('`((?:<s)?cript (?:[^>]+)?language=[ \'"]?php[ \'"]?(?:[^>]+)?>)`i ' , $ content , $ match ) === 1
138
+ ) {
136
139
$ error = 'Script style opening tag used; expected "<?php" but found "%s" ' ;
137
140
$ snippet = $ this ->getSnippet ($ content , $ match [1 ]);
138
141
$ data = array ($ match [1 ].$ snippet );
139
142
140
143
$ phpcsFile ->addError ($ error , $ stackPtr , 'ScriptOpenTagFound ' , $ data );
141
-
142
144
return ;
143
145
}
144
146
145
- if (T_INLINE_HTML === $ openTag ['code ' ] && false === $ this ->_aspTags ) {
146
- if (false !== strpos ($ content , '<%= ' )) {
147
+ if ($ openTag ['code ' ] === T_INLINE_HTML && $ this ->_aspTags === false ) {
148
+ if (strpos ($ content , '<%= ' ) !== false ) {
147
149
$ error = 'Possible use of ASP style short opening tags detected. Needs manual inspection. Found: %s ' ;
148
150
$ snippet = $ this ->getSnippet ($ content , '<%= ' );
149
151
$ data = array ('<%= ' .$ snippet );
150
152
151
153
$ phpcsFile ->addWarning ($ error , $ stackPtr , 'MaybeASPShortOpenTagFound ' , $ data );
152
- } else if (false !== strpos ($ content , '<% ' )) {
154
+ } else if (strpos ($ content , '<% ' ) !== false ) {
153
155
$ error = 'Possible use of ASP style opening tags detected. Needs manual inspection. Found: %s ' ;
154
156
$ snippet = $ this ->getSnippet ($ content , '<% ' );
155
157
$ data = array ('<% ' .$ snippet );
0 commit comments