DummyImageTaggingService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Service;
4
5
use App\Entity\Image;
6
use Doctrine\ORM\EntityManagerInterface;
7
8
class DummyImageTaggingService implements ImageTaggingServiceInterface
9
{
10
    /** @var EntityManagerInterface */
11
    private $entityManager;
12
13
    public function __construct(
14
        EntityManagerInterface $entityManager)
15
    {
16
        $this->entityManager = $entityManager;
17
    }
18
19
    public function tagImage(Image $image, bool $overwriteExisting = false): bool
20
    {
21
        if ($overwriteExisting === false && $image->getAutoTagsCount() > 0) {
22
            return false;
23
        }
24
25
        $image->setAutoTags(['dummy', 'image', 'tagging', 'service']);
26
        $this->entityManager->persist($image);
27
        $this->entityManager->flush(); // Calling the API's a lot more overhead; we might as well flush on every image.
28
        return true;
29
    }
30
}
31