Lines 100.00% 23 / 23
Methods 100.00% 7 / 7
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 getClassName 100.00% 1 / 1 100.00% 1 / 1 1
 getClassComment 100.00% 1 / 1 100.00% 1 / 1 1
 listDomains 100.00% 1 / 1 100.00% 1 / 1 1
 getDomainClassName 100.00% 1 / 1 100.00% 1 / 1 1
 buildPropertyComment 100.00% 1 / 1 100.00% 1 / 1 1
 [Stewart\Codegen\Emitter\RootEmitter] emitFile 100.00% 17 / 17 100.00% 1 / 1 2
 [Stewart\Codegen\Emitter\RootEmitter] listReservedMemberNames 100.00% 1 / 1 100.00% 1 / 1 2
11final readonly class ServicesRootEmitter extends RootEmitter
12{
13    protected function getClassName(): string
14    {
15        return 'Services';
16    }
17
18    protected function getClassComment(): string
19    {
20        return 'Every service Home Assistant offers, by domain.';
21    }
22
23    protected function listDomains(GenerationModel $model): DomainModelCollection
24    {
25        return $model->listServiceDomains();
26    }
27
28    protected function getDomainClassName(DomainModel $domain): string
29    {
30        return $domain->getServicesClass();
31    }
32
33    protected function buildPropertyComment(string $domain): string
34    {
35        return \sprintf('Services in the `%s` domain.', $domain);
36    }
37}

Inherited from Stewart\Codegen\Emitter\RootEmitter

19    public function emitFile(GenerationModel $model, EmitContext $context): GeneratedFile
20    {
21        $namespace = $context->createNamespace();
22        $context->importClass($namespace, HaContext::class, $this->getClassName());
23
24        $class = $namespace->addClass($this->getClassName())
25            ->setFinal()
26            ->addComment($this->getClassComment());
27
28        $class->addMethod('__construct')
29            ->addPromotedParameter('ha')
30            ->setType(HaContext::class)
31            ->setPrivate()
32            ->setReadOnly();
33
34        foreach ($this->listDomains($model) as $domain) {
35            $domainClass = $this->getDomainClassName($domain);
36
37            $class->addProperty($domain->accessor)
38                ->setType($context->resolveClassName($domainClass))
39                ->addComment($this->buildPropertyComment($domain->domain))
40                ->addHook('get', \sprintf('new %s($this->ha)', $domainClass));
41        }
42
43        return $context->printFile($namespace, $this->getClassName());
44    }
46    public function listReservedMemberNames(MemberScope $scope): array
47    {
48        return $scope === MemberScope::RootClasses ? self::RESERVED_MEMBER_NAMES : [];
49    }