Skip to content

Commit

Permalink
Bump to PHP 7.2 (#94)
Browse files Browse the repository at this point in the history
Bump to PHP 7.2
  • Loading branch information
TomasVotruba committed Nov 10, 2019
2 parents 54ebcc7 + 9c21cf9 commit 2af78d0
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 104 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
@@ -0,0 +1,9 @@
root = true

[*.{css,html,js,json,latte,neon,php,twig,xml,yaml,yml}]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4
92 changes: 65 additions & 27 deletions .travis.yml
@@ -1,35 +1,73 @@
os: linux
language: php

sudo: false

php:
- 7.1
- 7.2
- 7.3
- '7.2'
- '7.3'
- '7.4snapshot'

before_install:
# turn off XDebug
- phpenv config-rm xdebug.ini || return 0

install:
# install composer dependencies
- composer install

script:
# run tests
- vendor/bin/phpunit --coverage-clover coverage.xml
# turn off XDebug
- phpenv config-rm xdebug.ini || return 0
# check coding standard (defined in composer.json "scripts" section)
- composer check-cs
# check with phpstan (defined in composer.json "scripts" section)
- composer phpstan
# run PHP_CodeSniffer with ruleset
- vendor/bin/phpcs src tests -sp --standard=src/ObjectCalisthenics/ruleset.xml --extensions=php

after_script:
# upload coverage.xml file to Coveralls to analyze it
- |
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar
php php-coveralls.phar --verbose
- composer install --no-progress

jobs:
include:
-
stage: test
name: ECS
php: 7.3
script:
- composer check-cs

-
name: PHPStan
php: 7.3
script:
- composer phpstan

-
name: Rector
php: 7.3
script:
- vendor/bin/rector process src tests --dry-run --config rector-ci.yaml

-
name: 'Unit Tests'
script:
- vendor/bin/phpunit

-
name: 'Run PHP_CodeSniffer'
php: 7.3
script:
- vendor/bin/phpcs src tests -sp --standard=src/ObjectCalisthenics/ruleset.xml --extensions=php

-
stage: coverage
name: 'Test Coverage'
if: branch = master AND type = push
before_install:
- echo "keep xdebug"
script:
- vendor/bin/phpunit --coverage-clover coverage.xml
# upload coverage.xml file to Coveralls to analyze it
- wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar
- php php-coveralls.phar --verbose

allow_failures:
- php: '7.4snapshot'

matrix:
fast_finish: true

cache:
directories:
- $HOME/.composer/cache

# do not send success notifications, they have no value
notifications:
email:
on_success: never
email:
on_success: never
20 changes: 9 additions & 11 deletions README.md
Expand Up @@ -28,8 +28,6 @@ If you know what you want, jump right to the specific rule:
- [7. Keep Your Classes Small](#7-keep-your-classes-small)
- [9. Do not Use Getters and Setters](#9-do-not-use-getters-and-setters)



## How to quickly check 1 rule?

In [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
Expand Down Expand Up @@ -97,7 +95,7 @@ vendor/bin/phpcs ... --sniffs=ObjectCalisthenics.Metrics.MaxNestingLevel
In ECS:

```yml
# ecs.yml
# ecs.yaml
services:
ObjectCalisthenics\Sniffs\Metrics\MaxNestingLevelSniff: ~
```
Expand Down Expand Up @@ -161,7 +159,7 @@ vendor/bin/phpcs ... --sniffs=ObjectCalisthenics.ControlStructures.NoElse
In ECS:

```yml
# ecs.yml
# ecs.yaml
services:
ObjectCalisthenics\Sniffs\ControlStructures\NoElseSniff: ~
```
Expand Down Expand Up @@ -194,7 +192,7 @@ vendor/bin/phpcs ... --sniffs=ObjectCalisthenics.CodeAnalysis.OneObjectOperatorP
In ECS:

```yml
# ecs.yml
# ecs.yaml
services:
ObjectCalisthenics\Sniffs\CodeAnalysis\OneObjectOperatorPerLineSniff: ~
```
Expand Down Expand Up @@ -261,7 +259,7 @@ vendor/bin/phpcs ... --sniffs=ObjectCalisthenics.NamingConventions.ElementNameMi
In ECS:

```yml
# ecs.yml
# ecs.yaml
services:
ObjectCalisthenics\Sniffs\NamingConventions\ElementNameMinimalLengthSniff: ~
```
Expand All @@ -285,7 +283,7 @@ In PHP_CodeSniffer:
In ECS:

```yaml
# ecs.yml
# ecs.yaml
services:
ObjectCalisthenics\Sniffs\NamingConventions\ElementNameMinimalLengthSniff:
minLength: 3
Expand Down Expand Up @@ -386,7 +384,7 @@ vendor/bin/phpcs ... --sniffs=ObjectCalisthenics.Files.ClassTraitAndInterfaceLen
In ECS:

```yml
# ecs.yml
# ecs.yaml
services:
ObjectCalisthenics\Sniffs\Files\ClassTraitAndInterfaceLengthSniff: ~
ObjectCalisthenics\Sniffs\Files\FunctionLengthSniff: ~
Expand Down Expand Up @@ -427,7 +425,7 @@ In PHP_CodeSniffer:
In ECS:

```yaml
# ecs.yml
# ecs.yaml
services:
ObjectCalisthenics\Sniffs\Files\ClassTraitAndInterfaceLengthSniff:
maxLength: 200
Expand Down Expand Up @@ -493,7 +491,7 @@ vendor/bin/phpcs ... --sniffs=ObjectCalisthenics.Classes.ForbiddenPublicProperty
In ECS:

```yml
# ecs.yml
# ecs.yaml
services:
ObjectCalisthenics\Sniffs\Classes\ForbiddenPublicPropertySniff: ~
ObjectCalisthenics\Sniffs\NamingConventions\NoSetterSniff: ~
Expand All @@ -517,7 +515,7 @@ In PHP_CodeSniffer:
In ECS:

```yaml
# ecs.yml
# ecs.yaml
services:
ObjectCalisthenics\Sniffs\NamingConventions\NoSetterSniff:
allowedClasses:
Expand Down
29 changes: 13 additions & 16 deletions composer.json
Expand Up @@ -4,18 +4,20 @@
"license": "MIT",
"type": "phpcodesniffer-standard",
"require": {
"php": "^7.1",
"squizlabs/php_codesniffer": "^3.4",
"nette/utils": "^2.5|^3.0",
"slevomat/coding-standard": "^5.0"
"php": "^7.2",
"squizlabs/php_codesniffer": "^3.5",
"nette/utils": "^3.0",
"slevomat/coding-standard": "^5.0.4"
},
"require-dev": {
"phpunit/phpunit": "^7.5|^8.0",
"phpstan/phpstan": "^0.11.4",
"symplify/easy-coding-standard-tester": "^5.4",
"symplify/coding-standard": "^5.4",
"symplify/changelog-linker": "^5.4",
"tracy/tracy": "^2.5"
"phpunit/phpunit": "^8.4",
"phpstan/phpstan": "^0.11.19",
"symplify/easy-coding-standard-tester": "^6.1",
"symplify/coding-standard": "^6.1",
"symplify/changelog-linker": "^6.1",
"tracy/tracy": "^2.7",
"rector/rector": "^0.5.21",
"symplify/phpstan-extensions": "^6.1"
},
"autoload": {
"psr-4": {
Expand All @@ -29,14 +31,9 @@
},
"scripts": {
"complete-check": ["@phpstan", "@check-cs", "phpunit"],
"phpstan": "phpstan analyze src --level max",
"phpstan": "phpstan analyze src tests --error-format symplify",
"check-cs": "ecs check src tests",
"fix-cs": "ecs check src tests --fix",
"changelog": "changelog-linker dump-merges --in-categories"
},
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
}
}
}
11 changes: 6 additions & 5 deletions ecs.yml → ecs.yaml
@@ -1,10 +1,11 @@
imports:
- { resource: 'vendor/symplify/easy-coding-standard/config/symfony.yml' }
- { resource: 'vendor/symplify/easy-coding-standard/config/php70.yml' }
- { resource: 'vendor/symplify/easy-coding-standard/config/php71.yml' }
- { resource: 'vendor/symplify/easy-coding-standard/config/set/symfony.yaml' }
- { resource: 'vendor/symplify/easy-coding-standard/config/set/php70.yaml' }
- { resource: 'vendor/symplify/easy-coding-standard/config/set/php71.yaml' }
- { resource: 'vendor/symplify/easy-coding-standard/config/set/psr12.yaml' }
# custom
- { resource: 'vendor/symplify/easy-coding-standard/config/common.yml' }
- { resource: 'vendor/symplify/easy-coding-standard/config/symplify.yml' }
- { resource: 'vendor/symplify/easy-coding-standard/config/set/common.yaml' }
- { resource: 'vendor/symplify/easy-coding-standard/config/set/symplify.yaml' }
- { resource: 'config/object-calisthenics.yml' }

services:
Expand Down
13 changes: 8 additions & 5 deletions phpstan.neon
@@ -1,11 +1,14 @@
includes:
- 'vendor/symplify/phpstan-extensions/config/config.neon'

parameters:
# to allow installing with various phsptan versions without reporting old errors here
reportUnmatchedIgnoredErrors: false
level: max

autoload_files:
- %currentWorkingDirectory%/tests/bootstrap.php
- %currentWorkingDirectory%/vendor/squizlabs/php_codesniffer/autoload.php
excludes_analyse:
- **/ObjectCalisthenics/Helper/Slevomat/**
- 'tests/bootstrap.php'

ignoreErrors:
# false float positive
- '#Parameter \#1 \$start of method ObjectCalisthenics\\Sniffs\\CodeAnalysis\\OneObjectOperatorPerLineSniff::ignoreWhitespace\(\) expects int, float\|int given#'
- '#Method ObjectCalisthenics\\Sniffs\\Metrics\\MaxNestingLevelSniff::subtractFunctionNestingLevel\(\) should return int but returns float\|int#'
8 changes: 8 additions & 0 deletions rector-ci.yaml
@@ -0,0 +1,8 @@
parameters:
sets:
- 'dead-code'
- 'code-quality'
- 'coding-style'

autoload_paths:
- 'tests/bootstrap.php'
Expand Up @@ -12,7 +12,7 @@ public static function getStructureLengthInLines(File $file, int $position): int
$token = $tokens[$position];

// Skip function without body.
if (isset($token['scope_opener']) === false) {
if (! isset($token['scope_opener'])) {
return 0;
}

Expand Down
Expand Up @@ -49,11 +49,8 @@ private function isSniffClass(File $file, int $position): bool
$classNameTokenPosition = $file->findNext(T_STRING, $classTokenPosition);

$classNameToken = $file->getTokens()[$classNameTokenPosition];
if (Strings::endsWith($classNameToken['content'], 'Sniff')) {
return true;
}

return false;
return Strings::endsWith($classNameToken['content'], 'Sniff');
}

/**
Expand Down
Expand Up @@ -186,7 +186,7 @@ private function isInFluentInterfaceMode(): bool
*/
private function computeLastCallOfAnyFrom(array $methods): int
{
$calls = array_filter($this->callerTokens, function (array $token) use ($methods) {
$calls = array_filter($this->callerTokens, function (array $token) use ($methods): bool {
return in_array($token['token']['content'], $methods, true);
});
if (count($calls) > 0) {
Expand Down
Expand Up @@ -64,7 +64,7 @@ public function process(File $file, $position): void
$token = $tokens[$position];

// Ignore abstract methods.
if (isset($token['scope_opener']) === false) {
if (! isset($token['scope_opener'])) {
return;
}

Expand All @@ -79,8 +79,6 @@ public function process(File $file, $position): void
*/
private function iterateTokens(int $start, int $end, array $tokens): void
{
$this->currentPtr = $start + 1;

// Find the maximum nesting level of any token in the function.
for ($this->currentPtr = ($start + 1); $this->currentPtr < $end; ++$this->currentPtr) {
$nestedToken = $tokens[$this->currentPtr];
Expand Down
Expand Up @@ -54,11 +54,7 @@ private function shouldBeSkipped(int $elementNameLength, string $elementName): b
return true;
}

if ($this->isShortNameAllowed($elementName)) {
return true;
}

return false;
return $this->isShortNameAllowed($elementName);
}

private function isShortNameAllowed(string $variableName): bool
Expand Down
24 changes: 3 additions & 21 deletions tests/FileFactory.php
Expand Up @@ -2,6 +2,7 @@

namespace ObjectCalisthenics\Tests;

use Nette\Utils\FileSystem;
use PHP_CodeSniffer\Config;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Ruleset;
Expand Down Expand Up @@ -30,29 +31,10 @@ public function createFile(string $filePath): File
$ruleset = new Ruleset($config);

$file = new File($filePath, $ruleset, $config);
$file->setContent(file_get_contents($filePath));
$fileContent = FileSystem::read($filePath);
$file->setContent($fileContent);
$file->parse();

return $file;
}

public function createFileWithSniffClass(string $filePath, string $sniffClass): File
{
$config = new Config;
$ruleset = $this->createRulesetWithConfigAndSniffClass($sniffClass, $config);

$file = new File($filePath, $ruleset, $config);
$file->setContent(file_get_contents($filePath));
$file->parse();

return $file;
}

private function createRulesetWithConfigAndSniffClass(string $sniffClass, Config $config): Ruleset
{
$config->sniffs = [$sniffClass];
$config->standards = ['ObjectCalisthenics'];

return new Ruleset($config);
}
}

0 comments on commit 2af78d0

Please sign in to comment.