Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modernize php code #865

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/PHPCR/DocumentClassMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private function expandClassName(DocumentManagerInterface $dm, string $className
return null;
}

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

Expand Down
12 changes: 6 additions & 6 deletions lib/Doctrine/ODM/PHPCR/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class DocumentManager implements DocumentManagerInterface
/**
* @var TranslationStrategyInterface[]
*/
protected array $translationStrategy;
private array $translationStrategy;

protected LocaleChooserInterface $localeChooserStrategy;
private LocaleChooserInterface $localeChooserStrategy;
private ValueConverter $valueConverter;

public function __construct(SessionInterface $session, Configuration $config = null, EventManager $evm = null)
Expand Down Expand Up @@ -182,7 +182,7 @@ public function find(?string $className, $id): ?object
} catch (ItemNotFoundException $e) {
return null;
}
} elseif (0 !== strpos($id, '/')) {
} elseif (!str_starts_with($id, '/')) {
$id = '/'.$id;
}

Expand Down Expand Up @@ -220,7 +220,7 @@ public function findMany(?string $className, array $ids): Collection
foreach ($ids as $key => $id) {
if (UUIDHelper::isUUID($id)) {
$uuids[$id] = $key;
} elseif (0 !== strpos($id, '/')) {
} elseif (!str_starts_with($id, '/')) {
$ids[$key] = '/'.$id;
}
}
Expand Down Expand Up @@ -257,7 +257,7 @@ public function findTranslation(?string $className, string $id, string $locale,
} catch (ItemNotFoundException $e) {
return null;
}
} elseif (0 !== strpos($id, '/')) {
} elseif (!str_starts_with($id, '/')) {
$id = '/'.$id;
}

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

public function move(object $document, string $targetPath): void
{
if (0 !== strpos($targetPath, '/')) {
if (!str_starts_with($targetPath, '/')) {
$targetPath = '/'.$targetPath;
}

Expand Down
17 changes: 5 additions & 12 deletions lib/Doctrine/ODM/PHPCR/DocumentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,16 @@ public function find($id): ?object
* The ids may either be PHPCR paths or UUID's, but all must be of the same type
*
* @param string[] $ids document ids
*
* @return array|Collection of document objects
*/
public function findMany(array $ids): iterable
public function findMany(array $ids): Collection
{
return $this->dm->findMany($this->className, $ids);
}

/**
* Finds all documents in the repository.
*
* @return array|Collection the entities
*/
public function findAll(): iterable
public function findAll(): Collection
{
return $this->findBy([]);
}
Expand All @@ -83,12 +79,9 @@ public function findAll(): iterable
* an InvalidArgumentException if certain values of the sorting or limiting details are
* not supported.
*
* @param int|null $limit
* @param int|null $offset
*
* @return array|Collection the objects matching the criteria
* @return Collection the objects matching the criteria
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): iterable
public function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): Collection
{
$qb = $this->createQueryBuilder('a');

Expand Down Expand Up @@ -146,7 +139,7 @@ public function findBy(array $criteria, array $orderBy = null, $limit = null, $o
* @param mixed $value The value to search for
* @param string $alias The alias used
*/
protected function constraintField(ConstraintFactory $where, string $field, $value, string $alias): void
protected function constraintField(ConstraintFactory $where, string $field, mixed $value, string $alias): void
{
if ($field === $this->class->nodename) {
$where->eq()->name($alias)->literal($value);
Expand Down
11 changes: 4 additions & 7 deletions lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ClassMetadata implements ClassMetadataInterface
*/
public const GENERATOR_TYPE_AUTO = 4;

protected static $validVersionableMappings = ['simple', 'full'];
private static $validVersionableMappings = ['simple', 'full'];

/**
* READ-ONLY: The ReflectionProperty instances of the mapped class.
Expand Down Expand Up @@ -837,7 +837,7 @@ public function mapLifecycleCallbacks(array $mapping): void
*
* @throws MappingException
*/
protected function validateAndCompleteFieldMapping(array $mapping, self $inherited = null, bool $isField = true, $phpcrLabel = 'property'): array
private function validateAndCompleteFieldMapping(array $mapping, self $inherited = null, bool $isField = true, $phpcrLabel = 'property'): array
{
if ($inherited) {
if (!array_key_exists('inherited', $mapping)) {
Expand Down Expand Up @@ -916,10 +916,7 @@ protected function validateAndCompleteFieldMapping(array $mapping, self $inherit
return $mapping;
}

/**
* @param string|bool $phpcrLabel
*/
protected function validateAndCompleteAssociationMapping(array $mapping, self $inherited = null, $phpcrLabel = 'property'): array
private function validateAndCompleteAssociationMapping(array $mapping, self $inherited = null, bool|string $phpcrLabel = 'property'): array
{
$mapping = $this->validateAndCompleteFieldMapping($mapping, $inherited, false, $phpcrLabel);
if ($inherited) {
Expand Down Expand Up @@ -1083,7 +1080,7 @@ public function mapManyToMany(array $mapping, self $inherited = null): void
/**
* Sets the ID generator used to generate IDs for instances of this class.
*/
protected function setIdGenerator(int|string $generator): void
private function setIdGenerator(int|string $generator): void
{
if (is_string($generator)) {
$generator = constant('Doctrine\ODM\PHPCR\Mapping\ClassMetadata::GENERATOR_TYPE_'.strtoupper($generator));
Expand Down
16 changes: 7 additions & 9 deletions lib/Doctrine/ODM/PHPCR/Query/Builder/AbstractLeafNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@
*/
abstract class AbstractLeafNode extends AbstractNode
{
public function getNext()
public function getNext(): ?AbstractNode
{
return $this->getParent();
}

public function getChildren()
public function getChildren(): array
{
throw new RuntimeException(sprintf(
'Cannot call getChildren on leaf node "%s"',
$this->getName()
));
}

public function addChild(AbstractNode $node)
public function addChild(AbstractNode $node): static
{
throw new RuntimeException(sprintf(
'Cannot call addChild to leaf node "%s"',
$this->getName()
));
}

public function getCardinalityMap()
public function getCardinalityMap(): array
{
// no children , no cardinality map...
return [];
Expand All @@ -47,15 +47,13 @@ public function getCardinalityMap()
*
* e.g. my_alias.first_name
*
* @param string $field
*
* @return array
* @return string[] with exactly 2 elements
*/
protected function explodeField($field)
protected function explodeField(string $field): array
{
$parts = explode('.', $field);

if (2 == count($parts)) {
if (2 === count($parts)) {
return $parts;
}

Expand Down
Loading