Code Duplication    Length = 37-45 lines in 3 locations

src/Badger/Bundle/GameBundle/Doctrine/Saver/BadgeCompletionSaver.php 1 location

@@ 14-58 (lines=45) @@
11
 * @author  Adrien Pétremann <[email protected]>
12
 * @license http://opensource.org/licenses/MIT The MIT License (MIT)
13
 */
14
class BadgeCompletionSaver implements SaverInterface
15
{
16
    /** @var ObjectManager */
17
    protected $objectManager;
18
19
    /** @var EventDispatcherInterface */
20
    protected $eventDispatcher;
21
22
    /** @var string */
23
    protected $savedClass;
24
25
    /**
26
     * @param ObjectManager            $objectManager
27
     * @param EventDispatcherInterface $eventDispatcher
28
     * @param string                   $savedClass
29
     */
30
    public function __construct(
31
        ObjectManager $objectManager,
32
        EventDispatcherInterface $eventDispatcher,
33
        $savedClass
34
    ) {
35
        $this->objectManager   = $objectManager;
36
        $this->savedClass      = $savedClass;
37
        $this->eventDispatcher = $eventDispatcher;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function save($badgeCompletion, array $options = [])
44
    {
45
        if (false === ($badgeCompletion instanceof $this->savedClass)) {
46
            throw new \InvalidArgumentException(
47
                sprintf(
48
                    'Expects a "%s", "%s" provided.',
49
                    $this->savedClass,
50
                    ClassUtils::getRealClass($badgeCompletion)
51
                )
52
            );
53
        }
54
55
        $this->objectManager->persist($badgeCompletion);
56
        $this->objectManager->flush();
57
    }
58
}
59

src/Badger/Bundle/StorageUtilsBundle/Doctrine/Remover/BaseRemover.php 1 location

@@ 14-50 (lines=37) @@
11
 *
12
 * @license http://opensource.org/licenses/MIT The MIT License (MIT)
13
 */
14
class BaseRemover implements RemoverInterface
15
{
16
    /** @var ObjectManager */
17
    protected $objectManager;
18
19
    /** @var string */
20
    protected $removedClass;
21
22
    /**
23
     * @param ObjectManager $objectManager
24
     * @param string        $removedClass
25
     */
26
    public function __construct(ObjectManager $objectManager, $removedClass)
27
    {
28
        $this->objectManager = $objectManager;
29
        $this->removedClass = $removedClass;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function remove($object, array $options = [])
36
    {
37
        if (false === ($object instanceof $this->removedClass)) {
38
            throw new \InvalidArgumentException(
39
                sprintf(
40
                    'Expects a "%s", "%s" provided.',
41
                    $this->removedClass,
42
                    ClassUtils::getClass($object)
43
                )
44
            );
45
        }
46
47
        $this->objectManager->remove($object);
48
        $this->objectManager->flush();
49
    }
50
}
51

src/Badger/Bundle/StorageUtilsBundle/Doctrine/Saver/BaseSaver.php 1 location

@@ 14-50 (lines=37) @@
11
 *
12
 * @license http://opensource.org/licenses/MIT The MIT License (MIT)
13
 */
14
class BaseSaver implements SaverInterface
15
{
16
    /** @var ObjectManager */
17
    protected $objectManager;
18
19
    /** @var string */
20
    protected $savedClass;
21
22
    /**
23
     * @param ObjectManager $objectManager
24
     * @param string        $savedClass
25
     */
26
    public function __construct(ObjectManager $objectManager, $savedClass)
27
    {
28
        $this->objectManager = $objectManager;
29
        $this->savedClass = $savedClass;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function save($object, array $options = [])
36
    {
37
        if (false === ($object instanceof $this->savedClass)) {
38
            throw new \InvalidArgumentException(
39
                sprintf(
40
                    'Expects a "%s", "%s" provided.',
41
                    $this->savedClass,
42
                    ClassUtils::getClass($object)
43
                )
44
            );
45
        }
46
47
        $this->objectManager->persist($object);
48
        $this->objectManager->flush();
49
    }
50
}
51