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

68publishers / smart-nette-component / 3671567024

pending completion
3671567024

Pull #3

github

GitHub
Merge 8c2bf16fd into d93ee51a5
Pull Request #3: WIP: v1

389 of 389 new or added lines in 24 files covered. (100.0%)

408 of 419 relevant lines covered (97.37%)

0.97 hits per line

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

92.31
/src/TemplateResolver/ManualTemplateFileResolver.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace SixtyEightPublishers\SmartNetteComponent\TemplateResolver;
6

7
use RuntimeException;
8
use function sprintf;
9
use function realpath;
10
use function file_exists;
11
use function array_key_exists;
12

13
final class ManualTemplateFileResolver implements TemplateFileResolverInterface
14
{
15
        /** @var array<string>  */
16
        private array $templateFiles = [];
17

18
        public function __construct(
1✔
19
                private readonly TemplateFileResolverInterface $fallback,
20
                private readonly Metadata $metadata
21
        ) {
22
        }
1✔
23

24
        public function setFile(string $file, string $type = ''): void
1✔
25
        {
26
                if (false === file_exists($file)) {
1✔
27
                        $this->fileNotExists($file);
1✔
28
                }
29

30
                $realpath = realpath($file);
1✔
31

32
                if (!$realpath) {
1✔
33
                        $this->fileNotExists($file);
×
34
                }
35

36
                $this->templateFiles[$type] = $realpath;
1✔
37
        }
1✔
38

39
        public function setRelativeFile(string $file, string $type = ''): void
1✔
40
        {
41
                $this->setFile(sprintf(
1✔
42
                        '%s/%s',
1✔
43
                        $this->metadata->basePath,
1✔
44
                        $file
1✔
45
                ), $type);
46
        }
1✔
47

48
        public function resolve(string $type = ''): string
1✔
49
        {
50
                if (array_key_exists($type, $this->templateFiles)) {
1✔
51
                        return $this->templateFiles[$type];
1✔
52
                }
53

54
                return $this->fallback->resolve($type);
1✔
55
        }
56

57
        private function fileNotExists(string $file): never
1✔
58
        {
59
                throw new RuntimeException(sprintf(
1✔
60
                        'Template file %s for component %s does not exists.',
1✔
61
                        $file,
1✔
62
                        $this->metadata->name
1✔
63
                ));
64
        }
×
65
}
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

© 2025 Coveralls, Inc