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

FastyBird / datetime-factory / #34

29 Aug 2024 03:20PM UTC coverage: 79.31%. Remained the same
#34

push

github

web-flow
Merge pull request #5 from FastyBird/hotfix/service-naming

Fixing services names

1 of 2 new or added lines in 1 file covered. (50.0%)

23 of 29 relevant lines covered (79.31%)

0.79 hits per line

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

76.0
/src/DI/DateTimeFactoryExtension.php
1
<?php declare(strict_types = 1);
2

3
/**
4
 * DateTimeFactoryExtension.php
5
 *
6
 * @license        More in LICENSE.md
7
 * @copyright      https://www.fastybird.com
8
 * @author         Adam Kadlec <adam.kadlec@fastybird.com>
9
 * @package        FastyBird:DateTimeFactory!
10
 * @subpackage     DI
11
 * @since          0.1.0
12
 *
13
 * @date           08.03.20
14
 */
15

16
namespace FastyBird\DateTimeFactory\DI;
17

18
use DateTimeZone;
19
use FastyBird\DateTimeFactory;
20
use FastyBird\DateTimeFactory\Exceptions;
21
use Nette;
22
use Nette\DI;
23
use Nette\Schema;
24
use stdClass;
25
use function assert;
26
use function in_array;
27

28
/**
29
 * Date&Time factory extension container
30
 *
31
 * @package        FastyBird:DateTimeFactory!
32
 * @subpackage     DI
33
 *
34
 * @author         Adam Kadlec <adam.kadlec@fastybird.com>
35
 */
36
class DateTimeFactoryExtension extends DI\CompilerExtension
37
{
38

39
        public static function register(
40
                Nette\Bootstrap\Configurator $config,
41
                string $extensionName = 'dateTimeFactory',
42
        ): void
43
        {
44
                $config->onCompile[] = static function (
1✔
45
                        Nette\Bootstrap\Configurator $config,
46
                        DI\Compiler $compiler,
47
                ) use ($extensionName): void {
1✔
48
                        $compiler->addExtension($extensionName, new self());
1✔
49
                };
1✔
50
        }
1✔
51

52
        public function getConfigSchema(): Schema\Schema
53
        {
54
                return Schema\Expect::structure([
1✔
55
                        'timeZone' => Schema\Expect::string('UTC'),
1✔
56
                        'system' => Schema\Expect::bool(true),
1✔
57
                        'frozen' => Schema\Expect::anyOf(Schema\Expect::float(), Schema\Expect::mixed()),
1✔
58
                ]);
59
        }
60

61
        public function loadConfiguration(): void
62
        {
63
                $builder = $this->getContainerBuilder();
1✔
64
                $configuration = $this->getConfig();
1✔
65
                assert($configuration instanceof stdClass);
66

67
                if (
68
                        !in_array($configuration->timeZone, DateTimeZone::listIdentifiers(), true)
1✔
69
                ) {
70
                        throw new Exceptions\InvalidArgument('Timezone have to be valid PHP timezone string');
×
71
                }
72

73
                if ($configuration->system) {
1✔
74
                        $builder->addDefinition($this->prefix('datetime.system'), new DI\Definitions\ServiceDefinition())
1✔
75
                                ->setType(DateTimeFactory\SystemClock::class)
1✔
76
                                ->setArgument('timeZone', new DateTimeZone($configuration->timeZone))
1✔
77
                                ->setAutowired($configuration->frozen === null);
1✔
78
                }
79

80
                if ($configuration->frozen !== null) {
1✔
NEW
81
                        $builder->addDefinition($this->prefix('datetime.frozen'), new DI\Definitions\ServiceDefinition())
×
82
                                ->setType(DateTimeFactory\FrozenClock::class)
×
83
                                ->setArguments([
×
84
                                        'timestamp' => $configuration->frozen,
×
85
                                        'timeZone' => new DateTimeZone($configuration->timeZone),
×
86
                                ]);
87
                }
88
        }
1✔
89

90
}
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