Skip to content

Instantly share code, notes, and snippets.

@gaving
Last active August 29, 2015 14:22
Show Gist options
  • Save gaving/83a421d1fc5dc4c409e4 to your computer and use it in GitHub Desktop.
Save gaving/83a421d1fc5dc4c409e4 to your computer and use it in GitHub Desktop.
node_modules
var gulp = require('gulp');
var gutil = require('gutil');
var phpcbf = require('gulp-phpcbf');
gulp.task('phpcbf', function () {
return gulp.src(['test.php'])
.pipe(phpcbf({
bin: 'phpcbf',
standard: 'WordPress',
warningSeverity: 0
}))
.on('error', gutil.log)
.pipe(gulp.dest('.'));
});
gulp.task('default', ['phpcbf']);
{
"name": "gulp-phpcbf-test",
"version": "1.0.0",
"description": "",
"main": "Gulpfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://gist.github.com/gaving/83a421d1fc5dc4c409e4"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://gist.github.com/gaving/83a421d1fc5dc4c409e4"
},
"homepage": "https://gist.github.com/gaving/83a421d1fc5dc4c409e4",
"dependencies": {
"gulp": "^3.8.11",
"gulp-phpcbf": "^0.1.2",
"gutil": "^1.6.4"
}
}
<?php
/**
* This file is part of the Symfony-coding-standard (phpcs standard)
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Ludovic Fleury <[email protected]>
* @license MIT License
* @link https://github.com/ludofleury/Symfony-coding-standard
*/
if (class_exists('PEAR_Sniffs_Functions_FunctionCallSignatureSniff', true) === false) {
$error = 'Class PEAR_Sniffs_Functions_FunctionCallSignatureSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
/**
* Symfony_Sniffs_Functions_FunctionCallSignatureSniff.
*
* Allow indented fluent interface
*
* @category PHP
* @package PHP_CodeSniffer
* @author Ludovic Fleury <[email protected]>
* @license MIT License
* @link https://github.com/ludofleury/Symfony2-coding-standard
*/
class Symfony_Sniffs_Functions_FunctionCallSignatureSniff extends PEAR_Sniffs_Functions_FunctionCallSignatureSniff
{
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
// Find the next non-empty token.
$openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
// Not a function call.
return;
}
if (isset($tokens[$openBracket]['parenthesis_closer']) === false) {
// Not a function call.
return;
}
// Find the previous non-empty token.
$search = PHP_CodeSniffer_Tokens::$emptyTokens;
$search[] = T_BITWISE_AND;
$previous = $phpcsFile->findPrevious($search, ($stackPtr - 1), null, true);
if ($tokens[$previous]['code'] === T_FUNCTION) {
// It's a function definition, not a function call.
return;
}
if ($tokens[$openBracket-1]['code'] === T_STRING && $tokens[$openBracket-2]['code'] === T_OBJECT_OPERATOR) {
$previous = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 3), null, true);
if ($tokens[$previous]['code'] === T_CLOSE_PARENTHESIS) {
// It's a fluent interface chained call
return;
}
}
$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
if (($stackPtr + 1) !== $openBracket) {
// Checking this: $value = my_function[*](...).
$error = 'Space before opening parenthesis of function call prohibited';
$phpcsFile->addError($error, $stackPtr, 'SpaceBeforeOpenBracket');
}
$next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), null, true);
if ($tokens[$next]['code'] === T_SEMICOLON) {
if (in_array($tokens[($closeBracket + 1)]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === true) {
$error = 'Space after closing parenthesis of function call prohibited';
$phpcsFile->addError($error, $closeBracket, 'SpaceAfterCloseBracket');
}
}
// Check if this is a single line or multi-line function call.
if ($tokens[$openBracket]['line'] === $tokens[$closeBracket]['line']) {
$this->processSingleLineCall($phpcsFile, $stackPtr, $openBracket, $tokens);
} else {
$this->processMultiLineCall($phpcsFile, $stackPtr, $openBracket, $tokens);
}
}//end process()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment