« Previous - Version 11/66 (diff) - Next » - Current version
Andy Grunwald, 2012-04-13 19:22


FLOW3 / TYPO3 Phoenix Sniffs with code examples

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

Disallow multiple PHP tags

Sniff Description Notice Implemented PHPUnit Test
TYPO3.PHP.DisallowMultiplePHPTags False:
<?php
doSomething();
?>
<span>some html content</span>
<?php 
doSomethingMore(); 
?>
Correct:
<?php
doSomething();
echo '<span>some html content</span>';
doSomethingMore(); 
?>
Must have X X

Closing PHP Tag

Sniff Description Notice Implemented PHPUnit Test Hudson Tests
TYPO3.PHP.ClosingPHPTag False:
// Some code
// End of File
Correct:
// Some code
// End of File
?>
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

Deprecated functions

Sniff Description Notice Implemented PHPUnit Test
Generic.PHP.DeprecatedFunctions False:
ereg() / call_user_method()
Correct:
preg_match() / call_user_func()
Nice to have; Have a look at http://php.net/manual/de/migration53.deprecated.php X X

Eval

Sniff Description Notice Implemented PHPUnit Test
Squiz.PHP.Eval False:
$color = 'green';
$str = 'This is a $color tree.';
eval ("\$str = \"$str\";");
Correct:
$color = 'green';
$str = 'This is a ' . $color . ' tree.';
Should have if eval() is forbidden X X

Global keyword

Sniff Description Notice Implemented PHPUnit Test
Squiz.PHP.GlobalKeyword False:
global $BE_USER;
$BE_USER->doSomething();
Correct:
$GLOBALS['BE_USER']->doSomething();
Should 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

Line endings

Sniff Description Notice Implemented PHPUnit Test
Generic.Files.LineEndings UNIX Line endings only (\n) Must have X X

Whitespace

Trailing whitespace

Sniff Code Example Notice Implemented PHPUnit Test
Squiz.WhiteSpace.SuperfluousWhitespace False:
// In the next line there is whitespace after ...
// ... the word "code". Mark it to see it.
// Some code
Correct:
// In the next line there is _NO_ whitespace after ...
// ... the word "code". Mark it to see it.
// Some code
Must have X X

Disallow space indent

Sniff Code Example Notice Implemented PHPUnit Test
TYPO3.WhiteSpace.DisallowSpaceIndent Must have X X