Skip to content

Commit 4b30b3d

Browse files
authored
Use PHP 8.4 features (#22)
* Use PHP 8.1 features * Use PHP 8.1 features * Use PHP 8.1 features * Use PHP 8.1 features * Use PHP 8.1 features * Use PHP 8.1 features * Use PHP 8.1 features * Use PHP 8.1 features * Change email * Update PHPUnit and fix tests * Refactor * Fix type * Update for v12
1 parent ea8e71f commit 4b30b3d

File tree

163 files changed

+1618
-1408
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+1618
-1408
lines changed

.github/workflows/phpqa.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ jobs:
88
steps:
99
- uses: actions/checkout@master
1010
- name: PHPStan
11-
uses: docker://jakzal/phpqa:php8.0-alpine
11+
uses: docker://jakzal/phpqa:php8.4
1212
with:
1313
args: phpstan analyze src/ -l 1
1414
- name: PHP-CS-Fixer
15-
uses: docker://jakzal/phpqa:php8.0-alpine
15+
uses: docker://jakzal/phpqa:php8.4
1616
with:
1717
args: php-cs-fixer --dry-run --allow-risky=yes --no-interaction --ansi fix
1818
- name: Deptrac
19-
uses: docker://jakzal/phpqa:php8.0-alpine
19+
uses: docker://jakzal/phpqa:php8.4
2020
with:
2121
args: deptrac --no-interaction --ansi --formatter-graphviz-display=0

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
/coverage.clover
44
/.phpunit.result.cache
55
/vendor/
6+
/.idea
7+
/.composer

.scrutinizer.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ tools:
3535
enabled: true
3636
excluded_dirs: [tests]
3737
build:
38+
image: default-bionic
3839
environment:
39-
php: 8.0.1
40+
php: 8.4.0
4041
nodes:
4142
analysis:
4243
tests:

.styleci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
---
22
preset: psr2
33
risky: true
4-
version: 8
4+
version: 8.4
55
finder:
66
name:
77
- "*.php"
88
enabled:
99
- short_array_syntax
1010
- cast_spaces
11+
disabled:
12+
- lowercase_constants

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: php
22

33
php:
4-
- 8.0
4+
- 8.4
55

66
script:
77
- composer install --dev

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
## PHP Rule Engine
22

3-
43
[![Latest Stable Version](https://travis-ci.org/nicoSWD/php-rule-parser.svg?branch=master)](https://travis-ci.org/nicoSWD/php-rule-parser)
54
[![Build status][Master coverage image]][Master coverage]
65
[![Code Quality][Master quality image]][Master quality]
@@ -13,13 +12,10 @@ You're looking at a standalone PHP library to parse and evaluate text based rule
1312

1413
This library has initially been used to change and configure the behavior of certain "Workflows" (without changing actual code) in an intranet application, but it may serve a purpose elsewhere.
1514

16-
1715
Find me on Twitter: @[nicoSWD](https://twitter.com/nicoSWD)
1816

1917
(If you're using PHP 5, you might want to take a look at [version 0.4.0](https://github.com/nicoSWD/php-rule-parser/tree/0.4.0))
2018

21-
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/67203389-970c-419c-9430-a7f9a005bd94/big.png)](https://insight.sensiolabs.com/projects/67203389-970c-419c-9430-a7f9a005bd94)
22-
2319
## Install
2420

2521
Via Composer
@@ -40,32 +36,36 @@ This library works best with one of these bundles below, but they're not require
4036

4137
Test if a value is in a given array
4238
```php
43-
$variables = ['foo' => 6];
39+
$variables = [
40+
'coupon_code' => (string) $_POST['coupon_code'],
41+
];
4442

45-
$rule = new Rule('foo in [4, 6, 7]', $variables);
43+
$rule = new Rule('coupon_code in ["summer_discount", "summer21"]', $variables);
4644
var_dump($rule->isTrue()); // bool(true)
4745
```
4846

49-
Simple array manipulation
47+
Performing a regular expression
5048
```php
51-
$rule = new Rule('[1, 4, 3].join(".") === "1.4.3"');
49+
$variables = [
50+
'coupon_code' => (string) $_POST['coupon_code'],
51+
];
52+
53+
$rule = new Rule('coupon_code.test(/^summer20[0-9]{2}$/) == true', $variables);
5254
var_dump($rule->isTrue()); // bool(true)
5355
```
5456

5557
Test if a value is between a given range
5658
```php
57-
$variables = ['threshold' => 80];
59+
$variables = ['points' => 80];
5860

59-
$rule = new Rule('threshold >= 50 && threshold <= 100', $variables);
61+
$rule = new Rule('points >= 50 && points <= 100', $variables);
6062
var_dump($rule->isTrue()); // bool(true)
6163
```
6264

6365
Call methods on objects from within rules
6466
```php
6567
class User
6668
{
67-
// ...
68-
6969
public function points(): int
7070
{
7171
return 1337;
@@ -180,7 +180,7 @@ $highlighter = new Rule\Highlighter\Highlighter(new Rule\Tokenizer());
180180

181181
// Optional custom styles
182182
$highlighter->setStyle(
183-
Rule\Constants::GROUP_VARIABLE,
183+
TokenType::VARIABLE,
184184
'color: #007694; font-weight: 900;'
185185
);
186186

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{
2020
"name": "Nicolas Oelgart",
2121
"role": "Developer",
22-
"homepage": "https://nicoswd.com"
22+
"homepage": "https://nico.es"
2323
}
2424
],
2525
"autoload": {
@@ -33,11 +33,11 @@
3333
}
3434
},
3535
"require": {
36-
"php": ">=8.0"
36+
"php": ">=8.4"
3737
},
3838
"require-dev": {
39-
"phpunit/phpunit": "^7.0|^9.0",
40-
"mockery/mockery": "^1.0|^1.4"
39+
"phpunit/phpunit": "^12.3",
40+
"mockery/mockery": "^1.6"
4141
},
4242
"scripts": {
4343
"test": "vendor/bin/phpunit"

phpunit.xml.dist

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
4-
bootstrap="src/autoload.php">
5-
<coverage processUncoveredFiles="true">
6-
<include>
7-
<directory suffix=".php">src</directory>
8-
</include>
9-
</coverage>
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.3/phpunit.xsd"
4+
bootstrap="src/autoload.php"
5+
cacheDirectory=".phpunit.cache">
106
<testsuites>
117
<testsuite name="Unit tests">
128
<directory>tests/</directory>
139
</testsuite>
1410
</testsuites>
11+
<source>
12+
<include>
13+
<directory suffix=".php">src</directory>
14+
</include>
15+
</source>
1516
</phpunit>

src/Compiler/CompilerFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @license http://opensource.org/licenses/mit-license.php MIT
55
* @link https://github.com/nicoSWD
6-
* @author Nicolas Oelgart <nico@oelgart.com>
6+
* @author Nicolas Oelgart <hello@nico.es>
77
*/
88
namespace nicoSWD\Rule\Compiler;
99

src/Compiler/CompilerFactoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @license http://opensource.org/licenses/mit-license.php MIT
55
* @link https://github.com/nicoSWD
6-
* @author Nicolas Oelgart <nico@oelgart.com>
6+
* @author Nicolas Oelgart <hello@nico.es>
77
*/
88
namespace nicoSWD\Rule\Compiler;
99

0 commit comments

Comments
 (0)