« Previous - Version 19/98 (diff) - Next » - Current version
Andy Grunwald, 2012-04-18 08:32


TYPO3v4 Sniffs with code examples

Arrays

Array bracket spacing

Sniff Description Notice Implemented PHPUnit Test
Squiz.Arrays.ArrayBracketSpacing False:
$array[ 'Hello'];
$array ['Hello'];
Correct:
$array['Hello'];
Must have X X

Files

One Class per file

Sniff Description Notice Implemented PHPUnit Test
TYPO3.Files.OneClassPerFile False:
<?php
class foo {
    // Code
}

class bar {
    // Code
}
?>
Correct:
<?php
class foo {
    // Code
}
?>
Must have X X

Lowercased filename

Sniff Description Notice Implemented PHPUnit Test
TYPO3.Files.LowercasedFilename False:
CLASS.tx_MyExtIs_veryCool.php
Correct:
class.tx_myextis_verycool.php
This is impossible because filenames of unit tests need an uppercase Test suffix (t3lib_tcemainTest.php) See #9884 X X

Encoding UTF8

Sniff Description Notice Implemented PHPUnit Test
TYPO3.Files.EncodingUtf8 Files must be encoded in UTF-8 Must have X

One Interface per file

Sniff Description Notice Implemented PHPUnit Test
TYPO3.Files.OneInterfacePerFile False:
<?php
interface foo {
    // Code
}

interface bar {
    // Code
}
?>
Correct:
<?php
interface foo {
    // Code
}
?>
Must have X X

Line endings

Sniff Description Notice Implemented PHPUnit Test
Generic.Files.LineEndings Line endings in UNIX style (\n). No Windows (\r\n) or old MAC style (\r) Must have X X

Line length

Sniff Description Notice Implemented PHPUnit Test
Generic.Files.LineLength Line length of about 130 characters (including tabs) is fine Must have X X

Including file

Sniff Description Notice Implemented PHPUnit Test
TYPO3.Files.IncludingFile False:
include() / include_once() / require()
Correct:
require_once()
Must have X X

Classes

Lowercase class keywords

Sniff Description Notice Implemented PHPUnit Test
TYPO3.Classes.LowercaseClassKeywords False:
CLASS test {
    PRIVATE $foo;
    PUBLIC $bar;
    PROTECTED $baz;
}

Correct:
class test {
    private $foo;
    public $bar;
    protected $baz;
}
Should have X X

Self member reference

Sniff Description Notice Implemented PHPUnit Test
Squiz.Classes.SelfMemberReference
Verifies that:
- self:: is used instead of Self::
- self:: is used for local static member reference
- self:: is used instead of self ::
Should have X X

Debug

Debug code

Sniff Description Notice Implemented PHPUnit Test
TYPO3.Debug.DebugCode False:
$array = $this->doSomething();
# debug($array);
Correct:
$array = $this->doSomething();
Must have X X

NamingConventions

Valid variable name

Sniff Description Notice Implemented PHPUnit Test
TYPO3.NamingConventions.ValidVariableName False:
$BAD_name
Correct:
$goodName
Must have X X

Formatting

Disallow multiple statements

Sniff Description Notice Implemented PHPUnit Test
Generic.Formatting.DisallowMultipleStatements False:
$foo = 42; $bar = 23;
Correct:
$foo = 42; 
$bar = 23;
Could have X X

PHP

Character before PHP opening tag

Sniff Description Notice Implemented PHPUnit Test
TYPO3.PHP.CharacterBeforePHPOpeningTag False:

<?php
// Some code
?>
Correct:
<?php
// Some code
?>
Must have X X

Character after PHP closing tag

Sniff Description Notice Implemented PHPUnit Test
TYPO3.PHP.CharacterAfterPHPClosingTag False:
<?php
// Some code
?>

Correct:
<?php
// Some code
?>
Must have X X

#################################

Disallow short open tag

Sniff Description Notice Implemented PHPUnit Test
Generic.PHP.DisallowShortOpenTag False:
<?
Correct:
<?php
Must have X X

Non executable code

Sniff Description Notice Implemented PHPUnit Test
Squiz.PHP.NonExecutableCode False:
<?php
function foo() {
    return TRUE;
    echo 'bar';
}
?>
Correct:
<?php
function foo() {
    return TRUE;
}
?>
Could have X X