LoadCommentsData   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 4
dl 0
loc 51
ccs 0
cts 38
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B load() 0 43 5
A getOrder() 0 4 1
1
<?php
2
3
namespace Skobkin\Bundle\PointToolsBundle\DataFixtures\ORM;
4
5
use Doctrine\Common\DataFixtures\AbstractFixture;
6
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
7
use Doctrine\Common\Persistence\ObjectManager;
8
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment;
9
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post;
10
use Skobkin\Bundle\PointToolsBundle\Entity\User;
11
12
class LoadCommentsData extends AbstractFixture implements OrderedFixtureInterface
13
{
14
    public function load(ObjectManager $om)
15
    {
16
        /** @var Post $post */
17
        $post = $this->getReference('test_post_longpost');
18
19
        /** @var User[] $users */
20
        $users = [
21
            $this->getReference('test_user_99999'),
22
            $this->getReference('test_user_99998'),
23
            $this->getReference('test_user_99997'),
24
            $this->getReference('test_user_99996'),
25
            $this->getReference('test_user_99995'),
26
        ];
27
28
        $comments = [];
29
30
        foreach (range(1, 10000) as $num) {
31
            $comment = (new Comment())
32
                ->setNumber($num)
33
                ->setDeleted(mt_rand(0, 15) ? false : true)
34
                ->setCreatedAt(new \DateTime())
35
                ->setAuthor($users[array_rand($users)])
36
                ->setRec(false)
37
                ->setText(
38
                    'Some text with [link to @skobkin-ru site](https://skobk.in/) and `code block`'.PHP_EOL.
39
                    'and some quotation:'.PHP_EOL.
40
                    '> test test quote'.PHP_EOL.
41
                    'and some text after'
42
                )
43
            ;
44
45
            if (count($comments) > 0 && mt_rand(0, 1)) {
46
                $comment->setParent($comments[mt_rand(0, count($comments) - 1)]);
47
            }
48
49
            $post->addComment($comment);
50
            $comments[] = $comment;
51
52
            $om->persist($comment);
53
        }
54
55
        $om->flush();
56
    }
57
58
    public function getOrder(): int
59
    {
60
        return 3;
61
    }
62
}