function f() { doSomething(); // OK doSomethingElse(); // NOK {{Remove this empty statement.}} // NOK }
function f() { doSomething(); // OK doSomethingElse(); // NOK // NOK }
function myMethod() { // OK if (something) { // OK executeTask(); } else { // NOK doSomethingElse(); } }
<?php // basic function function doSomething($param, $anotherParam) { echo "First Param is {$param}\n"; echo "Second Param is {$anotherParam}\n"; } //$result = doSomething('foo', 'bar'); //var_dump($result); function doSomethingElse($param, $anotherParam) { return "{$param} {$anotherParam}"; } $result = doSomethingElse('foo', 'bar'); //var_dump($result); //scope $a = 1; function increment($a) { $a++; } increment($a); //var_dump($a); $b = null; if (true) { $b = 'foo'; } //var_dump($b); //by reference $a = 1;
if ($someCondition == true) { doSomething(); if ($otherCondition == true) { doSomethingElse($someVariable); } else { doSomethingElse($otherVariable); } } // and better than above if ($someCondition == true) { doSomething(); if ($otherCondition == true) { doSomethingElse($someVariable); doSomething($someVariable); } else { doSomethingElse($otherVariable); doSomething($someVariable); } } /* using some php keyword */ //using static keyword for singleton pattern //or check data was loaded, // function get_data($data_key) { static $dataset; if (!isset($dataset[$data_key])) { //query database or something like that to get data //set data to static variable } return $dataset[$data_key];
// OK break; } //Support alternate switch syntax switch ($a) { case 0: case 1: // NOK doSomething(); case 2: // NOK halt(); case 3: // OK echo ""; // this is intentional // this is intentional default: // OK doSomethingElse(); } switch ($a) { case 0: if ($b) { throw anException(); } else { throw otherException(); } default: break; }
<?php $a = 'function ' . ($node->byRef ? '&' : '') . $node->name . $this->pCommaSeparatedLines($node->params, '(', ')') . (null !== $node->returnType ? ' : ' . $this->pType($node->returnType) : '') . ' {' . $this->pStmts($node->stmts) . "\n" . '}'; $b = 'outside-left' . 'outside-left2' . ('1111111111' . '2222222222' . '3333333333' . '4444444444' . '5555555555' . '6666666666') . 'outside-right' . 'outside-right2' . 'xxxxxxxxxxxxxxxxxxxx' . 'dsrfiosjf sdoifj sdofijsd fiojsdf'; $c = $use . $traits . (empty($node->adaptations) ? ';' : ' {' . preg_replace('~\\n(?!$|\\n|' . $this->noIndentToken . ')~', "\n" . $this->indentation, $this->pStmts($node->adaptations) . "\n" . '}')); $text = ' ' . $this->getHelpOptionParam($option->name, $option->param, $option->multi); doSomething(doSomethingElse('01234567890123456789012345678901234567890123456789012345678901234567890123456789', doSomethingElseEntirely('01234567890123456789012345678901234567890123456789012345678901234567890123456789'))); return $use . $traits . (empty($node->adaptations) ? ';' : ' {' . preg_replace('~\\n(?!$|\\n|' . $this->noIndentToken . ')~', "\n" . $this->indentation, $this->pStmts($node->adaptations) . "\n" . '}')); if ($variable == '394i 309483094' || $variable === '394i30948349083498 n' && $variable !== 'okfkddfoksd fopdsk' && true && 1 && 2) { } if ($variable == '394i 309483094' && $variable === '394i30948349083498 n' || $variable !== 'okfkddfoksd fopdsk' || true || 1 || 2) { }
public function testMethod2() { doSomethingElse(); }