| Total Complexity | 5 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | class InfluxDBHandler extends AbstractProcessingHandler |
||
| 17 | { |
||
| 18 | public const POINT_MEASUREMENT = 'table_sync'; |
||
| 19 | |||
| 20 | private $database; |
||
| 21 | private $measurement; |
||
| 22 | |||
| 23 | public function __construct( |
||
| 24 | Database $database, |
||
| 25 | ?string $measurement, |
||
| 26 | int $level = Logger::INFO, |
||
| 27 | bool $bubble = true |
||
| 28 | ) { |
||
| 29 | parent::__construct($level, $bubble); |
||
| 30 | |||
| 31 | $this->database = $database; |
||
| 32 | $this->measurement = $measurement ?? self::POINT_MEASUREMENT; |
||
| 33 | } |
||
| 34 | |||
| 35 | public function setFormatter(FormatterInterface $formatter): HandlerInterface |
||
| 36 | { |
||
| 37 | if ($formatter instanceof TableSyncFormatter) { |
||
| 38 | return parent::setFormatter($formatter); |
||
| 39 | } |
||
| 40 | |||
| 41 | throw new InvalidArgumentException('InfluxDBHandler is only compatible with TableSyncFormatter'); |
||
| 42 | } |
||
| 43 | |||
| 44 | protected function write(array $record): void |
||
| 45 | { |
||
| 46 | $this->database->writePoints($record['formatted']); |
||
| 47 | } |
||
| 48 | |||
| 49 | protected function getDefaultFormatter(): FormatterInterface |
||
| 52 | } |
||
| 53 | } |
||
| 54 |