Code Monkey home page Code Monkey logo

phpcs-calisthenics-rules's Introduction

Object Calisthenics rules for PHP_CodeSniffer

DEPRECATED: PHP_CodeSniffer is great for handling spaces and char positions. Yet these rules are about code architecture and structure. In 2020, there is tool that suits this perfectly - PHPStan.

Saying that, object calisthenics were implemented as PHPStan rules in a symplify/phpstan-rules package. Use it instead ๐Ÿ‘‡

includes:
    - vendor/symplify/phpstan-rules/packages/object-calisthenics/config/object-calisthenics-rules.neon
    - vendor/symplify/phpstan-rules/packages/object-calisthenics/config/object-calisthenics-services.neon



Downloads

Object Calisthenics are set of rules in object-oriented code, that focuses of maintainability, readability, testability and comprehensibility. We're pragmatic first - they are easy to use all together or one by one.

Why Should You Use This in Your Project?

Read post by William Durand or check presentation by Guilherme Blanco.

Install

composer require object-calisthenics/phpcs-calisthenics-rules --dev

Usage

If you know what you want, jump right to the specific rule:

How to quickly check 1 rule?

In PHP_CodeSniffer

vendor/bin/phpcs src tests -sp \
--standard=vendor/object-calisthenics/phpcs-calisthenics-rules/src/ObjectCalisthenics/ruleset.xml \
--sniffs=ObjectCalisthenics.Classes.ForbiddenPublicProperty

In EasyCodingStandard

# ecs.yaml
services:
    ObjectCalisthenics\Sniffs\Classes\ForbiddenPublicPropertySniff: ~

then

vendor/bin/ecs check src

Implemented Rule Sniffs

โŒ

foreach ($sniffGroups as $sniffGroup) {
    foreach ($sniffGroup as $sniffKey => $sniffClass) {
        if (! $sniffClass instanceof Sniff) {
            throw new InvalidClassTypeException;
        }
    }
}

๐Ÿ‘

foreach ($sniffGroups as $sniffGroup) {
    $this->ensureIsAllInstanceOf($sniffGroup, Sniff::class);
}

// ...
private function ensureIsAllInstanceOf(array $objects, string $type)
{
    // ...
}

Use Only This Rule?

In PHP_CodeSniffer:

vendor/bin/phpcs ... --sniffs=ObjectCalisthenics.Metrics.MaxNestingLevel

In ECS:

# ecs.yaml
services:
    ObjectCalisthenics\Sniffs\Metrics\MaxNestingLevelSniff: ~

๐Ÿ”ง Configurable

In PHP_CodeSniffer:

<?xml version="1.0"?>
<ruleset name="my-project">
    <rule ref="ObjectCalisthenics.Metrics.MaxNestingLevel">
        <properties>
            <property name="maxNestingLevel" value="2"/>
        </properties>
    </rule>
</ruleset>

In ECS:

services:
    ObjectCalisthenics\Sniffs\Metrics\MaxNestingLevelSniff:
        maxNestingLevel: 2

โŒ

if ($status === self::DONE) {
    $this->finish();
} else {
    $this->advance();
}

๐Ÿ‘

if ($status === self::DONE) {
    $this->finish();
    return;
}

$this->advance();

Use Only This Rule?

In PHP_CodeSniffer:

vendor/bin/phpcs ... --sniffs=ObjectCalisthenics.ControlStructures.NoElse

In ECS:

# ecs.yaml
services:
    ObjectCalisthenics\Sniffs\ControlStructures\NoElseSniff: ~

โŒ

$this->container->getBuilder()->addDefinition(SniffRunner::class);

๐Ÿ‘

$containerBuilder = $this->getContainerBuilder();
$containerBuilder->addDefinition(SniffRunner::class);

Use Only This Rule?

In PHP_CodeSniffer:

vendor/bin/phpcs ... --sniffs=ObjectCalisthenics.CodeAnalysis.OneObjectOperatorPerLine

In ECS:

# ecs.yaml
services:
    ObjectCalisthenics\Sniffs\CodeAnalysis\OneObjectOperatorPerLineSniff: ~

๐Ÿ”ง Configurable

In PHP_CodeSniffer:

<?xml version="1.0"?>
<ruleset name="my-project">
    <rule ref="ObjectCalisthenics.CodeAnalysis.OneObjectOperatorPerLine">
        <properties>
            <property name="variablesHoldingAFluentInterface" type="array" value="$queryBuilder,$containerBuilder"/>
            <property name="methodsStartingAFluentInterface" type="array" value="createQueryBuilder"/>
            <property name="methodsEndingAFluentInterface" type="array" value="execute,getQuery"/>
        </properties>
    </rule>
</ruleset>

In ECS:

services:
    ObjectCalisthenics\Sniffs\CodeAnalysis\OneObjectOperatorPerLineSniff:
        variablesHoldingAFluentInterface: ["$queryBuilder", "$containerBuilder"]
        methodsStartingAFluentInterface: ["createQueryBuilder"]
        methodsEndingAFluentInterface: ["execute", "getQuery"]

This is related to class, trait, interface, constant, function and variable names.

โŒ

class EM
{
    // ...
}

๐Ÿ‘

class EntityMailer
{
    // ...
}

Use Only This Rule?

In PHP_CodeSniffer:

vendor/bin/phpcs ... --sniffs=ObjectCalisthenics.NamingConventions.ElementNameMinimalLength

In ECS:

# ecs.yaml
services:
    ObjectCalisthenics\Sniffs\NamingConventions\ElementNameMinimalLengthSniff: ~

๐Ÿ”ง Configurable

In PHP_CodeSniffer:

<?xml version="1.0"?>
<ruleset name="my-project">
    <rule ref="ObjectCalisthenics.NamingConventions.ElementNameMinimalLength">
        <properties>
            <property name="minLength" value="3"/>
            <property name="allowedShortNames" type="array" value="i,id,to,up"/>
        </properties>
    </rule>
</ruleset>

In ECS:

# ecs.yaml
services:
    ObjectCalisthenics\Sniffs\NamingConventions\ElementNameMinimalLengthSniff:
        minLength: 3
        allowedShortNames: ["i", "id", "to", "up"]

โŒ

class SimpleStartupController
{
    // 300 lines of code
}

๐Ÿ‘

class SimpleStartupController
{
    // 50 lines of code
}

โŒ

class SomeClass
{
    public function simpleLogic()
    {
        // 30 lines of code
    }
}

๐Ÿ‘

class SomeClass
{
    public function simpleLogic()
    {
        // 10 lines of code
    }
}

โŒ

class SomeClass
{
    // 20 properties
}

๐Ÿ‘

class SomeClass
{
    // 5 properties
}

โŒ

class SomeClass
{
    // 20 methods
}

๐Ÿ‘

class SomeClass
{
    // 5 methods
}

Use Only This Rule?

In PHP_CodeSniffer:

vendor/bin/phpcs ... --sniffs=ObjectCalisthenics.Files.ClassTraitAndInterfaceLength,ObjectCalisthenics.Files.FunctionLength,ObjectCalisthenics.Metrics.MethodPerClassLimit,ObjectCalisthenics.Metrics.PropertyPerClassLimit

In ECS:

# ecs.yaml
services:
    ObjectCalisthenics\Sniffs\Files\ClassTraitAndInterfaceLengthSniff: ~
    ObjectCalisthenics\Sniffs\Files\FunctionLengthSniff: ~
    ObjectCalisthenics\Sniffs\Metrics\MethodPerClassLimitSniff: ~
    ObjectCalisthenics\Sniffs\Metrics\PropertyPerClassLimitSniff: ~

๐Ÿ”ง Configurable

In PHP_CodeSniffer:

<?xml version="1.0"?>
<ruleset name="my-project">
    <rule ref="ObjectCalisthenics.Files.ClassTraitAndInterfaceLength">
        <properties>
            <property name="maxLength" value="200"/>
        </properties>
    </rule>
    <rule ref="ObjectCalisthenics.Files.FunctionLength">
        <properties>
            <property name="maxLength" value="20"/>
        </properties>
    </rule>
    <rule ref="ObjectCalisthenics.Metrics.PropertyPerClassLimit">
        <properties>
            <property name="maxCount" value="10"/>
        </properties>
    </rule>
    <rule ref="ObjectCalisthenics.Metrics.MethodPerClassLimit">
        <properties>
            <property name="maxCount" value="10"/>
        </properties>
    </rule>
</ruleset>

In ECS:

# ecs.yaml
services:
    ObjectCalisthenics\Sniffs\Files\ClassTraitAndInterfaceLengthSniff:
        maxLength: 200
    ObjectCalisthenics\Sniffs\Files\FunctionLengthSniff:
        maxLength: 20
    ObjectCalisthenics\Sniffs\Metrics\PropertyPerClassLimitSniff:
        maxCount: 10
    ObjectCalisthenics\Sniffs\Metrics\MethodPerClassLimitSniff:
        maxCount: 10

This rules is partially related to Domain Driven Design.

  • Classes should not contain public properties.
  • Method should represent behavior, not set values.

โŒ

class ImmutableBankAccount
{
    public $currency = 'USD';
    private $amount;

    public function setAmount(int $amount)
    {
        $this->amount = $amount;
    }
}

๐Ÿ‘

class ImmutableBankAccount
{
    private $currency = 'USD';
    private $amount;

    public function withdrawAmount(int $withdrawnAmount)
    {
        $this->amount -= $withdrawnAmount;
    }
}

Use Only This Rule?

In PHP_CodeSniffer:

vendor/bin/phpcs ... --sniffs=ObjectCalisthenics.Classes.ForbiddenPublicProperty,ObjectCalisthenics.NamingConventions.NoSetter

In ECS:

# ecs.yaml
services:
    ObjectCalisthenics\Sniffs\Classes\ForbiddenPublicPropertySniff: ~
    ObjectCalisthenics\Sniffs\NamingConventions\NoSetterSniff: ~

๐Ÿ”ง Configurable

In PHP_CodeSniffer:

<?xml version="1.0"?>
<ruleset name="my-project">
    <rule ref="ObjectCalisthenics.NamingConventions.NoSetter">
        <properties>
            <property name="allowedClasses" type="array" value="*\DataObject"/>
        </properties>
    </rule>
</ruleset>

In ECS:

# ecs.yaml
services:
    ObjectCalisthenics\Sniffs\NamingConventions\NoSetterSniff:
        allowedClasses: 
            - '*\DataObject'

Not Implemented Rules - Too Strict, Vague or Annoying

While using in practice, we found these rule to be too strict, vague or even annoying, rather than helping to write cleaner and more pragmatic code. They're also closely related with Domain Driven Design.

3. Wrap Primitive Types and Strings - Since PHP 7, you can use define(strict_types=1) and scalar type hints. For other cases, e.g. email, you can deal with that in your Domain via Value Objects.

4. Use First Class Collections - This rule makes sense, yet is too strict to be useful in practice. Even our code didn't pass it at all.

8. Do Not Use Classes With More Than Two Instance Variables - This depends on individual domain of each project. It doesn't make sense to make a rule for that.


3 Rules for Contributing

  • 1 feature per PR

  • every new feature must be covered by tests

  • all tests and style checks must pass

    composer complete-check

We will be happy to merge your feature then.

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

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

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?

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 ;)

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

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)

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)

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

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.

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.

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()?

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

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.

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.

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.

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 ?

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.

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.

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.

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.

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.

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?

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?

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

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?

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

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

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.