Skip to content

Commit

Permalink
[#100] Introduced strict types. Droped support for PHP 5 (#101)
Browse files Browse the repository at this point in the history
* Introduced strict types. Droped support for PHP 5

* CS Fixes

* CS Fix part.2

* Travis config

* Strong comparison in PaginationCriteria
  • Loading branch information
krzysztof-gzocha authored Dec 2, 2016
1 parent 5e1d477 commit 1c1d856
Show file tree
Hide file tree
Showing 62 changed files with 261 additions and 228 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ language: php
sudo: false

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

matrix:
include:
- php: 5.4
env: deps=low
- php: 7.0
env: deps=low
fast_finish: true
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### What is that?
*Searcher* is a framework-agnostic search query builder. Search queries are written using criterias and can be run against MySQL, MongoDB, ElasticSearch, files or whatever else you like.
Supported PHP versions: >=5.4, 7 and HHVM. **Now tested also with [Humbug](https://github.com/padraic/humbug)**
**Latest version is supporting only PHP 7**. **Now tested also with [Humbug](https://github.com/padraic/humbug)**

### See [this presentation](https://krzysztof-gzocha.github.io/searcher/) to understand better

Expand Down Expand Up @@ -51,7 +51,7 @@ class AgeRangeCriteria implements CriteriaInterface
* Only required method.
* If will return true, then it will be passed to some of the CriteriaBuilder(s)
*/
public function shouldBeApplied()
public function shouldBeApplied(): bool
{
return null !== $this->minimalAge && null !== $this->maximalAge;
}
Expand Down Expand Up @@ -80,7 +80,8 @@ class AgeRangeCriteriaBuilder implements CriteriaBuilderInterface

public function allowsCriteria(
CriteriaInterface $criteria
) {
): bool
{
return $criteria instanceof AgeRangeCriteria;
}

Expand All @@ -89,7 +90,8 @@ class AgeRangeCriteriaBuilder implements CriteriaBuilderInterface
*/
public function supportsSearchingContext(
SearchingContextInterface $searchingContext
) {
): bool
{
return $searchingContext instanceof QueryBuilderSearchingContext;
}
}
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@
}
},
"require":{
"php": ">=5.4"
"php": "^7"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
"phpunit/phpunit": "^5",
"phpmd/phpmd": "^2.4.3",
"doctrine/orm": "^2.5.0",
"doctrine/mongodb-odm": "^1.0.0",
"ruflin/elastica": ">=2.1.0",
"symfony/finder": "^2.0.5",
"phpdocumentor/reflection-docblock": "2.0.4"
"ruflin/elastica": "^2.1.0",
"symfony/finder": "^2.0.5"
},
"scripts": {
"test": ["phpunit tests/"],
Expand Down
4 changes: 2 additions & 2 deletions docs/chain-search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ injected into the ``$statisticSearcher``:
/**
* @param mixed $results
*/
public function transform($results, CriteriaCollectionInterface $criteria)
public function transform($results, CriteriaCollectionInterface $criteria): CriteriaCollectionInterface
{
// Assuming that UserIdsCriteria will holds an array of user IDs
$userIdsCriteria = new UserIdsCriteria(array_map(
Expand All @@ -72,7 +72,7 @@ injected into the ``$statisticSearcher``:
* @param mixed $results
* @return bool
*/
public function skip($results)
public function skip($results): bool
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/class/criteria-builder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ will support Doctrine's searching context which is ``\KGzocha\Searcher\Context\D
class SpecificAgeCriteriaBuilder extends AbstractORMCriteriaBuilder
{
public function allowsCriteria(CriteriaInterface $criteria)
public function allowsCriteria(CriteriaInterface $criteria): bool
{
return $criteria instanceof SpecificAgeCriteria;
}
Expand Down
16 changes: 8 additions & 8 deletions docs/class/criteria.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ In order to to do you can create very simple class:
{
private $age;
public function getAge()
public function getAge(): int
{
return $this->age;
}
public function setAge($age)
public function setAge(int $age)
{
$this->age = $age;
}
Expand All @@ -44,7 +44,7 @@ In order to to do you can create very simple class:
* Only required method.
* If will return true, then it will be passed to some of the CriteriaBuilder(s)
*/
public function shouldBeApplied()
public function shouldBeApplied(): bool
{
return null !== $this->age;
}
Expand Down Expand Up @@ -72,30 +72,30 @@ you should keep your ``Criteria`` as small as possible. It should be readable an
private $minimumAge;
private $maximumAge;
public function getMinimumAge()
public function getMinimumAge(): int
{
return $this->minimumAge;
}
public function setMinimumAge($age)
public function setMinimumAge(int $age)
{
$this->minimumAge = $age;
}
public function getMaximumAge()
public function getMaximumAge(): int
{
return $this->maximumAge;
}
public function setMaximumAge($age)
public function setMaximumAge(int $age)
{
$this->maximumAge = $age;
}
/**
* Please notice that there is OR condition inside
*/
public function shouldBeApplied()
public function shouldBeApplied(): bool
{
return null !== $this->minimumAge || null !== $this->maximumAge;
}
Expand Down
4 changes: 2 additions & 2 deletions docs/class/searching-context.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ It will allow all criteria builders (that are supporting this context) to use Fi
/**
* @return Finder
*/
public function getQueryBuilder()
public function getQueryBuilder(): Finder
{
return $this->finder;
}
/**
* @return Iterator
*/
public function getResults()
public function getResults(): \Iterator
{
// I assumed that you want Iterator as a result
return $this->finder->getIterator();
Expand Down
13 changes: 7 additions & 6 deletions docs/complete-example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ in the criteria. We do not care about the pagination, nor order of the results.
/**
* @param null|float $height
*/
public function __construct($height = null)
public function __construct(float $height = null)
{
$this->height = $height;
}
Expand All @@ -42,15 +42,15 @@ in the criteria. We do not care about the pagination, nor order of the results.
/**
* @param float $height
*/
public function setHeight($height)
public function setHeight(float $height)
{
$this->height = (float) $height;
$this->height = $height;
}
/**
* @inheritDoc
*/
public function shouldBeApplied()
public function shouldBeApplied(): bool
{
return $this->height != null;
}
Expand All @@ -75,7 +75,7 @@ in the criteria. We do not care about the pagination, nor order of the results.
/**
* @inheritDoc
*/
public function allowsCriteria(CriteriaInterface $criteria)
public function allowsCriteria(CriteriaInterface $criteria): bool
{
return $criteria instanceof HeightCriteria;
}
Expand All @@ -85,7 +85,8 @@ in the criteria. We do not care about the pagination, nor order of the results.
*/
public function supportsSearchingContext(
SearchingContextInterface $searchingContext
) {
): bool
{
return $searchingContext instanceof QueryBuilderSearchingContext;
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ What?
-----------------
*Searcher* is a framework-agnostic search query builder.
Search queries are written using Criterias and can be run against MySQL, MongoDB or even files.
Supported PHP versions: >=5.4, 7 and HHVM.
**Latest version is supporting only PHP 7.**
You can find searcher in two most important places:

- GitHub repository: https://github.com/krzysztof-gzocha/searcher
Expand Down
19 changes: 11 additions & 8 deletions src/KGzocha/Searcher/AbstractCollection.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace KGzocha\Searcher;

Expand Down Expand Up @@ -29,14 +30,16 @@ public function __construct($items = [])
*
* @return bool
*/
abstract protected function isItemValid($item);
abstract protected function isItemValid($item): bool;

/**
* {@inheritdoc}
*/
public function getIterator()
public function getIterator(): \Iterator
{
return new \ArrayIterator($this->items);
foreach ($this->items as $key => $item) {
yield $key => $item;
}
}

/**
Expand All @@ -50,9 +53,9 @@ public function count()
/**
* @param mixed $item
*
* @return $this
* @return self
*/
protected function addItem($item)
protected function addItem($item): AbstractCollection
{
$this->items[] = $item;

Expand All @@ -63,9 +66,9 @@ protected function addItem($item)
* @param string $name
* @param mixed $item
*
* @return $this
* @return self
*/
protected function addNamedItem($name, $item)
protected function addNamedItem(string $name, $item): AbstractCollection
{
$this->items[$name] = $item;

Expand All @@ -85,7 +88,7 @@ protected function getItems()
*
* @return mixed|null
*/
protected function getNamedItem($name)
protected function getNamedItem(string $name)
{
if (array_key_exists($name, $this->items)) {
return $this->items[$name];
Expand Down
13 changes: 7 additions & 6 deletions src/KGzocha/Searcher/Chain/Cell.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace KGzocha\Searcher\Chain;

Expand Down Expand Up @@ -36,25 +37,25 @@ public function __construct(
}

/**
* @return \KGzocha\Searcher\SearcherInterface
* @inheritdoc
*/
public function getSearcher()
public function getSearcher(): SearcherInterface
{
return $this->searcher;
}

/**
* @return TransformerInterface
* @inheritdoc
*/
public function getTransformer()
public function getTransformer(): TransformerInterface
{
return $this->transformer;
}

/**
* @return bool
* @inheritdoc
*/
public function hasTransformer()
public function hasTransformer(): bool
{
return !$this->transformer instanceof EndTransformer;
}
Expand Down
11 changes: 7 additions & 4 deletions src/KGzocha/Searcher/Chain/CellInterface.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php
declare(strict_types=1);

namespace KGzocha\Searcher\Chain;

use KGzocha\Searcher\SearcherInterface;

/**
* It represents single cell in the chain. It holds sub-searcher and it's transformer, which will
* transform results from it's sub-searcher to CriteriaCollection that can be used in next sub-search.
Expand All @@ -12,17 +15,17 @@
interface CellInterface
{
/**
* @return \KGzocha\Searcher\SearcherInterface
* @return SearcherInterface
*/
public function getSearcher();
public function getSearcher(): SearcherInterface;

/**
* @return TransformerInterface
*/
public function getTransformer();
public function getTransformer(): TransformerInterface;

/**
* @return bool
*/
public function hasTransformer();
public function hasTransformer(): bool;
}
Loading

0 comments on commit 1c1d856

Please sign in to comment.