Skip to content

Instantly share code, notes, and snippets.

@MasterHans
Last active October 21, 2016 08:41
Show Gist options
  • Select an option

  • Save MasterHans/a366f572a3a67e740c75b6bd2a743300 to your computer and use it in GitHub Desktop.

Select an option

Save MasterHans/a366f572a3a67e740c75b6bd2a743300 to your computer and use it in GitHub Desktop.
PHPStorm Ctrl+Alt+Shift+L
Цель данных рекомендаций – снижение сложности восприятия кода, написанного разными авторами
1,2 - пропущены
3. namespases, use
<?php
namespace Vendor\Package;
use FooClass;
use BarClass as Bar;
use OtherVendor\OtherPackage\BazClass;
// ... additional PHP code ...
5. true, false и null - в нижнем регистре
6. extends, implements на одной строке с именем класса:
class ClassName extends ParentClass implements \ArrayAccess, \Countable
можно так с интерфейсами:
class ClassName extends ParentClass implements
\ArrayAccess,
\Countable,
\Serializable
7. Braces for the classes (Фигурные скобки в определении класса):
Определение класса:
class ClassName
{
// константы, свойства, методы
}
9. Методы
class ClassName
{
public function fooBarBaz($arg1, &$arg2, $arg3 = [])
{
// тело метода
}
}
10. Аргументы метода:
Можно так
public function fooBarBaz($arg1, &$arg2, $arg3 = [])
Или так
class ClassName
{
public function aVeryLongMethodName(
ClassTypeHint $arg1,
&$arg2,
array $arg3 = []
) {
// тело метода
}
}
11. abstract и final - ДОЛЖНЫ располагаться перед указанием области видимости
static - ДОЛЖНО располагаться после указания области видимости.
abstract class ClassName
{
protected static $foo;
abstract protected function zim();
final public static function bar()
{
// тело метода
}
}
12. Вызовы методов и функций
bar();
$foo->bar($arg1);
Foo::bar($arg2, $arg3);
можно так
$foo->bar(
$longArgument,
$longerArgument,
$muchLongerArgument
);
13. if, elseif, else
Обращаем внимание на пробелы и положение круглых скобок
if ($expr1) {
// тело if
} elseif ($expr2) {
// тело elseif
} else {
// тело else
}
if ($a === $b) {
bar();
} elseif ($a > $b) {
$foo->bar($arg1);
} else {
BazClass::bar($arg2, $arg3);
}
14. while, do while
while ($expr) {
// structure body
}
do {
// тело конструкции
} while ($expr);
15. Конструкция for:
for ($i = 0; $i < 10; $i++) {
// тело for
}
16. foreach:
foreach ($iterable as $key => $value) {
// тело foreach
}
17. try, catch:
try {
// try body
} catch (FirstExceptionType $e) {
// catch body
} catch (OtherExceptionType $e) {
// catch body
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment