DummyImageTaggingService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A tagImage() 0 10 3
A __construct() 0 4 1
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