Skip to content

Commit

Permalink
update support php8
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Jul 23, 2021
1 parent 7c940d7 commit c4a978c
Show file tree
Hide file tree
Showing 42 changed files with 124 additions and 299 deletions.
2 changes: 1 addition & 1 deletion .php_cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2018 Thomas Klein, All rights reserved.
* Copyright © Thomas Klein, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
$finder = PhpCsFixer\Finder::create()
Expand Down
2 changes: 1 addition & 1 deletion .phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © 2018 Thomas Klein, All rights reserved.
* Copyright © Thomas Klein, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
-->
Expand Down
38 changes: 0 additions & 38 deletions autoloader.php

This file was deleted.

16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
},
"prefer-stable": true,
"require": {
"php": "^7.1||^8.0"
"php": "^8.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"phpmd/phpmd": "^2.6",
"sebastian/phpcpd": "^2.0",
"squizlabs/php_codesniffer": "^3.2",
"friendsofphp/php-cs-fixer": "^2.10",
"pdepend/pdepend": "^2.5",
"phpstan/phpstan": "@stable"
"phpunit/phpunit": "^9.5",
"phpmd/phpmd": "*",
"sebastian/phpcpd": "*",
"squizlabs/php_codesniffer": "*",
"friendsofphp/php-cs-fixer": "*",
"pdepend/pdepend": "*",
"phpstan/phpstan": "*"
},
"autoload": {
"psr-4": {
Expand Down
30 changes: 15 additions & 15 deletions examples/index.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © 2018 Thomas Klein, All rights reserved.
* Copyright © Thomas Klein, All rights reserved.
* See LICENSE bundled with this library for license details.
*/

require_once __DIR__.'/../autoloader.php';
require_once dirname(__DIR__) . '/vendor/autoload.php';

use LogicTree\LogicTreeFacade;
use LogicTree\Node\Combine;
use LogicTree\Node\Condition;
use LogicTree\Operator\OperatorInterface;
use LogicTree\Operator\OperatorPool;

/**
* Class CustomOperator
*/
class CustomOperator implements \LogicTree\Operator\OperatorInterface
class CustomOperator implements OperatorInterface
{
public const CODE = 'custom_op';

Expand All @@ -22,25 +28,19 @@ public function execute(...$expressions): bool
}
}

//$operatorPool = new \LogicTree\Operator\OperatorPool();
//$operatorPool->addOperator(\LogicTree\Operator\OperatorPool::TYPE_COMPARATOR, 'custom_operator', new CustomOperator());

//$conditionManager = new \LogicTree\Service\ConditionManager($operatorPool);
//$logicTreeFacade = new \LogicTree\LogicTreeFacade($conditionManager);

/**
* USE CASES
*/
$logicTreeFacade = new \LogicTree\LogicTreeFacade();
$logicTreeFacade = new LogicTreeFacade();

$dataSource = $logicTreeFacade->createDataSource(['value_1' => 'toto', 'value_2' => 5]);

$expr1 = new \LogicTree\Node\Condition('value_1', 'eq', 'toto');
$expr2 = new \LogicTree\Node\Condition('value_2', 'custom_op', 10);
$logicTree = new \LogicTree\Node\Combine('and', false, [$expr1, $expr2]);
$expr1 = new Condition('value_1', 'eq', 'toto');
$expr2 = new Condition('value_2', 'custom_op', 10);
$logicTree = new Combine('and', false, [$expr1, $expr2]);

// Add new operator
$logicTreeFacade->addOperator(\LogicTree\Operator\OperatorPool::TYPE_COMPARATOR, 'custom_op', new CustomOperator());
$logicTreeFacade->addOperator(OperatorPool::TYPE_COMPARATOR, 'custom_op', new CustomOperator());

// Execute combine conditions
var_dump($logicTreeFacade->executeCombineConditions($logicTree, $dataSource));
17 changes: 9 additions & 8 deletions src/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@

namespace LogicTree;

use ArrayAccess;
use InvalidArgumentException;
use function is_array;

/**
* @api
*/
class DataSource
{
/**
* Associative data array by key pair value
*
* @var array
*/
private $data;

public function __construct(iterable $data = [])
public function __construct(private iterable $data = [])
{
$this->setData($data);
}
Expand All @@ -31,6 +28,10 @@ public function getData(): array

public function setData(iterable $data): DataSource
{
if (!is_array($data) && !($data instanceof ArrayAccess)) {
throw new InvalidArgumentException('Data must be an array or implements ArrayAccess.');
}

$this->data = [];

foreach ($data as $key => $value) {
Expand Down
14 changes: 4 additions & 10 deletions src/LogicTreeFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,13 @@

class LogicTreeFacade
{
/**
* @var ConditionManager
*/
private $conditionManager;
private ConditionManager $conditionManager;

/**
* @var OperatorPool
*/
private $operatorPool;
private OperatorPool $operatorPool;

public function __construct(?ConditionManager $conditionManager = null)
public function __construct(?ConditionManager $conditionManager = null, ?OperatorPool $operatorPool = null)
{
$this->operatorPool = new OperatorPool();
$this->operatorPool = $operatorPool ?? new OperatorPool();
$this->conditionManager = $conditionManager ?? new ConditionManager($this->operatorPool);
}

Expand Down
8 changes: 2 additions & 6 deletions src/Node/AbstractNode.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Thomas Klein, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace LogicTree\Node;

abstract class AbstractNode implements NodeInterface
{
/**
* @var null|CombineInterface
*/
private $parent;
private ?CombineInterface $parent = null;

public function getParent(): ?CombineInterface
{
Expand Down
23 changes: 6 additions & 17 deletions src/Node/Combine.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Thomas Klein, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace LogicTree\Node;

Expand All @@ -12,33 +11,23 @@

final class Combine extends AbstractNode implements CombineInterface
{
/**
* @var string
*/
private $operator;

/**
* @var bool
*/
private $isInvert;

/**
* @var NodeInterface[]
*/
private $nodes;
private array $nodes;

/**
* @param string $operator
* @param bool $isInvert [optional] Is false by default.
* @param NodeInterface[] $children [optional] Is empty by default.
*/
public function __construct(
string $operator,
bool $isInvert = null,
array $children = []
private string $operator,
private bool $isInvert = false,
private array $children = []
) {
$this->setOperator($operator);
$this->setIsInvert($isInvert ?? false);
$this->setIsInvert($isInvert);
$this->setChildren($children);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Node/CombineInterface.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Thomas Klein, All right reserved.
*/
declare(strict_types=1);

namespace LogicTree\Node;

Expand Down
3 changes: 1 addition & 2 deletions src/Node/Condition.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Thomas Klein, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace LogicTree\Node;

Expand Down
3 changes: 1 addition & 2 deletions src/Node/ConditionInterface.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Thomas Klein, All right reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace LogicTree\Node;

Expand Down
3 changes: 1 addition & 2 deletions src/Node/NodeInterface.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Thomas Klein, All right reserved.
*/
declare(strict_types=1);

namespace LogicTree\Node;

Expand Down
7 changes: 3 additions & 4 deletions src/Operator/Comparator/AbstractCompareOne.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Thomas Klein, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace LogicTree\Operator\Comparator;

Expand All @@ -13,7 +12,7 @@

abstract class AbstractCompareOne implements OperatorInterface
{
public function execute(...$expressions): bool
public function execute(mixed ...$expressions): bool
{
$count = count($expressions);

Expand All @@ -30,5 +29,5 @@ public function execute(...$expressions): bool
* @param mixed $expression
* @return bool
*/
abstract public function executeComparison($expression): bool;
abstract public function executeComparison(mixed $expression): bool;
}
7 changes: 3 additions & 4 deletions src/Operator/Comparator/AbstractCompareTwo.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Thomas Klein, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace LogicTree\Operator\Comparator;

Expand All @@ -13,7 +12,7 @@

abstract class AbstractCompareTwo implements OperatorInterface
{
public function execute(...$expressions): bool
public function execute(mixed ...$expressions): bool
{
$count = count($expressions);

Expand All @@ -31,5 +30,5 @@ public function execute(...$expressions): bool
* @param mixed $expr2
* @return bool
*/
abstract public function executeComparison($expr1, $expr2): bool;
abstract public function executeComparison(mixed $expr1, mixed $expr2): bool;
}
5 changes: 2 additions & 3 deletions src/Operator/Comparator/EmptyOperator.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Thomas Klein, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace LogicTree\Operator\Comparator;

Expand All @@ -15,7 +14,7 @@ final class EmptyOperator extends AbstractCompareOne
{
public const CODE = 'empty';

public function executeComparison($expression): bool
public function executeComparison(mixed $expression): bool
{
return empty($expression);
}
Expand Down
Loading

0 comments on commit c4a978c

Please sign in to comment.