Skip to content

Commit 89b6545

Browse files
authored
Release for PHP 8 (#20)
* Require PHP >= 8.0 * Add not in token type * Separate booleans into two different tokens to fix token overriding bug * Cleanup * Fix phpstan issues
1 parent 14e958e commit 89b6545

Some content is hidden

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

68 files changed

+416
-483
lines changed

.scrutinizer.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ tools:
3535
enabled: true
3636
excluded_dirs: [tests]
3737
build:
38+
environment:
39+
php: 8.0.1
3840
nodes:
3941
analysis:
4042
tests:

.styleci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
preset: psr2
33
risky: true
4+
version: 8
45
finder:
56
name:
67
- "*.php"

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ php:
55
- 7.2
66
- 7.3
77
- 7.4
8+
- 8.0
89

910
script:
1011
- composer install --dev

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## PHP Rule Engine for PHP 7
1+
## PHP Rule Engine
22

33

44
[![Latest Stable Version](https://travis-ci.org/nicoSWD/php-rule-parser.svg?branch=master)](https://travis-ci.org/nicoSWD/php-rule-parser)

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nicoswd/php-rule-parser",
33
"type": "library",
4-
"description": "PHP 7 Rule Engine - Rule Parser & Evaluator",
4+
"description": "Rule Engine - Rule Parser & Evaluator",
55
"keywords": [
66
"rule",
77
"parser",
@@ -33,7 +33,7 @@
3333
}
3434
},
3535
"require": {
36-
"php": ">=7.1"
36+
"php": ">=8.0"
3737
},
3838
"require-dev": {
3939
"phpunit/phpunit": "^7.0|^9.0",

phpunit.xml.dist

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

src/Compiler/StandardCompiler.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,18 @@
1515

1616
class StandardCompiler implements CompilerInterface
1717
{
18-
const BOOL_TRUE = '1';
19-
const BOOL_FALSE = '0';
18+
private const BOOL_TRUE = '1';
19+
private const BOOL_FALSE = '0';
2020

21-
const LOGICAL_AND = '&';
22-
const LOGICAL_OR = '|';
21+
private const LOGICAL_AND = '&';
22+
private const LOGICAL_OR = '|';
2323

24-
const OPENING_PARENTHESIS = '(';
25-
const CLOSING_PARENTHESIS = ')';
24+
private const OPENING_PARENTHESIS = '(';
25+
private const CLOSING_PARENTHESIS = ')';
2626

27-
/** @var string */
28-
private $output = '';
29-
/** @var int */
30-
private $openParenthesis = 0;
31-
/** @var int */
32-
private $closedParenthesis = 0;
27+
private string $output = '';
28+
private int $openParenthesis = 0;
29+
private int $closedParenthesis = 0;
3330

3431
public function getCompiledRule(): string
3532
{
@@ -48,6 +45,7 @@ private function openParenthesis(): void
4845
$this->output .= self::OPENING_PARENTHESIS;
4946
}
5047

48+
/** @throws ParserException */
5149
private function closeParenthesis(): void
5250
{
5351
if ($this->openParenthesis < 1) {
@@ -58,6 +56,7 @@ private function closeParenthesis(): void
5856
$this->output .= self::CLOSING_PARENTHESIS;
5957
}
6058

59+
/** @throws ParserException */
6160
public function addParentheses(BaseToken $token): void
6261
{
6362
if ($token instanceof TokenOpeningParenthesis) {
@@ -70,6 +69,7 @@ public function addParentheses(BaseToken $token): void
7069
}
7170
}
7271

72+
/** @throws ParserException */
7373
public function addLogical(BaseToken $token): void
7474
{
7575
$lastChar = $this->getLastChar();
@@ -85,6 +85,7 @@ public function addLogical(BaseToken $token): void
8585
}
8686
}
8787

88+
/** @throws MissingOperatorException */
8889
public function addBoolean(bool $bool): void
8990
{
9091
$lastChar = $this->getLastChar();
@@ -105,26 +106,24 @@ private function isIncompleteCondition(): bool
105106
{
106107
$lastChar = $this->getLastChar();
107108

108-
return (
109+
return
109110
$lastChar === self::LOGICAL_AND ||
110-
$lastChar === self::LOGICAL_OR
111-
);
111+
$lastChar === self::LOGICAL_OR;
112112
}
113113

114114
private function expectOpeningParenthesis(): bool
115115
{
116116
$lastChar = $this->getLastChar();
117117

118-
return (
118+
return
119119
$lastChar === '' ||
120120
$lastChar === self::LOGICAL_AND ||
121121
$lastChar === self::LOGICAL_OR ||
122-
$lastChar === self::OPENING_PARENTHESIS
123-
);
122+
$lastChar === self::OPENING_PARENTHESIS;
124123
}
125124

126125
private function getLastChar(): string
127126
{
128-
return substr($this->output, -1);
127+
return substr($this->output, offset: -1);
129128
}
130129
}

src/Evaluator/Evaluator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
final class Evaluator implements EvaluatorInterface
1111
{
12-
const LOGICAL_AND = '&';
13-
const LOGICAL_OR = '|';
12+
private const LOGICAL_AND = '&';
13+
private const LOGICAL_OR = '|';
1414

15-
const BOOL_TRUE = '1';
16-
const BOOL_FALSE = '0';
15+
private const BOOL_TRUE = '1';
16+
private const BOOL_FALSE = '0';
1717

1818
public function evaluate(string $group): bool
1919
{
@@ -25,8 +25,8 @@ public function evaluate(string $group): bool
2525
'~\(([^()]+)\)~',
2626
$evalGroup,
2727
$group,
28-
-1,
29-
$count
28+
limit: -1,
29+
count: $count
3030
);
3131
} while ($count > 0);
3232

src/Expression/BaseExpression.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
*/
88
namespace nicoSWD\Rule\Expression;
99

10+
use nicoSWD\Rule\Parser\Exception\ParserException;
11+
1012
abstract class BaseExpression
1113
{
12-
/**
13-
* @param mixed $leftValue
14-
* @param mixed $rightValue
15-
* @return bool
16-
*/
17-
abstract public function evaluate($leftValue, $rightValue): bool;
14+
/** @throws ParserException */
15+
abstract public function evaluate(mixed $leftValue, mixed $rightValue): bool;
1816
}

src/Expression/EqualExpression.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
final class EqualExpression extends BaseExpression
1111
{
12-
public function evaluate($leftValue, $rightValue): bool
12+
public function evaluate(mixed $leftValue, mixed $rightValue): bool
1313
{
1414
return $leftValue == $rightValue;
1515
}

0 commit comments

Comments
 (0)