PHP code example of inspirecz / coding-standard-sniffs

1. Go to this page and download the library: Download inspirecz/coding-standard-sniffs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

inspirecz / coding-standard-sniffs example snippets


❌
$correct = false; # This is (invalid) hash comment

👍
$correct = true; // This is a valid comment

❌
//wrong inline comment
//   wrong inline comment
$a = 1; //wrong inline comment (missing space after "//")
$b = 2;// also wrong inline comment (missing space before "//")

👍
// correct inline comment with exactly one space after "//"
$a = 1; // correct inline comment
$b = 2; // correct inline comment

❌
if($foo) {
     //...
}

👍
if ($foo) { 
     //...
}

❌
if (
    $foo
    && $bar
)
{ //...

👍
if (
    $foo
    && $bar
) { //...

❌
public function foo(
    int $foo,
    string $bar,
)
{ //...

👍
public function foo(
    int $foo,
    string $bar,
) { //...

❌
public function foo(
    int $foo,
    string $bar, ) { //...

👍
public function foo(
    int $foo,
    string $bar,
) { //...

❌
public function foo(User $user,) { //...

👍
public function foo(User $user) { //...