From 3907b903addc4c95e37586bd6001ccbe23554a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Thu, 3 Jul 2025 20:09:13 +0200 Subject: [PATCH] code improvements --- src/RLS/PolicyManagers/TableRLSManager.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/RLS/PolicyManagers/TableRLSManager.php b/src/RLS/PolicyManagers/TableRLSManager.php index ccdee257..3f87bf3e 100644 --- a/src/RLS/PolicyManagers/TableRLSManager.php +++ b/src/RLS/PolicyManagers/TableRLSManager.php @@ -126,12 +126,11 @@ class TableRLSManager implements RLSPolicyManager */ public function shortestPaths(): array { - $cachedPaths = []; $shortestPaths = []; foreach ($this->getTableNames() as $tableName) { // Generate the shortest path from table named $tableName to the tenants table - $shortestPath = $this->shortestPathToTenantsTable($tableName, $cachedPaths); + $shortestPath = $this->shortestPathToTenantsTable($tableName); if ($this->isValidPath($shortestPath)) { // Format path steps to a more readable format (keep only the needed data) @@ -252,7 +251,7 @@ class TableRLSManager implements RLSPolicyManager */ protected function shortestPathToTenantsTable( string $table, - array &$cachedPaths, + array &$cachedPaths = [], array $visitedTables = [] ): array { // Return the shortest path for this table if it was already found and cached @@ -262,6 +261,9 @@ class TableRLSManager implements RLSPolicyManager // Reached tenants table (last step) if ($table === tenancy()->model()->getTable()) { + // This pretty much just means we set $cachedPaths['tenants'] to an + // empty path. The significance of an empty path is that this class + // considers it to mean "you are at the tenants table". $cachedPaths[$table] = $this->buildPath(); return $cachedPaths[$table];