Lines 0.00% 0 / 15
Functions and Methods 0.00% 0 / 2
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
GeneratedCodeDrift 0.00% 0 / 15 0.00% 0 / 2 30 0.00% 0 / 1
 __construct 0.00% 0 / 1 0.00% 0 / 1 2
 warnIfGeneratedCodeDrifted 0.00% 0 / 14 0.00% 0 / 1 20
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Broker;
6
7use Psr\Log\LoggerInterface;
8use Stewart\Support\Wire\GeneratedFormat;
9
10final readonly class GeneratedCodeDrift
11{
12    public function __construct(
13        private HaSession $session,
14        private LoggerInterface $logger,
15        private ?ManifestCheck $manifest = null,
16    ) {}
17
18    public function warnIfGeneratedCodeDrifted(): void
19    {
20        if ($this->manifest === null) {
21            return;
22        }
23
24        if (!$this->manifest->hasCurrentFormat()) {
25            $this->logger->warning('Generated classes were written by another stewart generate format; run stewart generate', [
26                'format' => $this->manifest->readFormatVersion(),
27                'expected_format' => GeneratedFormat::VERSION,
28            ]);
29        }
30
31        $drift = $this->manifest->findDrift($this->session->listEntityIds());
32
33        if ($drift === null) {
34            return;
35        }
36
37        $this->logger->warning('Generated entity classes no longer match Home Assistant; run stewart generate', [
38            'added' => $drift->added,
39            'removed' => $drift->removed,
40        ]);
41    }
42}