Yes, there is a ready one. It is called OpeningFunctionBraceBsdAllmanSniff, and you can find it under /path/to/CodeSniffer/Standards/Generic/Sniffs/Functions. But this is only for function declarations.
For control structures, you can take /path/to/Standards/Squiz/Sniffs/ControlStructures/ControlSignatureSniff.phpand configure an array of templates from
protected function getPatterns()
{
return array(
'try {EOL...} catch (...) {EOL',
'do {EOL...} while (...);EOL',
'while (...) {EOL',
'for (...) {EOL',
'if (...) {EOL',
'foreach (...) {EOL',
'} else if (...) {EOL',
'} elseif (...) {EOL',
'} else {EOL',
);
}
to, i.e.
protected function getPatterns()
{
return array(
'try {EOL...} catch (...) {EOL',
'do {EOL...} while (...);EOL',
'while (...) {EOL',
'for (...) {EOL',
'if (...)EOL{',
'foreach (...) {EOL',
'} else if (...) {EOL',
'} elseif (...) {EOL',
'} elseEOL{',
);
}
If you need to apply the same rule to a different management structure, you can go the same way by changing the patterns in the array.
: , , , getPatterns().