BatchOperationCollection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 31
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkValueIsValidOperationObject() 0 8 2
A isNotOperationObject() 0 3 1
A set() 0 5 1
1
<?php
2
/**
3
 * This file is part of the sauls/object-registry-bundle package.
4
 *
5
 * @author    Saulius Vaičeliūnas <[email protected]>
6
 * @link      http://saulius.vaiceliunas.lt
7
 * @copyright 2018
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Sauls\Bundle\ObjectRegistryBundle\Collection;
14
15
use Sauls\Bundle\ObjectRegistryBundle\Batch\Operation\OperationInterface;
16
use Sauls\Bundle\ObjectRegistryBundle\Exception\UnsupportedBatchOperationException;
17
use Sauls\Component\Collection\ArrayCollection;
18
19
class BatchOperationCollection extends ArrayCollection implements BatchOperationCollectionInterface
20
{
21
    /**
22
     * @param $key
23
     * @param OperationInterface $value
24
     */
25 2
    public function set($key, $value): void
26
    {
27 2
        $this->checkValueIsValidOperationObject($value);
28
29 1
        parent::set($value->getName(), $value);
30 1
    }
31
32
    /**
33
     * @param $value
34
     */
35 2
    private function checkValueIsValidOperationObject($value): void
36
    {
37 2
        if ($this->isNotOperationObject($value)) {
38 1
            throw new UnsupportedBatchOperationException(
39 1
                sprintf(
40 1
                    'Given batch operation of class `%s` should implement %s interface',
41 1
                    \get_class($value),
42 1
                    OperationInterface::class)
43
            );
44
        }
45 1
    }
46
47 2
    private function isNotOperationObject($value): bool
48
    {
49 2
        return false === \is_subclass_of($value, OperationInterface::class);
50
    }
51
}
52