Completed
Pull Request — 2.x (#521)
by Maximilian
01:42
created

LoadTreeData::load()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 60
rs 8.8727
c 0
b 0
f 0
cc 1
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrinePHPCRAdminBundle\Tests\Fixtures\App\DataFixtures\Phpcr;
15
16
use Doctrine\Common\DataFixtures\FixtureInterface;
17
use Doctrine\Common\Persistence\ObjectManager;
18
use PHPCR\Util\NodeHelper;
19
use Sonata\DoctrinePHPCRAdminBundle\Tests\Fixtures\App\Document\Content;
20
21
class LoadTreeData implements FixtureInterface
22
{
23
    public function load(ObjectManager $manager)
24
    {
25
        NodeHelper::createPath($manager->getPhpcrSession(), '/test');
26
27
        NodeHelper::createPath($manager->getPhpcrSession(), '/test/content');
28
        NodeHelper::createPath($manager->getPhpcrSession(), '/test/routes');
29
30
        $contentRoot = $manager->find(null, '/test/content');
31
        $routeRoot = $manager->find(null, '/test/routes');
32
33
        $singleRoute = new Content();
34
        $singleRoute->setName('route-1');
35
        $singleRoute->setTitle('Route 1');
36
        $singleRoute->setParentDocument($routeRoot);
37
        $manager->persist($singleRoute);
38
39
        $routeAlikeA = new Content();
40
        $routeAlikeA->setName('route-2');
41
        $routeAlikeA->setTitle('Route 2');
42
        $routeAlikeA->setParentDocument($routeRoot);
43
        $manager->persist($routeAlikeA);
44
45
        $routeAlikeB = new Content();
46
        $routeAlikeB->setName('route-3');
47
        $routeAlikeB->setTitle('Route 3');
48
        $routeAlikeB->setParentDocument($routeRoot);
49
        $manager->persist($routeAlikeB);
50
51
        $child = new Content();
52
        $child->setName('child');
53
        $child->setTitle('Content Child');
54
55
        $content = new Content();
56
        $content->setName('content-1');
57
        $content->setTitle('Content 1');
58
        $content->setSingleRoute($singleRoute);
59
        $content->addRoute($routeAlikeA);
60
        $content->addRoute($routeAlikeB);
61
        $content->setChild($child);
62
        $content->setParentDocument($contentRoot);
63
        $manager->persist($content);
64
65
        $childA = new Content();
66
        $childA->setName('content-3');
67
        $childA->setTitle('Content Child A');
68
69
        $childB = new Content();
70
        $childB->setName('content-3');
71
        $childB->setTitle('Content Child B');
72
73
        $content = new Content();
74
        $content->setName('content-2');
75
        $content->setParentDocument($contentRoot);
76
        $content->addChild($childA);
77
        $content->addChild($childB);
78
        $content->setTitle('Content 2');
79
        $manager->persist($content);
80
81
        $manager->flush();
82
    }
83
}
84