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

nextras / orm / 29191903500

12 Jul 2026 12:02PM UTC coverage: 91.963% (-0.2%) from 92.123%
29191903500

Pull #820

github

web-flow
Merge 8dab47905 into fc483811c
Pull Request #820: refactor OrmExtension for NetteDI (BC break!)

135 of 158 new or added lines in 8 files covered. (85.44%)

1 existing line in 1 file now uncovered.

4348 of 4728 relevant lines covered (91.96%)

5.39 hits per line

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

92.86
/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
        public function hasRepository(string $className): bool
46
        {
47
                return isset($this->repositories[$className]);
6✔
48
        }
49

50

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

57

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

70

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

78

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

91

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

© 2026 Coveralls, Inc