Skip to content

Commit

Permalink
Merge pull request #12 from LinioIT/feat/upgrade-to-php81
Browse files Browse the repository at this point in the history
feat: support to php 8.1
  • Loading branch information
klaussilveira authored Dec 29, 2022
2 parents 98ab9aa + ce65677 commit 6fbe474
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 16 deletions.
41 changes: 41 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests');

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit60Migration:risky' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_opening_tag' => true,
'concat_space' => ['spacing' => 'one'],
'declare_strict_types' => true,
'global_namespace_import' => ['import_classes' => true],
'increment_style' => ['style' => 'post'],
'list_syntax' => ['syntax' => 'short'],
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'method_chaining_indentation' => true,
'modernize_types_casting' => true,
'multiline_whitespace_before_semicolons' => true,
'no_superfluous_elseif' => true,
'no_superfluous_phpdoc_tags' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => true,
'phpdoc_align' => false,
'phpdoc_order' => true,
'php_unit_construct' => true,
'php_unit_dedicate_assert' => true,
'return_assignment' => true,
'single_line_comment_style' => true,
'ternary_to_null_coalescing' => true,
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
'void_return' => false,
])
->setFinder($finder)
->setUsingCache(true)
->setRiskyAllowed(true);
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"type": "library",
"license": "BSD-3-Clause",
"require": {
"php": "^7.4",
"linio/common": "^3.0"
"php": "^8.1",
"linio/common": "^4.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"phpstan/phpstan": "^0.12",
"friendsofphp/php-cs-fixer": "^3.0",
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^9.0",
"phpspec/prophecy-phpunit": "^2.0"
},
Expand All @@ -20,8 +20,8 @@
}
},
"scripts": {
"lint": "php-cs-fixer fix --verbose --show-progress=estimating",
"lint:check": "php-cs-fixer fix --dry-run --verbose --show-progress=estimating",
"lint": "php-cs-fixer fix --verbose --show-progress=dots",
"lint:check": "php-cs-fixer fix --dry-run --verbose --show-progress=dots",
"phpunit": "phpunit",
"phpstan": "phpstan analyze",
"test": [
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ parameters:
paths:
- src
ignoreErrors:
- '#evaluate\(\) has no return typehint specified#'
- '#evaluate\(\) has no return type specified#'
1 change: 1 addition & 0 deletions src/Ast/ComparisonOperationNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class ComparisonOperationNode extends OperationNode
{
/** @return bool */
public function evaluate()
{
switch ($this->operator) {
Expand Down
2 changes: 1 addition & 1 deletion src/Ast/CompileNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function setContext(Dictionary $context): void
$this->context = $context;
}

public function evaluate()
public function evaluate(): mixed
{
foreach ($this->children as $child) {
$child->evaluate();
Expand Down
2 changes: 1 addition & 1 deletion src/Ast/GetVariableExpressionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(string $key)
$this->key = $key;
}

public function evaluate()
public function evaluate(): mixed
{
return $this->getContext()->get($this->key);
}
Expand Down
1 change: 1 addition & 0 deletions src/Ast/IfControlNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function __construct(Node $condition, Node $statement)
$this->statement = $statement;
}

/** @return bool */
public function evaluate()
{
if ($this->condition->evaluate()) {
Expand Down
1 change: 1 addition & 0 deletions src/Ast/IfElseControlNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function __construct(array $conditionalExpressions, Node $elseStatement =
$this->elseStatement = $elseStatement;
}

/** @return void */
public function evaluate()
{
foreach ($this->conditionalExpressions as $conditionalExpression) {
Expand Down
1 change: 1 addition & 0 deletions src/Ast/LogicalOperationNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class LogicalOperationNode extends OperationNode
{
/** @return bool */
public function evaluate()
{
switch ($this->operator) {
Expand Down
1 change: 1 addition & 0 deletions src/Ast/MathOperationNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class MathOperationNode extends OperationNode
{
/** @return float|int */
public function evaluate()
{
switch ($this->operator) {
Expand Down
1 change: 1 addition & 0 deletions src/Ast/ScalarNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function __construct($value)
$this->value = $value;
}

/** @return scalar */
public function evaluate()
{
return $this->value;
Expand Down
1 change: 1 addition & 0 deletions src/Ast/SetVariableExpressionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function __construct(string $key, Node $value)
$this->value = $value;
}

/** @return void */
public function evaluate()
{
$this->getContext()->set($this->key, $this->value->evaluate());
Expand Down
1 change: 1 addition & 0 deletions src/Ast/StackedExpressionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function __construct(array $stack)
$this->stack = $stack;
}

/** @return void */
public function evaluate()
{
foreach ($this->stack as $stack) {
Expand Down
2 changes: 1 addition & 1 deletion src/Interpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function parse(string $inputString): CompileNode
return $this->parser->parse($inputString);
}

public function evaluate(string $inputString, Dictionary $context)
public function evaluate(string $inputString, Dictionary $context): mixed
{
$node = $this->parser->parse($inputString);
$node->setContext($context);
Expand Down
3 changes: 2 additions & 1 deletion tests/Ast/ComparisonOperationNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Linio\Component\RuleEngine\Ast;

use PHPUnit\Framework\TestCase;
use RuntimeException;

class ComparisonOperationNodeTest extends TestCase
{
Expand Down Expand Up @@ -64,7 +65,7 @@ public function testIsComparingLowerThanOrEqual(): void

public function testIsDetectingBadOperator(): void
{
$this->expectException(\RuntimeException::class);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Undefined comparison operator: XUL');

$node = new ComparisonOperationNode('XUL', new ScalarNode(1), new ScalarNode(1));
Expand Down
3 changes: 2 additions & 1 deletion tests/Ast/LogicalOperationNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Linio\Component\RuleEngine\Ast;

use PHPUnit\Framework\TestCase;
use RuntimeException;

class LogicalOperationNodeTest extends TestCase
{
Expand Down Expand Up @@ -34,7 +35,7 @@ public function testOr(): void

public function testIsDetectingBadOperator(): void
{
$this->expectException(\RuntimeException::class);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Undefined logical operator: XUL');

$node = new LogicalOperationNode('XUL', new ScalarNode(true), new ScalarNode(true));
Expand Down
3 changes: 2 additions & 1 deletion tests/Ast/MathOperationNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Linio\Component\RuleEngine\Ast;

use PHPUnit\Framework\TestCase;
use RuntimeException;

class MathOperationNodeTest extends TestCase
{
Expand Down Expand Up @@ -40,7 +41,7 @@ public function testIsRaisingToThePowerOf(): void

public function testIsDetectingBadOperator(): void
{
$this->expectException(\RuntimeException::class);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Undefined operator: XUL');

$node = new MathOperationNode('XUL', new ScalarNode(1), new ScalarNode(1));
Expand Down
5 changes: 3 additions & 2 deletions tests/Parser/Blockly/ControlsIfBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use SimpleXMLElement;

class ControlsIfBlockTest extends TestCase
{
Expand Down Expand Up @@ -62,7 +63,7 @@ public function testIsBuildingSimpleIfNode(): void

$block = new ControlsIfBlock();
$block->setParser($parser->reveal());
$node = $block->getNode($root, new \SimpleXmlElement($xml));
$node = $block->getNode($root, new SimpleXMLElement($xml));
$this->assertInstanceOf(StackedExpressionNode::class, $node);
$node->evaluate();
}
Expand Down Expand Up @@ -161,7 +162,7 @@ public function testIsBuildingCompoundIfNode(): void

$block = new ControlsIfBlock();
$block->setParser($parser->reveal());
$node = $block->getNode($root, new \SimpleXmlElement($xml));
$node = $block->getNode($root, new SimpleXMLElement($xml));
$this->assertInstanceOf(StackedExpressionNode::class, $node);
$node->evaluate();
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Parser/BlocklyXmlParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Linio\Component\RuleEngine\Parser;

use PHPUnit\Framework\TestCase;
use RuntimeException;

class BlocklyXmlParserTest extends TestCase
{
Expand Down Expand Up @@ -141,7 +142,7 @@ public function testIsParsingSimpleBlock(): void

public function testIsDetectingBadNodes(): void
{
$this->expectException(\RuntimeException::class);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Undefined node: foobar');

$blocklySource = <<<XML
Expand Down

0 comments on commit 6fbe474

Please sign in to comment.