-
-
Notifications
You must be signed in to change notification settings - Fork 506
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
Add some property typehints #2362
Conversation
* | ||
* @var string|null | ||
*/ | ||
public $name = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
is always initialized:
mongodb-odm/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1294Test.php
Lines 15 to 21 in 1577336
$user1 = new GH1294User(); | |
$user1->id = 'aaa111aaa'; | |
$user1->name = 'Steven'; | |
$user2 = new GH1294User(); | |
$user2->id = 'bbb111bbb'; | |
$user2->name = 'Jeff'; |
@@ -76,7 +76,7 @@ public function testFindWithOrOnCollectionWithDiscriminatorMap(): void | |||
|
|||
$sameCollection1->id = $ids[0]; | |||
$sameCollection1->name = 'First entry in SameCollection1'; | |||
$sameCollection1->test = 1; | |||
$sameCollection1->test = 'test'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is used as string
:
mongodb-odm/tests/Doctrine/ODM/MongoDB/Tests/Persisters/PersistenceBuilderTest.php
Lines 55 to 63 in 1577336
->field('test')->set('OK! TEST') | |
->field('id')->equals($id); | |
$query = $qb->getQuery(); | |
$query->execute(); | |
$this->dm->refresh($testCollection); | |
$this->assertEquals('OK! TEST', $testCollection->test); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm gonna trust you and all our tests with this :)
public function setClassMetadataFactoryName(string $cmfName): void | ||
{ | ||
$this->attributes['classMetadataFactoryName'] = $cmfName; | ||
} | ||
|
||
/** | ||
* @psalm-return class-string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be consistent with multi-line vs single-lined PHPDocs :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, I've used multiline for PHPDoc in methods (I've found a way to force this from phpcs), the single-lined one is forced by phpcs when only has one single line content.
@@ -87,8 +87,11 @@ class Configuration | |||
* @psalm-var array{ | |||
* autoGenerateHydratorClasses?: self::AUTOGENERATE_*, | |||
* autoGeneratePersistentCollectionClasses?: self::AUTOGENERATE_*, | |||
* classMetadataFactoryName?: class-string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to limit allowed classes here. It appears that it should only accept \Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory
. In fact, the class is marked as final
so I can't imagine anyone extending it but you can still create your own implementation that adds setDocumentManager
and getDocumentManager
methods (there is no common interface for that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, I've used class-string<ClassMetadataFactory>
and modified also defaultGridFSRepositoryClassName
and classMetadataFactoryName
, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also apply that to the getters and setters where applicable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, should be better now, thanks.
* defaultCommitOptions?: CommitOptions, | ||
* defaultDocumentRepositoryClassName?: string, | ||
* defaultGridFSRepositoryClassName?: class-string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should implement \Doctrine\ODM\MongoDB\Repository\GridFSRepository
@@ -68,6 +72,7 @@ public function testLifecycleListeners(): void | |||
$this->listener->called = []; | |||
|
|||
$document = $dm->find(TestDocument::class, $test->id); | |||
assert($document->embedded instanceof PersistentCollectionInterface); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use self::assertInstanceOf()
together with phpstan-phpunit
plugin instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, done.
1577336
to
62d22a2
Compare
62d22a2
to
1c89d70
Compare
Summary
This add some property type hints to
tests
directory, I've changed a couple of things that I would point out in the code. Since there are a lot missing, I'll try to make manageable PRs.