diff --git a/.editorconfig b/.editorconfig index a882442..4d165c2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,3 +5,6 @@ end_of_line = lf insert_final_newline = true indent_style = space indent_size = 4 + +[*.yml,*.yaml] +indent_size = 2 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..cefe791 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,32 @@ +name: Lint PHP Source Code + +on: + push: + branches: + - '**' + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Run linter + run: composer run-script lint diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml new file mode 100644 index 0000000..918406d --- /dev/null +++ b/.github/workflows/unit-test.yml @@ -0,0 +1,41 @@ +name: Unit Test + +on: + push: + branches: + - '**' + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Run test suite + run: composer run-script test:ci + + - name: Archive coverage results + uses: actions/upload-artifact@v2 + with: + name: code-coverage-report + path: cache/coverage diff --git a/README.md b/README.md index e630fe0..ebf7a8b 100644 --- a/README.md +++ b/README.md @@ -1 +1,21 @@ # An unofficial PHP implementation of JsonLogic + +### Usage + +- For an one-time logic to data use case, the `apply` function is enough: + + ```php + echo \JsonLogic\JsonLogic::apply($rule, $data); + ``` + +- For a rule runs tons times, e.g. find matched records in daily logs: + + ```php + $rule = \JsonLogic\JsonLogic::rule($rule); + + var_dump( + array_filter($logs, function ($log) use ($rule) { + return $rule->process($log); + }) + ); + ``` diff --git a/composer.json b/composer.json index 3615899..9a27eb5 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ }, "scripts": { "lint": "phpcs", - "test": "phpunit" + "test": "phpunit --stop-on-failure --no-coverage --colors=auto", + "test:ci": "phpunit --disallow-test-output -c phpunit.xml.dist" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f04479b..c8aa7a7 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,13 +3,9 @@ backupGlobals="false" backupStaticAttributes="false" bootstrap="tests/bootstrap.php" - colors="false" - convertErrorsToExceptions="true" - convertNoticesToExceptions="true" - convertWarningsToExceptions="true" - processIsolation="false" - stopOnFailure="false" cacheResultFile="cache/.phpunit.result.cache" + failOnRisky="true" + failOnWarning="true" > @@ -21,4 +17,11 @@ ./src/ + + + + + + + diff --git a/src/Fallbacks.php b/src/Fallbacks.php index c29fb69..1fa04d7 100644 --- a/src/Fallbacks.php +++ b/src/Fallbacks.php @@ -15,6 +15,8 @@ /** * For fully fallback to official JsonLogic lib + * + * phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps */ trait Fallbacks {