Skip to content

Commit cdea198

Browse files
committed
refactor: move setNamespace/setTenant/setSharedTables out of abstract Adapter
These were declared abstract on the base, forcing every implementation to provide them even when the underlying backend has no multi-tenant or namespace concept. No caller types against the abstract Adapter to invoke them — every consumer goes through the Usage facade. - Drop the three abstract method declarations from Adapter. - Both ClickHouse and Database adapters keep their concrete impls (the methods are still needed for current usage). - Facade now forwards via method_exists, so a future minimal adapter (no multi-tenancy, no namespacing) can extend Adapter without implementing dead stubs.
1 parent 68a4b6f commit cdea198

2 files changed

Lines changed: 9 additions & 27 deletions

File tree

src/Usage/Adapter.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -158,28 +158,4 @@ abstract public function sumDaily(array $queries = [], string $attribute = 'valu
158158
* @return array<string, int> Metric name => sum value
159159
*/
160160
abstract public function sumDailyBatch(array $metrics, array $queries = []): array;
161-
162-
/**
163-
* Set the namespace prefix for table names.
164-
*
165-
* @param string $namespace
166-
* @return self
167-
*/
168-
abstract public function setNamespace(string $namespace): self;
169-
170-
/**
171-
* Set the tenant ID for multi-tenant support.
172-
*
173-
* @param string|null $tenant
174-
* @return self
175-
*/
176-
abstract public function setTenant(?string $tenant): self;
177-
178-
/**
179-
* Enable or disable shared tables mode (multi-tenant with tenant column).
180-
*
181-
* @param bool $sharedTables
182-
* @return self
183-
*/
184-
abstract public function setSharedTables(bool $sharedTables): self;
185161
}

src/Usage/Usage.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ public function sumDailyBatch(array $metrics, array $queries = []): array
276276
public function setNamespace(string $namespace): self
277277
{
278278
$this->flush();
279-
$this->adapter->setNamespace($namespace);
279+
if (method_exists($this->adapter, 'setNamespace')) {
280+
$this->adapter->setNamespace($namespace);
281+
}
280282
return $this;
281283
}
282284

@@ -293,7 +295,9 @@ public function setNamespace(string $namespace): self
293295
public function setTenant(?string $tenant): self
294296
{
295297
$this->flush();
296-
$this->adapter->setTenant($tenant);
298+
if (method_exists($this->adapter, 'setTenant')) {
299+
$this->adapter->setTenant($tenant);
300+
}
297301
return $this;
298302
}
299303

@@ -310,7 +314,9 @@ public function setTenant(?string $tenant): self
310314
public function setSharedTables(bool $sharedTables): self
311315
{
312316
$this->flush();
313-
$this->adapter->setSharedTables($sharedTables);
317+
if (method_exists($this->adapter, 'setSharedTables')) {
318+
$this->adapter->setSharedTables($sharedTables);
319+
}
314320
return $this;
315321
}
316322

0 commit comments

Comments
 (0)