Passed
Push — dev ( 80e888...e274b6 )
by Janko
07:22
created

AchievementManager   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 43
ccs 18
cts 18
cp 1
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A reset() 0 4 1
A checkDatabaseItem() 0 18 5
A getAchievements() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Database;
6
7
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Stu\Module\Database\Lib\CreateDatabaseEntryInterface;
9
use Stu\Orm\Entity\User;
10
use Stu\Orm\Repository\DatabaseUserRepositoryInterface;
11
12
class AchievementManager implements AchievementManagerInterface
13
{
14
    /** @var array<string> */
15
    private static array $achievements = [];
16
17 7
    public function __construct(
18
        private readonly DatabaseUserRepositoryInterface $databaseUserRepository,
19
        private readonly CreateDatabaseEntryInterface $createDatabaseEntry
20 7
    ) {}
21
22 211
    #[Override]
23
    public function getAchievements(): array
24
    {
25 211
        return self::$achievements;
26
    }
27
28 7
    #[Override]
29
    public function checkDatabaseItem(?int $databaseEntryId, User $user): void
30
    {
31
        if (
32 7
            $databaseEntryId === null
33 7
            || $databaseEntryId < 1
34
        ) {
35 4
            return;
36
        }
37
38 3
        if (!$this->databaseUserRepository->exists($user->getId(), $databaseEntryId)) {
39 1
            $entry = $this->createDatabaseEntry->createDatabaseEntryForUser($user, $databaseEntryId);
40
41 1
            if ($entry !== null) {
42 1
                self::$achievements[] = sprintf(
43 1
                    'Neuer Datenbankeintrag: %s (+%d Punkte)',
44 1
                    $entry->getDescription(),
45 1
                    $entry->getCategory()->getPoints()
46 1
                );
47
            }
48
        }
49
    }
50
51 222
    #[Override]
52
    public static function reset(): void
53
    {
54 222
        self::$achievements = [];
55
    }
56
}
57