Passed
Push — master ( 1515b4...79261d )
by Kevin
05:02
created

PostFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 1
b 0
f 0
dl 0
loc 32
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getClass() 0 3 1
A published() 0 4 1
A getDefaults() 0 6 1
A withComments() 0 7 1
1
<?php
2
3
namespace Zenstruck\Foundry\Tests\Fixtures\Factories\ODM;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Zenstruck\Foundry\ModelFactory;
7
use Zenstruck\Foundry\Tests\Fixtures\Document\Comment;
8
use Zenstruck\Foundry\Tests\Fixtures\Document\Post;
9
use Zenstruck\Foundry\Tests\Fixtures\Document\User;
10
11
class PostFactory extends ModelFactory
12
{
13
    public function published(): self
14
    {
15
        return $this->addState(function() {
16
            return ['published_at' => self::faker()->dateTime()];
17
        });
18
    }
19
20
    public function withComments(): self
21
    {
22
        return $this->addState(function() {
23
            return [
24
                'comments' => new ArrayCollection([
25
                    new Comment(new User('user'), 'body'),
26
                    new Comment(new User('user'), 'body'),
27
                ]),
28
            ];
29
        });
30
    }
31
32
    protected static function getClass(): string
33
    {
34
        return Post::class;
35
    }
36
37
    protected function getDefaults(): array
38
    {
39
        return [
40
            'title' => self::faker()->sentence(),
41
            'body' => self::faker()->sentence(),
42
            'user' => new User('user'),
43
        ];
44
    }
45
}
46