Skip to content

Commit

Permalink
Drop support for PHP 7.4 (doctrine#2515)
Browse files Browse the repository at this point in the history
* Drop support for PHP 7.4, require PHP 8.0

* Enforce PHP 8 syntax in phpcs

* Fix static analysis errors

* Move psalm configuration to .dist file

* Set psalm phpVersion through config file

* Run PHPStan on PHP 8.2

* Remove superfluous assertion
  • Loading branch information
alcaeus authored Mar 28, 2023
1 parent 8b3f57a commit e235642
Show file tree
Hide file tree
Showing 125 changed files with 391 additions and 716 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
Expand All @@ -33,7 +32,7 @@ jobs:
- "highest"
include:
- dependencies: "lowest"
php-version: "7.4"
php-version: "8.0"
mongodb-version: "4.4"
driver-version: "1.11.0"
topology: "server"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"

services:
mongodb:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"

steps:
- name: "Checkout code"
Expand Down Expand Up @@ -88,4 +88,4 @@ jobs:
path: composer.lock

- name: "Run a static analysis with vimeo/psalm"
run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc) --php-version=${{ matrix.php-version }}"
run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc)"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ vendor/
.phpcs-cache
.phpunit.result.cache
phpcs.xml
psalm.xml
6 changes: 6 additions & 0 deletions UPGRADE-2.6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# UPGRADE FROM to 2.6

## PHP requirements

* MongoDB ODM 2.6 requires PHP 8.0 or newer. If you're not running PHP 8.0 yet,
it's recommended that you upgrade to PHP 8.0 before upgrading ODM.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{ "name": "Fran Moreno", "email": "franmomu@gmail.com" }
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.0",
"ext-mongodb": "^1.11",
"doctrine/annotations": "^1.12 || ^2.0",
"doctrine/cache": "^1.11 || ^2.0",
Expand Down
25 changes: 1 addition & 24 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,13 @@
/** @psalm-import-type PipelineExpression from Builder */
final class Aggregation implements IteratorAggregate
{
private DocumentManager $dm;

private ?ClassMetadata $classMetadata;

private Collection $collection;

/**
* @var array<string, mixed>
* @psalm-var PipelineExpression
*/
private array $pipeline;

/** @var array<string, mixed> */
private array $options;

private bool $rewindable;

/**
* @param array<string, mixed> $pipeline
* @param array<string, mixed> $options
* @psalm-param PipelineExpression $pipeline
*/
public function __construct(DocumentManager $dm, ?ClassMetadata $classMetadata, Collection $collection, array $pipeline, array $options = [], bool $rewindable = true)
public function __construct(private DocumentManager $dm, private ?ClassMetadata $classMetadata, private Collection $collection, private array $pipeline, private array $options = [], private bool $rewindable = true)
{
$this->dm = $dm;
$this->classMetadata = $classMetadata;
$this->collection = $collection;
$this->pipeline = $pipeline;
$this->options = $options;
$this->rewindable = $rewindable;
}

public function getIterator(): Iterator
Expand Down
11 changes: 1 addition & 10 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\ODM\MongoDB\Persisters\DocumentPersister;
use Doctrine\ODM\MongoDB\Types\Type;
use Doctrine\Persistence\Mapping\ClassMetadata as ClassMetadataInterface;
use LogicException;

use function array_map;
use function array_merge;
use function assert;
use function func_get_args;
use function is_array;
use function is_string;
Expand All @@ -29,10 +27,6 @@
*/
class Expr implements GenericOperatorsInterface
{
private DocumentManager $dm;

private ClassMetadata $class;

/** @var array<string, mixed> */
private array $expr = [];

Expand All @@ -44,11 +38,8 @@ class Expr implements GenericOperatorsInterface
/** @var array{case: mixed|self, then?: mixed|self}|null */
private ?array $switchBranch = null;

public function __construct(DocumentManager $dm, ClassMetadataInterface $class)
public function __construct(private DocumentManager $dm, private ClassMetadata $class)
{
assert($class instanceof ClassMetadata);
$this->dm = $dm;
$this->class = $class;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,14 @@
*/
abstract class AbstractBucket extends Stage
{
private DocumentManager $dm;

private ClassMetadata $class;

/** @var Bucket\AbstractOutput|null */
protected $output;

/** @var Expr|array<string, mixed>|string */
protected $groupBy;

public function __construct(Builder $builder, DocumentManager $documentManager, ClassMetadata $class)
public function __construct(Builder $builder, private DocumentManager $dm, private ClassMetadata $class)
{
$this->dm = $documentManager;
$this->class = $class;

parent::__construct($builder);
}

Expand Down
11 changes: 1 addition & 10 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/AbstractReplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,10 @@

abstract class AbstractReplace extends Operator
{
/** @var string|mixed[]|Expr|null */
protected $expression;
protected DocumentManager $dm;
protected ClassMetadata $class;

/** @param string|mixed[]|Expr|null $expression */
final public function __construct(Builder $builder, DocumentManager $documentManager, ClassMetadata $class, $expression = null)
final public function __construct(Builder $builder, protected DocumentManager $dm, protected ClassMetadata $class, protected $expression = null)
{
Operator::__construct($builder);

$this->dm = $documentManager;
$this->class = $class;
$this->expression = $expression;
}

private function getDocumentPersister(): DocumentPersister
Expand Down
6 changes: 1 addition & 5 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@
*/
class Count extends Stage
{
private string $fieldName;

public function __construct(Builder $builder, string $fieldName)
public function __construct(Builder $builder, private string $fieldName)
{
parent::__construct($builder);

$this->fieldName = $fieldName;
}

/** @psalm-return CountStageExpression */
Expand Down
6 changes: 1 addition & 5 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@
*/
class Output extends Stage
{
private Fill $fill;

private string $currentField = '';

/** @var array<string, array<string, mixed>> */
private $output = [];

public function __construct(Builder $builder, Fill $fill)
public function __construct(Builder $builder, private Fill $fill)
{
parent::__construct($builder);

$this->fill = $fill;
}

/** @param mixed|Expr $expression */
Expand Down
10 changes: 2 additions & 8 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,16 @@ class GraphLookup extends Stage

private Stage\GraphLookup\MatchStage $restrictSearchWithMatch;

private DocumentManager $dm;

private ClassMetadata $class;

private ?ClassMetadata $targetClass = null;

/**
* @param string $from Target collection for the $graphLookup operation to
* search, recursively matching the connectFromField to the connectToField.
*/
public function __construct(Builder $builder, string $from, DocumentManager $documentManager, ClassMetadata $class)
public function __construct(Builder $builder, string $from, private DocumentManager $dm, private ClassMetadata $class)
{
parent::__construct($builder);

$this->dm = $documentManager;
$this->class = $class;
$this->restrictSearchWithMatch = new GraphLookup\MatchStage($this->builder, $this);
$this->from($from);
}
Expand Down Expand Up @@ -152,7 +146,7 @@ public function from(string $from): self
// Check if mapped class with given name exists
try {
$this->targetClass = $this->dm->getClassMetadata($from);
} catch (BaseMappingException $e) {
} catch (BaseMappingException) {
$this->from = $from;

return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@

class MatchStage extends BaseMatchStage
{
private GraphLookup $graphLookup;

public function __construct(Builder $builder, GraphLookup $graphLookup)
public function __construct(Builder $builder, private GraphLookup $graphLookup)
{
parent::__construct($builder);

$this->graphLookup = $graphLookup;
}

public function getExpression(): array
Expand Down
6 changes: 1 addition & 5 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Limit.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@
*/
class Limit extends Stage
{
private int $limit;

public function __construct(Builder $builder, int $limit)
public function __construct(Builder $builder, private int $limit)
{
parent::__construct($builder);

$this->limit = $limit;
}

/** @psalm-return LimitStageExpression */
Expand Down
11 changes: 2 additions & 9 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
*/
class Lookup extends Stage
{
private DocumentManager $dm;

private ClassMetadata $class;

private ?ClassMetadata $targetClass = null;

private string $from;
Expand All @@ -56,13 +52,10 @@ class Lookup extends Stage

private bool $excludeLocalAndForeignField = false;

public function __construct(Builder $builder, string $from, DocumentManager $documentManager, ClassMetadata $class)
public function __construct(Builder $builder, string $from, private DocumentManager $dm, private ClassMetadata $class)
{
parent::__construct($builder);

$this->dm = $documentManager;
$this->class = $class;

$this->from($from);
}

Expand Down Expand Up @@ -97,7 +90,7 @@ public function from(string $from): self
// Check if mapped class with given name exists
try {
$this->targetClass = $this->dm->getClassMetadata($from);
} catch (BaseMappingException $e) {
} catch (BaseMappingException) {
$this->from = $from;

return $this;
Expand Down
8 changes: 2 additions & 6 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
*/
class Merge extends Stage
{
private DocumentManager $dm;

/**
* @var string|array
* @psalm-var OutputCollection
Expand All @@ -55,11 +53,9 @@ class Merge extends Stage

private ?string $whenNotMatched = null;

public function __construct(Builder $builder, DocumentManager $documentManager)
public function __construct(Builder $builder, private DocumentManager $dm)
{
parent::__construct($builder);

$this->dm = $documentManager;
}

/** @psalm-return MergeStageExpression */
Expand Down Expand Up @@ -105,7 +101,7 @@ public function into($collection): self
try {
$class = $this->dm->getClassMetadata($collection);
$this->into = $class->getCollection();
} catch (MappingException $e) {
} catch (MappingException) {
$this->into = $collection;
}

Expand Down
7 changes: 2 additions & 5 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Out.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@
*/
class Out extends Stage
{
private DocumentManager $dm;

/**
* @var array|string
* @psalm-var OutputCollection
*/
private $out;

public function __construct(Builder $builder, string $collection, DocumentManager $documentManager)
public function __construct(Builder $builder, string $collection, private DocumentManager $dm)
{
parent::__construct($builder);

$this->dm = $documentManager;
$this->out($collection);
}

Expand All @@ -56,7 +53,7 @@ public function out($collection): Stage\Out

try {
$class = $this->dm->getClassMetadata($collection);
} catch (BaseMappingException $e) {
} catch (BaseMappingException) {
$this->out = $collection;

return $this;
Expand Down
6 changes: 1 addition & 5 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@
*/
class Sample extends Stage
{
private int $size;

public function __construct(Builder $builder, int $size)
public function __construct(Builder $builder, private int $size)
{
parent::__construct($builder);

$this->size = $size;
}

/** @psalm-return SampleStageExpression */
Expand Down
Loading

0 comments on commit e235642

Please sign in to comment.