Git Product home page Git Product logo

phpcs-calisthenics-rules's People

Contributors

afilina avatar emanueleminotto avatar frenck avatar greg0ire avatar guilhermeblanco avatar jeroennoten avatar jeromegamez avatar krizon avatar michaelvickersuk avatar mihaeu avatar noplanman avatar nubs avatar roukmoute avatar stof avatar th3mouk avatar tomasvotruba avatar ufomelkor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpcs-calisthenics-rules's Issues

Don't import PSR2 ruleset by default

From what I understand PSR-2 isn't really part of calisthenics principles. And some projects aren't PSR-2. And will never be because reasons. :)

With current version of CodeSniffer it's much easier to use multiple rulesets (comma separated list of them), than throw something out (need to create custom ruleset, import another ruleset, then exclude parts you don't need/want).

Nette\Utils\Strings not found

Hello. After installing using composer:

PHP Fatal error: Uncaught Error: Class 'Nette\Utils\Strings' not found

Composer output:

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 5 updates, 0 removals
  - Updating doctrine/dbal (v2.6.2 => v2.6.3): Loading from cache
  - Updating phpdocumentor/reflection-docblock (4.1.1 => 4.2.0): Downloading (100%)         
  - Updating phpspec/prophecy (v1.7.2 => 1.7.3): Downloading (100%)         
  - Updating phpunit/php-file-iterator (1.4.2 => 1.4.5): Downloading (100%)         
  - Updating phpunit/php-token-stream (2.0.1 => 2.0.2): Downloading (100%)         
  - Installing nette/utils (v2.4.8): Downloading (100%)         
  - Installing object-calisthenics/phpcs-calisthenics-rules (v3.1.0): Downloading (100%)         
nette/utils suggests installing ext-intl (for script transliteration in Strings::webalize() and toAscii())
nette/utils suggests installing ext-gd (to use Image)
Writing lock file
Generating autoload files

Rule 2 misinterpreted with switch?

Hello!

I've just seen when a method contains a switch/case statement, for the interpreter there is two indentations level.
I understand the idea, but in fact there is only one level, no ?

Could we improve this rule?

See you ;)

About MethodPerClassLimitSniff

I was trying to make some research about Object Calisthenics

So about this sniff I was wondering.

  • Should the __constructor be included?
  • Should the private/protected methods be included?
  • Should any magic methods be included like __toString()?

Only one level ? And what abouht try catch ?

public function addLinkBetweenOauthClientAndUserFromIds($oauthClientId, $userId)
    {
        try {
            $oauthClient = $this->oauthClientRepository->get($oauthClientId);
            if ($oauthClient === null) {
                return false;
            }
            $user = $this->userRepository->get($userId);
            if ($user === null) {
                return false;
            }
            return $this->addLinkBetweenOauthClientAndUser($oauthClient, $user);
        } catch (Exception $exception) {
            $this->logger->error(
                'Can\'t link from their ids oauth client: ' . $oauthClient->getId() . ' and user: ' . $user->getId()
                . '. Error: ' .$exception->getMessage()
            );
            return false;
        }
    }

With a code like that, i mean code in a try catch, only one level seems too restrictive no ?
So maybe an exception of two level when the first or the second is a try catch ?

Only one level ? But how can you manage to exit a foreach ?

How to do to exit a loop properly when you can only have one level ?
I can't found a good solution.

$element = ['A1', 'A2', 'A3', 'A4', 'A5'];

function exitWhenA2Found($value, $element)
{
    if ($value === 'A2') {
        $element->seek($element->count() - 1);
    }
}


function test($element)
{
    $iterator = new ArrayIterator($element);
    foreach ($iterator as $value) {
        exitWhenA2Found($value, $iterator);
        echo $value . "\n";
    }
}

test($element);


// VS

function testClassic($element)
{
    $iterator = new ArrayIterator($element);
    foreach ($iterator as $value) {
        if ($value === 'A2') {
                break;
        }
        echo $value . "\n";
    }
}

This solution is the better one i found.
But i don't think its a nice solution because it's not natural at all, and you need to go into exitWhenA2Found to know it gonna emulate a break (and not really like a true break because all code after the call in the current iteration is executed)

Unclear data type issue with method argument

On this code:

    /**
     * Create object and set parameters from passed.
     *
     * @param array $args
     */
    public function __construct( $args ) { // line 19 here

        $this->type    = $args['type'];
        $this->timeout = $args['timeout'];
    }

I get following errors:

 19 | ERROR | Unable to retrieve data type of property "$args"
     |       | (ObjectCalisthenics.CodeAnalysis.ArrayPropertyPerClassLimit.InvalidPropertyType)
  19 | ERROR | Unable to retrieve data type of property "$args"
     |       | (ObjectCalisthenics.CodeAnalysis.InstancePropertyPerClassLimit.InvalidPropertyType)

From error message it's not clear:

  1. Why are there two of them for the line?
  2. What fix exactly does it expect?

In current form the message isn't either clear (what's the actual issue?) or actionable (what do I need to do to resolve it?).

PS same thing with rest of the methods in class, not just constructor.

Class 'Nette\Utils\Strings' not found possible problem with phpcs 3.2.3 ?

I always get this when trying to run phpcs.

I read the code and seems everything ok but the class Strings doesn't exists.

Error: Class 'Nette\Utils\Strings' not found in /Users/user/Sites/sniffs/phpcs-calisthenics-rules/src/ObjectCalisthenics/Helper/Naming.php on line 43

Call Stack:
0.0006 392504 1. {main}() /usr/local/bin/phpcs.phar:0
0.0057 743384 2. PHP_CodeSniffer\Runner->runPHPCS() /usr/local/bin/phpcs.phar:6
0.1221 8372216 3. PHP_CodeSniffer\Runner->run() phar:///usr/local/bin/phpcs.phar/src/Runner.php:2
0.1291 8898144 4. PHP_CodeSniffer\Runner->processFile() phar:///usr/local/bin/phpcs.phar/src/Runner.php:2
0.1291 8898144 5. PHP_CodeSniffer\Files\LocalFile->process() phar:///usr/local/bin/phpcs.phar/src/Runner.php:2
0.1291 8898144 6. PHP_CodeSniffer\Files\LocalFile->process() phar:///usr/local/bin/phpcs.phar/src/Files/LocalFile.php:2
0.1516 9349616 7. ObjectCalisthenics\Sniffs\NamingConventions\ElementNameMinimalLengthSniff->process() phar:///usr/local/bin/phpcs.phar/src/Files/File.php:2
0.1521 9356928 8. ObjectCalisthenics\Helper\Naming::getElementName() /Users/user/Sites/sniffs/phpcs-calisthenics-rules/src/ObjectCalisthenics/Sniffs/NamingConventions/ElementNameMinimalLengthSniff.php:39

Fix class member doc comment processing

When running this phpcs standard on a project that also uses Doctrine annotations, it keeps getting false positives.
We need to update member comment processor and make it reliable.

The project only works on phpcs 1.*

If I use 2.* versions I got this error:
Fatal error: Class 'PHP_CodeSniffer_CommentParser_MemberCommentParser' not found

It would be nice to upgrade the version or at least to update composer.json with the real requirements of the project.

Tag

Hi there, could we get tags so that it can be installed with Composer? I'm too lazy to add the "minimum stability" flag to the global composer.json :) and I think anyway that having tags is a good thing right? What do you think?

PHP_CodeSniffer 2.0.0 compatibility

When running phpcs-calisthenics-rules with PHP_CodeSniffer 2.0.0, i've the following error :
Fatal error: Class 'PHP_CodeSniffer_CommentParser_MemberCommentParser' not found in .composer/vendor/object-calisthenics/phpcs-calisthenics-rules/ObjectCalisthenics/PropertyTypePerClassLimitSniff.php on line 328

Phpcs and phpcs-calisthenics-rules installed globally through composer.

How to do overrides

Hello guys,
I'm using phpcs-calisthenics-rules with the PhpStorm inspector and when I do property overrides like this below I get an error like the second image with that content: https://gist.github.com/wilcorrea/93d37027c5fac6f7a74a566dab02bf93

If I change the visibility of property into the sniff class the "error disappeared"... but I believe it should be another way to override without receiving messages.


My override
image

Version installed on composer.lock (https://gist.github.com/wilcorrea/93d37027c5fac6f7a74a566dab02bf93)
image

Message of PhpStorm
image

SO and PHP version

PHP 7.0.17-2+deb.sury.org~trusty+1 (cli) (built: Mar 15 2017 09:38:47) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.17-2+deb.sury.org~trusty+1, Copyright (c) 1999-2017, by Zend Technologies

Rule 9 misinterpreted

Hey there,

thanks for the awesome project.

Rule 9 is actually No getters/setters/properties (Source: Original by Jeff Bay). If you write getters and setters for everything, you are still exposing mutable state and you are still not being precise about how the member is supposed to be used (Nice code example here).

I think this is probably a case of cannot implement or a warning whenever setters are encountered?

Impossible to suppress ObjectCalisthenics.Metrics.MethodPerClassLimit

It seems like a standard method of suppression (@phpcsSuppress ObjectCalisthenics.Metrics.MethodPerClassLimit) doesn't work when added to the class.

Is it a known issue or is there a different method of suppressing that check for a particular class without excluding the whole file? (which in my case is marked for refactoring)

Operator per line sniff miscounts something

For this code:

        $compiler // line 31
                ->subcompile( $this->getNode( 'body' ) )
                ->write( 'endwhile;' . "\n" );

I get this error:

31 | ERROR | Only one object operator per line.
    |       | (ObjectCalisthenics.CodeAnalysis.OneObjectOperatorPerLine)

Seems incorrect.

Missing dependency in v3.0

When I run the phpcs I get an error:

PHP Fatal error:  Uncaught Error: Class 'SlevomatCodingStandard\Helpers\PropertyHelper' not found in /home/bley/PhpstormProjects/reflections/vendor/object-calisthenics/phpcs-calisthenics-rules/src/ObjectCalisthenics/Helper/ClassAnalyzer.php:57

slevomat/coding-standard is just required as dev-dependency but seems to be necessary to run the sniffs.

Question about Fluent Interfaces

Hi,

is there any way to get rid of the Only one object operator per line. errors when using the Doctrine\DBAL\Query\QueryBuilder?

Eat your own dog food

When creating phpcs rules, it should also enforced to follow them internally too.
The idea is to finish all 10 rules, then update codebase to meet them.
Roadmap:

  • Create all rules (make it work)
  • Expand test cases to cover a good chunk of use cases (make it right)
  • Make internal code also follow the rules (make it fast)

That's a good exercise to show people how any code can be turned into compliant OC code.

Custom ruleset.xml

Hye guys,

I'm trying to use a custom ruleset.xml.

./vendor/bin/phpcs -sp app tests --standard=ruleset.xml

but I got stuck on this error.

ERROR: Referenced sniff "ObjectCalisthenics.Metrics.MaxNestingLevel" does not exist

Cheers.

Error when running PHPUnit

Perhaps I'm missing the obvious here...

Did a git clone, ran composer install, then phpunit:

RuntimeException: Could not find PHP_CodeSniffer test suite. Did you maybe forget to run composer installation with option "--prefer-source"? in /home/j/workspace/phpcs-calisthenics-rules/bootstrap.php on line 68

phpunit --version
PHPUnit 4.2.2 by Sebastian Bergmann.

commit 51b3b42

Error when run composer to install dependencies

I have in my composer.json file:

"require-dev": {
        "phpunit/phpunit": "4.*",
        "squizlabs/php_codesniffer": "dev-master",
        "object-calisthenics/phpcs-calisthenics-rules": "dev-master"
}

Raise the follow error

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for squizlabs/php_codesniffer dev-master -> satisfiable by squizlabs/php_codesniffer[dev-master].
    - object-calisthenics/phpcs-calisthenics-rules dev-master requires squizlabs/php_codesniffer ~1.5 -> satisfiable by squizlabs/php_codesniffer[1.5.x-dev].
    - Can only install one of: squizlabs/php_codesniffer[dev-master, 1.5.x-dev].
    - Installation request for object-calisthenics/phpcs-calisthenics-rules dev-master -> satisfiable by object-calisthenics/phpcs-calisthenics-rules[dev-master]

When I replace version of php_codesniffer to ~1.5 its works.

Request: 2.* release with phpcodesniffer-standard

I've got a situation where the production server has PHP 7.0 (limited to Object Calisthenics 2.*), but I want to use a Composer plugin for registering the PHP CodeSniffer standards in my project (requires OC define phpcodesniffer-standard value in composer.json).

Would it be possible to please add a 2.0.1 release that adds the required key to composer.json, without bumping the minimum version of PHP?

Upgrade to CodeSniffer 3

It is about to be released in next month or so.
We could plan next release (3.0) along with it, so it matches the version.
And is compatible with other modern Sniffs.

More specifcly about types on docBlocks

I want to be more specific about types in my docBlock, for example:

/**
 * @param string[] $bar
 */
public function Foo(array $bar) {
     // ...
}

But it's actually raise a error on CS validation.

Expected type hint "string[]"; found "array" for $bat at position 1

requires slevomat/coding-standard ^5.0.4 but it has already installed 6.0.1

Problem 1
  - object-calisthenics/phpcs-calisthenics-rules v3.6.0 requires slevomat/coding-standard ^5.0.4 -> satisfiable by slevomat/coding-standard[5.0.4] but these conflict with your requirements or minimum-stability.
  - object-calisthenics/phpcs-calisthenics-rules v3.5.1 requires slevomat/coding-standard ^5.0 -> satisfiable by slevomat/coding-standard[5.0.0, 5.0.1, 5.0.2, 5.0.3, 5.0.4] but these conflict with your requirements or minimum-stability.
  - object-calisthenics/phpcs-calisthenics-rules v3.5.0 requires slevomat/coding-standard ^5.0 -> satisfiable by slevomat/coding-standard[5.0.0, 5.0.1, 5.0.2, 5.0.3, 5.0.4] but these conflict with your requirements or minimum-stability.
  - object-calisthenics/phpcs-calisthenics-rules v3.6.0 requires slevomat/coding-standard ^5.0.4 -> satisfiable by slevomat/coding-standard[5.0.4] but these conflict with your requirements or minimum-stability.
  - Installation request for object-calisthenics/phpcs-calisthenics-rules ^3.5 -> satisfiable by object-calisthenics/phpcs-calisthenics-rules[v3.5.0, v3.5.1, v3.6.0].

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.