Giter Club home page Giter Club logo

yii2-coding-standards's Issues

Add Alphabetical sorting of use statements

Something that I do a lot in my projects is having my use statements sorted lexicographically (Uppercase first, lowercase then).
Please have a look at some sniffs that already implement that feature here and here.

How to install Yii2 coding standard

/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.

Line indented incorrectly in rules

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;
                }
            ],
        ];
    }
}

Undefined offset: 3 with PHP CodeSniffer 1.5.2

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.

php-cs vs php-cs-fixer

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,

PSR-12 standard release

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

Coding Standards Fixer for Yii 2

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)

What I did

  • I thought the Yii framework (and even 3rd party extensions whose want to stay up-to-date with the CS) can benefit from the work I have done (it's always cool when all code — yours and contributed — can be formatted in one command and you can even change some CS things fast and safely)
  • I wrote several fixers and a config builder and tested everything on the Yii 2 framework code (I tried to follow the Yii 2 CS as much as I could)
  • I'm ready to polish and tweak it to team's needs (and contribute/support it — although a code is not hard to understand)

Possible usage

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:

  • run composer require --dev yiisoft/yii2-cs-fixer
  • place .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')
    );
  • run php-cs-fixer fix to fix it (or php-cs-fixer fix --dry-run --diff to preview changes)

Summary

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

Indentation fixing

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?

Add tag to repository

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.

Why use the Coding-sandards extension

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.