Skip to content

Commit

Permalink
Remove unused UrlBuilder dependency in Database References
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Nov 15, 2024
1 parent c3b0209 commit 608887d
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 20 deletions.
4 changes: 1 addition & 3 deletions src/Firebase/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Kreait\Firebase\Database\Reference;
use Kreait\Firebase\Database\RuleSet;
use Kreait\Firebase\Database\Transaction;
use Kreait\Firebase\Database\UrlBuilder;
use Kreait\Firebase\Exception\InvalidArgumentException;
use Psr\Http\Message\UriInterface;

Expand All @@ -25,7 +24,6 @@ final class Database implements Contract\Database
public function __construct(
private readonly UriInterface $uri,
private readonly ApiClient $client,
private readonly UrlBuilder $urlBuilder,
) {
}

Expand All @@ -38,7 +36,7 @@ public function getReference(?string $path = null): Reference
$path = '/'.ltrim($path, '/');

try {
return new Reference($this->uri->withPath($path), $this->client, $this->urlBuilder);
return new Reference($this->uri->withPath($path), $this->client);
} catch (\InvalidArgumentException $e) {
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}
Expand Down
7 changes: 2 additions & 5 deletions src/Firebase/Database/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Reference implements Stringable
public function __construct(
UriInterface $uri,
private readonly ApiClient $apiClient,
private readonly UrlBuilder $urlBuilder,
private readonly Validator $validator = new Validator(),
) {
$this->validator->validateUri($uri);
Expand Down Expand Up @@ -93,7 +92,6 @@ public function getParent(): self
return new self(
$this->uri->withPath('/'.ltrim($parentPath, '/')),
$this->apiClient,
$this->urlBuilder,
$this->validator,
);
}
Expand All @@ -103,7 +101,7 @@ public function getParent(): self
*/
public function getRoot(): self
{
return new self($this->uri->withPath('/'), $this->apiClient, $this->urlBuilder, $this->validator);
return new self($this->uri->withPath('/'), $this->apiClient, $this->validator);
}

/**
Expand All @@ -122,7 +120,6 @@ public function getChild(string $path): self
return new self(
$this->uri->withPath($childPath),
$this->apiClient,
$this->urlBuilder,
$this->validator,
);
} catch (\InvalidArgumentException $e) {
Expand Down Expand Up @@ -326,7 +323,7 @@ public function push($value = null): self
$newKey = $this->apiClient->push($this->uri->getPath(), $value);
$newPath = sprintf('%s/%s', $this->uri->getPath(), $newKey);

return new self($this->uri->withPath($newPath), $this->apiClient, $this->urlBuilder, $this->validator);
return new self($this->uri->withPath($newPath), $this->apiClient, $this->validator);
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/Firebase/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ public function createDatabase(): Contract\Database
return new Database(
GuzzleUtils::uriFor($databaseUrl),
new Database\ApiClient($http, $resourceUrlBuilder),
$resourceUrlBuilder,
);
}

Expand Down
2 changes: 0 additions & 2 deletions tests/Unit/Database/ReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use GuzzleHttp\Psr7\Uri;
use Kreait\Firebase\Database\ApiClient;
use Kreait\Firebase\Database\Reference;
use Kreait\Firebase\Database\UrlBuilder;
use Kreait\Firebase\Exception\InvalidArgumentException;
use Kreait\Firebase\Exception\OutOfRangeException;
use Kreait\Firebase\Tests\UnitTestCase;
Expand All @@ -32,7 +31,6 @@ protected function setUp(): void
$this->reference = new Reference(
new Uri($url),
$this->apiClient,
UrlBuilder::create($url),
);
}

Expand Down
7 changes: 2 additions & 5 deletions tests/Unit/Database/UrlBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public static function invalidUrls(): Iterator
#[Test]
public function getGetUrl(string $baseUrl, string $path, array $queryParams, string $expected): void
{
$url = UrlBuilder::create($baseUrl)->getUrl($path, $queryParams);

$this->assertSame($expected, $url);
$this->assertSame($expected, UrlBuilder::create($baseUrl)->getUrl($path, $queryParams));
}

/**
Expand All @@ -64,9 +62,8 @@ public function getGetUrl(string $baseUrl, string $path, array $queryParams, str
public function emulated(string $emulatorHost, string $baseUrl, string $path, array $queryParams, string $expected): void
{
Util::putenv('FIREBASE_DATABASE_EMULATOR_HOST', $emulatorHost);
$url = UrlBuilder::create($baseUrl)->getUrl($path, $queryParams);

$this->assertSame($expected, $url);
$this->assertSame($expected, UrlBuilder::create($baseUrl)->getUrl($path, $queryParams));
}

public static function realUrls(): Iterator
Expand Down
5 changes: 1 addition & 4 deletions tests/Unit/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Kreait\Firebase\Database;
use Kreait\Firebase\Database\ApiClient;
use Kreait\Firebase\Database\RuleSet;
use Kreait\Firebase\Database\UrlBuilder;
use Kreait\Firebase\Exception\InvalidArgumentException;
use Kreait\Firebase\Tests\UnitTestCase;
use PHPUnit\Framework\Attributes\Test;
Expand All @@ -21,16 +20,14 @@ final class DatabaseTest extends UnitTestCase
{
private ApiClient&MockObject $apiClient;
private string $url;
private Uri $uri;
private Database $database;

protected function setUp(): void
{
$this->url = 'https://database.firebaseio.com';
$this->uri = new Uri($this->url);
$this->apiClient = $this->createMock(ApiClient::class);

$this->database = new Database($this->uri, $this->apiClient, UrlBuilder::create($this->url));
$this->database = new Database(new Uri($this->url), $this->apiClient);
}

#[Test]
Expand Down

0 comments on commit 608887d

Please sign in to comment.