Skip to content

Commit 970e074

Browse files
authored
Merge pull request #865 from doctrine/modernize-code
modernize php code
2 parents 7c4e151 + 6ce46b9 commit 970e074

Some content is hidden

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

54 files changed

+330
-509
lines changed

lib/Doctrine/ODM/PHPCR/DocumentClassMapper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private function expandClassName(DocumentManagerInterface $dm, string $className
1919
return null;
2020
}
2121

22-
if (false !== strpos($className, ':')) {
22+
if (str_contains($className, ':')) {
2323
$className = $dm->getClassMetadata($className)->getName();
2424
}
2525

lib/Doctrine/ODM/PHPCR/DocumentManager.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class DocumentManager implements DocumentManagerInterface
5656
/**
5757
* @var TranslationStrategyInterface[]
5858
*/
59-
protected array $translationStrategy;
59+
private array $translationStrategy;
6060

61-
protected LocaleChooserInterface $localeChooserStrategy;
61+
private LocaleChooserInterface $localeChooserStrategy;
6262
private ValueConverter $valueConverter;
6363

6464
public function __construct(SessionInterface $session, Configuration $config = null, EventManager $evm = null)
@@ -182,7 +182,7 @@ public function find(?string $className, $id): ?object
182182
} catch (ItemNotFoundException $e) {
183183
return null;
184184
}
185-
} elseif (0 !== strpos($id, '/')) {
185+
} elseif (!str_starts_with($id, '/')) {
186186
$id = '/'.$id;
187187
}
188188

@@ -220,7 +220,7 @@ public function findMany(?string $className, array $ids): Collection
220220
foreach ($ids as $key => $id) {
221221
if (UUIDHelper::isUUID($id)) {
222222
$uuids[$id] = $key;
223-
} elseif (0 !== strpos($id, '/')) {
223+
} elseif (!str_starts_with($id, '/')) {
224224
$ids[$key] = '/'.$id;
225225
}
226226
}
@@ -257,7 +257,7 @@ public function findTranslation(?string $className, string $id, string $locale,
257257
} catch (ItemNotFoundException $e) {
258258
return null;
259259
}
260-
} elseif (0 !== strpos($id, '/')) {
260+
} elseif (!str_starts_with($id, '/')) {
261261
$id = '/'.$id;
262262
}
263263

@@ -424,7 +424,7 @@ public function isDocumentTranslatable(object $document): bool
424424

425425
public function move(object $document, string $targetPath): void
426426
{
427-
if (0 !== strpos($targetPath, '/')) {
427+
if (!str_starts_with($targetPath, '/')) {
428428
$targetPath = '/'.$targetPath;
429429
}
430430

lib/Doctrine/ODM/PHPCR/DocumentRepository.php

+5-12
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,16 @@ public function find($id): ?object
5858
* The ids may either be PHPCR paths or UUID's, but all must be of the same type
5959
*
6060
* @param string[] $ids document ids
61-
*
62-
* @return array|Collection of document objects
6361
*/
64-
public function findMany(array $ids): iterable
62+
public function findMany(array $ids): Collection
6563
{
6664
return $this->dm->findMany($this->className, $ids);
6765
}
6866

6967
/**
7068
* Finds all documents in the repository.
71-
*
72-
* @return array|Collection the entities
7369
*/
74-
public function findAll(): iterable
70+
public function findAll(): Collection
7571
{
7672
return $this->findBy([]);
7773
}
@@ -83,12 +79,9 @@ public function findAll(): iterable
8379
* an InvalidArgumentException if certain values of the sorting or limiting details are
8480
* not supported.
8581
*
86-
* @param int|null $limit
87-
* @param int|null $offset
88-
*
89-
* @return array|Collection the objects matching the criteria
82+
* @return Collection the objects matching the criteria
9083
*/
91-
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): iterable
84+
public function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): Collection
9285
{
9386
$qb = $this->createQueryBuilder('a');
9487

@@ -146,7 +139,7 @@ public function findBy(array $criteria, array $orderBy = null, $limit = null, $o
146139
* @param mixed $value The value to search for
147140
* @param string $alias The alias used
148141
*/
149-
protected function constraintField(ConstraintFactory $where, string $field, $value, string $alias): void
142+
protected function constraintField(ConstraintFactory $where, string $field, mixed $value, string $alias): void
150143
{
151144
if ($field === $this->class->nodename) {
152145
$where->eq()->name($alias)->literal($value);

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

+4-7
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ClassMetadata implements ClassMetadataInterface
7373
*/
7474
public const GENERATOR_TYPE_AUTO = 4;
7575

76-
protected static $validVersionableMappings = ['simple', 'full'];
76+
private static $validVersionableMappings = ['simple', 'full'];
7777

7878
/**
7979
* READ-ONLY: The ReflectionProperty instances of the mapped class.
@@ -837,7 +837,7 @@ public function mapLifecycleCallbacks(array $mapping): void
837837
*
838838
* @throws MappingException
839839
*/
840-
protected function validateAndCompleteFieldMapping(array $mapping, self $inherited = null, bool $isField = true, $phpcrLabel = 'property'): array
840+
private function validateAndCompleteFieldMapping(array $mapping, self $inherited = null, bool $isField = true, $phpcrLabel = 'property'): array
841841
{
842842
if ($inherited) {
843843
if (!array_key_exists('inherited', $mapping)) {
@@ -916,10 +916,7 @@ protected function validateAndCompleteFieldMapping(array $mapping, self $inherit
916916
return $mapping;
917917
}
918918

919-
/**
920-
* @param string|bool $phpcrLabel
921-
*/
922-
protected function validateAndCompleteAssociationMapping(array $mapping, self $inherited = null, $phpcrLabel = 'property'): array
919+
private function validateAndCompleteAssociationMapping(array $mapping, self $inherited = null, bool|string $phpcrLabel = 'property'): array
923920
{
924921
$mapping = $this->validateAndCompleteFieldMapping($mapping, $inherited, false, $phpcrLabel);
925922
if ($inherited) {
@@ -1083,7 +1080,7 @@ public function mapManyToMany(array $mapping, self $inherited = null): void
10831080
/**
10841081
* Sets the ID generator used to generate IDs for instances of this class.
10851082
*/
1086-
protected function setIdGenerator(int|string $generator): void
1083+
private function setIdGenerator(int|string $generator): void
10871084
{
10881085
if (is_string($generator)) {
10891086
$generator = constant('Doctrine\ODM\PHPCR\Mapping\ClassMetadata::GENERATOR_TYPE_'.strtoupper($generator));

lib/Doctrine/ODM/PHPCR/Query/Builder/AbstractLeafNode.php

+7-9
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@
1212
*/
1313
abstract class AbstractLeafNode extends AbstractNode
1414
{
15-
public function getNext()
15+
public function getNext(): ?AbstractNode
1616
{
1717
return $this->getParent();
1818
}
1919

20-
public function getChildren()
20+
public function getChildren(): array
2121
{
2222
throw new RuntimeException(sprintf(
2323
'Cannot call getChildren on leaf node "%s"',
2424
$this->getName()
2525
));
2626
}
2727

28-
public function addChild(AbstractNode $node)
28+
public function addChild(AbstractNode $node): static
2929
{
3030
throw new RuntimeException(sprintf(
3131
'Cannot call addChild to leaf node "%s"',
3232
$this->getName()
3333
));
3434
}
3535

36-
public function getCardinalityMap()
36+
public function getCardinalityMap(): array
3737
{
3838
// no children , no cardinality map...
3939
return [];
@@ -47,15 +47,13 @@ public function getCardinalityMap()
4747
*
4848
* e.g. my_alias.first_name
4949
*
50-
* @param string $field
51-
*
52-
* @return array
50+
* @return string[] with exactly 2 elements
5351
*/
54-
protected function explodeField($field)
52+
protected function explodeField(string $field): array
5553
{
5654
$parts = explode('.', $field);
5755

58-
if (2 == count($parts)) {
56+
if (2 === count($parts)) {
5957
return $parts;
6058
}
6159

0 commit comments

Comments
 (0)