EntityWriter::write()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Cycle\Data\Writer;
6
7
use Cycle\ORM\EntityManagerInterface;
8
use Throwable;
9
use Yiisoft\Data\Writer\DataWriterInterface;
10
11
final class EntityWriter implements DataWriterInterface
12
{
13 2
    public function __construct(private EntityManagerInterface $entityManager)
14
    {
15 2
    }
16
17
    /**
18
     * @throws Throwable
19
     */
20 1
    public function write(iterable $items): void
21
    {
22 1
        foreach ($items as $entity) {
23 1
            $this->entityManager->persist($entity);
24
        }
25 1
        $this->entityManager->run();
26
    }
27
28 1
    public function delete(iterable $items): void
29
    {
30 1
        foreach ($items as $entity) {
31 1
            $this->entityManager->delete($entity);
32
        }
33 1
        $this->entityManager->run();
34
    }
35
}
36