Skip to content

Commit fd3f0d0

Browse files
committed
Merge branch 'next'
2 parents 5e78cc3 + 9f3e2b9 commit fd3f0d0

File tree

128 files changed

+2095
-2560
lines changed

Some content is hidden

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

128 files changed

+2095
-2560
lines changed

.github/workflows/hhvm.yml

-45
This file was deleted.

.github/workflows/php.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
php-version: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.4']
17+
php-version:
18+
- '7.4'
19+
- '8.0'
20+
- '8.1'
21+
# - '8.2'
1822

1923
steps:
2024
- uses: actions/checkout@v3

.styleci.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
risky: true
2+
3+
preset: symfony
4+
5+
enabled:
6+
- align_double_arrow
7+
- native_function_invocation
8+
- ordered_use
9+
- strict
10+
11+
disabled:
12+
- native_function_invocation_symfony
13+
- no_superfluous_phpdoc_tags_symfony
14+
- pow_to_exponentiation
15+
- pre_increment
16+
- unalign_double_arrow
17+
- yoda_style
18+
19+
finder:
20+
name:
21+
- "*.php"

README.md

+20-27
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Ruler is a simple stateless production rules engine for PHP 5.3+.
55

66
[![Package version](http://img.shields.io/packagist/v/ruler/ruler.svg?style=flat-square)](https://packagist.org/packages/ruler/ruler)
77
[![Build status](https://img.shields.io/github/workflow/status/bobthecow/Ruler/Unit%20Tests/main.svg?style=flat-square)](https://github.com/bobthecow/Ruler/actions?query=branch:main)
8+
[![StyleCI](https://styleci.io/repos/1906921/shield)](https://styleci.io/repos/1906921)
89

910
Ruler has an easy, straightforward DSL
1011
--------------------------------------
@@ -23,13 +24,11 @@ $rule = $rb->create(
2324
}
2425
);
2526

26-
$context = new Context(array(
27+
$context = new Context([
2728
'minNumPeople' => 5,
2829
'maxNumPeople' => 25,
29-
'actualNumPeople' => function() {
30-
return 6;
31-
},
32-
));
30+
'actualNumPeople' => fn() => 6,
31+
]);
3332

3433
$rule->execute($context); // "Yay!"
3534
```
@@ -42,22 +41,20 @@ $rule->execute($context); // "Yay!"
4241
```php
4342
$actualNumPeople = new Variable('actualNumPeople');
4443
$rule = new Rule(
45-
new Operator\LogicalAnd(array(
44+
new Operator\LogicalAnd([
4645
new Operator\LessThanOrEqualTo(new Variable('minNumPeople'), $actualNumPeople),
4746
new Operator\GreaterThanOrEqualTo(new Variable('maxNumPeople'), $actualNumPeople)
48-
)),
47+
]),
4948
function() {
5049
echo 'YAY!';
5150
}
5251
);
5352

54-
$context = new Context(array(
53+
$context = new Context([
5554
'minNumPeople' => 5,
5655
'maxNumPeople' => 25,
57-
'actualNumPeople' => function() {
58-
return 6;
59-
},
60-
));
56+
'actualNumPeople' => fn() => 6,
57+
]);
6158

6259
$rule->execute($context); // "Yay!"
6360
```
@@ -165,10 +162,10 @@ $eitherOne = $rb->create($rb->logicalOr($aEqualsB, $aDoesNotEqualB));
165162

166163
// Just to mix things up, we'll populate our evaluation context with completely
167164
// random values...
168-
$context = new Context(array(
165+
$context = new Context([
169166
'a' => rand(),
170167
'b' => rand(),
171-
));
168+
]);
172169

173170
// Hint: this is always true!
174171
$eitherOne->evaluate($context);
@@ -190,11 +187,9 @@ $rb->logicalXor($aEqualsB, $aDoesNotEqualB); // True if only one condition is tr
190187
`evaluate()` a Rule with Context to figure out whether it is true.
191188

192189
```php
193-
$context = new Context(array(
194-
'userName' => function() {
195-
return isset($_SESSION['userName']) ? $_SESSION['userName'] : null;
196-
}
197-
));
190+
$context = new Context([
191+
'userName' => fn() => $_SESSION['userName'] ?? null,
192+
]);
198193

199194
$userIsLoggedIn = $rb->create($rb['userName']->notEqualTo(null));
200195

@@ -238,7 +233,7 @@ $hiEveryoneElse = $rb->create(
238233
}
239234
);
240235

241-
$rules = new RuleSet(array($hiJustin, $hiJon, $hiEveryoneElse));
236+
$rules = new RuleSet([$hiJustin, $hiJon, $hiEveryoneElse]);
242237

243238
// Let's add one more Rule, so non-authenticated users have a chance to log in
244239
$redirectForAuthentication = $rb->create($rb->logicalNot($userIsLoggedIn), function() {
@@ -271,12 +266,10 @@ Rules.
271266
$context = new Context;
272267

273268
// Some static values...
274-
$context['reallyAnnoyingUsers'] = array('bobthecow', 'jwage');
269+
$context['reallyAnnoyingUsers'] = ['bobthecow', 'jwage'];
275270

276271
// You'll remember this one from before
277-
$context['userName'] = function() {
278-
return isset($_SESSION['userName']) ? $_SESSION['userName'] : null;
279-
};
272+
$context['userName'] = fn() => $_SESSION['userName'] ?? null;
280273

281274
// Let's pretend you have an EntityManager named `$em`...
282275
$context['user'] = function() use ($em, $context) {
@@ -333,7 +326,7 @@ $context['userRoles'] = function() use ($em, $context) {
333326
return $user->roles();
334327
} else {
335328
// return a default "anonymous" role if there is no current user
336-
return array('anonymous');
329+
return ['anonymous'];
337330
}
338331
};
339332

@@ -365,7 +358,7 @@ their convenient RuleBuilder interface:
365358
// We can skip over the Context Variable building above. We'll simply set our,
366359
// default roles on the VariableProperty itself, then go right to writing rules:
367360

368-
$rb['user']['roles'] = array('anonymous');
361+
$rb['user']['roles'] = ['anonymous'];
369362

370363
$rb->create(
371364
$rb->logicalAnd(
@@ -410,7 +403,7 @@ use Ruler\Value;
410403

411404
class ALotGreaterThan extends VariableOperator implements Proposition
412405
{
413-
public function evaluate(Context $context)
406+
public function evaluate(Context $context): bool
414407
{
415408
list($left, $right) = $this->getOperands();
416409
$value = $right->prepareValue($context)->getValue() * 10;

composer.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"name": "ruler/ruler",
3-
"description": "A simple stateless production rules engine for PHP 5.3.",
3+
"description": "A simple stateless production rules engine for modern PHP.",
44
"keywords": ["rules", "engine"],
55
"homepage": "https://github.com/bobthecow/Ruler",
66
"license": "MIT",
77
"require": {
8-
"php": ">=5.3.0"
8+
"php": ">=7.4"
99
},
1010
"require-dev": {
11-
"phpunit/phpunit": "4.8.35 | ^5.6.3 | ^6.5"
11+
"phpunit/phpunit": "^8.5.12 | ^9"
1212
},
1313
"autoload": {
1414
"psr-4": {
15-
"Ruler\\": "src/Ruler"
15+
"Ruler\\": "src/"
1616
}
1717
},
1818
"autoload-dev": {
1919
"psr-4": {
20-
"Ruler\\Test\\": "tests/Ruler/Test"
20+
"Ruler\\Test\\": "tests/"
2121
}
2222
},
2323
"authors": [

phpunit.xml.dist

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="./tests/bootstrap.php" colors="true">
3+
<phpunit bootstrap="./vendor/autoload.php" colors="true">
44
<testsuites>
55
<testsuite name="Ruler Test Suite">
6-
<directory suffix="Test.php">./tests/Ruler/Test/</directory>
6+
<directory suffix="Test.php">./tests/</directory>
77
</testsuite>
88
</testsuites>
99

1010
<filter>
1111
<whitelist>
12-
<directory suffix=".php">./src/Ruler/</directory>
12+
<directory suffix=".php">./src/</directory>
1313
</whitelist>
1414
</filter>
1515
</phpunit>

0 commit comments

Comments
 (0)