EntityWriter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10
c 2
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 0 6 2
A write() 0 6 2
A __construct() 0 2 1
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