Skip to content

Commit a95ea45

Browse files
authored
Merge pull request #2470 from IonBazan/feature/php-7.4
Make use of PHP 7.4 syntax
2 parents a4e0748 + b9fd914 commit a95ea45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+141
-256
lines changed

lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,7 @@ public function getPipeline(/* bool $applyFilters = true */): array
277277
}
278278

279279
$pipeline = array_map(
280-
static function (Stage $stage) {
281-
return $stage->getExpression();
282-
},
280+
static fn (Stage $stage) => $stage->getExpression(),
283281
$this->stages
284282
);
285283

lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,7 @@ public function cond($if, $then, $else): self
318318
public static function convertExpression($expression)
319319
{
320320
if (is_array($expression)) {
321-
return array_map(static function ($expression) {
322-
return static::convertExpression($expression);
323-
}, $expression);
321+
return array_map(static fn ($expression) => static::convertExpression($expression), $expression);
324322
}
325323

326324
if ($expression instanceof self) {

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Facet.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ class Facet extends Stage
2525
public function getExpression(): array
2626
{
2727
return [
28-
'$facet' => array_map(static function (Builder $builder) {
29-
return $builder->getPipeline(false);
30-
}, $this->pipelines),
28+
'$facet' => array_map(static fn (Builder $builder) => $builder->getPipeline(false), $this->pipelines),
3129
];
3230
}
3331

lib/Doctrine/ODM/MongoDB/DocumentNotFoundException.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

55
namespace Doctrine\ODM\MongoDB;
66

7+
use JsonException;
8+
79
use function json_encode;
810
use function sprintf;
911

12+
use const JSON_THROW_ON_ERROR;
13+
1014
/**
1115
* Class for exception when encountering proxy object that has
1216
* an identifier that does not exist in the database.
@@ -18,10 +22,15 @@ final class DocumentNotFoundException extends MongoDBException
1822
*/
1923
public static function documentNotFound(string $className, $identifier): self
2024
{
25+
try {
26+
$id = json_encode($identifier, JSON_THROW_ON_ERROR);
27+
} catch (JsonException $e) {
28+
}
29+
2130
return new self(sprintf(
2231
'The "%s" document with identifier %s could not be found.',
2332
$className,
24-
json_encode($identifier)
25-
));
33+
$id ?? false,
34+
), 0, $e ?? null);
2635
}
2736
}

lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use BadMethodCallException;
99
use DateTime;
1010
use DateTimeImmutable;
11+
use Doctrine\Common\Collections\Collection;
1112
use Doctrine\Instantiator\Instantiator;
1213
use Doctrine\Instantiator\InstantiatorInterface;
1314
use Doctrine\ODM\MongoDB\Id\IdGenerator;
@@ -1851,9 +1852,7 @@ public function getEmbeddedFieldsMappings(): array
18511852
{
18521853
return array_filter(
18531854
$this->associationMappings,
1854-
static function ($assoc) {
1855-
return ! empty($assoc['embedded']);
1856-
}
1855+
static fn ($assoc) => ! empty($assoc['embedded'])
18571856
);
18581857
}
18591858

@@ -2206,7 +2205,7 @@ public function mapField(array $mapping): array
22062205

22072206
if (! empty($mapping['collectionClass'])) {
22082207
$rColl = new ReflectionClass($mapping['collectionClass']);
2209-
if (! $rColl->implementsInterface('Doctrine\\Common\\Collections\\Collection')) {
2208+
if (! $rColl->implementsInterface(Collection::class)) {
22102209
throw MappingException::collectionClassDoesNotImplementCommonInterface($this->name, $mapping['fieldName'], $mapping['collectionClass']);
22112210
}
22122211
}

lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,7 @@ private function validateSchema(string $filename): void
738738
*/
739739
private function formatErrors(array $xmlErrors): string
740740
{
741-
return implode("\n", array_map(static function (LibXMLError $error): string {
742-
return sprintf('Line %d:%d: %s', $error->line, $error->column, $error->message);
743-
}, $xmlErrors));
741+
return implode("\n", array_map(static fn (LibXMLError $error): string => sprintf('Line %d:%d: %s', $error->line, $error->column, $error->message), $xmlErrors));
744742
}
745743

746744
/**

lib/Doctrine/ODM/MongoDB/PersistentCollection/DefaultPersistentCollectionGenerator.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function __construct(BaseCollection \$coll, DocumentManager \$dm, UnitOfW
154154
155155
CODE;
156156
$rc = new ReflectionClass($for);
157-
$rt = new ReflectionClass('Doctrine\\ODM\\MongoDB\\PersistentCollection\\PersistentCollectionTrait');
157+
$rt = new ReflectionClass(PersistentCollectionTrait::class);
158158
foreach ($rc->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
159159
if (
160160
$rt->hasMethod($method->name) ||
@@ -302,18 +302,14 @@ private function formatType(
302302
): string {
303303
if ($type instanceof ReflectionUnionType) {
304304
return implode('|', array_map(
305-
function (ReflectionType $unionedType) use ($method, $parameter) {
306-
return $this->formatType($unionedType, $method, $parameter);
307-
},
305+
fn (ReflectionType $unionedType) => $this->formatType($unionedType, $method, $parameter),
308306
$type->getTypes()
309307
));
310308
}
311309

312310
if ($type instanceof ReflectionIntersectionType) {
313311
return implode('&', array_map(
314-
function (ReflectionType $intersectedType) use ($method, $parameter) {
315-
return $this->formatType($intersectedType, $method, $parameter);
316-
},
312+
fn (ReflectionType $intersectedType) => $this->formatType($intersectedType, $method, $parameter),
317313
$type->getTypes()
318314
));
319315
}

lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,7 @@ public function getDeleteDiff()
249249
return array_udiff_assoc(
250250
$this->snapshot,
251251
$this->coll->toArray(),
252-
static function ($a, $b) {
253-
return $a === $b ? 0 : 1;
254-
}
252+
static fn ($a, $b) => $a === $b ? 0 : 1
255253
);
256254
}
257255

@@ -269,9 +267,7 @@ public function getInsertDiff()
269267
return array_udiff_assoc(
270268
$this->coll->toArray(),
271269
$this->snapshot,
272-
static function ($a, $b) {
273-
return $a === $b ? 0 : 1;
274-
}
270+
static fn ($a, $b) => $a === $b ? 0 : 1
275271
);
276272
}
277273

lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,10 @@ private function getValuePrepareCallback(PersistentCollectionInterface $coll): C
396396
{
397397
$mapping = $coll->getMapping();
398398
if (isset($mapping['embedded'])) {
399-
return function ($v) use ($mapping) {
400-
return $this->pb->prepareEmbeddedDocumentValue($mapping, $v);
401-
};
399+
return fn ($v) => $this->pb->prepareEmbeddedDocumentValue($mapping, $v);
402400
}
403401

404-
return function ($v) use ($mapping) {
405-
return $this->pb->prepareReferencedDocumentValue($mapping, $v);
406-
};
402+
return fn ($v) => $this->pb->prepareReferencedDocumentValue($mapping, $v);
407403
}
408404

409405
/**

lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ private function convertToDatabaseValue(string $fieldName, $value)
11761176
*/
11771177
private function prepareQueryElement(string $fieldName, $value = null, ?ClassMetadata $class = null, bool $prepareValue = true, bool $inNewObj = false): array
11781178
{
1179-
$class = $class ?? $this->class;
1179+
$class ??= $this->class;
11801180

11811181
// @todo Consider inlining calls to ClassMetadata methods
11821182

@@ -1662,9 +1662,7 @@ private function prepareReference(string $fieldName, object $value, array $mappi
16621662
}
16631663

16641664
return array_map(
1665-
static function ($key) use ($reference, $fieldName) {
1666-
return [$fieldName . '.' . $key, $reference[$key]];
1667-
},
1665+
static fn ($key) => [$fieldName . '.' . $key, $reference[$key]],
16681666
array_keys($keys)
16691667
);
16701668
}

0 commit comments

Comments
 (0)