Skip to content

Commit 8aed7fa

Browse files
committed
Changed coding standards + ini files for testing
1 parent 026b1a6 commit 8aed7fa

File tree

4 files changed

+36
-26
lines changed

4 files changed

+36
-26
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ php:
1111
- hhvm
1212

1313
before_script:
14-
- if [[ $TRAVIS_PHP_VERSION != "7.0" && $TRAVIS_PHP_VERSION != "nightly" && $TRAVIS_PHP_VERSION != "hhvm" ]]; then mv -f myconfig5.ini myconfig.ini; phpenv config-add myconfig.ini; fi
15-
- if [[ $TRAVIS_PHP_VERSION == "7.0" || $TRAVIS_PHP_VERSION == "nightly" ]]; then mv -f myconfig57.ini myconfig.ini; phpenv config-add myconfig.ini; fi
14+
- if [[ $TRAVIS_PHP_VERSION != "7.0" && $TRAVIS_PHP_VERSION != "nightly" && $TRAVIS_PHP_VERSION != "hhvm" ]]; then phpenv config-add php5-testingConfig.ini; fi
15+
- if [[ $TRAVIS_PHP_VERSION == "7.0" || $TRAVIS_PHP_VERSION == "nightly" ]]; then phpenv config-add php7-testingConfig.ini; fi
1616

1717
script:
1818
- if [ $TRAVIS_PHP_VERSION != "hhvm" ]; then php scripts/phpcs --config-set php_path php; fi
19-
- phpunit -d date.timezone=Australia/Sydney tests/AllTests.php
19+
- phpunit tests/AllTests.php
2020
- php scripts/phpcs CodeSniffer.php CodeSniffer --standard=PHPCS --report=summary -np
2121
- if [[ $TRAVIS_PHP_VERSION != "hhvm" && $TRAVIS_PHP_VERSION != "7.0" ]]; then pear package-validate package.xml; fi
2222
- if [ $TRAVIS_PHP_VERSION != "hhvm" ]; then php scripts/build-phar.php; fi

CodeSniffer/Standards/Generic/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,25 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
8080
return;
8181
}
8282

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';
9292
}
9393

94-
if (isset($error, $closer, $error_id) === true) {
94+
if (isset($error, $closer, $errorCode) === true) {
9595
$data = array($content);
9696

97-
if (false === $closer) {
98-
$phpcsFile->addError($error, $stackPtr, $error_id, $data);
97+
if ($closer === false) {
98+
$phpcsFile->addError($error, $stackPtr, $errorCode, $data);
9999
} 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) {
102102
$this->addChangeset($phpcsFile, $tokens, $stackPtr, $closer);
103103
}
104104
}
@@ -107,7 +107,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
107107
return;
108108
}//end if
109109

110-
if (T_OPEN_TAG_WITH_ECHO === $openTag['code'] && '<%=' === $content) {
110+
if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO && $content === '<%=') {
111111
$error = 'ASP style opening tag used with echo; expected "<?php echo %s ..." but found "%s %s ..."';
112112
$nextVar = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
113113
$snippet = $this->getSnippet($tokens[$nextVar]['content']);
@@ -119,37 +119,39 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
119119

120120
$closer = $this->findClosingTag($phpcsFile, $tokens, $stackPtr, '%>');
121121

122-
if (false === $closer) {
122+
if ($closer === false) {
123123
$phpcsFile->addError($error, $stackPtr, 'ASPShortOpenTagFound', $data);
124124
} else {
125125
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'ASPShortOpenTagFound', $data);
126-
if (true === $fix) {
126+
if ($fix === true) {
127127
$this->addChangeset($phpcsFile, $tokens, $stackPtr, $closer, true);
128128
}
129129
}
130130

131131
return;
132132
}//end if
133133

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+
) {
136139
$error = 'Script style opening tag used; expected "<?php" but found "%s"';
137140
$snippet = $this->getSnippet($content, $match[1]);
138141
$data = array($match[1].$snippet);
139142

140143
$phpcsFile->addError($error, $stackPtr, 'ScriptOpenTagFound', $data);
141-
142144
return;
143145
}
144146

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) {
147149
$error = 'Possible use of ASP style short opening tags detected. Needs manual inspection. Found: %s';
148150
$snippet = $this->getSnippet($content, '<%=');
149151
$data = array('<%='.$snippet);
150152

151153
$phpcsFile->addWarning($error, $stackPtr, 'MaybeASPShortOpenTagFound', $data);
152-
} else if (false !== strpos($content, '<%')) {
154+
} else if (strpos($content, '<%') !== false) {
153155
$error = 'Possible use of ASP style opening tags detected. Needs manual inspection. Found: %s';
154156
$snippet = $this->getSnippet($content, '<%');
155157
$data = array('<%'.$snippet);

myconfig5.ini renamed to php5-testingConfig.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
; Defines the default timezone used by the date functions
2+
; http://php.net/date.timezone
3+
date.timezone = "Australia/Sydney"
4+
15
; This directive determines whether or not PHP will recognize code between
26
; <? and ?> tags as PHP source which should be processed as such.
37
; http://php.net/short-open-tag

myconfig57.ini renamed to php7-testingConfig.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
; Defines the default timezone used by the date functions
2+
; http://php.net/date.timezone
3+
date.timezone = "Australia/Sydney"
4+
15
; This directive determines whether or not PHP will recognize code between
26
; <? and ?> tags as PHP source which should be processed as such.
37
; http://php.net/short-open-tag

0 commit comments

Comments
 (0)