~ubuntu-branches/ubuntu/utopic/php-codesniffer/utopic

« back to all changes in this revision

Viewing changes to PHP_CodeSniffer-1.3.4/CodeSniffer/Standards/MySource/Sniffs/Channels/ChannelExceptionSniff.php

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2012-05-31 16:37:24 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120531163724-u6aiaubu8ks5dh5z
Tags: 1.3.4-0.1
* Non-maintainer upload.
* New upstream release (Closes: #599617, #634825).
* Swtiched debian/copyright to format 1.0 (rewrite was needed anyway, as the
upstream license changed).
* Switched package to pkg-php-tools and debhelper 8 sequencer.
* Now running unit tests at build time (so depends on phpunit (>= 3.6)).
* Section is now PHP.
* Added missing Build-Depends-Indep: php-pear.
* Added missing ${misc:Depends}.
* Added Vcs fields.
* Added homepage field.
* Reviewed short and long description.
* Added dependency on php-timer.
* Standards-Version: is now 3.9.3 (lots of changes, see above...).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Ensures that all action classes throw ChannelExceptions only.
 
4
 *
 
5
 * PHP version 5
 
6
 *
 
7
 * @category  PHP
 
8
 * @package   PHP_CodeSniffer_MySource
 
9
 * @author    Greg Sherwood <gsherwood@squiz.net>
 
10
 * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
 
11
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
 
12
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 
13
 */
 
14
 
 
15
/**
 
16
 * Ensures that all action classes throw ChannelExceptions only.
 
17
 *
 
18
 * @category  PHP
 
19
 * @package   PHP_CodeSniffer_MySource
 
20
 * @author    Greg Sherwood <gsherwood@squiz.net>
 
21
 * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
 
22
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
 
23
 * @version   Release: 1.3.4
 
24
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 
25
 */
 
26
class MySource_Sniffs_Channels_ChannelExceptionSniff implements PHP_CodeSniffer_Sniff
 
27
{
 
28
 
 
29
 
 
30
    /**
 
31
     * Returns an array of tokens this test wants to listen for.
 
32
     *
 
33
     * @return array
 
34
     */
 
35
    public function register()
 
36
    {
 
37
        return array(T_THROW);
 
38
 
 
39
    }//end register()
 
40
 
 
41
 
 
42
    /**
 
43
     * Processes this sniff, when one of its tokens is encountered.
 
44
     *
 
45
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
 
46
     * @param int                  $stackPtr  The position of the current token in
 
47
     *                                        the stack passed in $tokens.
 
48
     *
 
49
     * @return void
 
50
     */
 
51
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 
52
    {
 
53
        $fileName = strtolower($phpcsFile->getFilename());
 
54
        $matches  = array();
 
55
        if (preg_match('|/systems/(.*)/([^/]+)?actions.inc$|', $fileName, $matches) === 0) {
 
56
            // This is not an actions.inc file.
 
57
            return;
 
58
        }
 
59
 
 
60
        $tokens = $phpcsFile->getTokens();
 
61
 
 
62
        $exception     = $phpcsFile->findNext(array(T_STRING, T_VARIABLE), ($stackPtr + 1));
 
63
        $exceptionName = $tokens[$exception]['content'];
 
64
 
 
65
        if ($exceptionName !== 'ChannelException') {
 
66
            $data  = array($exceptionName);
 
67
            $error = 'Channel actions can only throw ChannelException; found "%s"';
 
68
            $phpcsFile->addError($error, $exception, 'WrongExceptionType', $data);
 
69
        }
 
70
 
 
71
    }//end process()
 
72
 
 
73
 
 
74
}//end class
 
75
 
 
76
?>