yiisoft / yii2-coding-standards Goto Github PK
View Code? Open in Web Editor NEWYii 2 coding standards
Yii 2 coding standards
Title says it all :)
PS: This package should also be moved to the core and yii2-dev.
Please update your composer.json
to add support for PHP_CodeSniffer 2.*
branch.
In Yii2 Project, I am not getting that in php files having html or not, some file have space after <?php and some don't.
I can see that many files have space and some don't.
Please specify some standard.
http=>https
/opt/lampp/htdocs/www/wuzhishan$ /opt/lampp/bin/phpcs --extensions=php --standard=Yii2 ./
ERROR: the "Yii2" coding standard is not installed. The installed coding standards are PHPCS, Zend, Squiz, MySource, PSR2, PEAR and PSR1
I am so sorry that YII 2 coding standard is not installed. I cannot understand the Getting code.
I installed phpcs in my /opt/lampp/bin/phpcs.
my network is located in /opt/lampp/htdocs/www/wuzhishan/
this code from README.md
$ ./vendor/bin/phpcs --extensions=php --standard=Yii2 /home/resurtm/work/Yii2MegaApp/
what the last Yii2MegaApp means? is it an app?
Thank you.
I am unable to import the .jar files to the Netbeans.
Please suggest some alternative to Netbeans Users.
The link to the Manual & Guide
link under the Usefull Links needs to be updated it is throwing 404 Error, the link currently ponts to the url http://pear.php.net/manual/en/package.php.php-codesniffer.php
This code not valid for phpcs:
<?php
namespace test;
class NEW1
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['date'], 'date'],
[
['ip_manual'],
'filter',
'filter' => function ($v) {
if ($this->operator == 3 || $this->operator == 4) { //here
return null;
}
return $v;
} //and here
],
];
}
}
PHPCS requires ugly operations from me:
<?php
namespace test;
class NEW1
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['date'], 'date'],
[
['ip_manual'],
'filter',
'filter' => function ($v) {
if ($this->operator == 3 || $this->operator == 4) {
return null;
}
return $v;
}
],
];
}
}
When running phpcs 1.5.2 with the Yii2 standard, the following error occurs:
PHP Notice: Undefined offset: 3 in CodeSniffer.php on line 1050
This is because even though the PrivatePropertiesUnderscoreSniff.php file is not listed in the ruleset, it's still being loaded. However it should be in a subfolder, for example Yii2/Sniffs/Classes. Then the class should be renamed to Yii2_Sniffs_Classes_PrivatePropertiesUnderscoreSniff.
Hi, what are you using to format the code, php-cs-fixer or php-cs, in the repository of the core yii2 are the rules for php-cs-fixer, which is the one currently used,
Thks,
Since Yii2 mostly follows the new extended rules, can we have a new release tag that enforces this standard?
It would help the community and junior developers follow the rules.
Thank you!
R
Make new release
Since there's a 2.0.0-rc tag, I'd also expect an 2.0.0 now.
You're probably aware of php-cs-fixer
. Pretty useful and mature coding standards fixer.
It already includes lots of fixers (see the rules list) but Yii 2 has its specifics (especially PHPDocs)
Let's assume we've pushed several files to yii2-cs-fixer
— its composer.json
is basically dependency-free (I wrote fixers for php-cs-fixer
2.0):
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.0"
},
Then a project wishes to use our fixer will need:
composer require --dev yiisoft/yii2-cs-fixer
.php_cs.dist
with this:<?php
require_once __DIR__ . '/vendor/autoload.php';
return yii2\csfixer\Config::create()
->setFinder(
PhpCsFixer\Finder::create()
->in([
// customizable
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__ . '/yii2/framework',
])
// customizable
->exclude('views')
);
php-cs-fixer fix
to fix it (or php-cs-fixer fix --dry-run --diff
to preview changes)If you also think Yii 2 can benefit from this, I'm up to make it real — I will publish the source (it's not a prime-time ready yet — basically it misses docs) and tweak it to Yii 2 team needs.
In case you have questions or interested, I'm ready. If not, just close the issue. :)
There's a demo repository where I have applied fixes from my current configuration: https://github.com/sergeymakinen/yii2/commit/181e9e49d354a822d0add52062d4919bc2824b45
PHP_CodeSniffer config treats this code as valid
if (true) {
// Note two tabs instead of one
echo 'Hi there.', PHP_EOL;
}
Is there any way to fix this in CodeSniffer config?
Currently it breaks your implementation:
HP Fatal error: Interface 'PHP_CodeSniffer_Sniff' not found in ./vendor/yiisoft/yii2-coding-standards/Yii2/Sniffs/Files/SpacesAroundConcatSniff.php on line 13
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Version-3.0-Upgrade-Guide
Maybe up that to another version so that the v2.x implementations of CodeSniffer still work?
Need to provide it in phpshtorm_yii2.jar and others files
this package does not validate Documentation part of code style
Would be nice, if this repo could also introduce a version tag.
Otherwise you have to specify a development version in composer like @dev
or dev-master
.
Hardsetting 2.0.0 in the composer definition fails due to requirement of codesniffer 1.* where in the dev-master codesiffer * satisfies the dependency.
Should I be using 1.* if I am using 2.0.0 hardset?
Оr add it to an exception in this expansion, or change the class name generation, but so convenient to underscore ^_^
P.S. And phpcs requires use namespace
hello,
i came across your extension for the Yii coding standards and while going through the Yii-coding standards Docs i dont find anything that is not already covered by PhpCs, or maybe i am overlooking it.
The purpose of asking is that if i already am using the phpcs with PSR2 would i need to use this extension if i am working in Yii2 and how can it benefit me.
It seems there's no check for the rule "Add spaces around dot when concatenating strings":
https://github.com/yiisoft/yii2/blob/master/docs/internals/core-code-style.md#concatenation
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.