Completed
Push — master ( 106d3c...7eed6f )
by amaury
03:05
created

jmeter/DataFixtures/LoadNodeData.php (20 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace OpenOrchestra\jmeter\DataFixtures;
4
5
use Doctrine\Common\DataFixtures\AbstractFixture;
6
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
7
use Doctrine\Common\Persistence\ObjectManager;
8
use OpenOrchestra\DisplayBundle\DisplayBlock\Strategies\TinyMCEWysiwygStrategy;
9
use OpenOrchestra\ModelBundle\Document\Area;
10
use OpenOrchestra\ModelBundle\Document\Block;
11
use OpenOrchestra\ModelBundle\Document\Node;
12
use OpenOrchestra\ModelInterface\Model\NodeInterface;
13
use OpenOrchestra\ModelInterface\Model\AreaInterface;
14
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15
use Symfony\Component\DependencyInjection\ContainerInterface;
16
use OpenOrchestra\BackofficeBundle\Manager\RouteDocumentManager;
17
18
/**
19
 * Class LoadNodeData
20
 */
21
class LoadNodeData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
22
{
23
    /**
24
     * @var RouteDocumentManager
25
     */
26
    private $updateRoute;
27
    private $statusPublished;
28
29
    /**
30
     * {@inheritDoc}
31
     */
32
    public function setContainer(ContainerInterface $container = null)
33
    {
34
        $this->updateRoute = $container->get('open_orchestra_backoffice.manager.route_document');
0 ignored issues
show
It seems like $container is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
35
        $this->statusPublished = $container->get('open_orchestra_model.repository.status')->findOneBy(array('name' => 'published'));
36
    }
37
38
    const NUMBER_OF_NODE = 100;
39
40
    /**
41
     * @param ObjectManager $manager
42
     */
43
    public function load(ObjectManager $manager)
44
    {
45
        for ($i=0; self::NUMBER_OF_NODE > $i; $i++) {
46
            $name = 'node' . $i;
47
            $pattern = '/node' . $i;
48
            $content = 'Node ' . $i . 'on ' . self::NUMBER_OF_NODE;
49
            $this->generateSimpleNode($name, 'en', $manager, $content, $pattern);
50
            $this->generateSimpleNode($name, 'fr', $manager, $content, $pattern);
51
        }
52
        $manager->flush();
53
    }
54
55
    /**
56
     * @return int
57
     */
58
    public function getOrder()
59
    {
60
        return 300;
61
    }
62
63
    /**
64
     * @param string        $name
65
     * @param string        $language
66
     * @param ObjectManager $manager
67
     * @param string        $htmlBody
68
     * @param string        $pattern
69
     *
70
     * @return NodeInterface
71
     */
72
    public function generateSimpleNode($name, $language, ObjectManager $manager, $htmlBody = null, $pattern = null)
73
    {
74
        $areaHeader  = $this->generateHeaderArea();
75
        $areaContent = $this->generateContentArea();
76
        $areaFooter  = $this->generateFooterArea();
77
78
        $titleBlock = new Block();
79
        $titleBlock->setClass('block-body-header');
0 ignored issues
show
The method setClass() does not seem to exist on object<OpenOrchestra\ModelBundle\Document\Block>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
80
        $titleBlock->setComponent(TinyMCEWysiwygStrategy::TINYMCEWYSIWYG);
81
        $titleBlock->setAttributes(array('htmlContent' => '<h1>' . $name . '</h1>'));
82
83
        $contentBlock = new Block();
84
        $contentBlock->setClass('block-body');
0 ignored issues
show
The method setClass() does not seem to exist on object<OpenOrchestra\ModelBundle\Document\Block>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
85
        $contentBlock->setComponent(TinyMCEWysiwygStrategy::TINYMCEWYSIWYG);
86
        $contentBlock->setAttributes(array('htmlContent' => $htmlBody));
87
88
        $areaContent->addBlock(array('nodeId' => 0, 'blockId' => 0));
0 ignored issues
show
array('nodeId' => 0, 'blockId' => 0) is of type array<string,integer,{"n...","blockId":"integer"}>, but the function expects a object<OpenOrchestra\Mod...e\Model\BlockInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
89
        $areaContent->addBlock(array('nodeId' => 0, 'blockId' => 1));
0 ignored issues
show
array('nodeId' => 0, 'blockId' => 1) is of type array<string,integer,{"n...","blockId":"integer"}>, but the function expects a object<OpenOrchestra\Mod...e\Model\BlockInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
90
91
        $node = $this->generateNode($name, NodeInterface::ROOT_NODE_ID, $pattern, $name, $language);
92
93
        $node->addArea($areaHeader);
0 ignored issues
show
The method addArea() does not seem to exist on object<OpenOrchestra\Mod...ce\Model\NodeInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
94
        $node->addArea($areaContent);
0 ignored issues
show
The method addArea() does not seem to exist on object<OpenOrchestra\Mod...ce\Model\NodeInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
95
        $node->addArea($areaFooter);
0 ignored issues
show
The method addArea() does not seem to exist on object<OpenOrchestra\Mod...ce\Model\NodeInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
96
97
        $node->addBlock($titleBlock);
0 ignored issues
show
The method addBlock() does not seem to exist on object<OpenOrchestra\Mod...ce\Model\NodeInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
98
        $node->addBlock($contentBlock);
0 ignored issues
show
The method addBlock() does not seem to exist on object<OpenOrchestra\Mod...ce\Model\NodeInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
99
        $node->setInMenu(true);
100
101
        $routes = $this->updateRoute->createForNode($node);
102
        foreach ($routes as $route) {
103
            $manager->persist($route);
104
        }
105
106
        $manager->persist($node);
107
    }
108
109
    /**
110
     * @return AreaInterface
111
     */
112
    protected function generateHeaderArea()
113
    {
114
        $areaHeader = $this->generateArea('header');
115
        $areaHeader->setHtmlClass('area-header');
0 ignored issues
show
The method setHtmlClass() does not seem to exist on object<OpenOrchestra\Mod...ce\Model\AreaInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
116
        $areaHeader->addBlock(array('nodeId' => NodeInterface::TRANSVERSE_NODE_ID, 'blockId' => 0));
0 ignored issues
show
array('nodeId' => \OpenO...ODE_ID, 'blockId' => 0) is of type array<string,integer,{"blockId":"integer"}>, but the function expects a object<OpenOrchestra\Mod...e\Model\BlockInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
117
        $areaHeader->addBlock(array('nodeId' => NodeInterface::TRANSVERSE_NODE_ID, 'blockId' => 1));
0 ignored issues
show
array('nodeId' => \OpenO...ODE_ID, 'blockId' => 1) is of type array<string,integer,{"blockId":"integer"}>, but the function expects a object<OpenOrchestra\Mod...e\Model\BlockInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
118
119
        return $areaHeader;
120
    }
121
122
    /**
123
     * @return AreaInterface
124
     */
125
    protected function generateContentArea()
126
    {
127
        $areaContent = $this->generateArea('content');
128
        $areaContent->setHtmlClass('area-body');
0 ignored issues
show
The method setHtmlClass() does not seem to exist on object<OpenOrchestra\Mod...ce\Model\AreaInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
129
130
        return $areaContent;
131
    }
132
133
    /**
134
     * @return AreaInterface
135
     */
136
    protected function generateFooterArea()
137
    {
138
        $areaFooter = $this->generateArea('footer');
139
        $areaFooter->setHtmlClass('area-footer');
0 ignored issues
show
The method setHtmlClass() does not seem to exist on object<OpenOrchestra\Mod...ce\Model\AreaInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
140
        $areaFooter->addBlock(array('nodeId' => NodeInterface::TRANSVERSE_NODE_ID, 'blockId' => 2));
0 ignored issues
show
array('nodeId' => \OpenO...ODE_ID, 'blockId' => 2) is of type array<string,integer,{"blockId":"integer"}>, but the function expects a object<OpenOrchestra\Mod...e\Model\BlockInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
141
        $areaFooter->addBlock(array('nodeId' => NodeInterface::TRANSVERSE_NODE_ID, 'blockId' => 3));
0 ignored issues
show
array('nodeId' => \OpenO...ODE_ID, 'blockId' => 3) is of type array<string,integer,{"blockId":"integer"}>, but the function expects a object<OpenOrchestra\Mod...e\Model\BlockInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
142
        $areaFooter->addBlock(array('nodeId' => NodeInterface::TRANSVERSE_NODE_ID, 'blockId' => 4));
0 ignored issues
show
array('nodeId' => \OpenO...ODE_ID, 'blockId' => 4) is of type array<string,integer,{"blockId":"integer"}>, but the function expects a object<OpenOrchestra\Mod...e\Model\BlockInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
143
144
        return $areaFooter;
145
    }
146
147
    /**
148
     * @param string $name
149
     *
150
     * @return AreaInterface
151
     */
152
    protected function generateArea($name)
153
    {
154
        $area = new Area();
155
        $area->setAreaId($name);
0 ignored issues
show
The method setAreaId() does not seem to exist on object<OpenOrchestra\ModelBundle\Document\Area>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
156
        $area->setLabel($name);
0 ignored issues
show
The method setLabel() does not seem to exist on object<OpenOrchestra\ModelBundle\Document\Area>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
157
158
        return $area;
159
    }
160
161
    /**
162
     * @param string $nodeId
163
     * @param string $parentId
164
     * @param string $routePattern
165
     * @param string $name
166
     * @param string $language
167
     * @param string $type
168
     *
169
     * @return NodeInterface
170
     */
171
    protected function generateNode($nodeId, $parentId, $routePattern, $name, $language, $type = NodeInterface::TYPE_DEFAULT)
172
    {
173
        $node = new Node();
174
        $node->setNodeId($nodeId);
175
        $node->setNodeType($type);
176
        $node->setSiteId('2');
177
        $node->setParentId($parentId);
178
        $node->setPath('-');
179
        $node->setRoutePattern($routePattern);
180
        $node->setName($name);
181
        $node->setVersion(1);
182
        $node->setLanguage($language);
183
        $node->setDeleted(false);
184
        $node->setCreatedAt(new \Datetime());
185
        $node->setUpdatedAt(new \Datetime());
186
        $node->setStatus($this->statusPublished);
187
188
        return $node;
189
    }
190
191
}
192