Completed
Push — master ( f4905c...6812a9 )
by WEBEWEB
01:49
created

FormHelper::onPostHandleRequestWithCollection()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 3
nc 3
nop 3
1
<?php
2
3
/**
4
 * This file is part of the bootstrap-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\BootstrapBundle\Helper;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Doctrine\Common\Persistence\ObjectManager;
17
18
/**
19
 * Form helper.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Helper
23
 */
24
class FormHelper {
25
26
    /**
27
     * On post handle request with collection.
28
     *
29
     * @param Collection $oldCollection The old colection.
30
     * @param Collection $newCollection The new collection.
31
     * @param ObjectManager $manager The entities manager.
32
     * @return void
33
     */
34
    public static function onPostHandleRequestWithCollection(Collection $oldCollection, Collection $newCollection, ObjectManager $manager) {
35
        foreach ($oldCollection as $current) {
36
            if (true === $newCollection->contains($current)) {
37
                continue;
38
            }
39
            $manager->remove($current);
40
        }
41
    }
42
43
    /**
44
     * On pre handle request with collection.
45
     *
46
     * @param Collection $collection The collection.
47
     * @return Collection Returns the cloned collection.
48
     */
49
    public static function onPreHandleRequestWithCollection(Collection $collection) {
50
        $output = new ArrayCollection();
51
        foreach ($collection as $current) {
52
            $output->add($current);
53
        }
54
        return $output;
55
    }
56
57
}
58