Skip to content

Commit

Permalink
Merge pull request #119 from doctrine/require-php-71
Browse files Browse the repository at this point in the history
Require PHP 7.1
  • Loading branch information
Ocramius authored May 23, 2017
2 parents 38065c6 + 737931d commit f4b7fca
Show file tree
Hide file tree
Showing 20 changed files with 243 additions and 273 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ language: php
sudo: false

php:
- 7.0
- 7.1
- nightly

matrix:
fast_finish: true
allow_failures:
- nightly

before_install:
- if [[ $TRAVIS_PHP_VERSION = '7.1' ]]; then PHPUNIT_FLAGS="--coverage-clover clover.xml"; fi
Expand Down
15 changes: 8 additions & 7 deletions lib/Doctrine/Common/Collections/ArrayCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ArrayCollection implements Collection, Selectable
*
* @param array $elements
*/
public function __construct(array $elements = array())
public function __construct(array $elements = [])
{
$this->elements = $elements;
}
Expand Down Expand Up @@ -177,7 +177,8 @@ public function offsetGet($offset)
public function offsetSet($offset, $value)
{
if ( ! isset($offset)) {
return $this->add($value);
$this->add($value);
return;
}

$this->set($offset, $value);
Expand All @@ -190,7 +191,7 @@ public function offsetSet($offset, $value)
*/
public function offsetUnset($offset)
{
return $this->remove($offset);
$this->remove($offset);
}

/**
Expand Down Expand Up @@ -236,7 +237,7 @@ public function indexOf($element)
*/
public function get($key)
{
return isset($this->elements[$key]) ? $this->elements[$key] : null;
return $this->elements[$key] ?? null;
}

/**
Expand Down Expand Up @@ -338,7 +339,7 @@ public function forAll(Closure $p)
*/
public function partition(Closure $p)
{
$matches = $noMatches = array();
$matches = $noMatches = [];

foreach ($this->elements as $key => $element) {
if ($p($key, $element)) {
Expand All @@ -348,7 +349,7 @@ public function partition(Closure $p)
}
}

return array($this->createFrom($matches), $this->createFrom($noMatches));
return [$this->createFrom($matches), $this->createFrom($noMatches)];
}

/**
Expand All @@ -366,7 +367,7 @@ public function __toString()
*/
public function clear()
{
$this->elements = array();
$this->elements = [];
}

/**
Expand Down
18 changes: 10 additions & 8 deletions lib/Doctrine/Common/Collections/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Criteria
/**
* @var string[]
*/
private $orderings = array();
private $orderings = [];

/**
* @var int|null
Expand Down Expand Up @@ -137,9 +137,10 @@ public function andWhere(Expression $expression)
return $this->where($expression);
}

$this->expression = new CompositeExpression(CompositeExpression::TYPE_AND, array(
$this->expression, $expression
));
$this->expression = new CompositeExpression(
CompositeExpression::TYPE_AND,
[$this->expression, $expression]
);

return $this;
}
Expand All @@ -158,9 +159,10 @@ public function orWhere(Expression $expression)
return $this->where($expression);
}

$this->expression = new CompositeExpression(CompositeExpression::TYPE_OR, array(
$this->expression, $expression
));
$this->expression = new CompositeExpression(
CompositeExpression::TYPE_OR,
[$this->expression, $expression]
);

return $this;
}
Expand Down Expand Up @@ -200,7 +202,7 @@ public function getOrderings()
public function orderBy(array $orderings)
{
$this->orderings = array_map(
function ($ordering) {
function (string $ordering) : string {
return strtoupper($ordering) === Criteria::ASC ? Criteria::ASC : Criteria::DESC;
},
$orderings
Expand Down
42 changes: 22 additions & 20 deletions lib/Doctrine/Common/Collections/Expr/ClosureExpressionVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ClosureExpressionVisitor extends ExpressionVisitor
* directly or indirectly (through an accessor get*, is*, or a magic
* method, __get, __call).
*
* @param object $object
* @param object|array $object
* @param string $field
*
* @return mixed
Expand All @@ -46,7 +46,7 @@ public static function getObjectFieldValue($object, $field)
return $object[$field];
}

$accessors = array('get', 'is');
$accessors = ['get', 'is'];

foreach ($accessors as $accessor) {
$accessor .= $field;
Expand Down Expand Up @@ -102,12 +102,12 @@ public static function getObjectFieldValue($object, $field)
public static function sortByField($name, $orientation = 1, \Closure $next = null)
{
if ( ! $next) {
$next = function() {
$next = function() : int {
return 0;
};
}

return function ($a, $b) use ($name, $next, $orientation) {
return function ($a, $b) use ($name, $next, $orientation) : int {
$aValue = ClosureExpressionVisitor::getObjectFieldValue($a, $name);
$bValue = ClosureExpressionVisitor::getObjectFieldValue($b, $name);

Expand All @@ -129,42 +129,42 @@ public function walkComparison(Comparison $comparison)

switch ($comparison->getOperator()) {
case Comparison::EQ:
return function ($object) use ($field, $value) {
return function ($object) use ($field, $value) : bool {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) === $value;
};

case Comparison::NEQ:
return function ($object) use ($field, $value) {
return function ($object) use ($field, $value) : bool {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) !== $value;
};

case Comparison::LT:
return function ($object) use ($field, $value) {
return function ($object) use ($field, $value) : bool {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) < $value;
};

case Comparison::LTE:
return function ($object) use ($field, $value) {
return function ($object) use ($field, $value) : bool {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) <= $value;
};

case Comparison::GT:
return function ($object) use ($field, $value) {
return function ($object) use ($field, $value) : bool {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) > $value;
};

case Comparison::GTE:
return function ($object) use ($field, $value) {
return function ($object) use ($field, $value) : bool {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) >= $value;
};

case Comparison::IN:
return function ($object) use ($field, $value) {
return function ($object) use ($field, $value) : bool {
return in_array(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value);
};

case Comparison::NIN:
return function ($object) use ($field, $value) {
return function ($object) use ($field, $value) : bool {
return ! in_array(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value);
};

Expand All @@ -174,7 +174,7 @@ public function walkComparison(Comparison $comparison)
};

case Comparison::MEMBER_OF:
return function ($object) use ($field, $value) {
return function ($object) use ($field, $value) : bool {
$fieldValues = ClosureExpressionVisitor::getObjectFieldValue($object, $field);
if (!is_array($fieldValues)) {
$fieldValues = iterator_to_array($fieldValues);
Expand All @@ -183,12 +183,12 @@ public function walkComparison(Comparison $comparison)
};

case Comparison::STARTS_WITH:
return function ($object) use ($field, $value) {
return function ($object) use ($field, $value) : bool {
return 0 === strpos(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value);
};

case Comparison::ENDS_WITH:
return function ($object) use ($field, $value) {
return function ($object) use ($field, $value) : bool {
return $value === substr(ClosureExpressionVisitor::getObjectFieldValue($object, $field), -strlen($value));
};

Expand All @@ -211,7 +211,7 @@ public function walkValue(Value $value)
*/
public function walkCompositeExpression(CompositeExpression $expr)
{
$expressionList = array();
$expressionList = [];

foreach ($expr->getExpressionList() as $child) {
$expressionList[] = $this->dispatch($child);
Expand All @@ -234,14 +234,15 @@ public function walkCompositeExpression(CompositeExpression $expr)
*
* @return callable
*/
private function andExpressions($expressions)
private function andExpressions(array $expressions) : callable
{
return function ($object) use ($expressions) {
return function ($object) use ($expressions) : bool {
foreach ($expressions as $expression) {
if ( ! $expression($object)) {
return false;
}
}

return true;
};
}
Expand All @@ -251,14 +252,15 @@ private function andExpressions($expressions)
*
* @return callable
*/
private function orExpressions($expressions)
private function orExpressions(array $expressions) : callable
{
return function ($object) use ($expressions) {
return function ($object) use ($expressions) : bool {
foreach ($expressions as $expression) {
if ($expression($object)) {
return true;
}
}

return false;
};
}
Expand Down
25 changes: 13 additions & 12 deletions lib/Doctrine/Common/Collections/Expr/Comparison.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@
*/
class Comparison implements Expression
{
const EQ = '=';
const NEQ = '<>';
const LT = '<';
const LTE = '<=';
const GT = '>';
const GTE = '>=';
const IS = '='; // no difference with EQ
const IN = 'IN';
const NIN = 'NIN';
const CONTAINS = 'CONTAINS';
const MEMBER_OF = 'MEMBER_OF';
const EQ = '=';
const NEQ = '<>';
const LT = '<';
const LTE = '<=';
const GT = '>';
const GTE = '>=';
const IS = '='; // no difference with EQ
const IN = 'IN';
const NIN = 'NIN';
const CONTAINS = 'CONTAINS';
const MEMBER_OF = 'MEMBER_OF';
const STARTS_WITH = 'STARTS_WITH';
const ENDS_WITH = 'ENDS_WITH';
const ENDS_WITH = 'ENDS_WITH';

/**
* @var string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CompositeExpression implements Expression
/**
* @var Expression[]
*/
private $expressions = array();
private $expressions = [];

/**
* @param string $type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Doctrine\Tests\Common\Collections;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Tests\LazyArrayCollection;

/**
Expand All @@ -29,13 +30,14 @@
*/
class AbstractLazyCollectionTest extends BaseArrayCollectionTest
{
protected function buildCollection(array $elements = [])
protected function buildCollection(array $elements = []) : Collection
{
return new LazyArrayCollection(new ArrayCollection($elements));
}

public function testLazyCollection()
public function testLazyCollection() : void
{
/** @var LazyArrayCollection $collection */
$collection = $this->buildCollection(['a', 'b', 'c']);

$this->assertFalse($collection->isInitialized());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class LazyCollectionTest extends BaseCollectionTest
{
protected function setUp()
protected function setUp() : void
{
$this->collection = new LazyArrayCollection(new ArrayCollection());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Doctrine\Tests\Common\Collections;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

/**
* Tests for {@see \Doctrine\Common\Collections\ArrayCollection}.
Expand All @@ -28,7 +29,7 @@
*/
class ArrayCollectionTest extends BaseArrayCollectionTest
{
protected function buildCollection(array $elements = [])
protected function buildCollection(array $elements = []) : Collection
{
return new ArrayCollection($elements);
}
Expand Down
Loading

0 comments on commit f4b7fca

Please sign in to comment.