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

Add some property typehints #2362

Merged
merged 2 commits into from
Sep 2, 2021
Merged

Add some property typehints #2362

merged 2 commits into from
Sep 2, 2021

Conversation

franmomu
Copy link
Contributor

@franmomu franmomu commented Sep 2, 2021

Q A
Type improvement
BC Break no
Fixed issues

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.

@franmomu franmomu added the Task label Sep 2, 2021
*
* @var string|null
*/
public $name = '';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

name is always initialized:

$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';
Copy link
Contributor Author

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:

->field('test')->set('OK! TEST')
->field('id')->equals($id);
$query = $qb->getQuery();
$query->execute();
$this->dm->refresh($testCollection);
$this->assertEquals('OK! TEST', $testCollection->test);

Copy link
Member

@malarzm malarzm left a 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
Copy link
Member

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 :)

Copy link
Contributor Author

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,
Copy link
Member

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).

Copy link
Contributor Author

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!

Copy link
Member

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?

Copy link
Contributor Author

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,
Copy link
Member

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);
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, done.

@franmomu franmomu merged commit 0f64911 into doctrine:2.3.x Sep 2, 2021
@franmomu franmomu deleted the add_types_1 branch September 2, 2021 11:59
@malarzm malarzm added this to the 2.3.0 milestone Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants