Skip to content

Commit

Permalink
refactor #76 Various improvements and fixes (sstok)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

|Q            |A  |
|---          |---|
|Bug Fix?     |yes|
|New Feature? |no |
|BC Breaks?   |yes|
|Deprecations?|yes |
|Fixed Tickets|   |
|License      |MIT|

Commits
-------

3c81674 update PHPDoc of ValuesGroup
38bb172 mark SearchConditionBuilder:__construct protected
2faffb9 update grammar of some classes and interfaces
9b8c2d6 don't allow colons set/field names
a02d62b FieldSetBuilder::get() always return an object
00e01a0 [Optimizer] remove Closure usage in ValuesToRange
a38c9eb allow UnexpectedTypeException expected as array
9e84512 manual code review and improvements
4357780 increase minimum for version to PHP 5.4
9159975 manual code review and improvements
ece7c4a [Input] refactoring to reduce complexity
088ace5 Remove the possibility to mark a Field required
4cf48d9 update README.md - fix some typos
49d15c9 correct CS
da40a5b update UPGRADE.md
  • Loading branch information
sstok committed Jul 17, 2015
2 parents 4e9db44 + da40a5b commit 3acd003
Show file tree
Hide file tree
Showing 134 changed files with 3,084 additions and 3,390 deletions.
6 changes: 3 additions & 3 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ return Symfony\CS\Config\Config::create()
// use SYMFONY_LEVEL:
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
// and extra fixers:
->fixers(array(
->fixers([
'ordered_use',
//'strict',
'strict_param',
//'short_array_syntax',
'short_array_syntax',
'phpdoc_order',
'header_comment',
'-psr0',
))
])
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->exclude(array('bin', 'doc', 'spec'))
Expand Down
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
- hhvm-nightly

matrix:
include:
- php: 5.3
- php: 5.4
env: DEPENDENCIES='low'
- php: 5.6
env: DEPENDENCIES='dev'
allow_failures:
- php: 7.0
- php: hhvm-nightly
- env: DEPENDENCIES='dev'
fast_finish: true

Expand All @@ -35,5 +32,5 @@ install:
- if [ "$DEPENDENCIES" == "low" ]; then travis_retry composer update --prefer-lowest; fi;

script:
- bin/phpunit --configuration phpunit.xml.dist --verbose
- phpunit --configuration phpunit.xml.dist --verbose
- bin/phpspec run
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ in the "customer" table, the "invoices" data is stored in it's own table, and
the details of the invoice also have there own table.

Searching (using the FilterQuery syntax) can be as simple as:
`invoice_price: >"$20.00" invoice_row_label: ~*"my cool product"; customer_type: !consumer.`
`invoice_price: >"$20.00" invoice_row_label: ~*"my cool product"; customer_type: !consumer`.

You just searched in three relational tables using a single condition with a
user-friendly syntax. And that is just the start, checkout all the cool and
Expand All @@ -46,7 +46,7 @@ Search conditions can be as simple or complex as you need them to be.
Including grouping and nesting for the best possible result.

And to keep performance at a high rate, each search condition can be easily stored
in a persist or session-based cache. On top of that each condition processor provides
in a persistent or session-based cache. On top of that each condition processor provides
it's own specialized caching mechanise to further reduce overhead.

*In practice this means that the generated (SQL) query for the DB or index is cached.*
Expand All @@ -61,7 +61,7 @@ Input processing is provided for the most common formats.
Including a special format called FilterQuery which provides
a user-friendly syntax for creating any type of condition.

Each input processor transforms the input a normalized format,
Each input processor transforms the input to a normalized format,
and ensures that no malformed data is passed to the storage layer.

* Array
Expand Down Expand Up @@ -109,7 +109,7 @@ as separate packages. Building your own condition processor is also possible.
Requirements
------------

You need at least PHP 5.3.9, and Intl extension for international support.
You need at least PHP 5.4, and Intl extension for international support.

For framework integration you may use the following;

Expand Down Expand Up @@ -190,12 +190,12 @@ Contributing
------------

This is an open source project. If you'd like to contribute,
please read the [Contributing Code][1] part of Symfony for the basics. If you're submitting
please read the [Contributing Guidelines][1]. If you're submitting
a pull request, please follow the guidelines in the [Submitting a Patch][2] section.

[1]: http://symfony.com/doc/current/contributing/code/index.html
[2]: http://symfony.com/doc/current/contributing/code/patches.html#check-list
[1]: https://github.com/rollerworks/contributing
[2]: https://contributing.readthedocs.org/en/latest/code/patches.html
[3]: http://docutils.sourceforge.net/rst.html
[4]: http://sphinx-doc.org/
[5]: http://symfony.com/doc/current/contributing/documentation/format.html
[5]: https://contributing.readthedocs.org/en/latest/documentation/format.html
[6]: http://rollerworkssearch.readthedocs.org/en/latest/
79 changes: 44 additions & 35 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,38 @@ and easier to use.

* The `Rollerworks\Component\Search\Formatter\TransformFormatter` is removed,
transforming is now performed in the InputProcessor.

* `Rollerworks\Component\Search\Metadata\Field` is removed,
use `Rollerworks\Component\Search\Mapping\SearchField` instead.

* The methods `supportValueType()` and `setValueTypeSupport()` were added
to `Rollerworks\Component\Search\FieldConfigInterface`. If you implemented
this interface in your own code, you should add these two methods.

* The methods `hasRangeSupport()` and `hasCompareSupport()` were removed
from the `Rollerworks\Component\Search\FieldConfigInterface`. If you
relied upon these methods you need to change your code.
See description below for more details.

* The methods `setRequired()` and `isRequired()` were removed
from the `Rollerworks\Component\Search\FieldConfigInterface`.
And marked deprecated in `\Rollerworks\Component\Search\SearchField`.

Marking a field required has always been a bit unclear, *is the field required
to exists in the condition or in exactly every group?*. Th disambiguation
has been resolved by simple removing this functionality. If you do need this functionality,
you can do this by validating the SearchCondition with a custom validator.

### Type

* The options configuring of type has been changed to replace the deprecated
OptionsResolverInterface. Second the method is renamed to "configureOptions".

Before:

```php
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class TaskType extends AbstractFieldType
{
// ...
Expand All @@ -42,12 +51,12 @@ and easier to use.
}
}
```

After:

```php
use Symfony\Component\OptionsResolver\OptionsResolver;

class TaskType extends AbstractFieldType
{
// ...
Expand All @@ -59,22 +68,22 @@ and easier to use.
}
}
```

* Method `buildFieldView` has been renamed to `buildView` in both
`Rollerworks\Component\Search\FieldTypeInterface` and
`Rollerworks\Component\Search\FieldTypeExtensionInterface`.
* Configuring whether a type supports ranges/comparisons and/or pattern-matchers
now needs to be configured in the `buildType()` method.

* Configuring whether a type supports ranges/comparisons and/or pattern-matchers
now needs to be configured in the `buildType()` method.

**Note:** The parent type may already have enabled support for the
values-type, so you don't have to always enable this explicitly.
values-type, so you should not have to always enable this explicitly.

Before:

```php
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class TaskType extends AbstractFieldType
{
public function hasRangeSupport()
Expand All @@ -83,12 +92,12 @@ and easier to use.
}
}
```

After:

```php
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class TaskType extends AbstractFieldType
{
public function buildType(FieldConfigInterface $config, array $options)
Expand All @@ -100,31 +109,31 @@ and easier to use.

### Input

* Input processors are made reusable, configuration (limiting) must be passed as the
* Input processors are made reusable, configuration must be passed as the
first parameter of `Rollerworks\Component\Search\Input\InputProcessorInterface::process()`.
* When the created search-condition has errors an `InvalidSearchValuesException`

* When the created search condition has errors an `InvalidSearchValuesException`
will be thrown (after processing).

* Validation of ranges (correct bounds) is now performed when processing
the Input (not after).
the input (not after).

### Optimizers (former formatters)

Formatters are renamed to optimizers; The `Rollerworks\Component\Search\FormatterInterface`
is removed in favor of the new `Rollerworks\Component\Search\SearchConditionOptimizerInterface`.

### User error handling

Because its possible that a search-condition contains errors, each processor
Because it's possible that a search condition contains errors, each processor
that has a transforming or validating role will throw a
`Rollerworks\Component\Search\Exception\InvalidSearchValuesException`.

The `InvalidSearchValuesException` provides access to the search-condition,
The `InvalidSearchValuesException` provides access to the actual search condition,
but the condition will contain some values that are invalid.

**Note:** The `InvalidSearchValuesException` is thrown *after* processing,
so it contains all invalid values (and not just the first violation) in a field
so it contains all invalid values (and not just the first violation) in a field's
values list.

A `ValuesGroup` object no longer keeps track of errors, getting the errors
Expand All @@ -136,23 +145,23 @@ error-state of all nested groups.

### Validation

The default validator (Validator extension) is moved to `rollerworks/search-symfony-validator`,
The default validator (Validator extension) is moved to `rollerworks/search-symfony-validator`,
and no longer implements the old Formatter interface.

**Caution:** To prevent clashes with other validators the namespace of the validator
is changed to: `Rollerworks\Component\Search\Extension\Symfony\Validator`.

### Values

* Value objects `Compare`, `SingleValue`, `Range`, `PatternMatch` are now marked as
final and made immutable. To change a value, remove the original at the index and
add the new value object to the ValuesBag.

* `PatternMatch::getViewValue()` was removed as this value-type has no view version.

* All view-values are casted to strings now;
When no view value is provided the "normalized" value must support casting to a string!
When no view value is provided the "normalized" value must be castable to a string!

### SearchConditionSerializer

The `SearchConditionSerializer` no longer uses the static methods
Expand Down
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "rollerworks/search",
"description": "RollerworksSearch provides you with a light yet powerful search system",
"description": "RollerworksSearch provides you with a powerful search system",
"keywords": ["rollerworks", "filter", "search"],
"homepage": "https://rollerworks.github.io/",
"type": "library",
"license": "MIT",
"authors": [
Expand All @@ -15,7 +16,7 @@
}
],
"require": {
"php": ">=5.3.9",
"php": ">=5.4",
"symfony/options-resolver": "~2.3",
"symfony/property-access": "~2.3",
"symfony/intl": "~2.3",
Expand All @@ -25,16 +26,18 @@
},
"require-dev": {
"symfony/phpunit-bridge": "~2.7@dev",
"phpunit/phpunit": "~4.5",
"phpspec/phpspec": "^2.1.1",
"phpspec/prophecy": "^1.3.1",
"rollerworks/search-jms-metadata": "1.*@dev"
},
"autoload": {
"psr-4": { "Rollerworks\\Component\\Search\\": "src/" }
"psr-4": {
"Rollerworks\\Component\\Search\\": "src/"
}
},
"autoload-dev": {
"psr-4": { "Rollerworks\\Component\\Search\\Tests\\": "tests/" }
"psr-4": {
"Rollerworks\\Component\\Search\\Tests\\": "tests/"
}
},
"config": {
"bin-dir": "bin"
Expand Down
3 changes: 1 addition & 2 deletions doc/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ and tries to find the corresponding class-name ``Product`` as either ``Product.y
# Name is the search-field name
name: product_id
type: number
required: false
accept-ranges: true
accept-compares: true
Expand All @@ -113,7 +112,7 @@ and tries to find the corresponding class-name ``Product`` as either ``Product.y
<?xml version="1.0" encoding="UTF-8"?>
<properties>
<property id="id" name="product_id" required="false">
<property id="id" name="product_id">
<type name="number" />
</property>
<property id="name" name="product_name">
Expand Down
2 changes: 0 additions & 2 deletions doc/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ SearchField
+----------------------+------------------------------------------------------------------------------------+---------------------------------+
| SupportValueType | Indication which value-types are accepted by the field. | ``boolean`` |
+----------------------+------------------------------------------------------------------------------------+---------------------------------+
| Required | Indicates if the field must have at least one value. | ``boolean`` |
+----------------------+------------------------------------------------------------------------------------+---------------------------------+
| ModelRefClass | Model's fully qualified class-name reference. | ``string`` |
| | This is required for certain storage engines like Doctrine ORM. | |
+----------------------+------------------------------------------------------------------------------------+---------------------------------+
Expand Down
12 changes: 0 additions & 12 deletions doc/searches.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,6 @@ Please keep note of the following:

So displaying an error message is as simple as ``echo $e->getMessage();``.

FieldRequiredException
~~~~~~~~~~~~~~~~~~~~~~

The ``Rollerworks\Component\Search\Exception\FieldRequiredException``
is thrown when a required field is missing in the condition.

This exception provides the following properties:

* fieldName: Name of the field which is missing in the condition
* groupIdx: the group index in which the field is missing
* nestingLevel: the nesting level at which the field is missing

GroupsNestingException
~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion spec/Extension/Core/ChoiceList/ChoiceListSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ChoiceListSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith(array('creditcard', 'cash'), array('credit-card-payment', 'cash-payment'));
$this->beConstructedWith(['creditcard', 'cash'], ['credit-card-payment', 'cash-payment']);
}

function it_is_initializable()
Expand Down
4 changes: 2 additions & 2 deletions spec/Extension/Core/ChoiceList/SimpleChoiceListSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class SimpleChoiceListSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith(array(
$this->beConstructedWith([
'creditcard' => 'credit-card-payment',
'cash' => 'cash-payment',
));
]);
}

function it_is_initializable()
Expand Down

0 comments on commit 3acd003

Please sign in to comment.