Skip to content

Commit

Permalink
Merge branch '2.next-cake5'
Browse files Browse the repository at this point in the history
  • Loading branch information
skie committed Sep 12, 2024
2 parents 0cfca5e + 4aacfc4 commit 1030114
Show file tree
Hide file tree
Showing 30 changed files with 154 additions and 151 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,22 @@ jobs:
fi
- name: Setup problem matchers for PHPUnit
if: matrix.php-version == '8.1' && matrix.db-type == 'mysql'
if: matrix.php-version == '8.2' && matrix.db-type == 'mysql'
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run PHPUnit
run: |
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:[email protected]/cakephp?encoding=utf8'; fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:[email protected]/postgres'; fi
if [[ ${{ matrix.php-version }} == '8.1' ]]; then
export CODECOVERAGE=1 && vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
if [[ ${{ matrix.php-version }} == '8.2' ]]; then
export CODECOVERAGE=1 && vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi
- name: Submit code coverage
if: matrix.php-version == '8.1'
if: matrix.php-version == '8.2'
uses: codecov/codecov-action@v1

cs-stan:
Expand All @@ -92,7 +92,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
extensions: mbstring, intl, apcu
coverage: none

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Versions and branches
| ^5.0 | [2.0](https://github.com/cakedc/users/tree/2.next-cake5) | 2.0.0 | stable |
| ^4.5 | [1.0](https://github.com/cakedc/search-filter/tree/1.next-cake4) | 1.0.0 | stable |


## Overview

The SearchFilter plugin is a powerful and flexible solution for implementing advanced search functionality in CakePHP applications. It provides a robust set of tools for creating dynamic, user-friendly search interfaces with minimal effort.
Expand Down Expand Up @@ -111,7 +112,7 @@ class PostsController extends AppController
]);

$filters = $manager->formatFinders($search);
$query = $query->find('filters', $filters);
$query = $query->find('filters', params: $filters);
}

// Paginate the results
Expand Down
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
"license": "MIT",
"require": {
"php": ">=8.1",
"cakephp/cakephp": "^4.4",
"skie/cakephp-search": "^4.0"
"cakephp/cakephp": "^5.0",
"skie/cakephp-search": "^5.0"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^4.0",
"slevomat/coding-standard": "^8.0",
"phpunit/phpunit": "^9.5"
"cakephp/cakephp-codesniffer": "^5.0",
"phpunit/phpunit": "^10.0"
},
"scripts": {
"fixcode": [
Expand All @@ -29,7 +28,7 @@
"test": "phpunit --stderr",
"coverage-test": "phpunit --stderr --coverage-clover=clover.xml",
"stan": "phpstan.phar analyse --memory-limit=-1 src/",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:0.12.94 psalm/phar:~4.9.2 && mv composer.backup composer.json",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^1.9.0 psalm/phar:^5.1.0 && mv composer.backup composer.json",
"psalm": "psalm.phar --show-info=false",
"stan-rebuild-baseline": "phpstan.phar analyse ./src/ --generate-baseline",
"cs-check": "phpcs -n -p ./src ./tests",
Expand All @@ -43,7 +42,7 @@
"autoload-dev": {
"psr-4": {
"CakeDC\\SearchFilter\\Test\\": "tests/",
"CakeDC\\SearchFilter\\Test\\App\\": "tests/test_app/App/",
"CakeDC\\SearchFilter\\Test\\App\\": "tests/test_app/App/",
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
}
},
Expand Down
10 changes: 2 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,17 @@
<ini name="apc.enable_cli" value="1"/>
<env name="FIXTURE_SCHEMA_METADATA" value="./tests/schema.php"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="SearchFilter">
<directory>tests/TestCase/</directory>
<directory>./tests/</directory>
</testsuite>
</testsuites>

<!-- Setup fixture extension -->
<extensions>
<extension class="\Cake\TestSuite\Fixture\PHPUnitExtension"/>
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
</extensions>

<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>

</phpunit>
2 changes: 1 addition & 1 deletion src/Filter/Exception/MissingFilterException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ class MissingFilterException extends CakeException
/**
* @inheritDoc
*/
protected $_messageTemplate = 'Filter class %s could not be found.';
protected string $_messageTemplate = 'Filter class %s could not be found.';
}
1 change: 1 addition & 0 deletions src/Filter/FilterCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Exception;
use IteratorAggregate;
use Traversable;
use function Cake\I18n\__;

/**
* FilterCollection class
Expand Down
13 changes: 8 additions & 5 deletions src/Model/Filter/CriteriaFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

namespace CakeDC\SearchFilter\Model\Filter;

use Cake\ORM\Query;
use Cake\ORM\Query\SelectQuery;
use PlumSearch\Model\Filter\AbstractFilter;
use PlumSearch\Model\Filter\Exception\MissingFilterException;
use PlumSearch\Model\FilterRegistry;
use function Cake\I18n\__;

/**
* Class CriteriaFilter
Expand Down Expand Up @@ -44,13 +45,15 @@ public function __construct(FilterRegistry $registry, array $config = [])
/**
* Returns query with applied filter
*
* @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query Query.
* @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query Query.
* @param string $field Field name.
* @param array<string, mixed> $value Field value.
* @param string|array $value Field value.
* @param array<string, mixed> $data Filters values.
* @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
* @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
* @phpstan-param array<string, array{condition: string, value: mixed}>|string $value
*/
protected function _buildQuery(Query $query, string $field, $value, array $data = []): Query
protected function _buildQuery(SelectQuery $query, string $field, $value, array $data = []): SelectQuery
{
$criteria = $this->getConfig('criteria');
foreach ($value as $name => $values) {
Expand Down
8 changes: 4 additions & 4 deletions src/Model/Filter/Criterion/AndCriterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace CakeDC\SearchFilter\Model\Filter\Criterion;

use Cake\Database\Expression\QueryExpression;
use Cake\ORM\Query;
use Cake\ORM\Query\SelectQuery;

class AndCriterion extends BaseCriterion
{
Expand All @@ -31,14 +31,14 @@ public function __construct(array $criteria)
/**
* Finder method
*
* @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query
* @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query
* @param string $condition
* @param array<string, mixed> $values
* @param array<string, mixed> $criteria
* @param array<string, mixed> $options
* @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
* @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
*/
public function __invoke(Query $query, string $condition, array $values, array $criteria, array $options): Query
public function __invoke(SelectQuery $query, string $condition, array $values, array $criteria, array $options): SelectQuery
{
$filters = $this->buildFilter($condition, $values, $criteria, $options);
if (!empty($filters)) {
Expand Down
12 changes: 6 additions & 6 deletions src/Model/Filter/Criterion/BaseCriterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Cake\Database\Expression\ComparisonExpression;
use Cake\Database\Expression\QueryExpression;
use Cake\Database\ExpressionInterface;
use Cake\I18n\FrozenDate;
use Cake\I18n\FrozenTime;
use Cake\I18n\Date;
use Cake\I18n\DateTime;
use Cake\Utility\Hash;
use CakeDC\SearchFilter\Filter\AbstractFilter;

Expand Down Expand Up @@ -92,9 +92,9 @@ public function buildQueryByCondition(string|QueryExpression $field, string $con
}
if ($condition == AbstractFilter::COND_EQ) {
return function (QueryExpression $expr) use ($field, $value, $type): QueryExpression {
if ($value instanceof FrozenDate) {
if ($value instanceof Date) {
$value = $value->format('Y-m-d');
} elseif ($value instanceof FrozenTime) {
} elseif ($value instanceof DateTime) {
$value = $value->format('Y-m-d H:i');
}

Expand All @@ -111,9 +111,9 @@ public function buildQueryByCondition(string|QueryExpression $field, string $con
])
) {
return function (QueryExpression $expr) use ($field, $value, $type, $condition): QueryExpression {
if ($value instanceof FrozenDate) {
if ($value instanceof Date) {
$value = $value->format('Y-m-d');
} elseif ($value instanceof FrozenTime) {
} elseif ($value instanceof DateTime) {
$value = $value->format('Y-m-d H:i');
}

Expand Down
10 changes: 5 additions & 5 deletions src/Model/Filter/Criterion/BoolCriterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace CakeDC\SearchFilter\Model\Filter\Criterion;

use Cake\Database\ExpressionInterface;
use Cake\ORM\Query;
use Cake\ORM\Query\SelectQuery;
use CakeDC\SearchFilter\Filter\AbstractFilter;

class BoolCriterion extends BaseCriterion
Expand Down Expand Up @@ -39,14 +39,14 @@ public function isApplicable(mixed $value, string $condition): bool
/**
* Finder method
*
* @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query
* @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query
* @param string|null $condition
* @param array<string, mixed> $values
* @param array<string, mixed> $criteria
* @param array<string, mixed> $options
* @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
* @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
*/
public function __invoke(Query $query, $condition, array $values, array $criteria, $options): Query
public function __invoke(SelectQuery $query, ?string $condition, array $values, array $criteria, array $options): SelectQuery
{
$filter = $this->buildFilter($condition, $values, $criteria, $options);
if (!empty($filter)) {
Expand All @@ -59,7 +59,7 @@ public function __invoke(Query $query, $condition, array $values, array $criteri
/**
* @inheritDoc
*/
public function buildFilter(string $condition, array $values, array $criteria, array $options = []): array|callable|null
public function buildFilter(?string $condition, array $values, array $criteria, array $options = []): array|callable|null
{
$value = $this->getValues('value', AbstractFilter::COND_EQ, $values);

Expand Down
17 changes: 9 additions & 8 deletions src/Model/Filter/Criterion/DateCriterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
use Cake\Database\Expression\QueryExpression;
use Cake\Database\ExpressionInterface;
use Cake\Database\FunctionsBuilder;
use Cake\I18n\FrozenDate;
use Cake\ORM\Query;
use Cake\I18n\Date;
use Cake\I18n\DateTime;
use Cake\ORM\Query\SelectQuery;
use CakeDC\SearchFilter\Filter\AbstractFilter;

class DateCriterion extends BaseCriterion
Expand Down Expand Up @@ -61,14 +62,14 @@ public function isApplicable(mixed $value, string $condition): bool
/**
* Finder method
*
* @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query
* @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query
* @param string $condition
* @param array<string, mixed> $values
* @param array<string, mixed> $criteria
* @param array<string, mixed> $options
* @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
* @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
*/
public function __invoke(Query $query, string $condition, array $values, array $criteria, array $options): Query
public function __invoke(SelectQuery $query, string $condition, array $values, array $criteria, array $options): SelectQuery
{
$filter = $this->buildFilter($condition, $values, $criteria, $options);
if (!empty($filter)) {
Expand Down Expand Up @@ -180,10 +181,10 @@ protected function buildYearWeekExpression(string|ExpressionInterface $value): F
* Create a date/time object from a string
*
* @param string $dateStr
* @return \DateTimeInterface
* @return \Cake\I18n\Date|\Cake\I18n\DateTime
*/
protected function prepareTime(string $dateStr): \DateTimeInterface
protected function prepareTime(string $dateStr): DateTime|Date
{
return FrozenDate::createFromFormat($this->format, $dateStr);
return Date::createFromFormat($this->format, $dateStr);
}
}
9 changes: 5 additions & 4 deletions src/Model/Filter/Criterion/DateTimeCriterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
namespace CakeDC\SearchFilter\Model\Filter\Criterion;

use Cake\Database\ExpressionInterface;
use Cake\I18n\FrozenTime;
use Cake\I18n\Date;
use Cake\I18n\DateTime;

class DateTimeCriterion extends DateCriterion
{
Expand All @@ -29,10 +30,10 @@ public function __construct(string|ExpressionInterface $field, string $format =
* Create a date/time object from a string
*
* @param string $dateStr
* @return \DateTimeInterface
* @return \Cake\I18n\Date|\Cake\I18n\DateTime
*/
protected function prepareTime(string $dateStr): \DateTimeInterface
protected function prepareTime(string $dateStr): DateTime|Date
{
return FrozenTime::createFromFormat($this->format, $dateStr);
return DateTime::createFromFormat($this->format, $dateStr);
}
}
8 changes: 4 additions & 4 deletions src/Model/Filter/Criterion/InCriterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Cake\Database\Expression\QueryExpression;
use Cake\Database\ExpressionInterface;
use Cake\ORM\Query;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\Table;

class InCriterion extends BaseCriterion
Expand Down Expand Up @@ -44,14 +44,14 @@ public function __construct(string|ExpressionInterface $field, Table $table, Bas
/**
* Finder method
*
* @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query
* @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query
* @param string $condition
* @param array<string, mixed> $values
* @param array<string, mixed> $criteria
* @param array<string, mixed> $options
* @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
* @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
*/
public function __invoke(Query $query, string $condition, array $values, array $criteria, array $options): Query
public function __invoke(SelectQuery $query, string $condition, array $values, array $criteria, array $options): SelectQuery
{
$filter = $this->buildFilter($condition, $values, $criteria, $options);
if ($filter !== null) {
Expand Down
8 changes: 4 additions & 4 deletions src/Model/Filter/Criterion/LookupCriterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Cake\Database\Expression\QueryExpression;
use Cake\Database\ExpressionInterface;
use Cake\ORM\Query;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\Table;
use Cake\Validation\Validation;
use CakeDC\SearchFilter\Filter\AbstractFilter;
Expand Down Expand Up @@ -46,14 +46,14 @@ public function __construct(string|ExpressionInterface $field, Table $table, Bas
/**
* Finder method
*
* @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query
* @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query
* @param string $condition
* @param array<string, mixed> $values
* @param array<string, mixed> $criteria
* @param array<string, mixed> $options
* @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
* @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
*/
public function __invoke(Query $query, string $condition, array $values, array $criteria, array $options): Query
public function __invoke(SelectQuery $query, string $condition, array $values, array $criteria, array $options): SelectQuery
{
$filter = $this->buildFilter($condition, $values, $criteria, $options);
if (!empty($filter)) {
Expand Down
Loading

0 comments on commit 1030114

Please sign in to comment.