• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nextras / orm / 38978139491

16 Oct 2026 10:50PM UTC coverage: 92.11% (+0.1%) from 92.0%
38978139491

Pull #836

github

web-flow
Merge 702852b98 into d02a3bb2e
Pull Request #836: fix(nette-di): make initializeMetadata work with Nette DI lazy services

103 of 108 new or added lines in 3 files covered. (95.37%)

1 existing line in 1 file now uncovered.

4448 of 4829 relevant lines covered (92.11%)

5.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/src/Model/SimpleRepositoryLoader.php
1
<?php declare(strict_types = 1);
2

3
namespace Nextras\Orm\Model;
4

5

6
use Nextras\Orm\Entity\IEntity;
7
use Nextras\Orm\Repository\IRepository;
8
use function array_values;
9
use function get_class;
10

11

12
/**
13
 * Loads repositories from a static list of already instantiated repositories.
14
 * All repositories are considered initialized right away.
15
 */
16
class SimpleRepositoryLoader implements IRepositoryLoader
17
{
18
        /** @var array<class-string<IRepository<*>>, IRepository<*>> */
19
        private array $repositories = [];
20

21
        /** @var array<string, class-string<IRepository<*>>> */
22
        private array $nameToClassNameMap = [];
23

24

25
        /**
26
         * @param array<string, IRepository<*>> $repositories Map of a repository simple name and its instance. The name
27
         * is used for accessing the repository by name in contrast to accessing it by its class-string.
28
         * @param array<class-string<IEntity>, class-string<IRepository<IEntity>>> $entityClassNameToClassNameMap Map of an
29
         * entity class name to the class name of the repository that manages it.
30
         */
31
        public function __construct(
5 ✔
32
                array $repositories,
33
                private readonly array $entityClassNameToClassNameMap = [],
1 ✔
34
        )
35
        {
36
                foreach ($repositories as $name => $repository) {
6 ✔
37
                        $className = get_class($repository);
6 ✔
38
                        $this->repositories[$className] = $repository;
6 ✔
39
                        $this->nameToClassNameMap[$name] = $className;
6 ✔
40
                }
41
        }
6 ✔
42

43

44
        #[\Override]
45
        #[\NoDiscard]
46
        public function hasRepository(string $className): bool
47
        {
UNCOV
48
                return isset($this->repositories[$className]);
×
49
        }
50

51

52
        #[\Override]
53
        #[\NoDiscard]
54
        public function hasRepositoryByName(string $name): bool
55
        {
56
                return isset($this->nameToClassNameMap[$name]);
×
57
        }
58

59

60
        /**
61
         * @template T of IRepository<*>
62
         * @param class-string<T> $className
63
         * @return T|null
64
         */
65
        #[\Override]
66
        #[\NoDiscard]
67
        public function getRepository(string $className): IRepository|null
68
        {
69
                /** @var T|null */
70
                return $this->repositories[$className] ?? null;
6 ✔
71
        }
72

73

74
        #[\Override]
75
        #[\NoDiscard]
76
        public function getRepositoryByName(string $name): IRepository|null
77
        {
78
                $className = $this->nameToClassNameMap[$name] ?? null;
6 ✔
79
                return $className !== null ? $this->repositories[$className] : null;
6 ✔
80
        }
81

82

83
        /**
84
         * @template E of IEntity
85
         * @param class-string<E> $entityClassName
86
         * @return class-string<IRepository<E>>|null
87
         */
88
        #[\Override]
89
        #[\NoDiscard]
90
        public function getRepositoryClassNameForEntity(string $entityClassName): string|null
91
        {
92
                /** @var class-string<IRepository<E>>|null */
93
                return $this->entityClassNameToClassNameMap[$entityClassName] ?? null;
6 ✔
94
        }
95

96

97
        #[\Override]
98
        #[\NoDiscard]
99
        public function getInitializedRepositories(): array
100
        {
101
                return array_values($this->repositories);
6 ✔
102
        }
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc