Skip to content
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
21 changes: 21 additions & 0 deletions .phpstan/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,24 @@ parameters:
message: "#^Call to an undefined method Doctrine\\\\ODM\\\\PHPCR\\\\Query\\\\Builder\\\\AbstractNode\\:\\:setConverter\\(\\)\\.$#"
count: 1
path: ../tests/Doctrine/Tests/ODM/PHPCR/Query/Builder/QueryBuilderTest.php

-
message: '#^Access to an undefined property Doctrine\\ODM\\PHPCR\\Mapping\\Driver\\AttributeDriver\:\:\$classLocator\.$#'
identifier: property.notFound
count: 1
path: ../lib/Doctrine/ODM/PHPCR/Mapping/Driver/AttributeDriver.php
reportUnmatched: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need these in the baseline? can't we make sure that phpstan runs with the latest version of persistence?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that a complete upgrade to doctrine/persistence 4.0 requires many more changes. The current code is made to be forward-compatible with ColocatedMappingDriver of persistence 4.1, but the actual upgrade to this version has yet to be implemented.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I did locally is:

  1. I adjusted a "require" section:
"doctrine/data-fixtures": "^1.0 || ^2.0",
"doctrine/persistence": "^3.0 || ^4.0@dev",
  1. Ran AttributeDriverTest.

At first, the tests were failing due to incompatible method / property declarations.

Those that could be easily fixed w/o breaking the current tests on persistence 3.x, I've committed.
Those that would break the tests on persistence 3.x, I've only monkey-patched locally to verify that AttributeDriverTest works.

Therefore, current tests run on persistence 3.x.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, i see. so as is, these changes can not be used, its only preparation for persistence 4 compatibility?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes will kick in once persistence 4 comes into play


-
message: '#^Class Doctrine\\Persistence\\Mapping\\Driver\\ClassLocator not found\.$#'
identifier: class.notFound
count: 1
path: ../lib/Doctrine/ODM/PHPCR/Mapping/Driver/AttributeDriver.php
reportUnmatched: false

-
message: '#^Parameter \$paths of method Doctrine\\ODM\\PHPCR\\Mapping\\Driver\\AttributeDriver\:\:__construct\(\) has invalid type Doctrine\\Persistence\\Mapping\\Driver\\ClassLocator\.$#'
identifier: class.notFound
count: 2
path: ../lib/Doctrine/ODM/PHPCR/Mapping/Driver/AttributeDriver.php
reportUnmatched: false
7 changes: 7 additions & 0 deletions lib/Doctrine/ODM/PHPCR/Decorator/DocumentManagerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\ODM\PHPCR\ChildrenCollection;
use Doctrine\ODM\PHPCR\Configuration;
use Doctrine\ODM\PHPCR\DocumentManagerInterface;
use Doctrine\ODM\PHPCR\Mapping\ClassMetadata as PhpcrClassMetadata;
use Doctrine\ODM\PHPCR\Proxy\ProxyFactory;
use Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder;
use Doctrine\ODM\PHPCR\Query\Query;
Expand Down Expand Up @@ -38,6 +39,12 @@ public function __construct(DocumentManagerInterface $wrapped)
$this->wrapped = $wrapped;
}

/** @noinspection SenselessMethodDuplicationInspection - return type is made more specific to match {@see DocumentManagerInterface::getClassMetadata()} */
public function getClassMetadata(string $className): PhpcrClassMetadata
{
return $this->wrapped->getClassMetadata($className);
}

public function setTranslationStrategy(string $key, TranslationStrategyInterface $strategy): void
{
$this->wrapped->setTranslationStrategy($key, $strategy);
Expand Down
8 changes: 3 additions & 5 deletions lib/Doctrine/ODM/PHPCR/DocumentManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@
interface DocumentManagerInterface extends ObjectManager
{
/**
* @{@inheritDoc}
*
* Overwritten to tighten return type. We can't tighten the return type declaration because of Doctrine\Persistence\ObjectManagerDecorator.
* {@inheritdoc}
*
* @return PhpcrClassMetadata
* Overwritten to tighten the return type.
*/
public function getClassMetadata(string $className);
public function getClassMetadata(string $className): PhpcrClassMetadata;

/**
* Add or replace a translation strategy.
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ public function getAssociationTargetClass($fieldName): ?string
return $this->mappings[$fieldName]['targetDocument'];
}

public function getAssociationMappedByTargetField($assocName)
public function getAssociationMappedByTargetField($assocName): string
{
throw new BadMethodCallException(sprintf(
'%s not yet implemented in "%s"',
Expand All @@ -1326,7 +1326,7 @@ public function getAssociationMappedByTargetField($assocName)
));
}

public function isAssociationInverseSide($assocName)
public function isAssociationInverseSide($assocName): bool
{
throw new BadMethodCallException(sprintf(
'%s not yet implemented in "%s"',
Expand Down
14 changes: 10 additions & 4 deletions lib/Doctrine/ODM/PHPCR/Mapping/Driver/AttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
use Doctrine\ODM\PHPCR\Mapping\MappingException;
use Doctrine\Persistence\Mapping\ClassMetadata as PersistenceClassMetadata;
use Doctrine\Persistence\Mapping\Driver\ClassLocator;
use Doctrine\Persistence\Mapping\Driver\ColocatedMappingDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;

Expand Down Expand Up @@ -55,15 +56,20 @@ class AttributeDriver implements MappingDriver
private AttributeReader $reader;

/**
* @param array<string> $paths
* @param array<string>|ClassLocator $paths directory paths or class locator
*/
public function __construct(array $paths)
public function __construct(array|ClassLocator $paths)
{
$this->reader = new AttributeReader();
$this->addPaths($paths);

if ($paths instanceof ClassLocator) {
$this->classLocator = $paths;
} else {
$this->addPaths($paths);
}
}

public function isTransient($className)
public function isTransient($className): bool
{
$classAttributes = $this->reader->getClassAttributes(new \ReflectionClass($className));

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private function addMappingFromReference(ClassMetadata $class, string $fieldName
}
}

protected function loadMappingFile($file)
protected function loadMappingFile($file): array
{
if (!is_file($file)) {
throw new InvalidArgumentException(sprintf('File "%s" not found', $file));
Expand Down
16 changes: 10 additions & 6 deletions tests/Doctrine/Tests/ODM/PHPCR/Mapping/AttributeDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@
namespace Doctrine\Tests\ODM\PHPCR\Mapping;

use Doctrine\ODM\PHPCR\Mapping\Driver\AttributeDriver;
use Doctrine\Persistence\Mapping\Driver\FileClassLocator;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;

/**
* @group mapping
*/
class AttributeDriverTest extends AbstractMappingDriverTest
{
protected function loadDriver(): AttributeDriver
/** @param list<string> $paths */
protected function loadDriver(array $paths = []): AttributeDriver
{
return new AttributeDriver([]);
// Available in Doctrine Persistence 4.1+
if (class_exists(FileClassLocator::class)) {
$paths = FileClassLocator::createFromDirectories($paths);
}

return new AttributeDriver($paths);
}

protected function loadDriverForTestMappingDocuments(): MappingDriver
{
$attributeDriver = $this->loadDriver();
$attributeDriver->addPaths([__DIR__.'/Model']);

return $attributeDriver;
return $this->loadDriver([__DIR__.'/Model']);
}

/**
Expand Down