oggettoweb / oggetto-coding-standard Goto Github PK
View Code? Open in Web Editor NEWPHP Code Sniffer rules for Oggetto coding standard
PHP Code Sniffer rules for Oggetto coding standard
В таске #3 была задача проверять, что весь текст в коде на английском. Однако, часто необходимо использовать русский текст в строках (скажем, названия городов). Необходимо переделать снифф, чтобы он срабатывал на не-английский текст только в комментариях (т.к. изначально проблема была именно в русских комментариях к коду):
$string = 'Мама мыла раму'; // VALID
// Раму мыла мама — INVALID
/*
Мыла раму мама — INVALID
*/
Верно:
$x = array(
'foo' => 10,
'bar' => 20,
'baz_xxx' => 30,
);
Неверно:
$x = array(
'foo' => 10,
'bar' => 20,
'baz_xxx' => 30,
);
Надо сделать проверку на то, что каждый класс/метод содержит док блок
Инсталлеры хранятся в Magento в папках (app/code/local/XXX/YYY/sql/ZZZ/
)
Правильно:
class Foo
{
private $_foo = 42;
protected function _log()
{
}
public function test()
{
}
}
Неправильно:
class Foo
{
private $foo = 42;
protected function log()
{
}
public function _test()
{
}
}
Верно:
$x = array(1, 2, 3);
Неверно:
$x = array(1,2,3);
Правильно:
class Foo
{
private $_bar;
public function xxx()
{
}
}
Неправильно:
class Foo
{
public function xxx()
{
}
private $_bar;
}
Вот такой:
class Foo
{
/**
* Description (required)
*/
const FOO = 'foo';
}
Неправильно:
/**
* Returns a EcomDev_PHPUnit_Constraint_Or matcher object.
*/
public static function logicalOr()
Правильно:
/**
* Returns a EcomDev_PHPUnit_Constraint_Or matcher object.
*
* @return EcomDev_PHPUnit_Constraint_Or
*/
public static function logicalOr()
Неправильно:
switch($foo){
}
Правильно:
switch ($foo) {
}
Если в строку не встраиваются переменные, то используются одинарные кавычки:
Правильно:
$x = 'foo';
Неправильно:
$x = "foo";
, но, вот так верно:
$x = "foo{$var}";
$x = "foo $var"
Неправильно:
function xxx ()
{
}
Правильно:
function xxx()
{
}
Верно:
$x = 'foo'
. 'bar'
. 'baz';
Неверно:
$x = 'foo'
. 'bar'
. 'baz';
Верно:
$x = 'foo' . 'bar' . 'baz';
Неверно:
$x = 'foo'.'bar'.'baz';
Неправильно:
function foo()
{
return (42 + 43);
}
Правильно:
function foo()
{
return 42 + 43;
}
Неправильно:
class Foo
{
public $foo = 42;
}
Т.е. нельзя допускать объявления public-свойств в классе.
Неправильно:
function ($x,$y,$z)
Правильно:
function ($x, $y, $z)
Неправильно:
class Foo
{
var $foo = 42;
}
Вот так правильно:
function fooBarBaz()
Вот так неправильно:
function FooBar()
function foo_bar()
function Foo_Bar()
Our code must not call Zend_Debug::dump
Let's create a code sniffer rule!
Применимо только к Magento-проектам (т.е. файл с классом лежит в папке app/code/local
).
Если класс лежит в папке app/code/loca/Oggetto/Foo/Model/Bar.php
, то он должен называться Oggetto_Foo_Model_Bar
.
Правильно:
class Foo
{
private $_foo;
private $_bar;
public function foo()
{
}
public function bar()
{
}
}
Неправильно:
class Foo
{
private $_foo;
private $_bar;
public function foo()
{
}
public function bar()
{
}
}
Верно:
$x = array(
'foo',
'bar',
'baz'
);
Неверно:
$x = array(
'foo',
'bar',
'baz'
);
Если в теле функции встречается throw ...
, то у этой функции должен быть док-блок @throws XXX
Применимо только к Magento.
app/code/
, то он должен оканчиваться на .php
app/design/.../.../.../template/
, то он должен оканчиваться на .phtml
У свойств должен быть док-блок с описанием свойства и типом данных
class Foo
{
/**
* Description (required)
*
* @var XXX (required)
*/
protected $_originalStore = null;
}
Юнит-тесты Magento находятся в .php-файлах в папках app/code/local/XXX/YYY/Test/
Все public-методы в каждом классе, который наследуется от PHPUnit_Framework_TestCase
должны начинаться со слова test
Нельзя вот так:
$x = array(-1 => 'foo')
Вот так правильно:
class Foo_Bar_Baz
class Foo_Bar_BazClass
Вот так неправильно:
class foo_bar_baz
class Foo_Bar_bazClass
Должен быть формат
try {
// code
} catch (Exception $e) {
// code
}
Инсталлеры хранятся в Magento в папках (app/code/local/XXX/YYY/sql/ZZZ/)
Внутри файла должна встретиться конструкция:
try {
...
} catch (...) {
...
}
Добавить правило, проверяющее, что в коде нет текста на русском языке
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.