1<?php
2/**
3 * PSR2_Sniffs_Methods_FunctionCallSignatureSniff.
4 *
5 * PHP version 5
6 *
7 * @category  PHP
8 * @package   PHP_CodeSniffer
9 * @author    Greg Sherwood <gsherwood@squiz.net>
10 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
11 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
12 * @link      http://pear.php.net/package/PHP_CodeSniffer
13 */
14
15/**
16 * PSR2_Sniffs_Methods_FunctionCallSignatureSniff.
17 *
18 * @category  PHP
19 * @package   PHP_CodeSniffer
20 * @author    Greg Sherwood <gsherwood@squiz.net>
21 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
22 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
23 * @version   Release: @package_version@
24 * @link      http://pear.php.net/package/PHP_CodeSniffer
25 */
26class PSR2_Sniffs_Methods_FunctionCallSignatureSniff extends PEAR_Sniffs_Functions_FunctionCallSignatureSniff
27{
28
29    /**
30     * If TRUE, multiple arguments can be defined per line in a multi-line call.
31     *
32     * @var bool
33     */
34    public $allowMultipleArguments = false;
35
36
37    /**
38     * Processes single-line calls.
39     *
40     * @param PHP_CodeSniffer_File $phpcsFile   The file being scanned.
41     * @param int                  $stackPtr    The position of the current token
42     *                                          in the stack passed in $tokens.
43     * @param int                  $openBracket The position of the opening bracket
44     *                                          in the stack passed in $tokens.
45     * @param array                $tokens      The stack of tokens that make up
46     *                                          the file.
47     *
48     * @return void
49     */
50    public function isMultiLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens)
51    {
52        // If the first argument is on a new line, this is a multi-line
53        // function call, even if there is only one argument.
54        $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true);
55        if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
56            return true;
57        }
58
59        $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
60
61        $end = $phpcsFile->findEndOfStatement($openBracket + 1);
62        while ($tokens[$end]['code'] === T_COMMA) {
63            // If the next bit of code is not on the same line, this is a
64            // multi-line function call.
65            $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), $closeBracket, true);
66            if ($next === false) {
67                return false;
68            }
69
70            if ($tokens[$next]['line'] !== $tokens[$end]['line']) {
71                return true;
72            }
73
74            $end = $phpcsFile->findEndOfStatement($next);
75        }
76
77        // We've reached the last argument, so see if the next content
78        // (should be the close bracket) is also on the same line.
79        $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), $closeBracket, true);
80        if ($next !== false && $tokens[$next]['line'] !== $tokens[$end]['line']) {
81            return true;
82        }
83
84        return false;
85
86    }//end isMultiLineCall()
87
88
89}//end class
90