Skip to content

Commit

Permalink
Merge pull request #29 from object-calisthenics/php7
Browse files Browse the repository at this point in the history
PHP 7 bump, eat your own dog food
  • Loading branch information
Tomáš Votruba committed Nov 12, 2016
2 parents 881e842 + e065b86 commit 3c5a9b2
Show file tree
Hide file tree
Showing 44 changed files with 402 additions and 641 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
@@ -1,6 +1,7 @@
/tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
.travis.yml export-ignore
LICENSE export-ignore
phpunit.xml.dist export-ignore
phpunit.xml export-ignore
1 change: 0 additions & 1 deletion .gitignore
@@ -1,3 +1,2 @@
/vendor
composer.lock
phpunit.xml
13 changes: 1 addition & 12 deletions .scrutinizer.yml
@@ -1,16 +1,5 @@
before_commands:
- "composer install --prefer-source"

tools:
external_code_coverage:
timeout: 900
sensiolabs_security_checker: true
php_code_coverage:
enabled: true
php_analyzer:
config:
verify_php_doc_comments:
suggest_more_specific_types: false
external_code_coverage: true

checks:
php:
Expand Down
26 changes: 15 additions & 11 deletions .travis.yml
Expand Up @@ -7,22 +7,26 @@ cache:
- $HOME/.composer/cache

php:
- 5.6
- 7.0
- 7.1


matrix:
include:
- php: 7.0
env: PHPUNIT_FLAGS="--coverage-clover coverage.xml" CHECK_CS=true

install:
- composer selfupdate
- composer install --prefer-source

before_script:
- if [[ $TRAVIS_PHP_VERSION = '5.6' ]]; then PHPUNIT_FLAGS="--coverage-clover coverage.xml"; fi
- if [[ $TRAVIS_PHP_VERSION = '7.0' ]]; then vendor/bin/php-cs-fixer fix src --diff --dry-run -v --level=symfony; fi
- if [[ $TRAVIS_PHP_VERSION = '7.0' ]]; then vendor/bin/php-cs-fixer fix tests --diff --dry-run -v --level=symfony; fi

script:
# run tests
- vendor/bin/phpunit $PHPUNIT_FLAGS
- if [[ $TRAVIS_PHP_VERSION = '5.6' ]]; then vendor/bin/phpcs src tests --colors -p -s --extensions=php; fi
# check coding standard (defined in composer.json "scripts" section)
- if [[ "$CHECK_CS" != "" ]]; then composer check-cs; fi

after_script:
- if [[ $TRAVIS_PHP_VERSION = '5.6' ]]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.xml; fi
# upload coverage.xml file to Scrutinizer to analyze it
- |
if [[ PHPUNIT_FLAGS != "" ]]; then
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.xml
fi
12 changes: 10 additions & 2 deletions README.md
@@ -1,4 +1,10 @@
# PHPCS-Calisthenics-Rules
# Object Calisthenics rules for PHP_CodeSniffer

[![Build Status](https://img.shields.io/travis/object-calisthenics/phpcs-calisthenics-rules.svg?style=flat-square)](https://travis-ci.org/object-calisthenics/phpcs-calisthenics-rules)
[![Quality Score](https://img.shields.io/scrutinizer/g/object-calisthenics/phpcs-calisthenics-rules.svg?style=flat-square)](https://scrutinizer-ci.com/g/object-calisthenics/phpcs-calisthenics-rules)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/object-calisthenics/phpcs-calisthenics-rules.svg?style=flat-square)](https://scrutinizer-ci.com/g/object-calisthenics/phpcs-calisthenics-rules)
[![Latest stable](https://img.shields.io/packagist/v/object-calisthenics/phpcs-calisthenics-rules.svg?style=flat-square)](https://packagist.org/packages/object-calisthenics/phpcs-calisthenics-rules)


A [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer/) standard to verify Object Calisthenics rules.

Expand All @@ -8,7 +14,7 @@ A [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer/) standard to v
Install via [Composer](http://getcomposer.org/):

```sh
$ composer require object-calisthenics/phpcs-calisthenics-rules --dev
composer require object-calisthenics/phpcs-calisthenics-rules --dev
```

Then, enable it as part of your project code sniffer ruleset (ie. `phpcs.xml` in root project directory):
Expand All @@ -23,6 +29,8 @@ Then, enable it as part of your project code sniffer ruleset (ie. `phpcs.xml` in
```


---

# Object Calisthenics

[The ThoughtWorks Anthology](http://pragprog.com/book/twa/thoughtworks-anthology), a technical book published by [The Pragmatic Programmers](http://pragprog.com), introduced a technique called [Object Calisthenics](http://www.xpteam.com/jeff/writings/objectcalisthenics.rtf), proposed by [Jeff Bay](http://www.xpteam.com/jeff), who used to be the Technology Principal at [ThoughtWorks](http://www.thoughtworks.com).
Expand Down
23 changes: 15 additions & 8 deletions composer.json
@@ -1,24 +1,19 @@
{
"name": "object-calisthenics/phpcs-calisthenics-rules",
"description": "PHP CodeSniffer Object Calisthenics rules/sniffs",
"type": "library",
"license": "MIT",
"homepage": "https://github.com/object-calisthenics/phpcs-calisthenics-rules",
"keywords": [
"phpcs", "cs", "code", "coding", "standard", "standards", "style", "sniff", "sniffs", "sniffer",
"rule", "rules"
],
"authors": [
{ "name": "Guilherme Blanco", "email": "guilhermeblanco@hotmail.com" },
{ "name": "Tomas Votruba", "email": "info@tomasvotruba.cz" }
],
"require": {
"php": "^5.5|^7.0",
"php": "^7.0",
"squizlabs/php_codesniffer": "^2.4"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.0",
"fabpot/php-cs-fixer": "^1.11"
"phpunit/phpunit": "^5.6",
"fabpot/php-cs-fixer": "^1.12"
},
"autoload": {
"psr-4": {
Expand All @@ -29,5 +24,17 @@
"psr-4": {
"ObjectCalisthenics\\Tests\\": "tests"
}
},
"scripts": {
"check-cs": [
"vendor/bin/php-cs-fixer fix src --diff --dry-run -v --level=symfony",
"vendor/bin/php-cs-fixer fix tests --diff --dry-run -v --level=symfony",
"vendor/bin/phpcs src tests --colors -p -s --extensions=php --standard=src/ObjectCalisthenics/ruleset.xml"
],
"fix-cs": [
"vendor/bin/php-cs-fixer fix src -v --level=symfony",
"vendor/bin/php-cs-fixer fix tests -v --level=symfony",
"vendor/bin/phpcs src tests --colors -p -s --extensions=php --standard=src/ObjectCalisthenics/ruleset.xml"
]
}
}
6 changes: 0 additions & 6 deletions phpcs.xml

This file was deleted.

16 changes: 16 additions & 0 deletions phpunit.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite>
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
21 changes: 0 additions & 21 deletions phpunit.xml.dist

This file was deleted.

4 changes: 2 additions & 2 deletions src/ObjectCalisthenics/AbstractDataStructureLengthSniff.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace ObjectCalisthenics;

use ObjectCalisthenics\Helper\Structure\StructureMetrics;
Expand All @@ -11,8 +13,6 @@
* This sniff is the base for class, interface, trait, function and method
* length checks as part of "Keep your classes small" object calisthenics
* rule.
*
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
*/
abstract class AbstractDataStructureLengthSniff
{
Expand Down
64 changes: 15 additions & 49 deletions src/ObjectCalisthenics/AbstractIdentifierLengthSniff.php
@@ -1,13 +1,13 @@
<?php

declare(strict_types=1);

namespace ObjectCalisthenics;

use PHP_CodeSniffer_File;

/**
* Identifier length checker, part of "Do not abbreviate" OC rule.
*
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
*/
abstract class AbstractIdentifierLengthSniff
{
Expand All @@ -32,13 +32,6 @@ abstract class AbstractIdentifierLengthSniff
*/
protected $minLength = 3;

/**
* Maximum variable/method name length.
*
* @var int
*/
protected $maxLength = 32;

/**
* @var PHP_CodeSniffer_File
*/
Expand All @@ -49,10 +42,7 @@ abstract class AbstractIdentifierLengthSniff
*/
private $stackPtr;

/**
* {@inheritdoc}
*/
public function register()
public function register() : array
{
return [T_STRING];
}
Expand All @@ -75,48 +65,24 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)

$length = strlen($token['content']) - $this->tokenTypeLengthFactor;

$this->handleMaxLength($length);
$this->handleMinLength($length);
}

/**
* Whether if token is valid to be checked over using the current sniffer.
*
* @return bool
*/
abstract protected function isValid(PHP_CodeSniffer_File $phpcsFile, $stackPtr);
abstract protected function isValid(PHP_CodeSniffer_File $phpcsFile, int $stackPtr) : bool;

/**
* @param int $length
*/
private function handleMaxLength($length)
private function handleMinLength(int $length)
{
if ($length > $this->maxLength) {
$error = sprintf(
'Your %s is too long (currently %d chars, must be less or equals than %d chars)',
$this->tokenString,
$length,
$this->maxLength
);

$this->phpcsFile->addError($error, $this->stackPtr, sprintf('%sTooLong', ucfirst($this->tokenString)));
if ($length >= $this->minLength) {
return;
}
}

/**
* @param int $length
*/
private function handleMinLength($length)
{
if ($length < $this->minLength) {
$error = sprintf(
'Your %s is too short (currently %d chars, must be more or equals than %d chars)',
$this->tokenString,
$length,
$this->minLength
);

$this->phpcsFile->addError($error, $this->stackPtr, sprintf('%sTooShort', ucfirst($this->tokenString)));
}
$error = sprintf(
'Your %s is too short (currently %d chars, must be more or equals than %d chars)',
$this->tokenString,
$length,
$this->minLength
);

$this->phpcsFile->addError($error, $this->stackPtr, sprintf('%sTooShort', ucfirst($this->tokenString)));
}
}

0 comments on commit 3c5a9b2

Please sign in to comment.