Label   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B updateListLabels() 0 23 6
1
<?php
2
3
/**
4
 * AnimeDb package.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
9
 */
10
11
namespace AnimeDb\Bundle\CatalogBundle\Repository;
12
13
use AnimeDb\Bundle\CatalogBundle\Entity\Item as ItemEntity;
14
use Doctrine\ORM\EntityRepository;
15
use Doctrine\Common\Collections\ArrayCollection;
16
17
/**
18
 * @author  Peter Gribanov <[email protected]>
19
 */
20
class Label extends EntityRepository
21
{
22
    /**
23
     * @param ArrayCollection $new_labels
24
     */
25
    public function updateListLabels(ArrayCollection $new_labels)
26
    {
27
        $old_label = new ArrayCollection($this->findAll());
28
        // remove labels
29
        foreach ($old_label as $label) {
30
            if (!$new_labels->contains($label)) {
31
                foreach ($label->getItems() as $item) {
32
                    /* @var $item ItemEntity */
33
                    $item->removeLabel($label);
34
                }
35
                $this->getEntityManager()->remove($label);
36
            }
37
        }
38
39
        // add new labals
40
        foreach ($new_labels as $label) {
41
            if (!$old_label->contains($label)) {
42
                $this->getEntityManager()->persist($label);
43
            }
44
        }
45
46
        $this->getEntityManager()->flush();
47
    }
48
}
49