PHP code example of ely / php-code-style
1. Go to this page and download the library: Download ely/php-code-style 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/ */
ely / php-code-style example snippets
$finder = \PhpCsFixer\Finder::create()
->in(__DIR__);
return \Ely\CS\Config::create()
->setFinder($finder);
return \Ely\CS\Config::create([
'trailing_comma_in_multiline' => [
'elements' => ['arrays', 'arguments'],
],
])->setFinder($finder);
declare(strict_types=1);
namespace Vendor\Package;
use Vendor\Package\SomeNamespace\ClassA;
class Foo extends Bar implements FooInterface {
use SomeTrait;
private const SAMPLE_1 = 123;
private const SAMPLE_2 = 321;
public $field1;
public Typed $field2;
public function sampleFunction(
int $a,
private readonly int $b = null,
): array {
if ($a === $this->b) {
$result = bar();
} else {
$result = BazClass::bar($this->field1, $this->field2);
}
return $result;
}
public function setToNull(): self {
$this->field1 = null;
return $this;
}
}
function a() {
$a = '123';
return $a . ' is a number';
}
function b() {
$a = '123';
$b = 'is';
return $a . ' ' . $b . ' a number';
}
class Test {
public function method() {
$obj = new class extends Foo {
public function overriddenMethod() {
// code body
}
};
}
}
if (true) {
// some actions here
}
echo 'the next statement is here';
function foo(
string $input,
int $key = 0,
): void {}
sh
composer
sh
vendor/bin/php-cs-fixer fix