Skip to content

Commit

Permalink
Changed coding standards + ini files for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Aug 2, 2016
1 parent 026b1a6 commit 8aed7fa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -11,12 +11,12 @@ php:
- hhvm

before_script:
- 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
- if [[ $TRAVIS_PHP_VERSION == "7.0" || $TRAVIS_PHP_VERSION == "nightly" ]]; then mv -f myconfig57.ini myconfig.ini; phpenv config-add myconfig.ini; fi
- if [[ $TRAVIS_PHP_VERSION != "7.0" && $TRAVIS_PHP_VERSION != "nightly" && $TRAVIS_PHP_VERSION != "hhvm" ]]; then phpenv config-add php5-testingConfig.ini; fi
- if [[ $TRAVIS_PHP_VERSION == "7.0" || $TRAVIS_PHP_VERSION == "nightly" ]]; then phpenv config-add php7-testingConfig.ini; fi

script:
- if [ $TRAVIS_PHP_VERSION != "hhvm" ]; then php scripts/phpcs --config-set php_path php; fi
- phpunit -d date.timezone=Australia/Sydney tests/AllTests.php
- phpunit tests/AllTests.php
- php scripts/phpcs CodeSniffer.php CodeSniffer --standard=PHPCS --report=summary -np
- if [[ $TRAVIS_PHP_VERSION != "hhvm" && $TRAVIS_PHP_VERSION != "7.0" ]]; then pear package-validate package.xml; fi
- if [ $TRAVIS_PHP_VERSION != "hhvm" ]; then php scripts/build-phar.php; fi
Expand Down
Expand Up @@ -80,25 +80,25 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
return;
}

if (T_OPEN_TAG === $openTag['code']) {
if ('<%' === $content) {
$error = 'ASP style opening tag used; expected "<?php" but found "%s"';
$closer = $this->findClosingTag($phpcsFile, $tokens, $stackPtr, '%>');
$error_id = 'ASPOpenTagFound';
} else if (false !== strpos($content, '<script ')) {
$error = 'Script style opening tag used; expected "<?php" but found "%s"';
$closer = $this->findClosingTag($phpcsFile, $tokens, $stackPtr, '</script>');
$error_id = 'ScriptOpenTagFound';
if ($openTag['code'] === T_OPEN_TAG) {
if ($content === '<%') {
$error = 'ASP style opening tag used; expected "<?php" but found "%s"';
$closer = $this->findClosingTag($phpcsFile, $tokens, $stackPtr, '%>');
$errorCode = 'ASPOpenTagFound';
} else if (strpos($content, '<script ') !== false) {
$error = 'Script style opening tag used; expected "<?php" but found "%s"';
$closer = $this->findClosingTag($phpcsFile, $tokens, $stackPtr, '</script>');
$errorCode = 'ScriptOpenTagFound';
}

if (isset($error, $closer, $error_id) === true) {
if (isset($error, $closer, $errorCode) === true) {
$data = array($content);

if (false === $closer) {
$phpcsFile->addError($error, $stackPtr, $error_id, $data);
if ($closer === false) {
$phpcsFile->addError($error, $stackPtr, $errorCode, $data);
} else {
$fix = $phpcsFile->addFixableError($error, $stackPtr, $error_id, $data);
if (true === $fix) {
$fix = $phpcsFile->addFixableError($error, $stackPtr, $errorCode, $data);
if ($fix === true) {
$this->addChangeset($phpcsFile, $tokens, $stackPtr, $closer);
}
}
Expand All @@ -107,7 +107,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
return;
}//end if

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

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

if (false === $closer) {
if ($closer === false) {
$phpcsFile->addError($error, $stackPtr, 'ASPShortOpenTagFound', $data);
} else {
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'ASPShortOpenTagFound', $data);
if (true === $fix) {
if ($fix === true) {
$this->addChangeset($phpcsFile, $tokens, $stackPtr, $closer, true);
}
}

return;
}//end if

// Account for incorrect script open tags. The "(?:<s)?" in the regex is to work-around a bug in PHP 5.2.
if (T_INLINE_HTML === $openTag['code'] && 1 === preg_match('`((?:<s)?cript (?:[^>]+)?language=[\'"]?php[\'"]?(?:[^>]+)?>)`i', $content, $match)) {
// Account for incorrect script open tags.
// The "(?:<s)?" in the regex is to work-around a bug in PHP 5.2.
if ($openTag['code'] === T_INLINE_HTML
&& preg_match('`((?:<s)?cript (?:[^>]+)?language=[\'"]?php[\'"]?(?:[^>]+)?>)`i', $content, $match) === 1
) {
$error = 'Script style opening tag used; expected "<?php" but found "%s"';
$snippet = $this->getSnippet($content, $match[1]);
$data = array($match[1].$snippet);

$phpcsFile->addError($error, $stackPtr, 'ScriptOpenTagFound', $data);

return;
}

if (T_INLINE_HTML === $openTag['code'] && false === $this->_aspTags) {
if (false !== strpos($content, '<%=')) {
if ($openTag['code'] === T_INLINE_HTML && $this->_aspTags === false) {
if (strpos($content, '<%=') !== false) {
$error = 'Possible use of ASP style short opening tags detected. Needs manual inspection. Found: %s';
$snippet = $this->getSnippet($content, '<%=');
$data = array('<%='.$snippet);

$phpcsFile->addWarning($error, $stackPtr, 'MaybeASPShortOpenTagFound', $data);
} else if (false !== strpos($content, '<%')) {
} else if (strpos($content, '<%') !== false) {
$error = 'Possible use of ASP style opening tags detected. Needs manual inspection. Found: %s';
$snippet = $this->getSnippet($content, '<%');
$data = array('<%'.$snippet);
Expand Down
4 changes: 4 additions & 0 deletions myconfig5.ini → php5-testingConfig.ini
@@ -1,3 +1,7 @@
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Australia/Sydney"

; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such.
; http://php.net/short-open-tag
Expand Down
4 changes: 4 additions & 0 deletions myconfig57.ini → php7-testingConfig.ini
@@ -1,3 +1,7 @@
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Australia/Sydney"

; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such.
; http://php.net/short-open-tag
Expand Down

0 comments on commit 8aed7fa

Please sign in to comment.