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

Cleanup #2544

Merged
merged 13 commits into from
Sep 13, 2023
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v3"
with:
fetch-depth: 2

Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
run: composer remove --no-update --dev phpbench/phpbench

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "${{ matrix.dependencies }}"
composer-options: "--prefer-dist"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v3"

- name: Setup cache environment
id: extcache
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
run: "php --ri mongodb"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
uses: "ramsey/composer-install@v2"

- name: "Upload composer.lock as build artifact"
uses: actions/upload-artifact@v2
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- name: "Checkout code"
uses: "actions/checkout@v2"
uses: "actions/checkout@v3"

- name: Setup cache environment
id: extcache
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
run: "php --ri mongodb"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
uses: "ramsey/composer-install@v2"

- name: "Upload composer.lock as build artifact"
uses: actions/upload-artifact@v2
Expand All @@ -69,7 +69,7 @@ jobs:

steps:
- name: "Checkout code"
uses: "actions/checkout@v2"
uses: "actions/checkout@v3"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand All @@ -79,7 +79,7 @@ jobs:
php-version: "${{ matrix.php-version }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
uses: "ramsey/composer-install@v2"

- name: "Upload composer.lock as build artifact"
uses: actions/upload-artifact@v2
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"ext-bcmath": "*",
"doctrine/coding-standard": "^11.0",
"jmikola/geojson": "^1.0",
"phpbench/phpbench": "^1.0.0@dev",
"phpbench/phpbench": "^1.0.0",
"phpstan/phpstan": "^1.10.11",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5.5 || ^10.0.15",
"phpunit/phpunit": "^9.6 || ^10.0.15",
"squizlabs/php_codesniffer": "^3.5",
"symfony/cache": "^4.4 || ^5.0 || ^6.0",
"vimeo/psalm": "^5.9.0"
Expand All @@ -60,7 +60,6 @@
"Doctrine\\ODM\\MongoDB\\Benchmark\\": "benchmark",
"Doctrine\\ODM\\MongoDB\\Tests\\": "tests/Doctrine/ODM/MongoDB/Tests",
"Documents\\": "tests/Documents",
"Documents74\\": "tests/Documents74",
"Documents81\\": "tests/Documents81",
"Stubs\\": "tests/Stubs",
"TestDocuments\\" :"tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures"
Expand Down
11 changes: 6 additions & 5 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;

/**
* @Annotation
Expand All @@ -21,18 +22,18 @@ class Validation implements Annotation
/**
* @var string|null
* @Enum({
* \Doctrine\ODM\MongoDB\Mapping\ClassMetadata::SCHEMA_VALIDATION_ACTION_ERROR,
* \Doctrine\ODM\MongoDB\Mapping\ClassMetadata::SCHEMA_VALIDATION_ACTION_WARN,
* ClassMetadata::SCHEMA_VALIDATION_ACTION_ERROR,
* ClassMetadata::SCHEMA_VALIDATION_ACTION_WARN,
* })
*/
public $action;

/**
* @var string|null
* @Enum({
* \Doctrine\ODM\MongoDB\Mapping\ClassMetadata::SCHEMA_VALIDATION_LEVEL_OFF,
* \Doctrine\ODM\MongoDB\Mapping\ClassMetadata::SCHEMA_VALIDATION_LEVEL_STRICT,
* \Doctrine\ODM\MongoDB\Mapping\ClassMetadata::SCHEMA_VALIDATION_LEVEL_MODERATE,
* ClassMetadata::SCHEMA_VALIDATION_LEVEL_OFF,
* ClassMetadata::SCHEMA_VALIDATION_LEVEL_STRICT,
* ClassMetadata::SCHEMA_VALIDATION_LEVEL_MODERATE,
* })
*/
public $level;
Expand Down
8 changes: 8 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public function __construct(DocumentManager $documentManager)
$this->proxyFactory = $documentManager->getConfiguration()->buildGhostObjectFactory();
}

/**
* @param mixed $identifier
* @psalm-param ClassMetadata<T> $metadata
*
* @psalm-return T&GhostObjectInterface<T>
*
* @template T of object
*/
public function getProxy(ClassMetadata $metadata, $identifier): GhostObjectInterface
{
$documentPersister = $this->uow->getDocumentPersister($metadata->getName());
Expand Down
4 changes: 2 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ parameters:
path: lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php

-
message: "#^Parameter \\#2 \\$mapping of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\Driver\\\\XmlDriver\\:\\:addFieldMapping\\(\\) expects array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}, array\\<int\\|string, non\\-empty\\-array\\<int, string\\>\\|bool\\|string\\> given\\.$#"
message: "#^Parameter \\#2 \\$mapping of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\Driver\\\\XmlDriver\\:\\:addFieldMapping\\(\\) expects array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}, array\\<string, non\\-empty\\-array\\<int, string\\>\\|bool\\|string\\> given\\.$#"
count: 1
path: lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php

Expand Down Expand Up @@ -616,7 +616,7 @@ parameters:
path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php

-
message: "#^Method Doctrine\\\\ODM\\\\MongoDB\\\\Proxy\\\\Factory\\\\StaticProxyFactory\\:\\:createInitializer\\(\\) should return Closure\\(ProxyManager\\\\Proxy\\\\GhostObjectInterface\\<TDocument of object\\>&TDocument of object\\=, string\\=, array\\<string, mixed\\>\\=, Closure\\|null\\=, array\\<string, mixed\\>\\=\\)\\: bool but returns Closure\\(ProxyManager\\\\Proxy\\\\GhostObjectInterface, string, array, mixed, array\\)\\: true\\.$#"
message: "#^Method Doctrine\\\\ODM\\\\MongoDB\\\\Proxy\\\\Factory\\\\StaticProxyFactory\\:\\:createInitializer\\(\\) should return Closure\\(ProxyManager\\\\Proxy\\\\GhostObjectInterface\\<TDocument\\>&TDocument\\=, string\\=, array\\<string, mixed\\>\\=, Closure\\|null\\=, array\\<string, mixed\\>\\=\\)\\: bool but returns Closure\\(ProxyManager\\\\Proxy\\\\GhostObjectInterface, string, array, mixed, array\\)\\: true\\.$#"
count: 1
path: lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php

Expand Down
66 changes: 52 additions & 14 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.9.0@8b9ad1eb9e8b7d3101f949291da2b9f7767cd163">
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<file src="lib/Doctrine/ODM/MongoDB/Aggregation/Aggregation.php">
<MissingTemplateParam>
<code>IteratorAggregate</code>
Expand Down Expand Up @@ -46,7 +46,6 @@
<code><![CDATA[$this->fieldMappings]]></code>
</InvalidPropertyAssignmentValue>
<InvalidReturnStatement>
<code>$mapping</code>
<code>$mapping</code>
<code><![CDATA[array_filter(
$this->associationMappings,
Expand All @@ -55,7 +54,6 @@
</InvalidReturnStatement>
<InvalidReturnType>
<code>FieldMapping</code>
<code>FieldMappingConfig</code>
<code><![CDATA[array<string, FieldMapping>]]></code>
</InvalidReturnType>
<LessSpecificImplementedReturnType>
Expand All @@ -78,6 +76,23 @@
<code>$mapping</code>
<code>$options</code>
</InvalidArgument>
<InvalidPropertyFetch>
<code><![CDATA[$xmlRoot->field]]></code>
<code><![CDATA[$xmlRoot->id]]></code>
<code><![CDATA[$xmlRoot->{'also-load-methods'}]]></code>
<code><![CDATA[$xmlRoot->{'default-discriminator-value'}]]></code>
<code><![CDATA[$xmlRoot->{'discriminator-field'}]]></code>
<code><![CDATA[$xmlRoot->{'discriminator-map'}]]></code>
<code><![CDATA[$xmlRoot->{'embed-many'}]]></code>
<code><![CDATA[$xmlRoot->{'embed-one'}]]></code>
<code><![CDATA[$xmlRoot->{'indexes'}]]></code>
<code><![CDATA[$xmlRoot->{'lifecycle-callbacks'}]]></code>
<code><![CDATA[$xmlRoot->{'read-preference'}]]></code>
<code><![CDATA[$xmlRoot->{'reference-many'}]]></code>
<code><![CDATA[$xmlRoot->{'reference-one'}]]></code>
<code><![CDATA[$xmlRoot->{'schema-validation'}]]></code>
<code><![CDATA[$xmlRoot->{'shard-key'}]]></code>
</InvalidPropertyFetch>
<NoInterfaceProperties>
<code><![CDATA[$xmlRoot->field]]></code>
<code><![CDATA[$xmlRoot->id]]></code>
Expand All @@ -103,6 +118,21 @@
</RedundantCast>
<RedundantCondition>
<code>assert($attributes instanceof SimpleXMLElement)</code>
<code><![CDATA[isset($embed->{'default-discriminator-value'})]]></code>
<code><![CDATA[isset($embed->{'discriminator-field'})]]></code>
<code><![CDATA[isset($embed->{'discriminator-map'})]]></code>
<code><![CDATA[isset($field->{'generator-option'})]]></code>
<code><![CDATA[isset($partialFilterExpressionMapping->and)]]></code>
<code><![CDATA[isset($partialFilterExpressionMapping->field)]]></code>
<code><![CDATA[isset($reference->{'criteria'})]]></code>
<code><![CDATA[isset($reference->{'default-discriminator-value'})]]></code>
<code><![CDATA[isset($reference->{'discriminator-field'})]]></code>
<code><![CDATA[isset($reference->{'discriminator-map'})]]></code>
<code><![CDATA[isset($reference->{'prime'})]]></code>
<code><![CDATA[isset($reference->{'sort'})]]></code>
<code><![CDATA[isset($xmlIndex->{'option'})]]></code>
<code><![CDATA[isset($xmlIndex->{'partial-filter-expression'})]]></code>
<code><![CDATA[isset($xmlReadPreference->{'tag-set'})]]></code>
<code><![CDATA[isset($xmlRoot->field)]]></code>
<code><![CDATA[isset($xmlRoot->id)]]></code>
<code><![CDATA[isset($xmlRoot->{'default-discriminator-value'})]]></code>
Expand All @@ -117,6 +147,7 @@
<code><![CDATA[isset($xmlRoot->{'reference-one'})]]></code>
<code><![CDATA[isset($xmlRoot->{'schema-validation'})]]></code>
<code><![CDATA[isset($xmlRoot->{'shard-key'})]]></code>
<code><![CDATA[isset($xmlShardkey->{'option'})]]></code>
</RedundantCondition>
<TypeDoesNotContainType>
<code><![CDATA[$xmlRoot->getName() === 'document']]></code>
Expand All @@ -125,6 +156,7 @@
<code><![CDATA[$xmlRoot->getName() === 'mapped-superclass']]></code>
<code><![CDATA[$xmlRoot->getName() === 'query-result-document']]></code>
<code><![CDATA[$xmlRoot->getName() === 'view']]></code>
<code><![CDATA[isset($xmlRoot->metadata)]]></code>
<code><![CDATA[isset($xmlRoot->{'also-load-methods'})]]></code>
</TypeDoesNotContainType>
</file>
Expand All @@ -144,27 +176,23 @@
<code>array_values</code>
</RedundantFunctionCall>
</file>
<file src="lib/Doctrine/ODM/MongoDB/Proxy/Resolver/CachingClassNameResolver.php">
<InvalidPropertyAssignmentValue>
<code><![CDATA[$this->resolvedNames]]></code>
</InvalidPropertyAssignmentValue>
</file>
<file src="lib/Doctrine/ODM/MongoDB/Proxy/Resolver/ProxyManagerClassNameResolver.php">
<MoreSpecificImplementedParamType>
<code>$className</code>
</MoreSpecificImplementedParamType>
</file>
<file src="lib/Doctrine/ODM/MongoDB/Query/Builder.php">
<InvalidArgument>
<code>$query</code>
</InvalidArgument>
<InvalidPropertyAssignmentValue>
<code><![CDATA[$this->query]]></code>
<code><![CDATA[$this->query]]></code>
<code><![CDATA[$this->query]]></code>
<code><![CDATA[$this->query]]></code>
</InvalidPropertyAssignmentValue>
</file>
<file src="lib/Doctrine/ODM/MongoDB/Query/Expr.php">
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$current = &$this->newObj]]></code>
<code><![CDATA[$query = &$this->query]]></code>
<code><![CDATA[$query = &$this->query[$this->currentField]]]></code>
</UnsupportedPropertyReferenceUsage>
</file>
<file src="lib/Doctrine/ODM/MongoDB/Query/Query.php">
<MissingTemplateParam>
<code>IteratorAggregate</code>
Expand Down Expand Up @@ -288,6 +316,11 @@
<code>new ArrayCollection([$project])</code>
</InvalidArgument>
</file>
<file src="tests/Doctrine/ODM/MongoDB/Tests/Events/PreLoadEventArgsTest.php">
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$eventArgsData =& $eventArgs->getData()]]></code>
</UnsupportedPropertyReferenceUsage>
</file>
<file src="tests/Doctrine/ODM/MongoDB/Tests/Functional/CollectionPersisterTest.php">
<InvalidArgument>
<code><![CDATA[[$user->categories[0]->children, $user->categories[1]->children]]]></code>
Expand Down Expand Up @@ -385,6 +418,11 @@
<code>$collection</code>
</InvalidArgument>
</file>
<file src="tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM43Test.php">
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$data =& $e->getData()]]></code>
</UnsupportedPropertyReferenceUsage>
</file>
<file src="tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM81Test.php">
<InvalidNullableReturnType>
<code>DocumentManager</code>
Expand Down
3 changes: 1 addition & 2 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
findUnusedBaselineEntry="true"
findUnusedCode="false"
findUnusedPsalmSuppress="true"
phpVersion="8.1"
phpVersion="8.2"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand All @@ -15,7 +15,6 @@
<directory name="lib/Doctrine/ODM/MongoDB" />
<directory name="tests/Doctrine" />
<directory name="tests/Documents" />
<directory name="tests/Documents74" />
<ignoreFiles>
<file name="lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup/Match.php" />
<file name="lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,10 @@ class Profile extends BaseDocument
public $profile;
}

/** @ODM\MappedSuperclass @ODM\HasLifecycleCallbacks */
/**
* @ODM\MappedSuperclass
* @ODM\HasLifecycleCallbacks
*/
abstract class BaseDocument
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,8 @@ class DocumentPersisterTestDocumentWithVersion
public $name;

/**
* @ODM\Version @ODM\Field(type="int")
* @ODM\Version
* @ODM\Field(type="int")
*
* @var int
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ public function prePersist(): void
}
}

/** @ODM\MappedSuperclass @ODM\HasLifecycleCallbacks */
/**
* @ODM\MappedSuperclass
* @ODM\HasLifecycleCallbacks
*/
abstract class HasLifecycleCallbacksSuperAnnotated
{
/**
Expand Down Expand Up @@ -157,12 +160,18 @@ class HasLifecycleCallbacksSubExtendsSuperAnnotated extends HasLifecycleCallback
{
}

/** @ODM\Document @ODM\HasLifecycleCallbacks */
/**
* @ODM\Document
* @ODM\HasLifecycleCallbacks
*/
class HasLifecycleCallbacksSubAnnotatedExtendsSuper extends HasLifecycleCallbacksSuper
{
}

/** @ODM\Document @ODM\HasLifecycleCallbacks */
/**
* @ODM\Document
* @ODM\HasLifecycleCallbacks
*/
class HasLifecycleCallbacksSubAnnotatedExtendsSuperAnnotated extends HasLifecycleCallbacksSuperAnnotated
{
}
Expand All @@ -187,7 +196,10 @@ public function prePersist(): void
}
}

/** @ODM\Document @ODM\HasLifecycleCallbacks */
/**
* @ODM\Document
* @ODM\HasLifecycleCallbacks
*/
class HasLifecycleCallbacksSubOverrideAnnotatedExtendsSuper extends HasLifecycleCallbacksSuper
{
/** @ODM\PrePersist */
Expand All @@ -197,7 +209,10 @@ public function prePersist(): void
}
}

/** @ODM\Document @ODM\HasLifecycleCallbacks */
/**
* @ODM\Document
* @ODM\HasLifecycleCallbacks
*/
class HasLifecycleCallbacksSubOverrideAnnotatedExtendsSuperAnnotated extends HasLifecycleCallbacksSuperAnnotated
{
/** @ODM\PrePersist */
Expand Down
Loading
Loading