Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4

[*.yml,*.yaml]
indent_size = 2
32 changes: 32 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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);
})
);
```
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
15 changes: 9 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<testsuites>
<testsuite name="Json Logic Test Suite">
Expand All @@ -21,4 +17,11 @@
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="cache/coverage/report" lowUpperBound="35" highLowerBound="70" />
<log type="coverage-clover" target="cache/coverage/coverage.xml" />
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false" />
<log type="junit" target="cache/coverage/junit.xml" />
<log type="testdox-text" target="cache/coverage/testdox.txt" />
</logging>
</phpunit>
2 changes: 2 additions & 0 deletions src/Fallbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

/**
* For fully fallback to official JsonLogic lib
*
* phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
*/
trait Fallbacks
{
Expand Down