Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
radek-bruha committed Aug 31, 2020
1 parent 40d7138 commit a63c437
Show file tree
Hide file tree
Showing 65 changed files with 701 additions and 1,461 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/index.yml
Expand Up @@ -9,11 +9,11 @@ jobs:
- name: Clone environment
uses: actions/checkout@v1
- name: Set up environment
uses: docker://alpine:3.10
uses: docker://alpine:edge
with:
args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && composer global require hirak/prestissimo && composer install -o --no-ansi --no-suggest"
- name: Code Style Checker
uses: docker://alpine:3.10
uses: docker://alpine:edge
with:
args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && vendor/bin/phpcs bin src tests -p --ignore=tests/*/Data/* --extensions=php --standard=ruleset.xml"
codeStaticAnalysis:
Expand All @@ -23,11 +23,11 @@ jobs:
- name: Clone environment
uses: actions/checkout@v1
- name: Set up environment
uses: docker://alpine:3.10
uses: docker://alpine:edge
with:
args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && composer global require hirak/prestissimo && composer install -o --no-ansi --no-suggest"
- name: Code Static Analysis
uses: docker://alpine:3.10
uses: docker://alpine:edge
with:
args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && vendor/bin/phpstan analyse bin src tests -c ruleset.neon -l 7"
integrationTest:
Expand All @@ -37,24 +37,24 @@ jobs:
- name: Clone environment
uses: actions/checkout@v1
- name: Set up environment
uses: docker://alpine:3.10
uses: docker://alpine:edge
with:
args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && composer global require hirak/prestissimo && composer install -o --no-ansi --no-suggest"
- name: Integration Test
uses: docker://alpine:3.10
uses: docker://alpine:edge
with:
args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && vendor/bin/phpunit tests"
args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && vendor/bin/phpunit tests && chmod +x bin/phpunit-coverage-analyzer && bin/phpunit-coverage-analyzer"
infectionTest:
name: Infection Test
runs-on: ubuntu-latest
steps:
- name: Clone environment
uses: actions/checkout@v1
- name: Set up environment
uses: docker://alpine:3.10
uses: docker://alpine:edge
with:
args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && composer global require hirak/prestissimo && composer install -o --no-ansi --no-suggest"
- name: Infection Test
uses: docker://alpine:3.10
uses: docker://alpine:edge
with:
args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && export INFECTION=INFECTION && vendor/bin/infection -j8 --only-covered --no-ansi && export INFECTION"
9 changes: 4 additions & 5 deletions .travis.yml
@@ -1,20 +1,19 @@
language: php

php:
- 7.2
- 7.3
- 7.4

before_script:
- pecl install pcov
- phpenv config-rm xdebug.ini
- composer global require hirak/prestissimo -o --no-ansi --no-suggest
- composer install -o --no-ansi --no-suggest
- vendor/bin/phpunit tests

script:
- vendor/bin/phpcs bin src tests -p --ignore=tests/*/Data/* --extensions=php --standard=ruleset.xml
- vendor/bin/phpstan analyse bin src tests -c ruleset.neon -l 7
- vendor/bin/phpcs bin src tests --ignore=Data --standard=ruleset.xml
- vendor/bin/phpstan analyse bin src tests -c ruleset.neon -l 8 --error-format custom
- vendor/bin/phpunit tests --coverage-clover build/logs/clover.xml
- chmod +x bin/phpunit-coverage-analyzer && bin/phpunit-coverage-analyzer
- export INFECTION=INFECTION && vendor/bin/infection -j8 --coverage=var/coverage --only-covered --no-ansi && export INFECTION

after_success:
Expand Down
8 changes: 8 additions & 0 deletions bin/phpunit-coverage-analyzer
@@ -0,0 +1,8 @@
#!/usr/bin/env php
<?php declare(strict_types=1);

use Bruha\CodingStandard\CustomRules\Analyzer;

require __DIR__ . (is_file(__DIR__ . '/../../../autoload.php') ? '/../../../autoload.php' : '/../vendor/autoload.php');

exit(Analyzer::phpUnitCoverage((int) ($argv[1] ?? 0), $argv[2] ?? 'var/coverage/coverage-xml/index.xml'));
73 changes: 18 additions & 55 deletions composer.json
Expand Up @@ -5,7 +5,7 @@
"type": "library",
"autoload": {
"psr-4": {
"Bruha\\CodingStandard\\": "src/"
"Bruha\\CodingStandard\\": "src"
}
},
"autoload-dev": {
Expand All @@ -16,69 +16,32 @@
},
"bin": [
"bin/phpcs-analyzer",
"bin/phpunit-analyzer"
"bin/phpunit-analyzer",
"bin/phpunit-coverage-analyzer"
],
"require": {
"php": "^7.1",
"php": "^7.4",
"ext-simplexml": "*",
"ext-tokenizer": "*",
"brianium/paratest": "^3.0",
"cweagans/composer-patches": "^1.6",
"dg/bypass-finals": "^1.1",
"infection/infection": "^0.13",
"php-mock/php-mock-phpunit": "^2.4",
"phpstan/phpstan": "^0.11",
"phpstan/phpstan-deprecation-rules": "^0.11",
"phpstan/phpstan-doctrine": "^0.11",
"phpstan/phpstan-nette": "^0.11",
"phpstan/phpstan-phpunit": "^0.11",
"phpstan/phpstan-strict-rules": "^0.11",
"phpunit/phpunit": "^8.3",
"slevomat/coding-standard": "^5.0",
"squizlabs/php_codesniffer": "^3.4",
"brianium/paratest": "^4.2",
"dg/bypass-finals": "^v1.2",
"infection/infection": "^0.16",
"php-mock/php-mock-phpunit": "^2.6",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-deprecation-rules": "^0.12",
"phpstan/phpstan-doctrine": "^0.12",
"phpstan/phpstan-nette": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^9.3",
"slevomat/coding-standard": "^6.3",
"squizlabs/php_codesniffer": "^3.5",
"stesie/phpcs-doctrine-annotation-rules": "^1.2"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.1"
"php-coveralls/php-coveralls": "^2.2"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"patches": {
"brianium/paratest": {
"Cleaning": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPParaTest.patch"
},
"infection/infection": {
"Cleaning": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPInfectionOne.patch",
"Cleaning II": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPInfectionTwo.patch",
"Cleaning III": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPInfectionThree.patch",
"Cleaning IV": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPInfectionFour.patch",
"Cleaning V": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPInfectionFive.patch",
"Cleaning VI": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPInfectionSix.patch",
"Cleaning VII": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPInfectionSeven.patch",
"Cleaning VIII": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPInfectionEight.patch",
"Cleaning IX": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPInfectionNine.patch",
"Cleaning X": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPInfectionTen.patch"
},
"phpstan/phpstan": {
"Cleaning": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPStanOne.patch",
"Cleaning II": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPStanTwo.patch"
},
"phpunit/phpunit": {
"Cleaning": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPUnitOne.patch",
"Cleaning II": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPUnitTwo.patch"
},
"squizlabs/php_codesniffer": {
"Cleaning": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPCodeSnifferOne.patch",
"Cleaning II": "vendor/radek-bruha/coding-standard/src/CustomPatches/PHPCodeSnifferTwo.patch"
},
"stesie/phpcs-doctrine-annotation-rules": {
"Cleaning": "vendor/radek-bruha/coding-standard/src/CustomPatches/DoctrineAnnotationOne.patch",
"Cleaning II": "vendor/radek-bruha/coding-standard/src/CustomPatches/DoctrineAnnotationTwo.patch"
}
}
}
}
19 changes: 9 additions & 10 deletions phpunit.xml
Expand Up @@ -4,17 +4,16 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<coverage>
<report>
<html outputDirectory='var/coverage/coverage-html'/>
<xml outputDirectory='var/coverage/coverage-xml'/>
</report>
<include>
<directory>src</directory>
</whitelist>
</filter>
</include>
</coverage>
<logging>
<log type="coverage-html" target="var/coverage/coverage-html" lowUpperBound="50" highLowerBound="75"/>
<log type="coverage-xml" target="var/coverage/coverage-xml" lowUpperBound="50" highLowerBound="75"/>
<log type="junit" target="var/coverage/phpunit.junit.xml"/>
<junit outputFile='var/coverage/junit.xml'/>
</logging>
<extensions>
<extension class="Bruha\CodingStandard\CustomHooks\PhpUnitHook"/>
</extensions>
</phpunit>
11 changes: 8 additions & 3 deletions ruleset.neon
Expand Up @@ -8,14 +8,19 @@ includes:
- ./vendor/phpstan/phpstan-strict-rules/rules.neon
- ./vendor/phpstan/phpstan-deprecation-rules/rules.neon

services:
errorFormatter.custom:
factory: Bruha\CodingStandard\CustomReports\PhpStanReport

parameters:
excludes_analyse:
- tests/*/Data/*
ignoreErrors:
- '#Constant T_ANON_CLASS not found#'
- '#Constant T_DOC_COMMENT_CLOSE_TAG not found#'
- '#Constant T_DOC_COMMENT_OPEN_TAG not found#'
- '#Constant T_DOC_COMMENT_STRING not found#'
- '#Constant T_DOC_COMMENT_TAG not found#'
- '#Constant T_DOC_COMMENT_WHITESPACE not found#'
- '#Constant T_PARENT not found#'
- '#Constant T_SEMICOLON not found#'
- '#Constant T_STRING_CONCAT not found#'
- '#Constant T_STRING_CONCAT not found#'
- '#Expression ".+" on a separate line does not do anything#'
46 changes: 26 additions & 20 deletions ruleset.xml
@@ -1,5 +1,9 @@
<?xml version='1.0'?>
<ruleset xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='./vendor/squizlabs/php_codesniffer/phpcs.xsd' name='Bruha Coding Standard'>
<arg value="p"/>
<arg name="extensions" value="php"/>
<arg name="report" value="Bruha\CodingStandard\CustomReports\PhpCodeSnifferReport"/>

<rule ref='Generic'>
<exclude name='Generic.Arrays.DisallowShortArraySyntax.Found'/>
<exclude name='Generic.Classes.OpeningBraceSameLine.BraceOnNewLine'/>
Expand All @@ -10,6 +14,7 @@
<exclude name='Generic.Commenting.DocComment.ParamNotFirst'/>
<exclude name='Generic.Commenting.DocComment.TagValueIndent'/>
<exclude name='Generic.Files.EndFileNewline.NotFound'/>
<exclude name='Generic.Files.ExecutableFile.Executable'/>
<exclude name='Generic.Files.LineEndings.InvalidEOLChar'/>
<exclude name='Generic.Files.LineLength.TooLong'/>
<exclude name='Generic.Files.LowercasedFilename.NotFound'/>
Expand Down Expand Up @@ -82,23 +87,33 @@
<exclude name='SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix'/>
<exclude name='SlevomatCodingStandard.Classes.SuperfluousTraitNaming.SuperfluousSuffix'/>
<exclude name='SlevomatCodingStandard.Commenting.EmptyComment.EmptyComment'/>
<exclude name='SlevomatCodingStandard.Commenting.RequireOneLineDocComment.MultiLineDocComment'/>
<exclude name='SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment.MultiLinePropertyComment'/>
<exclude name='SlevomatCodingStandard.Commenting.UselessFunctionDocComment.UselessDocComment'/>
<exclude name='SlevomatCodingStandard.ControlStructures.DisallowShortTernaryOperator.DisallowedShortTernaryOperator'/>
<exclude name='SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed'/>
<exclude name='SlevomatCodingStandard.ControlStructures.NewWithoutParentheses.UselessParentheses'/>
<exclude name='SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator.MultiLineTernaryOperatorNotUsed'/>
<exclude name='SlevomatCodingStandard.ControlStructures.RequireYodaComparison.RequiredYodaComparison'/>
<exclude name='SlevomatCodingStandard.Files.LineLength'/>
<exclude name='SlevomatCodingStandard.Functions.DisallowArrowFunction'/>
<exclude name='SlevomatCodingStandard.Functions.TrailingCommaInCall.MissingTrailingComma'/>
<exclude name='SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation.NonFullyQualifiedClassName'/>
<exclude name='SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions.NonFullyQualifiedException'/>
<exclude name='SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalConstants.NonFullyQualified'/>
<exclude name='SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified'/>
<exclude name='SlevomatCodingStandard.Namespaces.UseOnlyWhitelistedNamespaces.NonFullyQualified'/>
<exclude name='SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators.DisallowedPostIncrementOperator'/>
<exclude name='SlevomatCodingStandard.Numbers.DisallowNumericLiteralSeparator'/>
<exclude name='SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators.DisallowedPostDecrementOperator'/>
<exclude name='SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators.DisallowedPostIncrementOperator'/>
<exclude name='SlevomatCodingStandard.PHP.DisallowReference'/>
<exclude name='SlevomatCodingStandard.PHP.RequireExplicitAssertion.RequiredExplicitAssertion'/>
<exclude name='SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax.DisallowedArrayTypeHintSyntax'/>
<exclude name='SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax.DisallowedArrayTypeHintSyntax'/>
<exclude name='SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint.DisallowedMixedTypeHint'/>
<exclude name='SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation'/>
<exclude name='SlevomatCodingStandard.TypeHints.PropertyTypeHint.UselessAnnotation'/>
<exclude name='SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation'/>
<exclude name='SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification'/>
<exclude name='SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification'/>
<exclude name='SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification'/>
Expand All @@ -110,7 +125,7 @@
<rule ref='Generic.Metrics.CyclomaticComplexity'>
<properties>
<property name='complexity' value='15'/>
<property name='absoluteComplexity ' value='15'/>
<property name='absoluteComplexity' value='15'/>
</properties>
</rule>

Expand Down Expand Up @@ -150,24 +165,6 @@
</properties>
</rule>

<rule ref='SlevomatCodingStandard.ControlStructures.ControlStructureSpacing'>
<properties>
<property name='tokensToCheck' type='array'>
<element value='T_DO'/>
<element value='T_FOR'/>
<element value='T_FOREACH'/>
<element value='T_GOTO'/>
<element value='T_IF'/>
<element value='T_SWITCH'/>
<element value='T_THROW'/>
<element value='T_TRY'/>
<element value='T_WHILE'/>
<element value='T_YIELD'/>
<element value='T_YIELD_FROM'/>
</property>
</properties>
</rule>

<rule ref='SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly'>
<properties>
<property name='searchAnnotations' value='true'/>
Expand All @@ -187,6 +184,15 @@
</properties>
</rule>

<rule ref='SlevomatCodingStandard.Whitespaces.DuplicateSpaces'>
<properties>
<property name='ignoreSpacesBeforeAssignment' value='true'/>
<property name='ignoreSpacesInAnnotation' value='true'/>
<property name='ignoreSpacesInComment' value='true'/>
<property name='ignoreSpacesInParameters' value='true'/>
</properties>
</rule>

<rule ref='SlevomatCodingStandard.Files.TypeNameMatchesFileName'>
<properties>
<property name='rootNamespaces' type='array'>
Expand Down
8 changes: 4 additions & 4 deletions src/CustomHooks/PhpUnitHook.php
Expand Up @@ -16,19 +16,19 @@ final class PhpUnitHook implements BeforeTestHook, AfterTestHook, AfterLastTestH
{

/**
* @var array
* @var mixed[]
*/
private $tests = [];
private array $tests = [];

/**
* @var float
*/
private $time = 0.0;
private float $time = 0.0;

/**
* @var int
*/
private $count = 0;
private int $count = 0;

/**
* @param string $test
Expand Down
14 changes: 0 additions & 14 deletions src/CustomPatches/DoctrineAnnotationOne.patch

This file was deleted.

0 comments on commit a63c437

Please sign in to comment.