LoadCommentData   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 4
c 3
b 1
f 1
lcom 0
cbo 1
dl 0
loc 50
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setContainer() 0 4 1
B load() 0 28 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Rafidion Michael
5
 * Date: 10/09/2015
6
 * Time: 00:23
7
 */
8
9
namespace Mykees\CommentBundle\DataFixtures\ORM;
10
11
use Doctrine\Common\DataFixtures\FixtureInterface;
12
use Doctrine\Common\Persistence\ObjectManager;
13
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
14
use Symfony\Component\DependencyInjection\ContainerInterface;
15
16
class LoadCommentData implements FixtureInterface,ContainerAwareInterface{
17
18
	public $container;
19
20
	/**
21
	 * Sets the Container.
22
	 *
23
	 * @param ContainerInterface|null $container A ContainerInterface instance or null
24
	 *
25
	 * @api
26
	 */
27
	public function setContainer(ContainerInterface $container = null)
28
	{
29
		$this->container = $container;
30
	}
31
32
	/**
33
	 * Load data fixtures with the passed EntityManager
34
	 *
35
	 * @param ObjectManager $manager
36
	 */
37
	public function load(ObjectManager $manager)
38
	{
39
		$comment_class = $this->container->getParameter('mykees_comment.comment.class');
40
41
		for($i=1; $i<=5 ;$i++)
42
		{
43
			$comment = new $comment_class();
44
			$comment->setUsername('admin'.$i);
45
			$comment->setEmail("admin-{$i}@gmail.com");
46
			$comment->setContent('contenu n-'.$i);
47
			$comment->setCreatedAt(new \DateTime());
48
			$comment->setModel('Post');
49
			if($i <= 3)
50
			{
51
				$comment->setModelId(1);
52
			}else{
53
				$comment->setModelId($i);
54
			}
55
			$comment->setParentId(0);
56
			$comment->setSpam(0);
57
			$comment->setIp("192.168.56.1");
58
			$comment->setDepth(0);
59
			$comment->setDepthReached(0);
60
61
			$manager->persist($comment);
62
			$manager->flush();
63
		}
64
	}
65
}