Skip to content

Commit 239bd98

Browse files
DemigodCodebobthecow
authored andcommitted
Update to PHP8
1 parent 5e78cc3 commit 239bd98

25 files changed

+61
-190
lines changed

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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: ['7.4', '8.0', '8.1', '8.2']
1818

1919
steps:
2020
- uses: actions/checkout@v3

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"homepage": "https://github.com/bobthecow/Ruler",
66
"license": "MIT",
77
"require": {
8-
"php": ">=5.3.0"
8+
"php": ">=8.0"
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": {

src/Ruler/Context.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct(array $values = array())
7373
*
7474
* @return boolean
7575
*/
76-
public function offsetExists($name)
76+
public function offsetExists($name): bool
7777
{
7878
return isset($this->keys[$name]);
7979
}
@@ -87,7 +87,7 @@ public function offsetExists($name)
8787
*
8888
* @throws InvalidArgumentException if the name is not defined
8989
*/
90-
public function offsetGet($name)
90+
public function offsetGet($name): mixed
9191
{
9292
if (!$this->offsetExists($name)) {
9393
throw new \InvalidArgumentException(sprintf('Fact "%s" is not defined.', $name));
@@ -123,7 +123,7 @@ public function offsetGet($name)
123123
*
124124
* @throws RuntimeException if a frozen fact overridden
125125
*/
126-
public function offsetSet($name, $value)
126+
public function offsetSet($name, $value): void
127127
{
128128
if (isset($this->frozen[$name])) {
129129
throw new \RuntimeException(sprintf('Cannot override frozen fact "%s".', $name));
@@ -138,7 +138,7 @@ public function offsetSet($name, $value)
138138
*
139139
* @param string $name The unique name for the fact
140140
*/
141-
public function offsetUnset($name)
141+
public function offsetUnset($name): void
142142
{
143143
if ($this->offsetExists($name)) {
144144
$value = $this->values[$name];

src/Ruler/Operator/Contains.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/Ruler/RuleBuilder.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function logicalXor(Proposition $prop, Proposition $prop2 = null)
117117
*
118118
* @return boolean
119119
*/
120-
public function offsetExists($name)
120+
public function offsetExists($name): bool
121121
{
122122
return isset($this->variables[$name]);
123123
}
@@ -129,7 +129,7 @@ public function offsetExists($name)
129129
*
130130
* @return Variable
131131
*/
132-
public function offsetGet($name)
132+
public function offsetGet($name): Variable
133133
{
134134
if (!isset($this->variables[$name])) {
135135
$this->variables[$name] = new RuleBuilder\Variable($this, $name);
@@ -143,10 +143,8 @@ public function offsetGet($name)
143143
*
144144
* @param string $name The Variable name
145145
* @param mixed $value The Variable default value
146-
*
147-
* @return Variable
148146
*/
149-
public function offsetSet($name, $value)
147+
public function offsetSet($name, $value): void
150148
{
151149
$this->offsetGet($name)->setValue($value);
152150
}
@@ -156,7 +154,7 @@ public function offsetSet($name, $value)
156154
*
157155
* @param string $name The Variable name
158156
*/
159-
public function offsetUnset($name)
157+
public function offsetUnset($name): void
160158
{
161159
unset($this->variables[$name]);
162160
}

src/Ruler/RuleBuilder/Variable.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function getProperty($name, $value = null)
8383
*
8484
* @return bool
8585
*/
86-
public function offsetExists($name)
86+
public function offsetExists($name): bool
8787
{
8888
return isset($this->properties[$name]);
8989
}
@@ -97,7 +97,7 @@ public function offsetExists($name)
9797
*
9898
* @return VariableProperty
9999
*/
100-
public function offsetGet($name)
100+
public function offsetGet($name): VariableProperty
101101
{
102102
return $this->getProperty($name);
103103
}
@@ -110,7 +110,7 @@ public function offsetGet($name)
110110
* @param string $name Property name
111111
* @param mixed $value The default Variable value
112112
*/
113-
public function offsetSet($name, $value)
113+
public function offsetSet($name, $value): void
114114
{
115115
$this->getProperty($name)->setValue($value);
116116
}
@@ -120,7 +120,7 @@ public function offsetSet($name, $value)
120120
*
121121
* @param string $name Property name
122122
*/
123-
public function offsetUnset($name)
123+
public function offsetUnset($name): void
124124
{
125125
unset($this->properties[$name]);
126126
}

tests/Ruler/Test/ContextTest.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
namespace Ruler\Test;
2626

27+
use InvalidArgumentException;
2728
use Ruler\Context;
2829
use Ruler\Test\Fixtures\Invokable;
2930
use Ruler\Test\Fixtures\Fact;
@@ -135,12 +136,10 @@ public function testConstructorInjection()
135136
$this->assertSame($params['param'], $context['param']);
136137
}
137138

138-
/**
139-
* @expectedException InvalidArgumentException
140-
* @expectedExceptionMessage Fact "foo" is not defined.
141-
*/
142139
public function testOffsetGetValidatesKeyIsPresent()
143140
{
141+
$this->expectException(InvalidArgumentException::class);
142+
$this->expectExceptionMessage('Fact "foo" is not defined.');
144143
$context = new Context();
145144
echo $context['foo'];
146145
}
@@ -214,12 +213,10 @@ public function testRawHonorsNullValues()
214213
$this->assertNull($context->raw('foo'));
215214
}
216215

217-
/**
218-
* @expectedException InvalidArgumentException
219-
* @expectedExceptionMessage Fact "foo" is not defined.
220-
*/
221216
public function testRawValidatesKeyIsPresent()
222217
{
218+
$this->expectException(InvalidArgumentException::class);
219+
$this->expectExceptionMessage('Fact "foo" is not defined.');
223220
$context = new Context();
224221
$context->raw('foo');
225222
}
@@ -253,22 +250,22 @@ public function settingNonInvokableObjectShouldTreatItAsParameter()
253250

254251
/**
255252
* @dataProvider badFactDefinitionProvider
256-
* @expectedException InvalidArgumentException
257-
* @expectedExceptionMessage Value is not a Closure or invokable object.
258253
*/
259254
public function testShareFailsForInvalidFactDefinitions($fact)
260255
{
256+
$this->expectException(InvalidArgumentException::class);
257+
$this->expectExceptionMessage('Value is not a Closure or invokable object.');
261258
$context = new Context();
262259
$context->share($fact);
263260
}
264261

265262
/**
266263
* @dataProvider badFactDefinitionProvider
267-
* @expectedException InvalidArgumentException
268-
* @expectedExceptionMessage Callable is not a Closure or invokable object.
269264
*/
270265
public function testProtectFailsForInvalidFactDefinitions($fact)
271266
{
267+
$this->expectException(InvalidArgumentException::class);
268+
$this->expectExceptionMessage('Callable is not a Closure or invokable object.');
272269
$context = new Context();
273270
$context->protect($fact);
274271
}

tests/Ruler/Test/Operator/AdditionTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ public function testInterface()
1818
$this->assertInstanceOf('Ruler\\VariableOperand', $op);
1919
}
2020

21-
/**
22-
* @expectedException \RuntimeException
23-
* @expectedExceptionMessage Arithmetic: values must be numeric
24-
*/
2521
public function testInvalidData()
2622
{
23+
$this->expectException(\RuntimeException::class);
24+
$this->expectExceptionMessage('Arithmetic: values must be numeric');
2725
$varA = new Variable('a', "string");
2826
$varB = new Variable('b', "blah");
2927
$context = new Context();

tests/Ruler/Test/Operator/CeilTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ public function testInterface()
1717
$this->assertInstanceOf('Ruler\\VariableOperand', $op);
1818
}
1919

20-
/**
21-
* @expectedException \RuntimeException
22-
* @expectedExceptionMessage Arithmetic: values must be numeric
23-
*/
2420
public function testInvalidData()
2521
{
22+
$this->expectException(\RuntimeException::class);
23+
$this->expectExceptionMessage('Arithmetic: values must be numeric');
2624
$varA = new Variable('a', "string");
2725
$context = new Context();
2826

tests/Ruler/Test/Operator/DivisionTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ public function testInterface()
1818
$this->assertInstanceOf('Ruler\\VariableOperand', $op);
1919
}
2020

21-
/**
22-
* @expectedException \RuntimeException
23-
* @expectedExceptionMessage Arithmetic: values must be numeric
24-
*/
2521
public function testInvalidData()
2622
{
23+
$this->expectException(\RuntimeException::class);
24+
$this->expectExceptionMessage('Arithmetic: values must be numeric');
2725
$varA = new Variable('a', "string");
2826
$varB = new Variable('b', "blah");
2927
$context = new Context();
@@ -32,12 +30,10 @@ public function testInvalidData()
3230
$op->prepareValue($context);
3331
}
3432

35-
/**
36-
* @expectedException \RuntimeException
37-
* @expectedExceptionMessage Division by zero
38-
*/
3933
public function testDivideByZero()
4034
{
35+
$this->expectException(\RuntimeException::class);
36+
$this->expectExceptionMessage('Division by zero');
4137
$varA = new Variable('a', rand(1, 100));
4238
$varB = new Variable('b', 0);
4339
$context = new Context();

0 commit comments

Comments
 (0)