Skip to content

Commit

Permalink
feat: implemented php8.1 features
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrankruijter committed Feb 10, 2022
1 parent 1e8d44b commit 4fb2c31
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: php
php:
- '8.0'
- '8.1'

before_script:
- composer install
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 3.0.0 - 2022-02-10
### Added
- PHP 8.1 feature implementation

### Removed
- `grizz-it/enum`, replaced by the native enums.

## 2.1.0 - 2021-02-23
### Added
- Compatibility for PHP 8.0
Expand All @@ -26,7 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial implementation of the package.

- [2.1.0 > Unreleased](https://github.com/grizz-it/search/compare/2.1.0...HEAD)
- [3.0.0 > Unreleased](https://github.com/grizz-it/search/compare/3.0.0...HEAD)
- [2.1.0 > 3.0.0](https://github.com/grizz-it/search/compare/2.1.0...3.0.0)
- [2.0.1 > 2.1.0](https://github.com/grizz-it/search/compare/2.0.1...2.1.0)
- [2.0.0 > 2.0.1](https://github.com/grizz-it/search/compare/2.0.0...2.0.1)
- [1.0.0 > 2.0.0](https://github.com/grizz-it/search/compare/1.0.0...2.0.0)
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"prefer-stable": true,
"minimum-stability": "stable",
"require": {
"php": "^8.0",
"grizz-it/enum": "^1.1"
"php": "^8.1"
},
"authors": [
{
Expand Down
87 changes: 35 additions & 52 deletions src/Common/ComparatorEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,117 +7,100 @@

namespace GrizzIt\Search\Common;

use GrizzIt\Enum\Enum;

/**
* @method static ComparatorEnum EQ()
* @method static ComparatorEnum NEQ()
* @method static ComparatorEnum GT()
* @method static ComparatorEnum GTEQ()
* @method static ComparatorEnum LT()
* @method static ComparatorEnum LTEQ()
* @method static ComparatorEnum IN()
* @method static ComparatorEnum NIN()
* @method static ComparatorEnum LIKE()
* @method static ComparatorEnum NOT_LIKE()
* @method static ComparatorEnum IS_NULL()
* @method static ComparatorEnum NOT_NULL()
*/
class ComparatorEnum extends Enum
enum ComparatorEnum
{
/**
* Equals comparator "=".
* Checks if the field equals the value.
*
* @var string
*/
public const EQ = 'eq';
case EQ;

/**
* Not equals comparator "!=".
* Checks if the field does not equal the value.
*
* @var string
*/
public const NEQ = 'neq';
case NEQ;

/**
* Greater than comparator ">".
* Checks if the field is greater than the value.
*
* @var string
*/
public const GT = 'gt';
case GT;

/**
* Greater than or equals comparator ">=".
* Checks if the field is greater than or equals the value.
*
* @var string
*/
public const GTEQ = 'gteq';
case GTEQ;

/**
* Less than comparator "<".
* Checks if the field is less than the value.
*
* @var string
*/
public const LT = 'lt';
case LT;

/**
* Less than or equals comparator "<=".
* Checks if the field is less than or equals the value.
*
* @var string
*/
public const LTEQ = 'lteq';
case LTEQ;

/**
* In comparator.
* Checks if the field occurs in the value.
*
* @var string
*/
public const IN = 'in';
case IN;

/**
* Not in comparator.
* Checks if the field does not occur in the value.
*
* @var string
*/
public const NIN = 'nin';
case NIN;

/**
* Like comparator.
* Checks if the field looks like the value.
*
* @var string
*/
public const LIKE = 'like';
case LIKE;

/**
* Not like comparator.
* Checks if the field does not look like the value.
*
* @var string
*/
public const NOT_LIKE = 'not_like';
case NOT_LIKE;

/**
* Is null comparator.
* Checks if the field is null.
*
* @var string
*/
public const IS_NULL = 'is_null';
case IS_NULL;

/**
* Is not null comparator.
* Checks if the field is not null.
*/
case NOT_NULL;

/**
* Retrieves the comparator name from the enum.
*
* @var string
* @return string
*/
public const NOT_NULL = 'not_null';
public function name(): string
{
return match($this) {
ComparatorEnum::EQ => 'eq',
ComparatorEnum::NEQ => 'neq',
ComparatorEnum::GT => 'gt',
ComparatorEnum::GTEQ => 'gteq',
ComparatorEnum::LT => 'lt',
ComparatorEnum::LTEQ => 'lteq',
ComparatorEnum::IN => 'in',
ComparatorEnum::NIN => 'nin',
ComparatorEnum::LIKE => 'like',
ComparatorEnum::NOT_LIKE => 'not_like',
ComparatorEnum::IS_NULL => 'is_null',
ComparatorEnum::NOT_NULL => 'not_null',
};
}
}
27 changes: 15 additions & 12 deletions src/Common/DirectionEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@

namespace GrizzIt\Search\Common;

use GrizzIt\Enum\Enum;

/**
* @method static DirectionEnum ASC()
* @method static DirectionEnum DESC()
*/
class DirectionEnum extends Enum
enum DirectionEnum
{
/**
* Directs the sorting in ascending order.
*
* @var string
*/
public const ASC = 'asc';
case ASC;

/**
* Directs the sorting in descending order.
*/
case DESC;

/**
* Retrieves the direction name from the enum.
*
* @var string
* @return string
*/
public const DESC = 'desc';
public function name(): string
{
return match($this) {
DirectionEnum::ASC => 'asc',
DirectionEnum::DESC => 'desc',
};
}
}
33 changes: 17 additions & 16 deletions src/Common/OperatorEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,34 @@

namespace GrizzIt\Search\Common;

use GrizzIt\Enum\Enum;

/**
* @method static OperatorEnum AND()
* @method static OperatorEnum OR()
* @method static OperatorEnum XOR()
*/
class OperatorEnum extends Enum
enum OperatorEnum
{
/**
* All checks should return true when joined with this operator.
*
* @var string
*/
public const AND = 'and';
case AND;

/**
* Any check should return true when joined with this operator.
*
* @var string
*/
public const OR = 'or';
case OR;

/**
* One of the checks should return true when joined with this operator.
*/
case XOR;

/**
* Retrieves the operator name from the enum.
*
* @var string
* @return string
*/
public const XOR = 'xor';
public function name(): string
{
return match($this) {
OperatorEnum::AND => 'and',
OperatorEnum::OR => 'or',
OperatorEnum::XOR => 'xor',
};
}
}
18 changes: 3 additions & 15 deletions src/Component/Criteria/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@

class Filter implements FilterInterface
{
/** @var string */
private string $field;

/** @var ComparatorEnum */
private ComparatorEnum $comparator;

/** @var mixed */
private mixed $value;

/**
* Constructor
*
Expand All @@ -29,13 +20,10 @@ class Filter implements FilterInterface
* @param mixed $value
*/
public function __construct(
string $field,
ComparatorEnum $comparator,
mixed $value
private string $field,
private ComparatorEnum $comparator,
private mixed $value
) {
$this->field = $field;
$this->comparator = $comparator;
$this->value = $value;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Criteria/FilterGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FilterGroup implements FilterGroupInterface
*/
public function __construct(OperatorEnum $operator = null)
{
$this->operator = $operator ?? OperatorEnum::AND();
$this->operator = $operator ?? OperatorEnum::AND;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Criteria/Limiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Limiter implements LimiterInterface
{
/** @var array */
private array $fields = [];
private array $fields;

/**
* Constructor
Expand Down
10 changes: 1 addition & 9 deletions src/Component/Criteria/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,14 @@

class Pager implements PagerInterface
{
/** @var int */
private int $page;

/** @var int */
private int $amount;

/**
* Constructor
*
* @param int $page
* @param int $amount
*/
public function __construct(int $page, int $amount)
public function __construct(private int $page, private int $amount)
{
$this->page = $page;
$this->amount = $amount;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Criteria/SearchCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SearchCriteria implements SearchCriteriaInterface
/**
* Adds a filter group to the criteria.
*
* @param FilterGroupInterface $filter
* @param FilterGroupInterface $filterGroup
*
* @return void
*/
Expand Down
16 changes: 5 additions & 11 deletions src/Component/Criteria/Sorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,16 @@

class Sorter implements SorterInterface
{
/** @var DirectionEnum */
private DirectionEnum $direction;

/** @var string */
private string $field;

/**
* Constructor
*
* @param string $field
* @param string $direction
* @param DirectionEnum $direction
*/
public function __construct(string $field, DirectionEnum $direction)
{
$this->field = $field;
$this->direction = $direction;
public function __construct(
private string $field,
private DirectionEnum $direction
) {
}

/**
Expand Down
Loading

0 comments on commit 4fb2c31

Please sign in to comment.